/* ===========================================================================
   Deckr — dark, high contrast, thumb-first.
   Latin text is sized for glanceability; Chinese is always noticeably larger
   because small hanzi are unreadable on a phone.
   =========================================================================== */

:root {
  --bg:        #0e1116;
  --surface:   #171d26;
  --surface-2: #212a36;
  --line:      #2c3644;
  --text:      #f2f5f8;
  --muted:     #9aa7b8;
  --accent:    #4cc9a7;
  --accent-dk: #123a30;
  --bad:       #ff6b6b;
  --bad-dk:    #3d1b1e;

  --pad: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* Kill the iOS tap flash and text selection — this is an app, not a document. */
button, label.btn, .seg {
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* Chinese wants a font stack that actually has traditional glyphs. */
.zh {
  font-family: "PingFang HK", "PingFang TC", "Hiragino Sans CNS",
               "Noto Sans HK", "Microsoft JhengHei", system-ui, sans-serif;
}

/* ---------------------------------------------------------------- screens */

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-t) + 12px) var(--pad) calc(var(--safe-b) + 24px);
}
.screen[hidden] { display: none; }

.home-head { margin: 8px 0 20px; }
.home-head h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.home-head .sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.section-title {
  margin: 28px 0 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ------------------------------------------------------------------ stats */

.stats {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}
.stat {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
}
.stat-num {
  display: block;
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stat-num.good { color: var(--accent); }
.stat-num.bad  { color: var(--bad); }
.stat-label {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

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

.btn {
  display: block;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 14px;
  font: inherit;
  font-weight: 600;
  text-align: center;
  padding: 16px;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
}
.btn:active { transform: scale(0.985); filter: brightness(1.15); }
.btn:disabled { opacity: 0.4; }

.btn-big { min-height: 60px; font-size: 19px; }

.btn-primary   { background: var(--accent); color: #06231b; }
.btn-secondary { background: var(--surface-2); border-color: var(--line); }
.btn-ghost     { background: transparent; border-color: var(--line); color: var(--text); padding: 14px; }
.btn-danger-ghost {
  background: transparent;
  border-color: var(--bad-dk);
  color: var(--bad);
  margin-top: 10px;
  padding: 14px;
}

.btn-note {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0.7;
}

.tool-row { display: flex; gap: 10px; }
.tool-row .btn { flex: 1; }
label.btn { line-height: normal; }

.footnote {
  margin: 16px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.notice {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bad-dk);
  border: 1px solid #5c2a2e;
  color: #ffc9c9;
  font-size: 14px;
}

/* -------------------------------------------------------------- deck list */

.deck-list { list-style: none; margin: 0; padding: 0 0 16px; }

.deck-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.deck-item[aria-checked="true"] {
  border-color: var(--accent);
  background: #14251f;
}

/* Custom checkbox — the native one is far too small for a thumb. */
.box {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #06231b;
}
.deck-item[aria-checked="true"] .box {
  background: var(--accent);
  border-color: var(--accent);
}
.box::after { content: ""; }
.deck-item[aria-checked="true"] .box::after { content: "✓"; font-weight: 800; }

.deck-name { flex: 1; font-weight: 600; }
.deck-meta { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------- quiz */

/* The quiz screen is height-bounded, not just min-height: that is what lets
   .back-scroll scroll internally while the answer bar stays pinned. */
#screen-quiz {
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  padding-bottom: 0;
  overflow: hidden;
}

.quiz-top {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  padding-bottom: 8px;
}
.btn-icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
}
.progress-track {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s ease;
}
.quiz-count {
  flex: 0 0 auto;
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.card-face { flex: 1 1 auto; display: flex; min-height: 0; }
.card-face[hidden] { display: none; }

/* --- front --- */
.card-front {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 8px calc(var(--safe-b) + 24px);
  cursor: pointer;
}
.kind-tag {
  font-size: 12px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 20px;
}
.front-text {
  font-size: clamp(28px, 8.5vw, 36px);
  font-weight: 600;
  line-height: 1.25;
  max-width: 18ch;
}
/* Chinese on the front (sign cards) gets much bigger. */
.front-text.zh {
  font-size: clamp(52px, 17vw, 76px);
  line-height: 1.15;
  font-weight: 500;
  letter-spacing: 0.03em;
}
.tap-hint {
  margin-top: 36px;
  font-size: 14px;
  color: var(--muted);
}

/* --- back --- */
.card-back { flex-direction: column; }

.back-scroll {
  flex: 1 1 auto;
  min-height: 0;               /* without this a flex item refuses to shrink */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 16px;
}

.back-prompt {
  display: block;
  width: 100%;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 4px 0 14px;
  margin-bottom: 22px;
  color: var(--muted);
  font: inherit;
  text-align: center;
  cursor: pointer;
}
#back-prompt-text {
  display: block;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}
#back-prompt-text.zh { font-size: 30px; font-weight: 500; }
.back-prompt-hint {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.65;
}

/* THE SEGMENT ROW.
   A flex-wrap container of inline-block columns. Each column is one segment
   and wraps as a whole unit — a segment never splits across two lines. */
.segments {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 10px 8px;
  margin-bottom: 22px;
}
.seg {
  display: inline-block;          /* the column is one indivisible box */
  vertical-align: top;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 10px 8px;
  min-width: 62px;
  max-width: 46vw;
  font: inherit;
  color: var(--text);
  cursor: pointer;
}
.seg:disabled { opacity: 1; }        /* no voice just means it cannot be tapped */
.seg:active { background: var(--accent-dk); border-color: var(--accent); }
.seg.speaking { background: var(--accent-dk); border-color: var(--accent); }

.seg-zh {
  display: block;
  font-size: clamp(27px, 8.5vw, 36px);
  line-height: 1.2;
  font-weight: 500;
  white-space: nowrap;            /* keep a segment's hanzi on one line */
}
.seg-jp {
  display: block;
  margin-top: 4px;
  font-size: 15px;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.seg-en {
  display: block;
  margin-top: 3px;
  font-size: 12.5px;
  line-height: 1.25;
  color: var(--muted);
}

.back-english {
  margin: 0 0 20px;
  text-align: center;
  font-size: 16px;
  color: var(--muted);
}

.btn-speak {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 62px;
  font-size: 19px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.btn-speak .speak-glyph { font-size: 23px; }

/* THE ANSWER BAR.
   Pinned to the bottom, above the home indicator, with a wide gutter between
   the two buttons so a thumb cannot catch the wrong one. */
.answer-bar {
  flex: 0 0 auto;
  display: flex;
  gap: 20px;
  padding: 12px 0 calc(var(--safe-b) + 12px);
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}
.answer-bar .btn {
  flex: 1;
  min-height: 68px;
  font-size: 19px;
  border-radius: 18px;
}
.btn-got    { background: var(--accent); color: #06231b; }
.btn-missed { background: var(--bad-dk); color: #ffb3b3; border-color: #5c2a2e; }

/* ---------------------------------------------------------------- summary */

.missed-list { list-style: none; margin: 0; padding: 0; flex: 1 1 auto; }
.missed-list:empty::after {
  content: "Nothing missed. 叻仔!";
  display: block;
  padding: 20px 0;
  color: var(--muted);
}
.missed-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.missed-body { flex: 1; min-width: 0; }
.missed-zh { display: block; font-size: 26px; line-height: 1.25; }
.missed-jp { display: block; font-size: 14px; color: var(--accent); font-weight: 600; }
.missed-en { display: block; font-size: 14px; color: var(--muted); }
.missed-speak { flex: 0 0 auto; font-size: 22px; opacity: 0.8; }

.summary-actions { margin-top: 22px; display: flex; flex-direction: column; gap: 10px; }

/* --------------------------------------------------------- accessibility */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .btn:active { transform: none; }
}
