:root {
  color-scheme: light dark;
  --bg: #f8f4ec;
  --surface: #fffdfa;
  --surface-2: #f0eadf;
  --text: #171514;
  --muted: #665f57;
  --border: #d7ccbd;
  --accent: #2f6f68;
  --accent-strong: #194f4a;
  --gold: #d99a27;
  --rose: #b94b4b;
  --focus: #0b7285;
  --pixel-shadow: 6px 6px 0 #241f1a;
  --pixel-shadow-soft: 4px 4px 0 rgb(36 31 26 / 18%);
  --radius: 0;
  --content: 72ch;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151413;
    --surface: #1f1d1b;
    --surface-2: #292622;
    --text: #f5efe5;
    --muted: #cbbfaf;
    --border: #4a4038;
    --accent: #70bcb2;
    --accent-strong: #9ee0d8;
    --gold: #e0ad4b;
    --rose: #ee8984;
    --focus: #8bd7e7;
    --pixel-shadow: 6px 6px 0 #000;
    --pixel-shadow-soft: 4px 4px 0 rgb(0 0 0 / 42%);
  }
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgb(36 31 26 / 5%) 1px, transparent 1px),
    linear-gradient(rgb(36 31 26 / 5%) 1px, transparent 1px),
    var(--bg);
  background-size: 18px 18px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  font-size: 18px;
  line-height: 1.7;
  min-height: 100vh;
  text-rendering: optimizeLegibility;
}

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

a {
  color: var(--accent-strong);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--rose);
}

a:focus-visible,
button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

img {
  height: auto;
  max-width: 100%;
}

.pixel-art,
.hero-mascot,
.article-end img,
.language-choice img,
.not-found-panel img {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.skip-link {
  background: var(--text);
  border: 3px solid var(--gold);
  color: var(--bg);
  left: 1rem;
  padding: 0.6rem 0.8rem;
  position: fixed;
  top: 1rem;
  transform: translateY(-160%);
  z-index: 20;
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  align-items: center;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 3px solid var(--text);
  display: grid;
  gap: 0.8rem 1rem;
  grid-template-columns: auto 1fr auto;
  margin: 0 auto;
  max-width: none;
  padding: 1rem clamp(1rem, 4vw, 2rem);
}

.brand {
  align-items: center;
  color: var(--text);
  display: inline-flex;
  font-weight: 800;
  gap: 0.55rem;
  letter-spacing: 0.02em;
  text-decoration: none;
}

.brand-mark {
  align-items: center;
  background: var(--text);
  border: 3px solid var(--text);
  box-shadow: 3px 3px 0 var(--gold);
  color: var(--bg);
  display: inline-flex;
  font-size: 0.82rem;
  height: 2.3rem;
  justify-content: center;
  width: 2.3rem;
}

.site-nav,
.language-nav {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.site-nav {
  justify-content: center;
}

.language-nav {
  justify-content: flex-end;
}

.site-nav a,
.language-nav a {
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.95rem;
  padding: 0.35rem 0.55rem;
  text-decoration: none;
}

.site-nav a:hover,
.language-nav a:hover,
.site-nav a[aria-current="page"],
.language-nav a[aria-current="page"] {
  background: var(--surface-2);
  border-color: var(--text);
  color: var(--text);
}

.page-main {
  flex: 1 0 auto;
  margin: 0 auto;
  max-width: 1180px;
  padding: clamp(1.2rem, 4vw, 2.5rem) clamp(1rem, 4vw, 2rem) 4rem;
  width: 100%;
}

.home-hero,
.language-choice,
.not-found-panel {
  align-items: center;
  background: var(--surface);
  border: 3px solid var(--text);
  box-shadow: var(--pixel-shadow);
  display: grid;
  gap: clamp(1.2rem, 5vw, 3rem);
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 30vh;
  padding: clamp(1rem, 4vw, 2rem);
}

.language-choice,
.not-found-panel {
  grid-template-columns: auto minmax(0, 1fr);
}

.hero-mascot {
  max-height: 300px;
  object-fit: contain;
}

h1,
h2,
h3 {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  letter-spacing: 0;
  line-height: 1.22;
  margin: 0 0 0.8rem;
}

h1 {
  font-size: 4.4rem;
}

.article-header h1,
.page-heading h1 {
  font-size: 3.4rem;
}

h2 {
  font-size: 2rem;
}

h3 {
  font-size: 1.2rem;
}

.lead {
  color: var(--muted);
  font-size: 1.24rem;
  margin: 0 0 1.2rem;
  max-width: 58ch;
}

.hero-links,
.language-choice-links {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.button-link {
  align-items: center;
  background: var(--accent-strong);
  border: 3px solid var(--text);
  border-radius: var(--radius);
  box-shadow: 4px 4px 0 var(--text);
  color: var(--surface);
  display: inline-flex;
  font-weight: 750;
  min-height: 2.7rem;
  padding: 0.45rem 0.85rem;
  text-decoration: none;
}

.button-link:hover {
  background: var(--rose);
  border-color: var(--rose);
  color: white;
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 var(--text);
}

.button-link-secondary {
  background: transparent;
  color: var(--accent-strong);
}

.button-link-secondary:hover {
  color: white;
}

.home-section,
.home-meta-grid,
.list-main,
.article-main {
  margin-top: clamp(2rem, 6vw, 4rem);
}

.section-heading {
  align-items: baseline;
  border-bottom: 3px solid var(--text);
  border-top: 0;
  display: flex;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.55rem;
  padding-top: 0;
}

.post-list {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, var(--content));
}

.post-card {
  background: var(--surface);
  border: 3px solid var(--text);
  border-radius: var(--radius);
  box-shadow: var(--pixel-shadow-soft);
  padding: 1rem;
}

.post-card h3 a {
  color: var(--text);
  text-decoration: none;
}

.post-card-meta,
.article-meta {
  color: var(--muted);
  font-size: 0.95rem;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.tag-row a {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.86rem;
  padding: 0.18rem 0.5rem;
  text-decoration: none;
}

.tag-row a:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.home-meta-grid {
  border-top: 2px solid var(--border);
  display: grid;
  gap: 2rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding-top: 1.4rem;
}

.term-grid {
  display: grid;
  gap: 0.65rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  list-style: none;
  margin: 0;
  padding: 0;
}

.term-grid a {
  align-items: center;
  background: var(--surface);
  border: 3px solid var(--text);
  border-radius: var(--radius);
  color: var(--text);
  display: flex;
  justify-content: space-between;
  padding: 0.7rem 0.8rem;
  text-decoration: none;
}

.term-grid strong {
  color: var(--gold);
}

.simple-list,
.archive-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.simple-list li,
.archive-list li {
  align-items: baseline;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  padding: 0.55rem 0;
}

.simple-list span,
.archive-list time {
  color: var(--muted);
  font-size: 0.92rem;
  white-space: nowrap;
}

.article-shell,
.page-heading {
  max-width: var(--content);
}

.article-languages {
  align-items: center;
  background: var(--surface);
  border: 3px solid var(--text);
  box-shadow: 4px 4px 0 var(--gold);
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 1.2rem 0;
  padding: 0.7rem 0.8rem;
}

.article-languages a[aria-current="page"] {
  color: var(--text);
  font-weight: 800;
}

.prose {
  margin-top: 2rem;
  max-width: var(--content);
}

.prose > * + * {
  margin-top: 1rem;
}

.prose h2,
.prose h3 {
  margin-top: 2.1rem;
}

.prose p,
.prose li {
  overflow-wrap: anywhere;
}

.prose blockquote {
  border-left: 4px solid var(--accent);
  color: var(--muted);
  margin-left: 0;
  padding-left: 1rem;
}

.prose pre {
  background: #111;
  border: 3px solid var(--text);
  border-radius: var(--radius);
  color: #f6f0e8;
  overflow-x: auto;
  padding: 1rem;
}

.prose code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.prose :not(pre) > code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--rose);
  padding: 0.1rem 0.25rem;
}

.table-wrap {
  overflow-x: auto;
}

.prose table {
  border-collapse: collapse;
  min-width: 36rem;
  width: 100%;
}

.prose th,
.prose td {
  border: 2px solid var(--border);
  padding: 0.5rem 0.65rem;
  text-align: left;
}

.prose img {
  border-radius: var(--radius);
  image-rendering: pixelated;
}

.article-footer {
  border-top: 2px solid var(--border);
  margin-top: 2.5rem;
  padding-top: 1.2rem;
}

.article-end {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  gap: 0.65rem;
}

.article-end img {
  width: 72px;
}

.post-neighbors {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 1.2rem 0;
}

.post-neighbors a {
  border: 3px solid var(--text);
  border-radius: var(--radius);
  box-shadow: var(--pixel-shadow-soft);
  color: var(--text);
  padding: 0.8rem;
  text-decoration: none;
}

.post-neighbors span {
  color: var(--muted);
  display: block;
  font-size: 0.85rem;
}

.archive-list section {
  border-top: 1px solid var(--border);
  padding: 1.2rem 0;
}

.not-found-panel[data-i18n-panel="en"] {
  display: none;
}

html[data-preferred-locale="en"] .not-found-panel[data-i18n-panel="zh-CN"] {
  display: none;
}

html[data-preferred-locale="en"] .not-found-panel[data-i18n-panel="en"] {
  display: grid;
}

.site-footer {
  align-items: center;
  border-top: 3px solid var(--text);
  color: var(--muted);
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  font-size: 0.92rem;
  gap: 1rem;
  justify-content: space-between;
  margin: 0 auto;
  max-width: 1180px;
  padding: 1.2rem clamp(1rem, 4vw, 2rem) 2rem;
}

.site-footer p {
  margin: 0;
}

.empty {
  color: var(--muted);
}

@media (max-width: 820px) {
  .site-header {
    grid-template-columns: 1fr;
  }

  .site-nav,
  .language-nav {
    justify-content: flex-start;
  }

  .home-hero,
  .language-choice,
  .not-found-panel {
    grid-template-columns: 1fr;
  }

  .language-choice img,
  .not-found-panel img,
  .hero-mascot {
    justify-self: start;
    max-width: 220px;
  }

  .home-meta-grid,
  .post-neighbors {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 3.1rem;
  }

  .article-header h1,
  .page-heading h1 {
    font-size: 2.55rem;
  }

  h2 {
    font-size: 1.65rem;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 17px;
  }

  .simple-list li,
  .archive-list li {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.1rem;
  }

  h1 {
    font-size: 2.45rem;
  }

  .article-header h1,
  .page-heading h1 {
    font-size: 2.1rem;
  }

  .lead {
    font-size: 1.08rem;
  }
}
