/* Learn Korean - Hangul (web) — hanji paper palette of the 2.0 app
   (lib/constants/app_colors.dart, app_theme.dart, widgets/common.dart).
   A few text colours are slightly darker/lighter than the app so every
   text/background pair meets WCAG AA (4.5:1). */

:root {
  --bg: #F5F0E8;
  --card: #EDE5D5;
  --card-raised: #FBF8F2;
  --border: #C9B99A;
  --gold: #8B6914;          /* fills (buttons, progress, selected) */
  --gold-text: #7D5E10;     /* gold text on cards (app: #8B6914, 4.1:1) */
  --gold-on: #FFF8E7;
  --green: #4E6A36;         /* text (app: #5C7A3E, 3.9:1 on card) */
  --red: #8B2020;
  --red-badge: #8B2020;
  --text: #3D2B1A;
  --text-2: #6B4F2A;
  --text-muted: #75644F;    /* app: #9B8B7A, 2.6:1 on card */
  --ink: #3D2B1A;
  --on-ink: #F5F0E8;
  --ink-track: #6B4F2A;
  --ink-muted: #C9B99A;
  --correct-bg: #506D38;    /* app: #5C7A3E */
  --correct-text: #E8F0DC;
  --wrong-bg: #8B2020;
  --wrong-text: #F5D5D5;
  --focus: #8B6914;
  --shadow: 0 1px 2px rgba(61, 43, 26, .06), 0 4px 14px rgba(61, 43, 26, .07);
  --scrim: rgba(28, 24, 20, .45);

  --radius: 14px;
  --radius-sm: 10px;
  --tabbar-h: 66px;
  --appbar-h: 56px;
  --sidebar-w: 272px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --font-ko: "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", "Nanum Gothic",
    system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #1C1814;
  --card: #27211B;
  --card-raised: #302820;
  --border: #4A3F33;
  --gold: #D4A84B;
  --gold-text: #D4A84B;
  --gold-on: #241C10;
  --green: #9CBF78;
  --red: #E0766B;
  --red-badge: #B23A2E;
  --text: #F1E8DA;
  --text-2: #CDBDA5;
  --text-muted: #A89884;    /* app: #9A8B78, 4.4:1 on raised cards */
  --ink: #3A2E21;
  --on-ink: #F1E8DA;
  --ink-track: #5A4A37;
  --ink-muted: #B5A58F;
  --correct-bg: #4F6B35;
  --correct-text: #EAF3DE;
  --wrong-bg: #8E3A32;
  --wrong-text: #FBE3E0;
  --focus: #D4A84B;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  --scrim: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* ── Base ─────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: var(--appbar-h);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

:lang(ko) { font-family: var(--font-ko); }

h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg, canvas { display: block; }
kbd {
  font: 600 .75em/1 var(--font);
  padding: .2em .45em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--card-raised);
  color: var(--text-2);
}

.icon { width: 24px; height: 24px; fill: currentColor; flex: none; }

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

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
[tabindex="-1"]:focus { outline: none; }

.skip-link {
  position: absolute;
  left: 12px; top: -60px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--gold);
  color: var(--gold-on);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: 12px; }

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

/* ── Shell: bottom tab bar on phones, sidebar on desktop ──── */

.main {
  display: block;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.main:focus { outline: none; }
body.is-sub .main { padding-bottom: env(safe-area-inset-bottom); }

.brand, .sidebar__footer { display: none; }

.tabbar {
  position: fixed;
  z-index: 20;
  left: 0; right: 0; bottom: 0;
  display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 0 max(4px, env(safe-area-inset-left)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-right));
  background: var(--card);
  border-top: 1px solid var(--border);
}
body.is-sub .tabbar { display: none; }

.tabbar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  border-radius: 12px;
}
.tabbar__icon {
  display: grid;
  place-items: center;
  width: 60px; height: 30px;
  border-radius: 16px;
  transition: background-color .2s;
}
.tabbar__item .icon--on { display: none; }
.tabbar__item[aria-current="page"] { color: var(--text); font-weight: 700; }
.tabbar__item[aria-current="page"] .tabbar__icon { background: var(--bg); color: var(--gold); }
.tabbar__item[aria-current="page"] .icon--on { display: block; }
.tabbar__item[aria-current="page"] .icon--off { display: none; }
.tabbar__item:hover .tabbar__icon { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.tabbar__item:focus-visible { outline-offset: -3px; }

@media (min-width: 960px) {
  .shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100vh;
  }
  .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 24px 16px 20px;
    background: var(--card);
    border-right: 1px solid var(--border);
    overflow-y: auto;
  }
  .brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px;
    text-decoration: none;
    border-radius: var(--radius-sm);
  }
  .brand__icon { width: 44px; height: 44px; border-radius: 11px; box-shadow: 0 0 0 1px var(--border); }
  .brand__text { display: flex; flex-direction: column; min-width: 0; }
  .brand__name { font-weight: 800; font-size: 15px; letter-spacing: -.2px; line-height: 1.25; }
  .brand__tagline { font-size: 12.5px; color: var(--text-muted); }

  .main, body.is-sub .main { padding-bottom: 0; }

  .tabbar, body.is-sub .tabbar {
    position: static;
    display: flex;
    flex-direction: column;
    gap: 4px;
    height: auto;
    padding: 0;
    background: none;
    border: 0;
  }
  .tabbar__item {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    height: 48px;
    padding: 0 10px;
    font-size: 15px;
  }
  .tabbar__icon { width: 44px; height: 32px; }
  .tabbar__item:hover { background: color-mix(in srgb, var(--bg) 55%, transparent); }
  .tabbar__item[aria-current="page"] { background: var(--bg); }

  .sidebar__footer {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: auto;
  }
  .sidebar__links {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 8px;
    font-size: 13px;
    color: var(--text-muted);
  }
  .sidebar__links a { color: var(--text-2); text-underline-offset: 3px; }
}

.get-app {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.get-app__title { font-weight: 700; font-size: 14px; }
.get-app__text { margin: 4px 0 12px; font-size: 13px; color: var(--text-2); }
.get-app__link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
}
.get-app__link .icon { color: var(--gold-text); }
.get-app__link:hover { border-color: var(--gold); }
.get-app__link .icon { width: 20px; height: 20px; }

/* ── Layout containers ───────────────────────────────────── */

.page {
  width: min(100% - 40px, 560px);
  margin-inline: auto;
  padding: 14px 0 28px;
}
.page--wide { width: min(100% - 40px, 560px); }
.page--grid { width: min(100% - 32px, 720px); padding-top: 8px; }
.page--detail { width: min(100% - 40px, 560px); padding-top: 8px; padding-bottom: 12px; }
.page--narrow { width: min(100% - 40px, 480px); padding-top: 4px; }
.page--words { width: 100%; padding: 0; }

@media (min-width: 960px) {
  .page { padding-top: 32px; }
  .page--wide { width: min(100% - 64px, 920px); }
  .page--grid { width: min(100% - 64px, 920px); padding-top: 16px; }
  .page--detail { width: min(100% - 64px, 960px); padding-top: 16px; }
  .page--narrow { padding-top: 12px; }
}

.screen { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.screen > .page { flex: 1 0 auto; }

/* ── Headers ─────────────────────────────────────────────── */

.tab-header { text-align: center; margin-bottom: 14px; }
.tab-header__title { font-size: 20px; font-weight: 800; letter-spacing: -.3px; line-height: 1.3; }
.tab-header__subtitle { margin-top: 2px; font-size: 13px; color: var(--text-muted); }
@media (min-width: 960px) {
  .page--wide > .tab-header, .page > .tab-header { text-align: left; margin-bottom: 20px; }
  .tab-header__title { font-size: 26px; }
  .tab-header__subtitle { font-size: 14px; }
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) minmax(56px, auto);
  align-items: center;
  height: var(--appbar-h);
  padding: 0 4px;
  background: var(--bg);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--border) 50%, transparent);
}
.appbar__title {
  grid-column: 2;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.appbar__action { grid-column: 3; justify-self: end; padding-right: 12px; }
.appbar--plain { grid-template-columns: 56px minmax(0, 1fr) 56px; }
@media (min-width: 960px) {
  .appbar { padding: 0 24px; grid-template-columns: 64px minmax(0, 1fr) minmax(64px, auto); }
}

.section-label {
  margin: 24px 4px 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── Cards & buttons ─────────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.card--raised { background: var(--card-raised); }
.card--pad { padding: 12px; }
.card--interactive {
  text-decoration: none;
  transition: border-color .15s, box-shadow .15s, transform .1s;
}
.card--interactive:hover { border-color: var(--gold); box-shadow: var(--shadow); }
.card--interactive:active { transform: scale(.995); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  transition: filter .15s, background-color .15s, border-color .15s;
}
.btn--filled { background: var(--gold); color: var(--gold-on); }
.btn--filled:hover { filter: brightness(1.08); }
.btn--outlined { background: var(--card); color: var(--text-2); border-color: var(--border); font-size: 15px; font-weight: 500; }
.btn--outlined:hover { border-color: var(--gold); color: var(--text); }
.btn--text { width: auto; min-height: 44px; background: none; color: var(--gold-text); }
.btn--text:hover { background: color-mix(in srgb, var(--gold) 10%, transparent); }
.btn--danger { color: var(--red); }
.btn--small { width: auto; min-height: 44px; font-size: 14px; padding: 0 14px; }
.btn--small .icon { width: 20px; height: 20px; }
.btn--compact { padding: 0 6px; gap: 4px; font-size: 14px; white-space: nowrap; }
.btn--compact .icon { width: 20px; height: 20px; }
@media (min-width: 400px) { .btn--compact { font-size: 15px; gap: 6px; } }
.btn[disabled] { opacity: .5; cursor: default; }

.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-row--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 48px; height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text);
}
.icon-btn:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.icon-btn[disabled] { color: var(--border); cursor: default; background: none; }
.icon-btn--lg .icon { width: 32px; height: 32px; }

.speak-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px; height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--gold-text);
  position: relative;
}
.speak-btn .icon { width: 20px; height: 20px; }
.speak-btn:hover { border-color: var(--gold); }
.speak-btn::after { content: ""; position: absolute; inset: -4px; } /* 48px touch target */

/* ── Learn ───────────────────────────────────────────────── */

.notice-banner {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 16px;
  padding: 6px 4px 6px 14px;
  background: var(--card-raised);
  border-color: var(--gold);
}
.notice-banner__text {
  flex: 1;
  font-size: 13px;
  line-height: 1.4;
  text-decoration: none;
  white-space: pre-line;
}
a.notice-banner__text:hover { text-decoration: underline; }
.notice-banner__close { color: var(--text-muted); }
.notice-banner__close .icon { width: 18px; height: 18px; }

.progress-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--ink);
  border-color: var(--ink);
  color: var(--on-ink);
  text-decoration: none;
  transition: box-shadow .15s, transform .1s;
}
.progress-card:hover { box-shadow: var(--shadow); }
.progress-card:active { transform: scale(.995); }
.progress-card__body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.progress-card__title { font-size: 16px; font-weight: 700; }
.progress-card__meta { margin-top: 8px; font-size: 13px; color: var(--ink-muted); }
.progress-card__play {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--gold-on);
}

.progress-bar {
  display: block;
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--card);
  overflow: hidden;
}
.progress-bar > span {
  position: absolute; inset: 0 auto 0 0;
  border-radius: inherit;
  background: var(--gold);
  transition: width .3s ease;
}
.progress-bar--ink { height: 6px; margin-top: 10px; background: var(--ink-track); }

.category-list { display: grid; gap: 10px; }
@media (min-width: 720px) { .category-list { grid-template-columns: 1fr 1fr; } }
.category-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 10px 12px 14px;
  color: inherit;
}
.category-card__glyph {
  display: grid; place-items: center;
  flex: none;
  width: 52px; height: 52px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}
.category-card__body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.category-card__title { font-size: 16px; font-weight: 700; }
.category-card__meta { font-size: 13px; color: var(--text-muted); }
.category-card__chevron { color: var(--text-muted); }
/* "안녕" needs to shrink to fit the 52px box (the app uses FittedBox). */
.category-list li:last-child .category-card__glyph { font-size: 19px; }

.get-app-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 14px;
  margin-top: 28px;
  padding: 14px;
  background: transparent;
  border-style: dashed;
}
.get-app-inline__icon { width: 48px; height: 48px; border-radius: 12px; box-shadow: 0 0 0 1px var(--border); }
.get-app-inline__body { flex: 1 1 160px; min-width: 0; }
.get-app-inline__title { font-size: 14px; font-weight: 700; }
.get-app-inline__text { font-size: 13px; color: var(--text-2); }
.get-app-inline .btn { flex: 1 0 100%; }
@media (min-width: 480px) { .get-app-inline .btn { flex: 0 0 auto; } }
@media (min-width: 960px) {
  .learn .get-app-inline { display: none; } /* the sidebar has it */
}
.get-app-inline--settings { margin-top: 24px; }

/* ── Letter grid ─────────────────────────────────────────── */

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
}
@media (min-width: 600px) { .item-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); } }

.item-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  aspect-ratio: .78;
  padding: 10px 6px 8px;
  transition: border-color .15s, box-shadow .15s;
}
.item-cell:hover { border-color: var(--gold); box-shadow: var(--shadow); }
.item-cell__link {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
  text-decoration: none;
  border-radius: var(--radius);
}
/* The whole card opens the letter; the speak button sits above the link. */
.item-cell__link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.item-cell__link:focus-visible { outline: none; }
.item-cell__link:focus-visible::after { outline: 3px solid var(--focus); outline-offset: 2px; }
.item-cell__char {
  flex: 1;
  display: grid;
  place-items: center;
  font-size: clamp(34px, 9vw, 44px);
  font-weight: 700;
  line-height: 1.1;
}
.item-cell__char.glyph--jamo { font-size: clamp(40px, 11vw, 52px); }
@media (min-width: 600px) {
  .item-cell__char { font-size: 52px; }
  .item-cell__char.glyph--jamo { font-size: 62px; }
}
.item-cell__roman {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  color: var(--gold-text);
}
.item-cell .speak-btn { margin-top: 6px; z-index: 1; }

/* ── Chips (syllables, word jump bar) ─────────────────────── */

.chip-bar {
  position: sticky;
  top: var(--appbar-h);
  z-index: 5;
  background: var(--bg);
}
.chip-bar__inner {
  display: flex;
  gap: 8px;
  width: min(100% - 32px, 720px);
  margin-inline: auto;
  padding: 6px 2px 8px;
  overflow-x: auto;
  scrollbar-width: thin;
}
@media (min-width: 960px) {
  .chip-bar__inner { width: min(100% - 64px, 920px); flex-wrap: wrap; overflow: visible; }
}
.chip {
  flex: none;
  display: grid;
  place-items: center;
  min-width: 48px;
  height: 44px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}
.chip:hover { border-color: var(--gold); }
.chip[aria-pressed="true"], .chip.is-current {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--gold-on);
}
.chip--sm { min-width: 40px; height: 40px; padding: 0; font-size: 18px; }

.caption { margin: 0 4px 10px; font-size: 13px; color: var(--text-muted); }

/* ── Item detail ─────────────────────────────────────────── */

.detail { display: grid; gap: 24px; touch-action: pan-y; }
.detail__main { display: grid; gap: 10px; align-content: start; }
.detail__side .section-label { margin-top: 0; }
@media (min-width: 960px) {
  .detail { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 32px; align-items: start; }
  .detail__side { padding-top: 4px; }
}

.detail-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  margin-bottom: 4px;
  padding: 28px 20px 24px;
  text-align: center;
  transition: border-color .15s;
  container-type: inline-size;
}
.detail-card:hover { border-color: var(--gold); }
.detail-card__char {
  display: grid;
  place-items: center;
  height: 140px;
  max-width: 100%;
  font-size: min(120px, calc(92cqi / var(--len, 1)));
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
}
.detail-card__char.glyph--jamo { font-size: 140px; }
.detail-card__roman { margin-top: 8px; font-size: 22px; font-weight: 700; color: var(--gold-text); }
.detail-card__desc { margin-top: 6px; font-size: 15px; line-height: 1.4; color: var(--text-2); }
.detail-card__name { margin-top: 10px; font-size: 13px; color: var(--text-muted); }

.example-list { overflow: hidden; }
.example-list li + li { border-top: 1px solid var(--border); }
.example-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  border: 0;
  background: none;
  text-align: left;
}
.example-row:hover { background: color-mix(in srgb, var(--card-raised) 70%, transparent); }
.example-row:focus-visible { outline-offset: -3px; }
.example-row__char { font-size: 20px; font-weight: 700; white-space: nowrap; }
.example-row__meta {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text-2);
}
.example-row__icon { width: 20px; height: 20px; color: var(--gold-text); }

.pager {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  width: min(100% - 24px, 560px);
  margin-inline: auto;
  padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.pager__hint { flex: 1; text-align: center; font-size: 12px; color: var(--text-muted); }
.hint-keys { display: none; }
@media (hover: hover) and (pointer: fine) {
  .hint-touch { display: none; }
  .hint-keys { display: inline; }
}
@media (min-width: 960px) {
  .pager { position: static; width: min(100% - 64px, 960px); padding-top: 12px; }
  .screen > .page--detail { flex: 0 0 auto; }
}

/* ── Words ───────────────────────────────────────────────── */

.page--words .tab-header { width: min(100% - 40px, 760px); margin: 0 auto; padding-top: 14px; }
@media (min-width: 960px) { .page--words .tab-header { width: min(100% - 64px, 1000px); padding-top: 32px; } }

.words-toolbar {
  position: sticky;
  top: 0;
  z-index: 6;
  padding: 0 max(20px, calc((100% - 760px) / 2)) 4px;
  background: var(--bg);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--border) 50%, transparent);
}
@media (min-width: 960px) {
  .words-toolbar { padding-inline: max(32px, calc((100% - 1000px) / 2)); padding-top: 8px; }
}
.search { position: relative; display: flex; align-items: center; }
.search__icon { position: absolute; left: 12px; color: var(--text-muted); pointer-events: none; }
.search__input {
  width: 100%;
  height: 48px;
  padding: 0 48px 0 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-raised);
  font-size: 16px;
  appearance: none;
}
.search__input::placeholder { color: var(--text-muted); opacity: 1; }
.search__input:placeholder-shown { padding-right: 12px; }
.search__input::-webkit-search-cancel-button { display: none; }
.search__input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.search__input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.search__clear { position: absolute; right: 0; color: var(--text-muted); }

.jump-bar {
  display: flex;
  gap: 6px;
  padding: 10px 0 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.jump-bar::-webkit-scrollbar { display: none; }
.jump-bar[hidden] { display: none; }
@media (min-width: 960px) { .jump-bar { flex-wrap: wrap; overflow: visible; } }

.words-count { padding: 6px 4px 2px; text-align: right; font-size: 12px; color: var(--text-muted); }

.words-list {
  --row-h: 4rem;
  --cols: 1;
  width: min(100% - 40px, 760px);
  margin: 0 auto;
  padding-bottom: 24px;
}
@media (min-width: 1200px) {
  .words-list { --cols: 2; width: min(100% - 64px, 1000px); }
}
@media (min-width: 960px) and (max-width: 1199.98px) { .words-list { width: min(100% - 64px, 760px); } }

.word-section {
  scroll-margin-top: calc(var(--toolbar-h, 120px) + 4px);
  content-visibility: auto;
  contain-intrinsic-size: auto calc(2.5rem + var(--rows) * var(--row-h) / var(--cols));
}
.word-section__label {
  display: flex;
  align-items: center;
  height: 2.5rem;
  padding: 12px 4px 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .8px;
  color: var(--text-muted);
}
.word-list { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); column-gap: 32px; }
.words-list > .word-list { padding-top: 4px; }

.word-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--row-h);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.word-row__link {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  height: 100%;
  padding-left: 4px;
  text-decoration: none;
  border-radius: 8px;
}
.word-row__link:hover .word-row__char { text-decoration: underline; text-decoration-color: var(--gold); text-underline-offset: 4px; }
.word-row__link:focus-visible { outline-offset: -2px; }
.word-row__top { display: flex; align-items: baseline; gap: 10px; min-width: 0; white-space: nowrap; overflow: hidden; }
.word-row__char { font-size: 18px; font-weight: 700; }
.word-row__roman {
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  font-weight: 600;
  color: var(--gold-text);
}
.word-row__meaning {
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text-2);
}

/* ── Quiz stages ─────────────────────────────────────────── */

/* minmax(0, …) so the nowrap subtitles ellipsize instead of widening the column past the screen */
.stage-list { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 720px) { .stage-list { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stage-tile {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 12px 14px;
  color: inherit;
  text-align: left;
}
.stage-tile--cleared { background: var(--card-raised); border-color: var(--gold); }
.stage-tile--locked { cursor: not-allowed; }
.stage-tile--locked > * { opacity: .55; }
.stage-tile__badge {
  display: grid; place-items: center;
  flex: none;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--on-ink);
  font-size: 18px;
  font-weight: 800;
}
.stage-tile--cleared .stage-tile__badge { background: var(--gold); color: var(--gold-on); }
.stage-tile--locked .stage-tile__badge { background: var(--border); color: var(--bg); }
:root[data-theme="dark"] .stage-tile--open .stage-tile__badge { box-shadow: inset 0 0 0 1px var(--border); }
.stage-tile__body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stage-tile__title { font-size: 16px; font-weight: 700; }
.stage-tile__subtitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text-muted);
}
.stage-tile__score { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.stage-tile__best { font-size: 11px; color: var(--text-muted); }

.stars { display: inline-flex; }
.stars .icon { width: 18px; height: 18px; color: var(--border); }
.stars .star--on { color: var(--gold); }

/* ── Quiz ────────────────────────────────────────────────── */

.screen--quiz { height: 100vh; height: 100dvh; min-height: 0; }
.quiz-score { font-weight: 700; color: var(--gold-text); white-space: nowrap; }

.quiz {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: min(100% - 40px, 520px);
  min-height: 0;
  margin-inline: auto;
  padding: 4px 0 calc(16px + env(safe-area-inset-bottom));
}
.quiz__progress { display: flex; align-items: center; gap: 12px; }
.quiz__progress .progress-bar { flex: 1; }
.quiz__count { font-weight: 700; font-variant-numeric: tabular-nums; }
.quiz__streak {
  height: 20px;
  margin: 8px 0;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--red);
}
.quiz__prompt {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 120px;
  max-height: 360px;
  padding: 14px 16px 20px;
  container-type: inline-size;
}
.quiz__hint { font-size: 13px; font-weight: 400; color: var(--text-muted); text-align: center; }
.quiz__content { flex: 1; display: grid; place-items: center; min-height: 0; }
.quiz__glyph {
  --max: 110px;
  font-size: min(var(--max), calc(88cqi / var(--len, 1)), 22vh);
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
}
.quiz__glyph.glyph--jamo { --max: 160px; }
.quiz__meaning { font-size: 24px; font-weight: 700; text-align: center; line-height: 1.3; }
.sound-btn {
  display: grid; place-items: center;
  width: 96px; height: 96px;
  border: 0;
  border-radius: 50%;
  background: var(--gold);
  color: var(--gold-on);
}
.sound-btn .icon { width: 48px; height: 48px; }
.sound-btn:hover { filter: brightness(1.08); }

.quiz__options { flex: none; display: grid; gap: 10px; margin-top: 16px; }
.option {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  height: 56px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  transition: background-color .18s, color .18s, border-color .18s, transform .18s;
}
.option:hover:not([aria-disabled]) { border-color: var(--gold); }
.option__key {
  justify-self: center;
  visibility: hidden; /* keeps the 44px column so the label stays centered */
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
}
@media (hover: hover) and (pointer: fine) { .option__key { visibility: visible; } }
.option__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 20px;
  font-weight: 600;
  text-align: center;
}
.option__label--jamo { font-size: 30px; }
.option__mark { display: grid; place-items: center; }
.option[aria-disabled] { cursor: default; }
.option--correct { background: var(--correct-bg); border-color: var(--correct-bg); color: var(--correct-text); transform: scale(1.03); }
.option--wrong { background: var(--wrong-bg); border-color: var(--wrong-bg); color: var(--wrong-text); }
.option--dimmed { color: var(--text-muted); }
.option--correct .option__key, .option--wrong .option__key { color: inherit; border-color: currentColor; }

.quiz__feedback {
  display: grid;
  place-items: center;
  flex: none;
  height: 52px;
  margin-top: 10px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
  overflow: hidden;
}
.quiz__feedback--correct { background: var(--correct-bg); color: var(--correct-text); }
.quiz__feedback--wrong { background: var(--wrong-bg); color: var(--wrong-text); }
.quiz__keys { display: none; margin-top: 12px; text-align: center; font-size: 12px; color: var(--text-muted); }
@media (hover: hover) and (pointer: fine) { .quiz__keys { display: block; } }

@media (max-height: 640px) {
  .option { height: 46px; }
  .quiz__options { gap: 8px; margin-top: 10px; }
  .quiz__options + .quiz__feedback { height: 44px; }
  .quiz__keys { display: none; }
}

/* ── Result ──────────────────────────────────────────────── */

.result { padding-top: 8px; }
.result__stars { display: flex; justify-content: center; align-items: center; }
.result-star { color: var(--border); animation: star-pop .6s cubic-bezier(.34, 1.56, .64, 1) both; animation-delay: calc(var(--i) * 180ms); }
.result-star .icon { width: 56px; height: 56px; }
.result-star--big .icon { width: 72px; height: 72px; }
.result-star.is-on { color: var(--gold); }
@keyframes star-pop { from { transform: scale(0); } to { transform: scale(1); } }
.result__headline { margin-top: 8px; text-align: center; font-size: 26px; font-weight: 800; }
.result__hint { margin-top: 4px; text-align: center; color: var(--text-2); }
.result__stats { display: grid; gap: 8px; margin-top: 20px; }
.stat { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; }
.stat dt { color: var(--text-2); }
.stat dd { font-size: 17px; font-weight: 700; }
.stat--highlight dd { font-size: 20px; color: var(--gold-text); }
.missed-list { overflow: hidden; }
.missed-list li + li { border-top: 1px solid var(--border); }
.missed-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 8px 16px;
  border: 0;
  background: none;
  text-align: left;
}
.missed-row:hover { background: color-mix(in srgb, var(--card-raised) 70%, transparent); }
.missed-row:focus-visible { outline-offset: -3px; }
.missed-row__char { font-size: 26px; font-weight: 700; min-width: 40px; }
.missed-row__char--jamo { font-size: 40px; }
.missed-row__meta { flex: 1; min-width: 0; font-size: 14px; color: var(--text-2); }
.missed-row__icon { color: var(--gold-text); }
.result__actions { display: grid; gap: 10px; margin-top: 24px; }

/* ── Stroke practice ─────────────────────────────────────── */

.stroke { display: flex; flex-direction: column; }
.stroke__roman { text-align: center; font-size: 20px; font-weight: 700; color: var(--gold-text); }
.stroke__desc { margin-top: 4px; text-align: center; font-size: 14px; color: var(--text-2); }
.stroke-pad {
  width: 100%;
  max-width: 360px;
  margin: 16px auto 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}
.stroke-pad__canvas {
  width: 100%;
  aspect-ratio: 1;
  touch-action: none;
  cursor: crosshair;
  background: var(--card-raised);
  -webkit-user-select: none;
  user-select: none;
}
.stroke__status { min-height: 1.4em; text-align: center; font-size: 13px; color: var(--text-muted); }
.stroke__status.is-done { color: var(--green); font-weight: 700; }
.stroke .btn-row { margin: 16px 0 10px; }

/* ── Settings ────────────────────────────────────────────── */

.segmented {
  display: flex;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  min-width: 0;
}
.segmented__option { position: relative; flex: 1; display: flex; }
.segmented__option + .segmented__option { border-left: 1px solid var(--border); }
.segmented input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.segmented__label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  pointer-events: none;
}
.segmented__label .icon { width: 18px; height: 18px; }
.segmented input:checked + .segmented__label { background: var(--gold); color: var(--gold-on); font-weight: 600; }
.segmented input:hover:not(:checked) + .segmented__label { background: color-mix(in srgb, var(--gold) 10%, transparent); }
.segmented input:focus-visible + .segmented__label { outline: 3px solid var(--focus); outline-offset: -3px; }

.setting-row { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 16px; }
.setting-row__label { flex: 1; color: var(--text-2); }
.setting-row .segmented { flex: none; }
.setting-note { padding: 12px 16px; font-size: 13px; color: var(--text-muted); }
.setting-note--warn { color: var(--red); }
.divider { height: 1px; background: var(--border); }

.list-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  font-size: 16px;
  text-align: left;
  text-decoration: none;
}
.list-btn:hover { background: color-mix(in srgb, var(--card-raised) 70%, transparent); }
.list-btn:focus-visible { outline-offset: -3px; }
.list-btn--danger { color: var(--red); }
.list-btn--link { color: var(--green); }
.list-btn__trail { width: 18px; height: 18px; margin-left: auto; color: var(--text-muted); }
.info-row { display: flex; justify-content: space-between; gap: 12px; padding: 14px 16px; }
.info-row span:first-child { color: var(--text-2); }
.info-row span:last-child { font-weight: 600; text-align: right; }

/* ── Feedback: toast, dialog, loading ────────────────────── */

.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  max-width: min(92vw, 480px);
  padding: 12px 18px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  box-shadow: var(--shadow);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast:empty { visibility: hidden; }
body.is-sub .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 960px) {
  .toast, body.is-sub .toast { bottom: 24px; left: calc(50% + var(--sidebar-w) / 2); }
}

.dialog {
  width: min(92vw, 400px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
.dialog::backdrop { background: var(--scrim); }
.dialog__body { display: block; padding: 24px 24px 16px; }
.dialog__title { font-size: 20px; font-weight: 700; }
.dialog__message { margin-top: 12px; font-size: 14px; line-height: 1.6; color: var(--text-2); white-space: pre-line; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dialog--centered .dialog__title, .dialog--centered .dialog__message { text-align: center; }
.dialog--centered .dialog__title { font-size: 18px; }
.dialog--centered .dialog__actions .btn { width: 100%; min-height: 48px; }

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 160px;
  color: var(--text-muted);
  font-size: 14px;
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { padding: 48px 16px; text-align: center; color: var(--text-muted); }
.empty-state p + p, .empty-state p + .btn { margin-top: 12px; }
.empty-state .btn { width: auto; }

.boot { min-height: 60vh; }
.boot__message { padding: 48px 20px; text-align: center; }
