/* Cíkǎ — xuan paper & vermilion.
   Hairlines, not shadows. Serif hanzi, italic pinyin. One accent colour.
   Light "paper" by default; automatic "ink-stone" dark mode. */

:root {
  --paper: #f3eee3;
  --paper-2: #faf7f0;
  --paper-3: #ebe4d4;
  --ink: #1d1b18;
  --ink-2: #5d574d;
  --ink-3: #958d7f;
  --line: #d7cdb8;
  --line-2: #c4b89f;
  --vermilion: #c2321e;
  --vermilion-2: #a1281a;
  --vermilion-soft: rgba(194, 50, 30, 0.10);
  --jade: #2f7a5c;
  --jade-soft: rgba(47, 122, 92, 0.12);
  --gold: #a9801f;
  --seal-shadow: rgba(120, 40, 20, 0.25);
  --fiber: rgba(80, 60, 30, 0.035);

  --serif-latin: "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --serif-hanzi: "Noto Serif SC", "Noto Serif CJK SC", "Songti SC", "STSong", "SimSun", "Source Han Serif SC", "Noto Sans CJK SC", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;

  --radius: 6px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141517;
    --paper-2: #1b1d21;
    --paper-3: #23262b;
    --ink: #ece6d8;
    --ink-2: #aaa294;
    --ink-3: #6e685e;
    --line: #2c2f35;
    --line-2: #3c4048;
    --vermilion: #e04a30;
    --vermilion-2: #f26a4f;
    --vermilion-soft: rgba(224, 74, 48, 0.16);
    --jade: #4fa882;
    --jade-soft: rgba(79, 168, 130, 0.16);
    --gold: #d1a441;
    --seal-shadow: rgba(0, 0, 0, 0.5);
    --fiber: rgba(255, 245, 220, 0.02);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, var(--fiber), transparent 60%),
    radial-gradient(ellipse 60% 40% at 90% 110%, var(--fiber), transparent 60%),
    var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 20px 64px;
}

h1, h2, h3 { font-family: var(--serif-latin); font-weight: 500; letter-spacing: -0.01em; line-height: 1.15; margin: 0; }

.hanzi, .zh { font-family: var(--serif-hanzi); font-weight: 400; }
.pinyin, .py { font-family: var(--serif-latin); font-style: italic; font-weight: 400; }
.eyebrow {
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ------------------------------------------------------------ masthead */

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 28px 0 14px;
  border-bottom: 1px solid var(--ink);
  margin-bottom: 28px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  border: 0;
  background: none;
  padding: 0;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.brand { flex-shrink: 0; white-space: nowrap; }
.brand .zh { font-size: 2rem; line-height: 1; letter-spacing: 0.04em; }
.brand .latin { font-family: var(--serif-latin); font-style: italic; font-size: 1.05rem; color: var(--ink-2); }

.masthead-side { display: flex; align-items: center; gap: 14px; min-width: 0; }
.masthead-side button { white-space: nowrap; }

.today {
  display: flex;
  gap: 14px;
  font-family: var(--serif-latin);
  font-size: 0.95rem;
  color: var(--ink-2);
  white-space: nowrap;
}
.today b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.today .sep { color: var(--line-2); }

@media (max-width: 520px) {
  .masthead { padding-top: 20px; }
  .brand { gap: 8px; }
  .brand .zh { font-size: 1.7rem; }
  .brand .latin { display: none; }
  .masthead-side { gap: 8px; }
  .today { font-size: 0.85rem; gap: 8px; }
}

/* ------------------------------------------------------------ buttons */

button {
  font-family: var(--sans);
  font-size: 0.92rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--ink);
  padding: 9px 16px;
  cursor: pointer;
  line-height: 1.2;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.08s;
}
button:hover { border-color: var(--ink); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: default; transform: none; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--vermilion); outline-offset: 2px; }

.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn-primary:hover { background: var(--vermilion); border-color: var(--vermilion); color: #fff; }
.btn-accent { background: var(--vermilion); border-color: var(--vermilion); color: #fff; }
.btn-accent:hover { background: var(--vermilion-2); border-color: var(--vermilion-2); }
.btn-ghost { border-color: transparent; color: var(--ink-2); padding-left: 8px; padding-right: 8px; }
.btn-ghost:hover { color: var(--ink); border-color: transparent; background: var(--paper-3); }
.btn-danger { color: var(--vermilion); }
.btn-danger:hover { border-color: var(--vermilion); background: var(--vermilion-soft); }
.btn-small { padding: 6px 11px; font-size: 0.82rem; }
.btn-icon {
  width: 34px; height: 34px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-color: transparent; color: var(--ink-2); font-size: 0.95rem;
}
.btn-icon:hover { background: var(--paper-3); color: var(--ink); border-color: transparent; }
.btn-icon.danger:hover { color: var(--vermilion); background: var(--vermilion-soft); }
.btn-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.btn-icon svg .fill { fill: currentColor; stroke: none; }

/* ------------------------------------------------------------ forms */

input[type="text"], input[type="password"] {
  width: 100%;
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--ink);
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s var(--ease);
}
input::placeholder { color: var(--ink-3); }
input:focus { border-color: var(--ink); }
input[lang="zh"] { font-family: var(--serif-hanzi); font-size: 1.15rem; }

label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 16px 0 6px;
}
label:first-child { margin-top: 0; }
.hint { font-size: 0.8rem; color: var(--ink-3); margin-top: 6px; }

/* ------------------------------------------------------------ packs */

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 22px; }
.toolbar .spacer { flex: 1; }

.pack-grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 600px) { .pack-grid { grid-template-columns: 1fr 1fr; } }

.pack-card {
  position: relative;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  transition: border-color 0.15s var(--ease);
}
.pack-card:hover { border-color: var(--line-2); }
.pack-card .mark {
  position: absolute;
  right: -6px; top: -18px;
  font-family: var(--serif-hanzi);
  font-size: 6.5rem;
  line-height: 1;
  color: var(--ink);
  opacity: 0.045;
  pointer-events: none;
  user-select: none;
}
.pack-card h2 { font-size: 1.35rem; padding-right: 48px; }
.pack-card h2 .zh { font-size: 1.3em; }
.pack-desc { margin: -6px 0 0; font-size: 0.88rem; color: var(--ink-2); }

.pack-meter { display: flex; height: 3px; gap: 2px; border-radius: 2px; overflow: hidden; margin-top: 4px; }
.pack-meter span { display: block; min-width: 2px; }
.pack-meter .due { background: var(--vermilion); }
.pack-meter .known { background: var(--jade); }
.pack-meter .new { background: var(--line-2); }
.pack-meter .empty { background: var(--line); flex: 1; }

.pack-figures { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.8rem; color: var(--ink-3); }
.pack-figures b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.pack-figures .due b { color: var(--vermilion); }
.pack-figures .known b { color: var(--jade); }

.pack-actions { display: flex; gap: 8px; margin-top: 4px; }
.pack-actions button { flex: 1; }

.empty {
  text-align: center;
  color: var(--ink-3);
  padding: 56px 20px;
  border: 1px dashed var(--line-2);
  border-radius: var(--radius);
}
.empty .zh { font-size: 3rem; display: block; margin-bottom: 10px; color: var(--ink-2); }

/* ------------------------------------------------------------ login */

.login-wrap { min-height: 80dvh; display: flex; align-items: center; justify-content: center; }
.login { width: 100%; max-width: 320px; text-align: center; }
.login .seal-mark {
  width: 64px; height: 64px;
  margin: 0 auto 22px;
  border-radius: 4px;
  background: var(--vermilion);
  color: #fff;
  font-family: var(--serif-hanzi);
  font-size: 2.2rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 3px var(--vermilion);
  transform: rotate(-3deg);
}
.login h1 { font-size: 2rem; }
.login h1 .zh { font-size: 1.15em; margin-right: 8px; }
.login h1 .latin { font-style: italic; font-weight: 400; color: var(--ink-2); }
.login p { margin: 6px 0 28px; color: var(--ink-3); font-size: 0.9rem; }
.login input { text-align: center; font-size: 1.05rem; padding: 12px; }
.login .btn-primary { width: 100%; margin-top: 10px; padding: 12px; }
.login-error { color: var(--vermilion); font-size: 0.85rem; min-height: 1.3em; margin-top: 10px; }

/* ------------------------------------------------------------ manage */

.pack-head { margin-bottom: 24px; }
.pack-head h1 { font-size: 2.2rem; }
.pack-head h1 .zh { font-size: 1.25em; }
.pack-head .pack-sub { margin: 4px 0 0; color: var(--ink-2); }
.pack-head .eyebrow { margin-top: 8px; }

.add-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
  padding: 16px 18px 18px;
  margin-bottom: 28px;
}
.add-card-grid { display: grid; gap: 8px; grid-template-columns: 1fr 1fr 1.3fr auto; }
@media (max-width: 600px) { .add-card-grid { grid-template-columns: 1fr; } }

.card-list { border-top: 1px solid var(--line); }
.card-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px 16px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
}
.card-main { min-width: 0; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.card-hanzi { font-family: var(--serif-hanzi); font-size: 1.75rem; line-height: 1.1; }
.card-pinyin { font-family: var(--serif-latin); font-style: italic; font-size: 1.05rem; color: var(--vermilion); }
.card-english { color: var(--ink-2); font-size: 0.9rem; }
@media (max-width: 600px) { .card-english { flex-basis: 100%; } }
.card-side { display: flex; align-items: center; gap: 10px; }
.card-state { font-size: 0.72rem; color: var(--ink-3); white-space: nowrap; letter-spacing: 0.04em; }
.card-state.due { color: var(--vermilion); }
.card-actions { display: flex; gap: 2px; }

/* ------------------------------------------------------------ review */

.review-top {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: -8px 0 10px;
}
.review-count { font-family: var(--serif-latin); font-size: 0.95rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.review-count b { color: var(--ink); font-weight: 600; }

.progress { height: 2px; background: var(--line); margin-bottom: 36px; }
.progress span { display: block; height: 100%; background: var(--vermilion); width: 0; transition: width 0.4s var(--ease); }

.review-card {
  position: relative;
  text-align: center;
  padding: 8px 0 24px;
  animation: rise 0.35s var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.prompt-label { margin-bottom: 18px; }
.prompt-value { margin: 0 auto 30px; word-break: break-word; max-width: 100%; }
.prompt-value.hanzi { font-size: clamp(4rem, 18vw, 7rem); line-height: 1.05; }
.prompt-value.pinyin { font-size: clamp(2.2rem, 9vw, 3.4rem); color: var(--vermilion); line-height: 1.15; }
.prompt-value.english { font-family: var(--serif-latin); font-size: clamp(1.8rem, 7vw, 2.6rem); line-height: 1.2; }

.task-label { font-family: var(--serif-latin); font-style: italic; font-size: 1.05rem; color: var(--ink-2); margin-bottom: 18px; }

.answer-form { display: flex; flex-direction: column; align-items: center; gap: 18px; }
input.answer-input {
  max-width: 380px;
  text-align: center;
  font-family: var(--serif-latin);
  font-size: 1.6rem;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  padding: 6px 4px 8px;
}
input.answer-input:focus { border-bottom-color: var(--vermilion); }
input.answer-input:focus-visible { outline: none; }
input.answer-input::placeholder { font-style: italic; color: var(--ink-3); font-size: 1.1rem; }

.mc-grid { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; max-width: 520px; margin: 0 auto; }
@media (min-width: 520px) { .mc-grid { grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); } }
.mc-choice {
  font-family: var(--serif-hanzi);
  font-size: 2rem;
  padding: 22px 8px;
  background: var(--paper-2);
  border-color: var(--line);
  line-height: 1.1;
}
.mc-choice:hover { border-color: var(--ink); }

/* reveal */
.reveal { animation: rise 0.3s var(--ease); }
.reveal-grid { display: grid; gap: 4px; justify-items: center; margin: 0 auto 26px; }
.reveal-hanzi { font-family: var(--serif-hanzi); font-size: 3.2rem; line-height: 1.1; }
.reveal-pinyin { font-family: var(--serif-latin); font-style: italic; font-size: 1.4rem; color: var(--vermilion); }
.reveal-english { font-family: var(--serif-latin); font-size: 1.15rem; color: var(--ink-2); }

.seal {
  position: absolute;
  top: -6px; right: 4%;
  width: 78px; height: 78px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif-hanzi);
  font-size: 2.4rem;
  color: var(--vermilion);
  border: 3px solid var(--vermilion);
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 3.5px var(--vermilion);
  background: var(--paper);
  transform: rotate(-12deg);
  animation: stamp 0.45s var(--ease) both;
  mix-blend-mode: multiply;
  pointer-events: none;
}
.seal.wrong { color: var(--ink-2); border-color: var(--ink-2); box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 3.5px var(--ink-2); transform: rotate(8deg); }
@media (prefers-color-scheme: dark) { .seal { mix-blend-mode: normal; } }
@keyframes stamp {
  0%   { opacity: 0; transform: rotate(-12deg) scale(1.8); }
  55%  { opacity: 1; transform: rotate(-12deg) scale(0.95); }
  100% { opacity: 1; transform: rotate(-12deg) scale(1); }
}
.seal.wrong { animation-name: stamp-wrong; }
@keyframes stamp-wrong {
  0%   { opacity: 0; transform: rotate(8deg) scale(1.8); }
  55%  { opacity: 1; transform: rotate(8deg) scale(0.95); }
  100% { opacity: 1; transform: rotate(8deg) scale(1); }
}
@media (max-width: 480px) { .seal { width: 64px; height: 64px; font-size: 2rem; right: 0; top: 0; } }

.result-banner { font-family: var(--serif-latin); font-size: 1.15rem; margin-bottom: 22px; }
.result-banner .zh { margin-right: 8px; }
.result-banner.right { color: var(--jade); }
.result-banner.wrong { color: var(--vermilion); }
.result-note { font-size: 0.85rem; color: var(--gold); margin: -14px 0 20px; }
.result-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.next-in { margin-top: 18px; font-size: 0.8rem; color: var(--ink-3); font-family: var(--serif-latin); font-style: italic; }

.review-summary { text-align: center; padding: 48px 20px; }
.review-summary .seal-big {
  width: 96px; height: 96px; margin: 0 auto 26px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif-hanzi); font-size: 3rem;
  color: var(--vermilion); border: 3px solid var(--vermilion); border-radius: 10px;
  box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 3.5px var(--vermilion);
  transform: rotate(-6deg);
  animation: stamp 0.5s var(--ease) both;
}
.review-summary h1 { font-size: 2rem; }
.review-summary .score { font-family: var(--serif-latin); font-size: 1.1rem; color: var(--ink-2); margin: 8px 0 0; }
.review-summary .score b { color: var(--ink); font-weight: 600; }
.review-summary .note { color: var(--ink-3); font-size: 0.9rem; margin-top: 12px; }

/* ------------------------------------------------------------ overlays */

.toast {
  position: fixed;
  left: 50%; bottom: 28px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  z-index: 50;
  max-width: 90vw;
  animation: rise 0.25s var(--ease);
}

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 18, 15, 0.45);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 40;
}
.modal {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  animation: rise 0.25s var(--ease);
}
.modal h2 { font-size: 1.4rem; margin-bottom: 14px; }
.modal p { margin: 0; color: var(--ink-2); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 22px; }

.spinner {
  display: inline-block; width: 0.9em; height: 0.9em;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin 0.7s linear infinite; vertical-align: -0.12em; margin-right: 4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.w-full { width: 100%; }
.mt-28 { margin-top: 28px; }
.fw-normal { font-weight: 400; text-transform: none; letter-spacing: 0; }

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