:root {
  /* 响应式间距与视口高度（随屏幕宽高自适应） */
  --gutter: 1.5rem;
  --top-gap: 6rem;
  --bottom-gap: 1.5rem;
  --viewport-height: 100vh;

  /* Typography */
  --sans:
    'Inter',
    -apple-system,
    BlinkMacSystemFont,
    'PingFang SC',
    'HarmonyOS Sans SC',
    'MiSans',
    'Hiragino Sans GB',
    'Noto Sans SC',
    'Source Han Sans SC',
    'Microsoft YaHei',
    sans-serif;
  --serif: Besley, Baskerville, Georgia, 'Times New Roman', Times, serif;
  --mono:
    'JetBrains Mono',
    'SF Mono',
    SFMono-Regular,
    ui-monospace,
    Menlo,
    Consolas,
    'Liberation Mono',
    'PingFang SC',
    monospace;

  --font-size-s: 0.8125rem;
  --font-size-m: 0.9375rem;
  --font-size-l: 1.0625rem;

  --font-weight-light: 350;
  --font-weight-regular: 400;
  --font-weight-bold: 500;

  --spacing-s: -0.08em;
  --spacing-m: -0.02em;

  /* Light Mode Colors (Default) */
  --bg: #FAF7F2;
  --text-primary: rgba(0, 0, 0, 0.85);
  --text-secondary: rgba(0, 0, 0, 0.4);
  --text-tertiary: rgba(0, 0, 0, 0.24);
  --border: rgba(80, 60, 40, 0.12);
  --selection: rgba(0, 0, 0, 0.08);
  --code-bg: rgba(0, 0, 0, 0.04);
  --mark: #f3ffc4;

  /* Syntax Theme  */
  --astro-code-foreground: rgba(0, 0, 0, 0.85);
  --astro-code-background: rgba(0, 0, 0, 0.03);
  --astro-code-token-constant: rgba(0, 0, 0, 0.85);
  --astro-code-token-string: rgba(0, 0, 0, 0.85);
  --astro-code-token-comment: rgba(0, 0, 0, 0.35);
  --astro-code-token-keyword: rgba(0, 0, 0, 0.55);
  --astro-code-token-parameter: rgba(0, 0, 0, 0.85);
  --astro-code-token-function: rgba(0, 0, 0, 0.85);
  --astro-code-token-string-expression: rgba(0, 0, 0, 0.55);
  --astro-code-token-punctuation: rgba(0, 0, 0, 0.55);
  --astro-code-token-link: rgba(0, 0, 0, 0.55);
}

/* Light Mode (Explicit) */
html.light {
  --bg: #FAF7F2;
  --text-primary: rgba(0, 0, 0, 0.85);
  --text-secondary: rgba(0, 0, 0, 0.4);
  --text-tertiary: rgba(0, 0, 0, 0.24);
  --border: rgba(80, 60, 40, 0.12);
  --selection: rgba(0, 0, 0, 0.08);
  --code-bg: rgba(0, 0, 0, 0.04);
  --mark: #f3ffc4;

  /* Syntax Theme  */
  --astro-code-foreground: rgba(0, 0, 0, 0.85);
  --astro-code-background: rgba(0, 0, 0, 0.03);
  --astro-code-token-constant: rgba(0, 0, 0, 0.85);
  --astro-code-token-string: rgba(0, 0, 0, 0.85);
  --astro-code-token-comment: rgba(0, 0, 0, 0.35);
  --astro-code-token-keyword: rgba(0, 0, 0, 0.5);
  --astro-code-token-parameter: rgba(0, 0, 0, 0.85);
  --astro-code-token-function: rgba(0, 0, 0, 0.85);
  --astro-code-token-string-expression: rgba(0, 0, 0, 0.55);
  --astro-code-token-punctuation: rgba(0, 0, 0, 0.55);
  --astro-code-token-link: rgba(0, 0, 0, 0.55);
}

/* Dark Mode (Explicit) */
html.dark {
  --bg: #1c1c1c;
  --text-primary: rgba(255, 255, 255, 0.9);
  --text-secondary: rgba(255, 255, 255, 0.4);
  --text-tertiary: rgba(255, 255, 255, 0.24);
  --border: rgba(255, 255, 255, 0.1);
  --selection: rgba(255, 255, 255, 0.08);
  --code-bg: rgba(255, 255, 255, 0.04);
  --mark: #545b37;

  /* Syntax Theme  */
  --astro-code-foreground: rgba(255, 255, 255, 0.9);
  --astro-code-background: rgba(255, 255, 255, 0.03);
  --astro-code-token-constant: rgba(255, 255, 255, 0.9);
  --astro-code-token-string: rgba(255, 255, 255, 0.9);
  --astro-code-token-comment: rgba(255, 255, 255, 0.35);
  --astro-code-token-keyword: rgba(255, 255, 255, 0.55);
  --astro-code-token-parameter: rgba(255, 255, 255, 0.9);
  --astro-code-token-function: rgba(255, 255, 255, 0.9);
  --astro-code-token-string-expression: rgba(255, 255, 255, 0.55);
  --astro-code-token-punctuation: rgba(255, 255, 255, 0.55);
  --astro-code-token-link: rgba(255, 255, 255, 0.55);
}

@supports (height: 100dvh) {
  :root {
    --viewport-height: 100dvh;
  }
}

/* 高度自适应：矮屏压缩上下留白，高屏放宽 */
@media (max-height: 820px) {
  :root {
    --top-gap: 4.5rem;
  }
}

@media (max-height: 720px) {
  :root {
    --top-gap: 3.5rem;
    --bottom-gap: 1.15rem;
  }
}

@media (max-height: 620px) {
  :root {
    --top-gap: 2.5rem;
    --bottom-gap: 0.9rem;
  }
}

@media (min-height: 1061px) {
  :root {
    --top-gap: 6.5rem;
    --bottom-gap: 2rem;
  }
}

/* 宽度自适应：窄屏收窄左右边距，宽屏略微放宽 */
@media (max-width: 520px) {
  :root {
    --gutter: 1.25rem;
  }
}

@media (max-width: 380px) {
  :root {
    --gutter: 1rem;
  }
}

@media (min-width: 1400px) {
  :root {
    --gutter: 1.75rem;
  }
}

html {
  background-color: var(--bg);
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s ease-out;
}

body {
  font-family: var(--sans);
  font-feature-settings: 'ss03' 1;
  font-size: var(--font-size-m);
  line-height: 1.75;
  color: var(--text-primary);
  min-height: var(--viewport-height);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  letter-spacing: normal;
  margin: 0 auto;
  width: 100%;
  overscroll-behavior-y: contain;
  text-autospace: normal;
  text-spacing-trim: space-first;
  line-break: strict;
  word-break: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-synthesis: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

body[data-centered='true'] {
  padding: var(--top-gap)
    max(var(--gutter), env(safe-area-inset-right))
    calc(var(--bottom-gap) + env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
}

body[data-centered='false'] {
  padding: var(--top-gap) 0 calc(var(--bottom-gap) + env(safe-area-inset-bottom));
  margin: 0 var(--gutter) 0 8rem;
}

@media (max-width: 768px) {
  body[data-centered='true'],
  body[data-centered='false'] {
    padding: var(--top-gap)
      max(var(--gutter), env(safe-area-inset-right))
      calc(var(--bottom-gap) + env(safe-area-inset-bottom))
      max(var(--gutter), env(safe-area-inset-left));
    margin: 0 auto;
  }
}

/* 媒体元素不撑破容器 */
img,
video,
iframe {
  max-width: 100%;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

::selection {
  background-color: var(--selection);
}

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 1.5px dashed var(--text-tertiary);
  border-radius: 0.25rem;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.date {
  margin: 0;
  font-weight: var(--font-weight-light);
  color: var(--text-secondary);
  opacity: 0.75;
  flex-shrink: 0;
  letter-spacing: var(--spacing-s);
  font-variant-numeric: tabular-nums;
  font-feature-settings:
    'tnum' 1,
    'zero' 0,
    'cv01' 1,
    'cv02' 1,
    'calt' 1,
    'ss03' 1,
    'ordn' 1;
}

.date .month {
  letter-spacing: var(--spacing-m);
}

.sr-only {
  border: 0;
  padding: 0;
  margin: 0;
  position: absolute !important;
  height: 1px;
  width: 1px;
  overflow: hidden;
  clip: rect(1px 1px 1px 1px);
  clip: rect(1px, 1px, 1px, 1px);
  clip-path: inset(50%);
  white-space: nowrap;
}
