:root {
  --max-width: 40rem;
  --text: #2a2a2a;
  --text-muted: #6a6a6a;
  --bg: #fefefe;
  --link: #1a4d8c;
  --link-hover: #0d3666;
  --border: #e0e0e0;
  --code-bg: #f3f3f3;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #e8e8e8;
    --text-muted: #a0a0a0;
    --bg: #1a1a1a;
    --link: #7eb8f5;
    --link-hover: #b3d4f9;
    --border: #3a3a3a;
    --code-bg: #2a2a2a;
  }
}

/* High-contrast preference, light mode */
@media (prefers-contrast: more) {
  :root {
    --text: #000;
    --text-muted: #333;
    --bg: #fff;
    --link: #00308f;
    --link-hover: #001f5c;
    --border: #555;
    --code-bg: #ececec;
  }
}

/* High-contrast preference, dark mode */
@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root {
    --text: #fff;
    --text-muted: #d8d8d8;
    --bg: #000;
    --link: #a8d4ff;
    --link-hover: #d6e9ff;
    --border: #999;
    --code-bg: #1f1f1f;
  }
}

* { box-sizing: border-box; }

html {
  font-size: 17px;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", "PingFang TC", "Hiragino Sans", "Noto Sans TC", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

html[lang="zh-TW"] body {
  line-height: 1.85;
}

/* Skip link, hidden until focused */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--link);
  color: #fff;
  padding: 0.75rem 1rem;
  text-decoration: none;
  font-weight: 600;
  z-index: 100;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
}

/* Focus styles */
:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 3px;
  border-radius: 2px;
}

/* Layout */
.site-header,
.site-footer,
main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}

main {
  padding-top: 2.5rem;
  padding-bottom: 4rem;
}

/* Skip-link target: no visible ring when reached programmatically,
   but preserve keyboard focus visibility if user navigates here via Tab */
main:focus:not(:focus-visible) { outline: none; }

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--border);
  padding-top: 1.5rem;
  padding-bottom: 1rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.site-title {
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  color: var(--text);
}

.site-title:hover { color: var(--link); }

.site-header nav a {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-decoration: none;
  display: inline-block;
  min-height: 2.75rem;       /* ≥44px tap target */
  min-width: 2.75rem;
  padding: 0.6rem 0.4rem;
  text-align: center;
}

.site-header nav a:hover {
  color: var(--link);
  text-decoration: underline;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding-top: 2rem;
  padding-bottom: 2rem;
  margin-top: 3rem;
  font-size: 0.9rem;
}

.site-footer p { margin: 0.5rem 0; }

.site-footer .quiet {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 1rem;
}

.site-footer .meta {
  color: var(--text-muted);
}

/* Links */
a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

a:hover {
  color: var(--link-hover);
  text-decoration-thickness: 2px;
}

/* Typography */
h1, h2, h3 {
  line-height: 1.25;
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  font-weight: 700;
}

h1 {
  font-size: 1.875rem;
  margin-top: 0;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.35rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

h3 { font-size: 1.1rem; }

p, li {
  margin-bottom: 1rem;
}

ul, ol { padding-left: 1.5rem; }

/* Post layout */
.post-header {
  margin-bottom: 2.5rem;
}

.post-meta {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

.post-meta time { font-variant-numeric: tabular-nums; }

article hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

article blockquote {
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  color: var(--text-muted);
  font-style: italic;
  margin: 1.5rem 0;
}

article code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

article a {
  word-wrap: break-word;
}

/* Header anchor links from markdown-it-anchor */
article h2 a,
article h3 a {
  color: inherit;
  text-decoration: none;
}

article h2 a:hover,
article h3 a:hover {
  color: var(--link);
  text-decoration: underline;
}

/* Home / list page */
.home-header {
  margin-bottom: 3rem;
}

.home-header .tagline {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin-top: 0.5rem;
}

.post-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.post-list li {
  margin-bottom: 0.85rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.post-list li:last-child { border-bottom: none; }

.post-list a {
  display: flex;
  gap: 1rem;
  text-decoration: none;
  align-items: baseline;
  color: var(--text);
}

.post-list a:hover .post-title {
  color: var(--link);
  text-decoration: underline;
}

.post-num {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 0.85rem;
  min-width: 2.5ch;
  text-align: right;
  flex-shrink: 0;
}

.post-title {
  color: var(--text);
  font-weight: 500;
}
