/* ==========================================================================
   kotobạn — app styles
   Mobile-first, vanilla. Uses the --kb-* brand tokens with sensible
   fallbacks so the app looks right even before tokens.css loads.
   Layout classes use plain names; kb-* classes come from components.css.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--kb-bg, #faf6ed);
  color: var(--kb-ink, #201914);
  font-family: var(--kb-font-body, system-ui, -apple-system, "Segoe UI", sans-serif);
  font-size: 1rem;
  line-height: 1.55;
  min-height: 100dvh;
}

img, svg { max-width: 100%; }

a { color: var(--kb-primary, #bc3b1a); }
a:hover { color: var(--kb-ink, #201914); }

h1, h2, h3 {
  font-family: var(--kb-font-display, Georgia, serif);
  line-height: 1.2;
  margin: 0 0 0.6rem;
  overflow-wrap: break-word;
}
h1 { font-size: 1.7rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }

p { margin: 0 0 0.9rem; overflow-wrap: break-word; }

.muted { color: var(--kb-muted, #8a7c63); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--kb-muted, #8a7c63);
  margin: 0 0 0.4rem;
}
.native { color: var(--kb-muted, #8a7c63); font-weight: 400; }

.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;
}

/* ---- page frame --------------------------------------------------------- */

.wrap {
  max-width: 30rem; /* 480px */
  margin: 0 auto;
  padding: 1rem 1rem calc(6.5rem + env(safe-area-inset-bottom, 0px));
  min-width: 0;
}

.stack > * + * { margin-top: 1rem; }
.stack-tight > * + * { margin-top: 0.6rem; }

/* ---- top bar ------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--kb-surface, #fffdf7);
  border-bottom: 1px solid var(--kb-line, #e6dac0);
}
.topbar-in {
  max-width: 30rem;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: calc(0.55rem + env(safe-area-inset-top, 0px)) 1rem 0.55rem;
  min-height: 56px;
}
.brand {
  font-family: var(--kb-font-display, Georgia, serif);
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--kb-ink, #201914);
  text-decoration: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.brand .shared { color: var(--kb-primary, #bc3b1a); }
.topbar-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}
.topbar-email {
  font-size: 0.8rem;
  color: var(--kb-muted, #8a7c63);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 38vw;
}
.linklike {
  background: none; border: 0; padding: 0.6rem 0.4rem;
  color: var(--kb-primary, #bc3b1a);
  font: inherit; font-weight: 600; cursor: pointer;
  min-height: 44px; text-decoration: none;
  display: inline-flex; align-items: center;
}

/* ---- bottom tab bar (authed) --------------------------------------------- */

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  display: flex;
  background: var(--kb-surface, #fffdf7);
  border-top: 1px solid var(--kb-line, #e6dac0);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 60px;
  padding: 0.4rem 0.25rem;
  color: var(--kb-muted, #8a7c63);
  font-size: 0.72rem;
  font-weight: 600;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.tab .ico { font-size: 1.35rem; line-height: 1; }
.tab.active { color: var(--kb-primary, #bc3b1a); }

/* ---- hero / landing ------------------------------------------------------- */

.hero { text-align: center; padding: 1.5rem 0 0.5rem; }
#wordmark-slot { min-height: 120px; }

.badges {
  display: flex; gap: 0.5rem; justify-content: center;
  flex-wrap: wrap; margin: 1rem 0;
}
.pitch {
  font-size: 1.05rem;
  color: var(--kb-ink-soft, #4e4536);
  max-width: 26rem;
  margin-left: auto; margin-right: auto;
}
.lang-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin: 1.25rem 0;
}
.lang-card { text-align: left; }
.lang-card .native-big {
  font-family: var(--kb-font-display, Georgia, serif);
  font-size: 1.6rem; display: block; margin-bottom: 0.25rem;
}
.cta-row {
  display: flex; gap: 0.75rem; justify-content: center;
  flex-wrap: wrap; margin: 1.25rem 0;
}
.cta-row .kb-btn { flex: 1 1 160px; }
.footer-note {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--kb-line, #e6dac0);
  font-size: 0.8rem;
  color: var(--kb-muted, #8a7c63);
  text-align: center;
}

/* ---- auth ----------------------------------------------------------------- */

.auth-wrap { max-width: 24rem; margin: 2rem auto 0; }
.auth-wrap h1 { text-align: center; }
.auth-alt { text-align: center; margin-top: 1.25rem; }

/* ---- dashboard ------------------------------------------------------------- */

.streak {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-weight: 700; font-size: 0.9rem;
  margin-bottom: 0.9rem;
}
.streak .flame { font-size: 1.2rem; }

.level-row { margin-bottom: 0.85rem; }
.level-row:last-child { margin-bottom: 0; }
.level-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 0.5rem; margin-bottom: 0.3rem;
}
.level-name { font-weight: 700; font-size: 0.9rem; }
.level-cap { font-size: 0.78rem; color: var(--kb-muted, #8a7c63); }

.setup { margin-top: 1.1rem; padding-top: 1.1rem; border-top: 1px solid var(--kb-line, #e6dac0); }
.setup-row { display: flex; gap: 0.6rem; margin-bottom: 0.75rem; }
.setup-row .kb-field { flex: 1 1 0; margin-bottom: 0; min-width: 0; }
.setup-links { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.25rem; }

/* ---- session timer ---------------------------------------------------------- */

.timerbar {
  position: sticky;
  top: calc(57px + env(safe-area-inset-top, 0px)); /* below .topbar */
  z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem;
  background: var(--kb-surface, #fffdf7);
  border: 1px solid var(--kb-line, #e6dac0);
  border-radius: var(--kb-radius-sm, 9px);
  padding: 0.5rem 0.9rem;
  margin-bottom: 1rem;
  box-shadow: var(--kb-shadow, 0 1px 2px rgba(32,25,20,0.07));
}
.timer-clock {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}
.timerbar--low .timer-clock { color: var(--kb-warn, #a85b08); }
.timerbar--low { border-color: var(--kb-warn, #a85b08); }
.timer-meta { font-size: 0.8rem; color: var(--kb-muted, #8a7c63); }

/* ---- question cards ---------------------------------------------------------- */

.qcard { margin-bottom: 1rem; }
.q-headword {
  font-family: var(--kb-font-display, Georgia, serif);
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.15;
  margin: 0.25rem 0 0.35rem;
  overflow-wrap: break-word;
}
.q-reading { color: var(--kb-muted, #8a7c63); font-size: 1.05rem; margin-bottom: 0.5rem; }
.q-prompt { font-weight: 600; font-size: 1.05rem; margin: 0.75rem 0; }
.q-sentence {
  font-size: 1.15rem; line-height: 1.7; margin: 0.75rem 0;
  padding: 0.9rem 1rem;
  background: var(--kb-surface-2, #f1e9d7);
  border-radius: var(--kb-radius-sm, 9px);
}
.q-blank {
  display: inline-block; min-width: 3.2em;
  border-bottom: 3px solid var(--kb-primary, #bc3b1a);
  text-align: center; font-weight: 700; padding: 0 0.3em;
}

.choices { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 0.5rem; }
.choice {
  justify-content: flex-start;
  text-align: left;
  min-height: 56px;
  white-space: normal;
  line-height: 1.4;
}
.choice--picked { border-color: var(--kb-primary, #bc3b1a); background: var(--kb-primary-soft, #f8e2d4); }
.choice--right { border-color: var(--kb-success, #2e7d4f); background: #e7f2ea; }
.choice--wrong { border-color: var(--kb-danger, #a32020); background: #f9e9e9; }

.know-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-top: 1rem; }
.know-row .kb-btn { min-height: 60px; font-size: 1.05rem; }

.type-row { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 0.5rem; }
.type-input { font-size: 1.3rem; padding: 0.9rem 1rem; }
.type-preview {
  min-height: 2.2em; font-size: 1.6rem; text-align: center;
  font-family: var(--kb-font-display, Georgia, serif);
  color: var(--kb-ink-soft, #4e4536);
}

.qfeedback { margin-top: 0.9rem; }

/* ---- word detail -------------------------------------------------------------- */

.d-head { margin-bottom: 0.25rem; }
.d-headword {
  font-family: var(--kb-font-display, Georgia, serif);
  font-size: 2.4rem; font-weight: 800; line-height: 1.1;
  margin: 0 0 0.3rem; overflow-wrap: break-word;
}
.d-reading { font-size: 1.15rem; color: var(--kb-ink-soft, #4e4536); margin-bottom: 0.25rem; }
.d-romaji { font-size: 0.9rem; color: var(--kb-muted, #8a7c63); }
.d-meaning { font-size: 1.2rem; font-weight: 600; margin: 0.75rem 0; }
.d-chips { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.5rem 0 0; }

.d-sec { margin-top: 1.4rem; }
.d-sec > h3 {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--kb-muted, #8a7c63);
  font-family: var(--kb-font-body, system-ui, sans-serif);
  margin-bottom: 0.6rem;
}

.tone-tiles { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.tone-tile {
  background: var(--kb-surface, #fffdf7);
  border: 1px solid var(--kb-line, #e6dac0);
  border-bottom: 3px solid var(--kb-muted, #8a7c63);
  border-radius: var(--kb-radius-sm, 9px);
  padding: 0.55rem 0.7rem;
  text-align: center;
  min-width: 68px;
}
.tone-tile .syl { font-size: 1.35rem; font-weight: 700; line-height: 1.2; }
.tone-tile .tone { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--kb-muted, #8a7c63); margin-top: 0.15rem; }
.tone-ngang { border-bottom-color: #9a8f7a; }
.tone-huyen { border-bottom-color: #4a6fa5; }
.tone-sac   { border-bottom-color: #bc3b1a; }
.tone-hoi   { border-bottom-color: #d99a26; }
.tone-nga   { border-bottom-color: #7a4a9e; }
.tone-nang  { border-bottom-color: #201914; }

.kanji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 0.5rem;
}
.kanji-cell {
  background: var(--kb-surface-2, #f1e9d7);
  border-radius: var(--kb-radius-sm, 9px);
  padding: 0.6rem 0.4rem;
  text-align: center;
}
.kanji-cell .k { font-size: 1.7rem; font-weight: 700; line-height: 1.2; }
.kanji-cell .r { font-size: 0.8rem; color: var(--kb-ink-soft, #4e4536); }
.kanji-cell .m { font-size: 0.72rem; color: var(--kb-muted, #8a7c63); }

.example {
  border-left: 3px solid var(--kb-line, #e6dac0);
  padding: 0.1rem 0 0.1rem 0.85rem;
  margin: 0 0 0.85rem;
}
.example .ex-s { font-size: 1.05rem; }
.example .ex-r { font-size: 0.9rem; color: var(--kb-ink-soft, #4e4536); }
.example .ex-t { font-size: 0.9rem; color: var(--kb-muted, #8a7c63); }

.hook {
  background: var(--kb-primary-soft, #f8e2d4);
  border-radius: var(--kb-radius-sm, 9px);
  padding: 0.9rem 1rem;
  font-size: 0.95rem;
}

.statline {
  display: flex; gap: 1.25rem; flex-wrap: wrap;
  font-size: 0.9rem; color: var(--kb-ink-soft, #4e4536);
}
.statline b { font-size: 1.15rem; display: block; color: var(--kb-ink, #201914); }

.rel-chips { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.rel-chip {
  display: inline-flex; align-items: center;
  min-height: 44px; padding: 0.5rem 0.9rem;
  border: 1px solid var(--kb-line, #e6dac0);
  border-radius: 999px; background: var(--kb-surface, #fffdf7);
  color: var(--kb-ink, #201914); text-decoration: none; font-weight: 600;
}
.rel-chip small { color: var(--kb-muted, #8a7c63); font-weight: 400; margin-left: 0.35rem; }

/* ---- placement ----------------------------------------------------------------- */

.bands { list-style: none; margin: 1rem 0; padding: 0; }
.bands li {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; padding: 0.8rem 0;
  border-bottom: 1px solid var(--kb-line, #e6dac0);
  min-height: 56px;
}
.bands li:last-child { border-bottom: 0; }
.band-level { font-weight: 700; }

/* ---- word bank ------------------------------------------------------------------ */

.filters { display: grid; gap: 0.7rem; margin-bottom: 1rem; }
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.filter-row .kb-field, .filters .kb-field { margin-bottom: 0; }

.banklist { list-style: none; margin: 0; padding: 0; }
.bankrow {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.85rem 0.25rem;
  border-bottom: 1px solid var(--kb-line, #e6dac0);
  text-decoration: none; color: inherit;
  min-height: 68px;
}
.bankrow:first-child { border-top: 1px solid var(--kb-line, #e6dac0); }
.bankrow-main { flex: 1 1 0; min-width: 0; }
.bankrow-head { font-weight: 700; font-size: 1.05rem; overflow-wrap: break-word; }
.bankrow-read { font-size: 0.85rem; color: var(--kb-muted, #8a7c63); }
.bankrow-mean {
  font-size: 0.9rem; color: var(--kb-ink-soft, #4e4536);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.bankrow .chev { color: var(--kb-muted, #8a7c63); flex: none; }

.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; margin-top: 1.1rem;
}
.empty {
  text-align: center; padding: 2.5rem 1rem;
  color: var(--kb-muted, #8a7c63);
}

/* ---- toast ------------------------------------------------------------------------ */

.toast {
  position: fixed;
  bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  background: var(--kb-ink, #201914);
  color: var(--kb-bg, #faf6ed);
  padding: 0.7rem 1.15rem;
  border-radius: 999px;
  font-size: 0.88rem;
  max-width: 92vw;
  text-align: center;
  box-shadow: var(--kb-shadow, 0 1px 2px rgba(32,25,20,0.07));
}

/* ---- misc --------------------------------------------------------------------------- */

.loading { text-align: center; padding: 3rem 1rem; color: var(--kb-muted, #8a7c63); }
.divider { border: 0; border-top: 1px solid var(--kb-line, #e6dac0); margin: 1.5rem 0; }
.backlink { display: inline-flex; align-items: center; min-height: 44px; margin-bottom: 0.5rem; font-weight: 600; text-decoration: none; }

@media (min-width: 720px) {
  h1 { font-size: 2rem; }
  .wrap { padding-left: 1.5rem; padding-right: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
