@font-face {
  font-family: "Archivo";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/archivo-var-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Archivo";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/archivo-var-latinext.woff2") format("woff2");
}
@font-face {
  font-family: "Mandarin SC";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/songti-sc-regular-186.woff2?v=6") format("woff2");
}
@font-face {
  font-family: "Mandarin SC";
  font-style: normal;
  font-weight: 900;
  font-display: swap;
  src: url("/fonts/songti-sc-black-186.woff2?v=6") format("woff2");
}

:root {
  color-scheme: light dark;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-muted: #ececea;
  --ink: #171717;
  --ink-soft: #514f4b;
  --ink-faint: #69655f;
  --accent: #b83425;
  --accent-strong: #932719;
  --accent-ink: #ffffff;
  --success: #2f6d3d;
  --warning: #765600;
  --danger: #a2291d;
  --line: #d8d6d1;
  --focus: #0969da;
  --radius: 14px;
  --radius-small: 10px;
  --tap: 44px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --z-sticky: 10;
  --z-modal: 30;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151515;
    --surface: #202020;
    --surface-muted: #2d2d2b;
    --ink: #f5f4f0;
    --ink-soft: #cbc7c0;
    --ink-faint: #b0aaa1;
    --accent: #e65f4d;
    --accent-strong: #f07867;
    --accent-ink: #1c0805;
    --success: #88c796;
    --warning: #e7c45e;
    --danger: #ff8b7d;
    --line: #44413d;
    --focus: #68a8ff;
  }
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Archivo", sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button, input { font: inherit; }
button { color: inherit; }
a { color: var(--accent-strong); }

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

.skip-link {
  position: fixed;
  inset-block-start: 8px;
  inset-inline-start: 8px;
  z-index: var(--z-modal);
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

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

.app {
  width: min(100%, 480px);
  min-height: 100vh;
  min-height: 100dvh;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-inline: 1px solid var(--line);
}

.topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  background: var(--bg);
  border-block-end: 1px solid var(--line);
}
.brand {
  color: var(--ink);
  font-weight: 900;
  letter-spacing: -0.025em;
  text-decoration: none;
}
.brand span { color: var(--accent-strong); }
.streak {
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.streak strong { color: var(--accent-strong); }

.main {
  flex: 1;
  padding: 24px 20px calc(88px + env(safe-area-inset-bottom));
}
.status {
  min-height: 1.5em;
  margin: 0 0 4px;
  color: var(--ink-soft);
  font-size: 0.9rem;
  text-align: center;
}
.status:empty { min-height: 0; }
.status.is-error { color: var(--danger); }
.view[hidden], [hidden] { display: none !important; }

.view-home { text-align: center; }
.home-glyph, .end-glyph, .hanzi {
  font-family: "Mandarin SC", serif;
}
.home-glyph {
  margin-block: 8px 0;
  color: var(--accent);
  font-size: 7.5rem;
  font-weight: 900;
  line-height: 1;
}
.view-home h1 {
  margin: 8px 0 0;
  font-size: 1.75rem;
  line-height: 1.1;
  letter-spacing: -0.03em;
  text-wrap: balance;
}
.home-lede {
  max-width: 32ch;
  margin: 12px auto 0;
  color: var(--ink-soft);
  text-wrap: pretty;
}
.progress-block {
  margin: 30px 0 20px;
  text-align: start;
}
.progress-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-block-end: 8px;
  color: var(--ink-soft);
  font-size: 0.9rem;
}
.progress-line strong { color: var(--ink); font-variant-numeric: tabular-nums; }
progress {
  width: 100%;
  height: 12px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-muted);
}
progress::-webkit-progress-bar { background: var(--surface-muted); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }

.btn {
  min-height: var(--tap);
  padding: 12px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 750;
  transition: transform 160ms var(--ease), background-color 160ms ease;
}
.btn:hover:not(:disabled) { background: var(--surface-muted); }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { cursor: not-allowed; opacity: 0.55; }
.btn-primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-large {
  width: 100%;
  min-height: 62px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.btn-main { font-size: 1.05rem; }
.btn-sub { font-size: 0.84rem; font-weight: 500; }
.text-button {
  min-height: var(--tap);
  padding: 8px 2px;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  cursor: pointer;
  font-weight: 700;
}

.next-words {
  margin-block-start: 36px;
  text-align: start;
}
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-block-end: 2px solid var(--ink);
}
.section-heading h2 {
  margin: 0;
  font-size: 1.05rem;
}
.word-mini, .word-list { list-style: none; margin: 0; padding: 0; }
.word-mini li {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding-block: 9px;
  border-block-end: 1px solid var(--line);
}
.wz-hanzi { min-width: 40px; font-family: "Mandarin SC", serif; font-size: 1.55rem; }
.wz-meta { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.wz-pinyin { color: var(--accent-strong); font-weight: 750; }
.wz-de { min-width: 0; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wz-rank { color: var(--ink-faint); font-size: 0.8rem; }
.empty-row { color: var(--ink-soft); }

.session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-block-end: 20px;
}
.session-counter { color: var(--ink-soft); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.study-card {
  width: 100%;
  min-height: 360px;
  padding: 28px;
  border: 0;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  box-shadow: 0 6px 8px rgb(0 0 0 / 0.14);
  transition: transform 180ms var(--ease), background-color 180ms ease;
}
.study-card[aria-expanded="true"] {
  background: var(--surface);
  color: var(--ink);
}
.study-card:active { transform: scale(0.99); }
.card-front, .card-back {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}
.hanzi { font-size: 8rem; font-weight: 900; line-height: 1; }
.pinyin { color: var(--accent-strong); font-size: 2.25rem; font-weight: 800; }
.meaning { max-width: 28ch; font-size: 1.25rem; text-align: center; overflow-wrap: anywhere; }
.rank { color: var(--ink-soft); font-size: 0.9rem; }
.card-tools {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.audio-btn {
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 2px;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  cursor: pointer;
  font-weight: 750;
}
.card-hint { margin: 0; color: var(--ink-soft); font-size: 0.9rem; }
.rate-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.rate-again { color: var(--danger); border-color: currentColor; }
.rate-good { color: var(--success); border-color: currentColor; }
.rate-easy { color: var(--warning); border-color: currentColor; }

.view-sessionend { padding-block-start: 42px; text-align: center; }
.end-glyph { color: var(--accent); font-size: 6rem; font-weight: 900; line-height: 1; }
.view-sessionend h1 { margin: 12px 0 0; font-size: 2rem; letter-spacing: -0.03em; }
.sessionend-stats { margin: 14px 0 0; color: var(--ink-soft); }
.sessionend-cheer { margin: 6px 0 30px; }

.list-heading h1, #settingsTitle { margin: 0; font-size: 1.75rem; letter-spacing: -0.03em; }
.list-heading p { margin: 4px 0 20px; color: var(--ink-soft); }
.list-toolbar {
  position: sticky;
  inset-block-start: 58px;
  z-index: 2;
  padding-block: 8px 14px;
  background: var(--bg);
}
.search {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--ink);
}
.search::placeholder { color: var(--ink-faint); opacity: 1; }
.word-list li { border-block-end: 1px solid var(--line); }
.word-row {
  width: 100%;
  min-height: 66px;
  padding: 10px 4px;
  border: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: start;
}
.word-row:hover { background: var(--surface-muted); }
.wl-hanzi { min-width: 46px; font-family: "Mandarin SC", serif; font-size: 1.65rem; text-align: center; }
.wl-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.wl-pinyin { color: var(--accent-strong); font-weight: 750; }
.wl-de { color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wl-status {
  flex-shrink: 0;
  padding: 4px 7px;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 0.72rem;
}
.wl-status.s-learn { color: var(--accent-strong); }
.wl-status.s-known { color: var(--success); }
.empty-hint { padding: 40px 0; color: var(--ink-soft); text-align: center; }

#settingsTitle { margin-block-end: 24px; }
.settings-group {
  margin: 0 0 16px;
  padding: 18px 0;
  border: 0;
  border-block-end: 1px solid var(--line);
}
.settings-group legend, .settings-group h2 { margin: 0; font-size: 1.05rem; font-weight: 800; }
.settings-hint, .settings-group p { margin: 5px 0 14px; color: var(--ink-soft); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  min-height: var(--tap);
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
  font-weight: 750;
}
.seg input:checked + span { border-color: var(--accent-strong); color: var(--accent-strong); }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 3px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.switch-row p { margin-block-end: 0; }
.switch { position: relative; flex-shrink: 0; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch > span[aria-hidden] {
  width: 54px;
  height: 32px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-muted);
}
.switch > span[aria-hidden]::after {
  content: "";
  position: absolute;
  inset-block-start: 4px;
  inset-inline-start: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 2px 4px rgb(0 0 0 / 0.28);
  transition: transform 180ms var(--ease);
}
.switch input:checked + span { border-color: var(--accent); background: var(--accent); }
.switch input:checked + span::after { transform: translateX(22px); }
.switch input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 3px; }
.danger-zone .btn { width: 100%; }
.btn-danger { color: var(--danger); border-color: currentColor; }
.btn-danger-solid { border-color: transparent; background: var(--danger); color: #fff; }
.footer-note { color: var(--ink-soft); text-align: center; }

.tabbar {
  position: fixed;
  inset: auto 0 0;
  z-index: var(--z-sticky);
  width: min(100%, 480px);
  margin-inline: auto;
  display: flex;
  padding-block-end: env(safe-area-inset-bottom);
  border-block-start: 1px solid var(--line);
  background: var(--surface);
}
.tab {
  flex: 1;
  min-height: 52px;
  border: 0;
  border-block-start: 3px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-weight: 650;
}
.tab[aria-current="page"] { border-block-start-color: var(--accent); color: var(--accent-strong); }
body.session-active .tabbar { display: none; }
body.session-active .main { padding-block-end: 32px; }

.modal {
  width: min(calc(100% - 36px), 360px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
.modal::backdrop { background: rgb(0 0 0 / 0.64); }
.modal form { padding: 24px; }
.modal h2 { margin: 0; font-size: 1.25rem; }
.modal p { margin: 10px 0 22px; color: var(--ink-soft); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

@media (max-width: 360px) {
  .main { padding-inline: 16px; }
  .hanzi { font-size: 6.8rem; }
  .rate-row { gap: 6px; }
  .rate-row .btn { padding-inline: 8px; }
  .wl-status { font-size: 0.68rem; }
}

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

@media (forced-colors: active) {
  progress, .btn, .study-card, .seg span, .wl-status { forced-color-adjust: auto; }
}
