/* =========================================================================
   Jago Bahasa — Design System
   ========================================================================= */

:root {
  /* Brand */
  --brand: #6d5efc;
  --brand-600: #5a48f0;
  --brand-700: #4d3ddb;
  --brand-soft: rgba(109, 94, 252, .14);
  --accent: #ff9f43;
  --accent-soft: rgba(255, 159, 67, .16);
  --success: #2dd4a7;
  --danger: #ff5e7a;
  --danger-600: #e02a4c; /* darker fill so white button text clears 4.5:1 */
  --warning: #ffce4a;
  /* The three above are FILL colours. When the same hue is used as text or as a
     standalone icon it needs 4.5:1 against the surface, which the light theme
     overrides below provide. Dark mode is bright-on-dark and already passes. */
  --success-text: var(--success);
  --danger-text: var(--danger);
  --accent-text: var(--accent);

  /* Radii & shadows */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-pill: 999px;
  --shadow-1: 0 1px 2px rgba(10, 12, 30, .06), 0 2px 8px rgba(10, 12, 30, .05);
  --shadow-2: 0 8px 30px rgba(10, 12, 30, .12);
  --shadow-pop: 0 18px 50px rgba(40, 30, 120, .28);

  /* Typography */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-cjk: "Noto Sans CJK", "Hiragino Sans", "Microsoft YaHei", "Malgun Gothic", var(--font);

  /* Motion */
  --ease: cubic-bezier(.22, .61, .36, 1);
  --t-fast: .16s;
  --t-med: .3s;

  --maxw: 1080px;
}

/* ---- Dark (default) ---- */
[data-theme="dark"] {
  --bg: #0f1226;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #1c1d4a 0%, transparent 60%),
             radial-gradient(900px 500px at 110% 10%, #2a1b52 0%, transparent 55%);
  --surface: #171a35;
  --surface-2: #1f2244;
  --surface-3: #262a52;
  --line: rgba(255, 255, 255, .08);
  --line-strong: rgba(255, 255, 255, .16);
  /* Interactive controls (inputs, quiz options, word chips) must have a 3:1
     boundary to satisfy WCAG 1.4.11; the decorative --line dividers need not. */
  --line-input: rgba(255, 255, 255, .36);
  --text: #eef0ff;
  --text-dim: #aab0d8;
  --text-faint: #7e85b3;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  --shadow-2: 0 14px 40px rgba(0, 0, 0, .45);
}

/* ---- Light ---- */
[data-theme="light"] {
  --bg: #f4f5fc;
  --bg-grad: radial-gradient(1100px 560px at 8% -12%, #e7e6ff 0%, transparent 60%),
             radial-gradient(900px 480px at 112% 6%, #ffe9d4 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f7f8fe;
  --surface-3: #eef0fb;
  --line: rgba(20, 24, 60, .09);
  --line-strong: rgba(20, 24, 60, .16);
  --line-input: rgba(20, 24, 60, .50);
  --text: #161a33;
  --text-dim: #515877;
  /* #878da8 only reached 2.89:1 on --surface-3; this clears 3:1 everywhere. */
  --text-faint: #6f7590;
  /* Mint, coral and amber are lovely as fills but unreadable as text on a light
     page (1.74:1, 2.94:1 and 2.04:1). These darker twins clear 4.5:1 while
     keeping the hue; the fills themselves are untouched. */
  --success-text: #0a785d;
  --danger-text: #d1123a;
  --accent-text: #a75500;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  line-height: 1.5;
  min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

@media (min-width: 760px) {
  body { padding-bottom: 40px; }
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; letter-spacing: -.02em; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; }

.skip-link {
  position: fixed; left: 12px; top: -60px; z-index: 200;
  background: var(--brand); color: #fff; padding: 10px 16px; border-radius: var(--r-sm);
  transition: top var(--t-fast) var(--ease);
}
.skip-link:focus { top: 12px; }

:focus-visible { outline: 2.5px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* =========================================================================
   App bar
   ========================================================================= */
.appbar {
  position: sticky; top: 0; z-index: 60;
  /* Clear the notch/status bar on iPhone X/11+ (esp. installed to Home Screen). */
  padding-top: env(safe-area-inset-top);
  background: var(--surface); /* opaque fallback for iOS < 16.2 (no color-mix) */
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.appbar__inner {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: center; gap: 14px;
  padding: 10px clamp(14px, 4vw, 28px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.12rem; letter-spacing: -.02em; }
.brand__logo { border-radius: 9px; box-shadow: var(--shadow-1); }
.brand__accent { color: var(--brand); }
.brand__name { white-space: nowrap; }

.topnav { display: none; margin-left: 8px; gap: 4px; }
@media (min-width: 760px) {
  .topnav { display: flex; }
}
.topnav a {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 14px; border-radius: var(--r-pill);
  color: var(--text-dim); font-weight: 600; font-size: .94rem;
  transition: background var(--t-fast), color var(--t-fast);
}
.topnav a:hover { background: var(--surface-3); color: var(--text); }
.topnav a.is-active { background: var(--brand-soft); color: var(--brand); }
.topnav__ico { font-size: 1rem; }

.appbar__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.iconbtn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text); border-radius: var(--r-pill);
  padding: 8px 12px; cursor: pointer; font-weight: 700; font-size: .85rem;
  transition: transform var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}
.iconbtn:hover { background: var(--surface-3); transform: translateY(-1px); }
.iconbtn:active { transform: translateY(0); }
.iconbtn__label { letter-spacing: .03em; }

.theme-ico { font-size: 1.05rem; }
[data-theme="dark"] .theme-ico--light { display: none; }
[data-theme="light"] .theme-ico--dark { display: none; }

.ui-lang-menu {
  position: absolute; right: clamp(14px, 4vw, 28px); top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-md); box-shadow: var(--shadow-pop);
  padding: 6px; min-width: 200px; z-index: 80;
  display: grid; gap: 2px;
}
.ui-lang-menu[hidden] { display: none; }
.ui-lang-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; color: var(--text); cursor: pointer;
  padding: 10px 12px; border-radius: var(--r-sm); text-align: left; font-size: .94rem; font-weight: 600;
}
.ui-lang-menu button:hover { background: var(--surface-3); }
.ui-lang-menu button[aria-selected="true"] { background: var(--brand-soft); color: var(--brand); }
.ui-lang-menu .flag { font-size: 1.2rem; }

/* =========================================================================
   Layout & shared
   ========================================================================= */
.main { max-width: var(--maxw); margin: 0 auto; padding: clamp(18px, 4vw, 32px) clamp(14px, 4vw, 28px) 60px; }
.view { animation: fade .35s var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.section-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 8px 0 16px; }
.section-head h2 { font-size: clamp(1.25rem, 3.4vw, 1.6rem); }
.section-head p { margin: 4px 0 0; color: var(--text-dim); font-size: .94rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; font-weight: 800; color: var(--brand); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-1);
}
.grid { display: grid; gap: 16px; }
.cols-auto { grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  border: 0; cursor: pointer; font-weight: 700; font-size: .96rem;
  padding: 12px 20px; border-radius: var(--r-pill); color: #fff;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-700) 100%);
  box-shadow: 0 8px 22px -8px var(--brand);
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast), filter var(--t-fast);
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 14px 30px -10px var(--brand); }
.btn:active { transform: translateY(0); }
.btn--ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line-strong); box-shadow: none; }
.btn--ghost:hover { background: var(--surface-3); box-shadow: none; }
.btn--accent { background: linear-gradient(135deg, #ffb259, var(--accent)); box-shadow: 0 8px 22px -8px var(--accent); color: #3a2200; }
.btn--block { width: 100%; }
.btn--sm { padding: 9px 15px; font-size: .88rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-3); border: 1px solid var(--line);
  padding: 5px 11px; border-radius: var(--r-pill); font-size: .8rem; font-weight: 700; color: var(--text-dim);
}
.chip--brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.chip--accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.chip--success { background: rgba(45,212,167,.14); color: var(--success-text); border-color: transparent; }

.progress { height: 9px; background: var(--surface-3); border-radius: var(--r-pill); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand), var(--accent)); transition: width .6s var(--ease); }

/* =========================================================================
   Hero / Home
   ========================================================================= */
.hero {
  position: relative; overflow: hidden;
  border-radius: var(--r-lg); padding: clamp(22px, 5vw, 40px);
  background: linear-gradient(135deg, var(--brand-700), var(--brand) 55%, #7d6bff);
  color: #fff; box-shadow: var(--shadow-2);
}
.hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(420px 220px at 88% -20%, rgba(255,255,255,.28), transparent 60%);
}
.hero__row { display: grid; gap: 22px; align-items: center; position: relative; z-index: 1; }
@media (min-width: 720px) { .hero__row { grid-template-columns: 1.4fr 1fr; } }
.hero h1 { font-size: clamp(1.7rem, 5vw, 2.6rem); margin-bottom: .3em; }
.hero p { color: rgba(255,255,255,.92); margin: 0 0 18px; max-width: 46ch; }
.hero__cta { display: flex; gap: 10px; flex-wrap: wrap; }
.hero .btn--ghost { background: rgba(255,255,255,.16); color: #fff; border-color: rgba(255,255,255,.3); backdrop-filter: blur(4px); }
.hero .btn--ghost:hover { background: rgba(255,255,255,.26); }

.streak-card {
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.22);
  border-radius: var(--r-md); padding: 18px; backdrop-filter: blur(6px);
}
.streak-card .big { font-size: 2.6rem; font-weight: 800; line-height: 1; }
.streak-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; margin-top: 14px; }
.streak-grid span {
  aspect-ratio: 1; border-radius: 8px; background: rgba(255,255,255,.18);
  display: grid; place-items: center; font-size: .68rem; font-weight: 700;
}
.streak-grid span.on { background: var(--accent); color: #3a2200; }

/* Stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-top: 18px; }
.stat { padding: 18px; }
.stat .num { font-size: 1.9rem; font-weight: 800; letter-spacing: -.03em; display: flex; align-items: center; gap: 8px; }
.stat .lbl { color: var(--text-dim); font-size: .85rem; font-weight: 600; margin-top: 2px; }
.stat .ico { font-size: 1.4rem; }

/* =========================================================================
   Course cards
   ========================================================================= */
.course-card { padding: 0; overflow: hidden; cursor: pointer; transition: transform var(--t-fast) var(--ease), box-shadow var(--t-med); }
.course-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-2); border-color: var(--line-strong); }
.course-card__top { padding: 18px 18px 14px; display: flex; align-items: center; gap: 14px; }
.flag {
  width: 52px; height: 52px; flex: 0 0 auto; border-radius: 14px;
  display: grid; place-items: center; font-size: 1.9rem;
  background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--line);
}
.course-card__top h3 { margin: 0; font-size: 1.08rem; }
.course-card__top .native { color: var(--text-faint); font-size: .82rem; font-weight: 600; }
.course-card__body { padding: 0 18px 16px; }
.course-card__meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; }
.course-card__foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.course-card__foot small { color: var(--text-dim); font-weight: 700; }

/* =========================================================================
   Lesson list & detail
   ========================================================================= */
.crumb { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: .9rem; font-weight: 600; margin-bottom: 14px; flex-wrap: wrap; }
.crumb a:hover { color: var(--brand); }
.crumb span.sep { opacity: .5; }

.course-header { display: flex; gap: 18px; align-items: center; padding: 22px; margin-bottom: 20px; flex-wrap: wrap; }
.course-header .flag { width: 64px; height: 64px; font-size: 2.3rem; }
.course-header h1 { font-size: clamp(1.4rem, 4vw, 2rem); margin: 0; }
.course-header p { margin: 4px 0 0; color: var(--text-dim); }
.course-header .progress-wrap { flex: 1 1 220px; min-width: 200px; }

.lesson-row {
  display: flex; align-items: center; gap: 14px; padding: 16px 18px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface);
  cursor: pointer; transition: transform var(--t-fast), border-color var(--t-fast), background var(--t-fast);
}
.lesson-row:hover { transform: translateX(3px); border-color: var(--brand); background: var(--surface-2); }
.lesson-row__num {
  width: 42px; height: 42px; flex: 0 0 auto; border-radius: 12px; display: grid; place-items: center;
  font-weight: 800; background: var(--brand-soft); color: var(--brand); font-size: 1.05rem;
}
.lesson-row.done .lesson-row__num { background: rgba(45,212,167,.16); color: var(--success-text); }
.lesson-row__main { flex: 1; min-width: 0; }
.lesson-row__main h3 { margin: 0 0 2px; font-size: 1.02rem; }
.lesson-row__main p { margin: 0; color: var(--text-dim); font-size: .86rem; }
.lesson-row__arrow { color: var(--text-faint); font-size: 1.3rem; }

/* Vocab cards */
.vocab-list { display: grid; gap: 12px; }
.vocab {
  display: flex; align-items: center; gap: 16px; padding: 16px 18px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--shadow-1);
}
.vocab__term { font-size: 1.5rem; font-weight: 800; letter-spacing: -.01em; }
.vocab__term.cjk { font-family: var(--font-cjk); }
.vocab__reading { color: var(--brand); font-weight: 700; font-size: .9rem; }
.vocab__mid { flex: 1; min-width: 0; }
.vocab__meaning { font-weight: 700; }
.vocab__ex { color: var(--text-dim); font-size: .86rem; margin-top: 3px; }

/* ---- Conversation / dialogue (chat bubbles) ---- */
.dialog { display: grid; gap: 12px; margin: 2px 0; }
.dialog__turn { display: flex; align-items: flex-end; gap: 8px; max-width: 100%; }
.dialog__turn--b { flex-direction: row-reverse; }
.dialog__who {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: .82rem; color: #fff;
}
.dialog__who--a { background: linear-gradient(135deg, var(--brand), var(--brand-700)); }
.dialog__who--b { background: linear-gradient(135deg, var(--accent), #ff8a3d); }
.dialog__who--c { background: linear-gradient(135deg, #10b981, #059669); }
.dialog__who--d { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }
.dialog__bubble {
  max-width: min(82%, 640px); padding: 12px 14px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-1);
}
.dialog__turn--a .dialog__bubble { border-bottom-left-radius: 5px; }
.dialog__turn--b .dialog__bubble { border-bottom-right-radius: 5px; background: var(--brand-soft); border-color: transparent; }
.dialog__term { font-size: 1.15rem; font-weight: 800; line-height: 1.35; }
.dialog__term.cjk { font-family: var(--font-cjk); }
.dialog__mean { color: var(--text-dim); font-weight: 700; font-size: .9rem; margin-top: 3px; }
.dialog__speak { margin-top: 8px; }

/* ---- Daily goal card ---- */
.daily-card { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 18px 20px; }
.daily-ring { width: 76px; height: 76px; flex: 0 0 auto; }
.daily-card__txt { flex: 1 1 200px; display: flex; flex-direction: column; gap: 2px; }
.daily-card__txt strong { font-size: 1.05rem; }
.daily-card__txt > span { color: var(--text-dim); font-weight: 700; font-size: .9rem; }
.daily-card__actions { display: flex; flex-direction: column; gap: 8px; }
.goal-picker { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.goal-opt {
  padding: 6px 11px; border-radius: var(--r-pill); border: 1px solid var(--line);
  background: var(--surface-3); color: var(--text-dim); font-weight: 700; font-size: .8rem; cursor: pointer;
  transition: transform var(--t-fast), background var(--t-fast), color var(--t-fast);
}
.goal-opt:hover { transform: translateY(-1px); }
.goal-opt.on { background: var(--brand); color: #fff; border-color: transparent; }

/* ---- Typing practice ---- */
.type-form { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 16px; }
.type-input {
  width: 100%; max-width: 460px; padding: 15px 18px; font-size: 1.25rem; font-weight: 700; text-align: center;
  border-radius: var(--r-md); border: 2px solid var(--line-input); background: var(--surface); color: var(--text);
  transition: border-color var(--t-fast);
}
.type-input:focus { outline: none; border-color: var(--brand); }
.type-input:disabled { opacity: .8; }
.type-input.cjk { font-family: var(--font-cjk); }
.type-feedback { font-weight: 700; font-size: 1rem; text-align: center; min-height: 1.4em; }
.type-feedback.ok { color: var(--success-text); }
.type-feedback.no { color: var(--danger-text); }
.type-feedback em { color: var(--text-dim); font-style: normal; }

/* ---- Match game ---- */
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.match-col { display: grid; gap: 10px; align-content: start; }
.match-cell {
  padding: 14px 12px; border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-weight: 700; font-size: 1rem; cursor: pointer;
  min-height: 58px; text-align: center;
  transition: transform var(--t-fast), border-color var(--t-fast), background var(--t-fast);
}
.match-cell:hover:not(.done) { transform: translateY(-2px); border-color: var(--brand); }
.match-cell.cjk { font-family: var(--font-cjk); }
.match-cell.sel { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.match-cell.done { visibility: hidden; }
.match-cell.bad { border-color: var(--danger); background: rgba(255,94,122,.12); color: var(--danger-text); animation: mShake .4s; }
@keyframes mShake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-5px)} 75%{transform:translateX(5px)} }

/* ---- Favorite star ---- */
.favbtn {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  background: transparent; border: 1px solid var(--line); color: var(--text-faint); font-size: 1.15rem; line-height: 1;
  transition: transform var(--t-fast), color var(--t-fast), background var(--t-fast);
}
.favbtn:hover { transform: scale(1.08); color: var(--accent-text); }
.favbtn.on { color: var(--accent-text); border-color: transparent; background: var(--accent-soft); }

/* ---- Speaking (pronunciation) ---- */
.speak-zone { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 18px; }
.mic-btn {
  width: 84px; height: 84px; border-radius: 50%; border: 0; cursor: pointer; color: #fff; font-size: 2rem;
  background: linear-gradient(135deg, var(--brand), var(--brand-700)); box-shadow: var(--shadow-1);
  transition: transform var(--t-fast);
}
.mic-btn:hover { transform: scale(1.05); }
.mic-btn.listening { animation: micPulse 1.1s infinite; }
@keyframes micPulse { 0%{box-shadow:0 0 0 0 rgba(109,94,252,.5)} 70%{box-shadow:0 0 0 18px rgba(109,94,252,0)} 100%{box-shadow:0 0 0 0 rgba(109,94,252,0)} }
.speak-hint { color: var(--text-dim); font-weight: 700; font-size: .9rem; }

/* ---- Hands-free audio ---- */
.audio-card { text-align: center; padding: 30px 18px; }
.audio-term { font-size: clamp(2rem, 8vw, 3rem); font-weight: 800; }
.audio-term.cjk { font-family: var(--font-cjk); }
.audio-mean { color: var(--text-dim); font-weight: 700; font-size: 1.1rem; margin-top: 8px; }
.audio-controls { display: flex; gap: 10px; justify-content: center; align-items: center; margin-top: 18px; flex-wrap: wrap; }

/* ---- Sentence builder ---- */
.build-mean { font-size: 1.25rem; font-weight: 700; margin-top: 4px; }
.build-answer {
  min-height: 58px; display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; margin: 14px 0;
  border: 2px dashed var(--line-input); border-radius: var(--r-md); align-content: flex-start;
}
.build-bank { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.build-placeholder { color: var(--text-faint); font-weight: 600; align-self: center; }
.chip-word {
  padding: 10px 14px; border-radius: var(--r-sm); border: 1px solid var(--line-input);
  background: var(--surface); color: var(--text); font-weight: 700; font-size: 1rem; cursor: pointer;
  transition: transform var(--t-fast), border-color var(--t-fast);
}
.chip-word:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--brand); }
.chip-word:disabled { opacity: .35; cursor: default; }
.build-answer .chip-word { background: var(--brand-soft); border-color: transparent; color: var(--brand); }

/* ---- Stats: heatmap, trend, bars ---- */
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 13px); gap: 3px; min-width: max-content; }
.hm-cell { width: 13px; height: 13px; border-radius: 3px; background: var(--surface-3); }
.hm-blank { background: transparent; }
.hm-0 { background: var(--surface-3); }
.hm-1 { background: color-mix(in srgb, var(--brand) 30%, var(--surface-3)); }
.hm-2 { background: color-mix(in srgb, var(--brand) 55%, var(--surface-3)); }
.hm-3 { background: color-mix(in srgb, var(--brand) 78%, var(--surface-3)); }
.hm-4 { background: var(--brand); }
.hm-legend { display: flex; align-items: center; gap: 4px; margin-top: 10px; color: var(--text-dim); font-size: .8rem; font-weight: 700; }
.hm-legend .hm-cell { display: inline-block; }
.trend { display: flex; gap: 5px; align-items: flex-end; height: 96px; }
.trend-bar { flex: 1; background: var(--surface-3); border-radius: 5px; display: flex; align-items: flex-end; overflow: hidden; min-width: 6px; }
.trend-bar i { width: 100%; min-height: 3px; background: linear-gradient(180deg, var(--brand), var(--brand-700)); border-radius: 5px; }
.bar-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.bar-row__lbl { flex: 0 0 34%; font-weight: 700; font-size: .9rem; }
.bar-row__val { flex: 0 0 auto; font-weight: 800; font-size: .9rem; min-width: 44px; text-align: right; }
.bar-row__val small { color: var(--text-faint); font-weight: 600; }

/* ---- Settings ---- */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.set-row:last-child { border-bottom: 0; }
.set-row > span { font-weight: 700; }
.accent-swatches { display: flex; gap: 8px; }
.accent-sw { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.accent-sw.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.accent-sw--violet { background: #6d5efc; }
.accent-sw--blue { background: #3b82f6; }
.accent-sw--green { background: #10b981; }
.accent-sw--orange { background: #f97316; }
.accent-sw--pink { background: #ec4899; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-pill); overflow: hidden; }
.seg-opt { padding: 7px 15px; background: var(--surface); color: var(--text-dim); border: 0; font-weight: 700; cursor: pointer; }
.seg-opt.on { background: var(--brand); color: #fff; }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch__track { position: absolute; inset: 0; background: var(--surface-3); border-radius: 999px; transition: background var(--t-fast); cursor: pointer; }
.switch__track::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform var(--t-fast); }
.switch input:checked + .switch__track { background: var(--brand); }
.switch input:checked + .switch__track::before { transform: translateX(20px); }
.time-input { padding: 8px 10px; border-radius: var(--r-sm); border: 1px solid var(--line-input); background: var(--surface); color: var(--text); font-weight: 700; }

/* ---- Accessibility toggles ---- */
:root.text-lg { font-size: 112.5%; }
:root.dyslexic body { letter-spacing: .035em; word-spacing: .12em; line-height: 1.75; }

/* ---- Dictionary / global search ---- */
.dict-controls { padding: 14px; margin-bottom: 14px; display: grid; gap: 12px; }
.dict-search {
  width: 100%; padding: 13px 16px; border-radius: var(--r-md); border: 1.5px solid var(--line-input);
  background: var(--surface-2); color: var(--text); font-size: 1.02rem; font-family: inherit;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.dict-search:focus { outline: none; border-color: var(--brand); background: var(--surface); }
.dict-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.dict-select {
  padding: 9px 12px; border-radius: var(--r-md); border: 1.5px solid var(--line-input);
  background: var(--surface-2); color: var(--text); font-size: .9rem; font-family: inherit; font-weight: 600; cursor: pointer;
}
.dict-select:focus { outline: none; border-color: var(--brand); }
.dict-check { margin: 0; }
.dict-count { color: var(--text-dim); font-size: .86rem; font-weight: 600; margin: 0 2px 12px; }
.dict-results { display: grid; gap: 10px; }
.dict-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; box-shadow: var(--shadow-1); }
.dict-item__head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.dict-item__flag { font-size: 1.15rem; }
.dict-item__crumb { color: var(--text-dim); font-size: .78rem; font-weight: 700; }
.dict-item__lvl { margin-left: auto; }
.dict-vocab { border: 0; padding: 0; background: transparent; box-shadow: none; }

/* ---- Daily review (SRS) + cloze ---- */
.review-cta { display: flex; align-items: center; gap: 14px; padding: 16px 18px; text-decoration: none; color: inherit; }
.review-cta__ico { font-size: 1.8rem; }
.review-cta__txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.review-cta__txt strong { font-size: 1.05rem; }
.review-cta__txt span { color: var(--text-dim); font-size: .86rem; font-weight: 600; }
.review-wrap { max-width: 560px; margin: 0 auto; }
.review-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.review-top .progress { flex: 1; }
.review-card { text-align: center; padding: 28px 20px; }
.review-term { font-size: clamp(2rem, 7vw, 2.6rem); font-weight: 800; letter-spacing: -.01em; }
.review-term.cjk { font-family: var(--font-cjk); }
.review-answer { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.review-mean { font-size: 1.2rem; font-weight: 700; }
.review-actions { margin-top: 14px; text-align: center; }
.review-actions .btn { min-width: 220px; }
.review-grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.grade { padding: 13px 6px; font-size: .86rem; border: 0; }
.grade--again { background: var(--danger); color: #fff; }
.grade--hard { background: var(--warning); color: #3a2a00; }
.grade--good { background: var(--brand); color: #fff; }
.grade--easy { background: var(--success); color: #04231a; }
.cloze-sentence { font-size: 1.3rem; font-weight: 700; line-height: 1.55; margin-top: 6px; }
.cloze-sentence.cjk { font-family: var(--font-cjk); }
.quiz-opt.cjk { font-family: var(--font-cjk); }
.speakbtn {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; cursor: pointer;
  background: var(--surface-3); border: 1px solid var(--line); color: var(--text); font-size: 1.15rem;
  transition: transform var(--t-fast), background var(--t-fast);
}
.speakbtn:hover { background: var(--brand-soft); color: var(--brand); transform: scale(1.06); }
.speakbtn:active { transform: scale(.96); }

/* No voice installed for this language. The button still works — it shows the
   word and says why it stayed silent — but it stops promising audio it cannot
   deliver. Dashed, because a dashed control reads as "unavailable" without
   the greyed-out look of one that is disabled and unclickable. */
.is-mute {
  opacity: .55; border-style: dashed !important;
  border-color: var(--line-strong) !important;
}
.is-mute:hover { background: var(--surface-3); color: var(--text); transform: none; }
.is-mute::after {
  content: "🚫"; position: absolute; right: -2px; bottom: -2px;
  font-size: .62rem; line-height: 1; filter: grayscale(1);
}
.speakbtn.is-mute, .btn.is-mute { position: relative; }

/* Practice launcher */
.practice-bar { display: flex; gap: 12px; flex-wrap: wrap; margin: 22px 0; }

/* =========================================================================
   Flashcards
   ========================================================================= */
.flash-wrap { max-width: 460px; margin: 0 auto; text-align: center; }
.flash-count { color: var(--text-dim); font-weight: 700; margin-bottom: 14px; }
.flashcard {
  perspective: 1400px; height: 280px; cursor: pointer; margin-bottom: 18px;
}
.flashcard__inner {
  position: relative; width: 100%; height: 100%; transition: transform .6s var(--ease);
  -webkit-transform-style: preserve-3d; transform-style: preserve-3d;
}
.flashcard.flipped .flashcard__inner { transform: rotateY(180deg); }
.flashcard__face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: var(--r-lg); display: grid; place-content: center; gap: 10px; padding: 24px;
  box-shadow: var(--shadow-2);
}
.flashcard__front { background: var(--surface); border: 1px solid var(--line-strong); }
.flashcard__front .big { font-size: 2.6rem; font-weight: 800; }
.flashcard__front .big.cjk { font-family: var(--font-cjk); }
.flashcard__back { background: linear-gradient(135deg, var(--brand-700), var(--brand)); color: #fff; transform: rotateY(180deg); }
.flashcard__back .big { font-size: 2rem; font-weight: 800; }
.flashcard__hint { color: var(--text-faint); font-size: .82rem; }
.flash-actions { display: flex; gap: 12px; }
.flash-actions .btn { flex: 1; }

/* =========================================================================
   Quiz
   ========================================================================= */
.quiz-wrap { max-width: 580px; margin: 0 auto; }
.quiz-top { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.quiz-top .progress { flex: 1; }
.quiz-q { padding: 26px 22px; text-align: center; margin-bottom: 18px; }
.quiz-q .ask { color: var(--text-dim); font-size: .9rem; font-weight: 700; margin-bottom: 8px; }
.quiz-q .term { font-size: 2.1rem; font-weight: 800; }
.quiz-q .term.cjk { font-family: var(--font-cjk); }
.quiz-options { display: grid; gap: 12px; }
.quiz-opt {
  text-align: left; padding: 16px 18px; border-radius: var(--r-md); cursor: pointer;
  background: var(--surface); border: 1.5px solid var(--line-input); color: var(--text);
  font-size: 1rem; font-weight: 600; transition: transform var(--t-fast), border-color var(--t-fast), background var(--t-fast);
}
.quiz-opt:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--brand); }
.quiz-opt.correct { border-color: var(--success); background: rgba(45,212,167,.14); color: var(--success-text); }
.quiz-opt.wrong { border-color: var(--danger); background: rgba(255,94,122,.12); color: var(--danger-text); }
.quiz-opt:disabled { cursor: default; }

.quiz-result { text-align: center; padding: 34px 22px; }
.quiz-result .ring { width: 140px; height: 140px; margin: 0 auto 18px; }
.quiz-result h2 { font-size: 1.6rem; }
.quiz-result .scoreline { color: var(--text-dim); font-weight: 700; margin-bottom: 8px; }
.xp-pop { color: var(--accent-text); font-weight: 800; font-size: 1.2rem; }

/* Achievements */
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.ach { padding: 18px; text-align: center; opacity: .45; filter: grayscale(.8); transition: opacity var(--t-med), filter var(--t-med), transform var(--t-fast); }
.ach.unlocked { opacity: 1; filter: none; }
.ach.unlocked:hover { transform: translateY(-3px); }
.ach .emoji { font-size: 2.2rem; }
.ach h4 { margin: 8px 0 2px; font-size: .95rem; }
.ach p { margin: 0; color: var(--text-dim); font-size: .78rem; }

/* Empty / misc */
.empty { text-align: center; padding: 50px 20px; color: var(--text-dim); }
.empty .emoji { font-size: 3rem; margin-bottom: 10px; }

.feature-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.feature { padding: 20px; }
.feature .emoji { font-size: 1.8rem; }
.feature h3 { font-size: 1.05rem; margin: 10px 0 6px; }
.feature p { margin: 0; color: var(--text-dim); font-size: .9rem; }

.prose { max-width: 70ch; }
.prose p { color: var(--text-dim); }
.prose h2 { margin-top: 28px; }

/* Kaki halaman Tentang: hak cipta + kredit pembuat, sengaja tak mencolok. */
.about-credit { text-align: center; color: var(--text-faint); margin-top: 30px; font-size: .85rem; line-height: 1.7; }
.about-credit a { color: var(--text-dim); text-decoration: underline; text-underline-offset: 2px; }
.about-credit a:hover { color: var(--text); }

/* =========================================================================
   Bottom nav (mobile)
   ========================================================================= */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: flex; justify-content: space-around;
  background: var(--surface); /* opaque fallback for iOS < 16.2 (no color-mix) */
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--line);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
}
@media (min-width: 760px) { .bottomnav { display: none; } }
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--text-faint); font-size: .68rem; font-weight: 700; padding: 6px 0; border-radius: var(--r-sm);
  transition: color var(--t-fast);
}
.bottomnav a span:first-child { font-size: 1.3rem; }
.bottomnav a.is-active { color: var(--brand); }

/* Toast & install */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 120;
  background: var(--surface); color: var(--text); border: 1px solid var(--line-strong);
  padding: 12px 18px; border-radius: var(--r-pill); box-shadow: var(--shadow-pop);
  font-weight: 700; font-size: .9rem; opacity: 0; transition: opacity var(--t-med), transform var(--t-med);
  pointer-events: none; max-width: 92vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (min-width: 760px) { .toast { bottom: 28px; } }

.install-fab {
  position: fixed; right: 16px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 110;
  display: inline-flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--brand), var(--brand-700)); color: #fff;
  border: 0; border-radius: var(--r-pill); padding: 12px 18px; font-weight: 800; cursor: pointer;
  box-shadow: var(--shadow-pop); animation: bob 2.6s ease-in-out infinite;
}
@media (min-width: 760px) { .install-fab { bottom: 24px; } }
@keyframes bob { 0%,100% { transform: translateY(0);} 50%{ transform: translateY(-5px);} }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 130; overflow: hidden; }
.confetti i {
  position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(105vh) rotate(640deg); opacity: .9; } }

/* =========================================================================
   Accessibility utilities & view transitions
   ========================================================================= */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: .26s; }
}

/* =========================================================================
   Avatar
   ========================================================================= */
.avatar {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-700));
  color: #fff; font-weight: 800; font-size: .9rem; letter-spacing: .02em; flex: 0 0 auto;
}
.avatar--sm { width: 30px; height: 30px; font-size: .8rem; }
.avatar--lg { width: 64px; height: 64px; font-size: 1.5rem; }
.iconbtn--avatar { padding: 5px; }

/* =========================================================================
   Account menu (appbar dropdown)
   ========================================================================= */
.account-menu {
  position: absolute; right: clamp(14px, 4vw, 28px); top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  box-shadow: var(--shadow-pop); padding: 6px; min-width: 240px; z-index: 80; display: grid; gap: 2px;
}
.account-menu[hidden] { display: none; }
.account-menu a, .account-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; color: var(--text); cursor: pointer; padding: 11px 12px;
  border-radius: var(--r-sm); text-align: left; font-size: .94rem; font-weight: 600; text-decoration: none;
}
.account-menu a:hover, .account-menu button:hover { background: var(--surface-3); }
.account-menu__head {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px 12px;
  border-bottom: 1px solid var(--line); margin-bottom: 4px;
}
.account-menu__id { min-width: 0; }
.account-menu__id strong { display: block; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 168px; }
.account-menu__id small { display: block; color: var(--text-faint); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 168px; }

/* =========================================================================
   Guest banner
   ========================================================================= */
.guest-banner {
  display: flex; align-items: center; gap: 16px; padding: 16px 18px; margin-bottom: 18px; flex-wrap: wrap;
  background: linear-gradient(135deg, var(--brand-soft), transparent); border: 1px solid var(--line-strong);
}
.guest-banner__icon { font-size: 1.8rem; }
.guest-banner__text { flex: 1 1 220px; min-width: 0; }
.guest-banner__text strong { display: block; }
.guest-banner__text p { margin: 2px 0 0; color: var(--text-dim); font-size: .88rem; }
.guest-banner__actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* =========================================================================
   Auth forms
   ========================================================================= */
.auth-wrap { max-width: 440px; margin: 10px auto; }
.auth-card { padding: clamp(22px, 5vw, 32px); }
.auth-head { text-align: center; margin-bottom: 18px; }
.auth-logo {
  width: 60px; height: 60px; border-radius: 18px; display: grid; place-items: center; font-size: 1.9rem; margin: 0 auto 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-700)); box-shadow: var(--shadow-pop);
}
.auth-head h1 { font-size: 1.5rem; margin: 0 0 6px; }
.auth-head p { margin: 0; color: var(--text-dim); font-size: .92rem; }

.field { margin-bottom: 14px; }
.field > label { display: block; font-weight: 700; font-size: .86rem; margin-bottom: 6px; }
.field input {
  width: 100%; padding: 12px 14px; border-radius: var(--r-md); border: 1.5px solid var(--line-input);
  background: var(--surface-2); color: var(--text); font-size: 1rem; font-family: inherit;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.field input:focus { outline: none; border-color: var(--brand); background: var(--surface); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.field input:disabled { opacity: .6; cursor: not-allowed; }
.field-err { color: var(--danger-text); font-size: .8rem; font-weight: 600; margin: 6px 0 0; min-height: 1px; }

.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 46px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px;
  border: 0; background: transparent; cursor: pointer; border-radius: 8px; font-size: 1.05rem; color: var(--text-dim);
}
.pw-toggle:hover { background: var(--surface-3); }
.pw-toggle[aria-pressed="true"] { color: var(--brand); }

.pw-meter { height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; margin-top: 8px; }
.pw-meter i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--danger); transition: width var(--t-med), background var(--t-med); }
.pw-meter i[data-score="2"] { background: var(--warning); }
.pw-meter i[data-score="3"] { background: #7bd389; }
.pw-meter i[data-score="4"] { background: var(--success); }
.pw-label { font-size: .78rem; color: var(--text-dim); margin: 4px 0 0; font-weight: 600; }

.check { display: flex; align-items: flex-start; gap: 9px; font-size: .88rem; color: var(--text-dim); cursor: pointer; margin-bottom: 6px; }
.check input { margin-top: 2px; accent-color: var(--brand); width: 16px; height: 16px; }

.auth-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 16px; flex-wrap: wrap; }
.auth-note { font-size: .8rem; color: var(--text-faint); margin: 12px 0 0; text-align: center; }
.auth-hint { font-size: .8rem; color: var(--text-faint); margin: 0 0 12px; }
.auth-alt { text-align: center; margin-top: 16px; font-size: .9rem; color: var(--text-dim); }
.auth-alt a { color: var(--brand); font-weight: 700; }
.auth-error { color: var(--danger-text); font-weight: 600; font-size: .88rem; margin: 0 0 10px; min-height: 1px; }
.auth-sep { display: flex; align-items: center; gap: 12px; margin: 16px 0; color: var(--text-faint); font-size: .82rem; }
.auth-sep::before, .auth-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.btn--block { width: 100%; }
.btn.is-busy { opacity: .7; cursor: progress; }

/* =========================================================================
   Account page
   ========================================================================= */
.account-head { display: flex; gap: 16px; align-items: center; margin-bottom: 22px; flex-wrap: wrap; }
.account-head h1 { font-size: clamp(1.4rem, 4vw, 1.9rem); margin: 0; }
.account-head p { margin: 2px 0 0; color: var(--text-dim); }
.account-meta { font-size: .82rem; color: var(--text-faint); }
.account-section { padding: 20px 22px; margin-bottom: 16px; }
.account-section h2 { font-size: 1.1rem; margin: 0 0 14px; }
.account-section--danger { border-color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.account-danger-desc { font-size: .85rem; color: var(--text-dim); margin: 0 0 14px; }
.account-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.sync-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn--danger { background: linear-gradient(135deg, #e8365a, var(--danger-600)); box-shadow: 0 8px 22px -8px var(--danger); color: #fff; }

/* =========================================================================
   Modal dialog
   ========================================================================= */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200; background: rgba(8, 10, 24, .55); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px; animation: fade .2s var(--ease);
}
.modal { max-width: 420px; width: 100%; padding: 24px; }
.modal h3 { margin: 0 0 8px; font-size: 1.2rem; }
.modal p { margin: 0 0 18px; color: var(--text-dim); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }

/* =========================================================================
   Skeleton loaders
   ========================================================================= */
.skeleton-wrap { display: grid; gap: 12px; }
.skeleton {
  height: 64px; border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%; animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* =========================================================================
   Word of the Day · Dictation · Catalogue filter
   ========================================================================= */
.wod { padding: 18px 20px; }
.wod__head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.wod__head .chip { margin-left: auto; text-decoration: none; }
.wod__body { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.wod__main { flex: 1 1 220px; }
.wod__term { font-size: clamp(1.5rem, 5vw, 2rem); font-weight: 800; line-height: 1.25; }
.wod__mean { color: var(--text-dim); font-weight: 700; margin-top: 2px; }
.wod__actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.dictation-play { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 6px; flex-wrap: wrap; }
.dictation-big { width: 68px; height: 68px; font-size: 1.9rem; }

.course-filter { padding: 12px 14px; margin-bottom: 16px; }
/* A filtered-out card must collapse even though .card sets its own display. */
.grid > [hidden] { display: none !important; }

/* =========================================================================
   Book dictionary (Kamus) · language guide · zero→expert path
   ========================================================================= */

/* ---- shared chips ---- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip--tap { text-decoration: none; cursor: pointer; font-family: inherit; transition: transform var(--t-fast), border-color var(--t-fast); }
.chip--tap:hover { transform: translateY(-1px); border-color: var(--brand); }
.chip--tap.is-on { background: var(--brand); color: #fff; border-color: transparent; }
.chip--pos { font-style: italic; font-weight: 600; }
.chip--gen { text-transform: lowercase; }
.chip--band { letter-spacing: .04em; }
.chip--band-A1, .chip--band-A2 { background: rgba(45,212,167,.14); color: var(--success-text); border-color: transparent; }
.chip--band-B1, .chip--band-B2 { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.chip--band-C1, .chip--band-C2 { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.chip--tap.is-on.chip--band-A1, .chip--tap.is-on.chip--band-A2,
.chip--tap.is-on.chip--band-B1, .chip--tap.is-on.chip--band-B2,
.chip--tap.is-on.chip--band-C1, .chip--tap.is-on.chip--band-C2 { background: var(--brand); color: #fff; }

/* ---- the shelf ---- */
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; }
.shelf-book {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 14px 16px; text-decoration: none; color: inherit;
  border-left: 5px solid var(--brand);
}
.shelf-book:hover { transform: translateY(-3px); }
.shelf-book__flag { font-size: 1.5rem; }
.shelf-book__name { font-weight: 800; }
.shelf-book__native { color: var(--text-faint); font-size: .82rem; font-weight: 600; margin-bottom: 6px; }
.dict-item__def { color: var(--text-dim); font-size: .88rem; margin: 8px 2px 0; }

/* ---- one volume ---- */
.book-header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 18px 20px; margin-bottom: 14px; }
.book-header h1 { font-size: clamp(1.3rem, 4vw, 1.7rem); }
.book-header__native { font-weight: 600; color: var(--text-faint); font-size: 1rem; }
.book-header p { color: var(--text-dim); font-size: .9rem; font-weight: 600; margin: 4px 0 0; }
.book-header__acts { display: flex; gap: 8px; flex-wrap: wrap; }
.book-header__acts .btn { text-decoration: none; }

.band-strip { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.alpha-strip { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.alpha {
  min-width: 34px; padding: 6px 9px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--line-input); color: var(--text-dim);
  font-family: inherit; font-weight: 800; font-size: .85rem; cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.alpha:hover { background: var(--surface-3); color: var(--text); }
.alpha.is-on { background: var(--brand); border-color: transparent; color: #fff; }

.book-list { display: grid; gap: 8px; }
.book-letter {
  font-size: 1.5rem; font-weight: 800; color: var(--brand);
  border-bottom: 2px solid var(--line); padding-bottom: 4px; margin: 16px 0 4px;
}
.dict-entry {
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.3fr) auto auto;
  align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 11px 14px; text-decoration: none; color: inherit;
  transition: border-color var(--t-fast), transform var(--t-fast);
}
.dict-entry:hover { border-color: var(--brand); transform: translateY(-1px); }
.dict-entry__head { min-width: 0; }
.dict-entry__w { font-size: 1.12rem; font-weight: 800; }
.dict-entry__w.cjk { font-family: var(--font-cjk); }
.dict-entry__r { display: block; color: var(--brand); font-weight: 700; font-size: .82rem; }
.dict-entry__ipa { display: block; color: var(--text-faint); font-size: .78rem; }
.dict-entry__gloss { min-width: 0; font-weight: 600; color: var(--text-dim); font-size: .92rem; }
.dict-entry__tags { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.dict-entry__act { display: flex; align-items: center; gap: 4px; }
@media (max-width: 700px) {
  .dict-entry { grid-template-columns: 1fr auto; grid-template-areas: "head act" "gloss act" "tags tags"; }
  .dict-entry__head { grid-area: head; }
  .dict-entry__gloss { grid-area: gloss; }
  .dict-entry__tags { grid-area: tags; justify-content: flex-start; }
  .dict-entry__act { grid-area: act; }
}

/* ---- a single page ---- */
.entry { padding: 22px 24px; }
.entry__head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 14px; }
.entry__w { font-size: clamp(1.8rem, 6vw, 2.6rem); line-height: 1.15; }
.entry__w.cjk { font-family: var(--font-cjk); }
.entry__r { color: var(--brand); font-weight: 700; margin-top: 2px; }
.entry__ipa { color: var(--text-faint); font-size: .95rem; }
.entry__tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.entry__acts { display: flex; gap: 8px; margin-left: auto; }
.entry__gloss { font-size: 1.15rem; font-weight: 700; margin: 16px 0 0; }
.entry__block { margin-top: 18px; }
.entry__block h2 {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-faint); margin: 0 0 6px;
}
.entry__block p { margin: 0; color: var(--text-dim); }
.entry__ex { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.entry__ex.cjk { font-family: var(--font-cjk); }
.entry__exm { margin-top: 3px; font-size: .9rem; }
.entry__note { background: var(--surface-2); border-radius: var(--r-md); padding: 12px 14px; border-left: 4px solid var(--accent); }
.entry__nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.entry__nav .btn { text-decoration: none; }

/* ---- front matter ---- */
.guide-block { padding: 18px 20px; margin-top: 14px; }
.guide-block h3 { font-size: 1.05rem; margin: 0 0 12px; }
.guide-table { width: 100%; border-collapse: collapse; }
.guide-table th { text-align: left; padding: 8px 12px 8px 0; font-weight: 800; white-space: nowrap; vertical-align: top; }
.guide-table td { padding: 8px 0; color: var(--text-dim); border-bottom: 1px solid var(--line); }
.guide-table tr:last-child td { border-bottom: 0; }
.guide-grammar { margin: 0; padding-left: 20px; display: grid; gap: 14px; }
.guide-grammar p { margin: 3px 0 0; color: var(--text-dim); font-size: .92rem; }
.guide-ex { font-weight: 700; color: var(--brand); }

/* ---- zero → expert path ---- */
.path-links { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.path-links .btn { text-decoration: none; }
.path-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.path-pick { display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-decoration: none; color: inherit; }
.path-pick__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.path-pick__pct { font-weight: 800; color: var(--brand); }
.stage-legend { padding: 14px 18px; display: grid; gap: 8px; }
.stage-legend__row { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-weight: 600; font-size: .9rem; }

.stages { display: grid; gap: 14px; }
.stage { padding: 18px 20px; border-left: 5px solid var(--surface-3); }
.stage--done { border-left-color: var(--success); }
.stage__head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.stage__icon { font-size: 1.9rem; }
.stage__head h2 { font-size: 1.1rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.stage__head small { color: var(--text-faint); font-weight: 700; font-size: .78rem; display: block; margin-top: 5px; }
.stage__sub { font-size: .75rem; text-transform: uppercase; letter-spacing: .09em; color: var(--text-faint); margin: 16px 0 8px; }
.stage__can { margin: 0; padding-left: 20px; color: var(--text-dim); display: grid; gap: 4px; font-size: .93rem; }
.stage__lessons { display: flex; flex-wrap: wrap; gap: 8px; }
.stage__empty { color: var(--text-faint); font-size: .9rem; margin: 0; }
.stage__drill { display: inline-block; margin-top: 14px; text-decoration: none; }

.drill-def { font-size: 1.15rem; font-weight: 700; line-height: 1.45; }
.drill-gloss { color: var(--text-dim); font-weight: 600; margin-top: 6px; }

/* ------------------------------------------------------------ stage exam */
.stage--passed { border-left-color: var(--accent); }
.stage__exam { display: inline-block; margin: 14px 0 0 10px; text-decoration: none; }
.stage__drill + .stage__exam { margin-left: 10px; }
.chip--pass { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }

.exam-prompt { font-size: 1.2rem; font-weight: 700; line-height: 1.5; }
.exam-note { color: var(--text-faint); font-size: .84rem; text-align: center; margin: 14px 0 0; }
/* Under exam conditions a tap only confirms it was recorded — no verdict. */
.quiz-opt.chosen { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.exam-result--pass { border: 1px solid var(--accent); }
.exam-verdict { color: var(--text-dim); font-weight: 600; margin: 10px auto 0; max-width: 46ch; }
.exam-review { text-align: left; margin-top: 20px; border-top: 1px solid var(--line); padding-top: 14px; }
.exam-review h3 { font-size: .75rem; text-transform: uppercase; letter-spacing: .09em; color: var(--text-faint); margin: 0 0 8px; }
.exam-misses { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.exam-misses li { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; font-size: .93rem; }
.exam-misses a { font-weight: 800; text-decoration: none; color: var(--brand); }
.exam-misses span { color: var(--text-dim); }

/* ------------------------------------------------------------ certificate */
.cert { background: var(--surface-2); border: 1px solid var(--line); border-radius: 20px; padding: 10px; }
.cert__inner { border: 2px solid var(--accent); border-radius: 14px; padding: 30px 24px; text-align: center; }
.cert__seal { font-size: 3rem; line-height: 1; }
.cert__eyebrow { text-transform: uppercase; letter-spacing: .16em; font-size: .72rem; font-weight: 800; color: var(--text-faint); margin: 10px 0 0; }
.cert__lang { font-size: 1.6rem; margin: 6px 0 14px; }
.cert__awarded, .cert__for { color: var(--text-faint); font-size: .86rem; margin: 0; }
.cert__name { font-size: 1.5rem; font-weight: 800; margin: 4px 0 14px; }
.cert__band { font-size: 1.1rem; font-weight: 700; margin: 6px 0 14px; display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; }
.cert__can { list-style: none; margin: 0 auto; padding: 0; max-width: 46ch; color: var(--text-dim); font-size: .9rem; display: grid; gap: 4px; text-align: left; }
.cert__meta { display: flex; justify-content: center; gap: 26px; flex-wrap: wrap; margin-top: 22px; }
.cert__meta small { display: block; color: var(--text-faint); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
.cert__meta strong { font-size: 1rem; }
.cert__final { margin: 14px auto 0; font-weight: 800; font-size: .92rem; color: var(--accent-text); }
.cert__foot { color: var(--text-faint); font-size: .76rem; margin: 22px 0 0; }

/* The comprehensive paper's badge — gold rather than a band colour, because
   it certifies the whole ladder rather than any one rung of it. */
.chip--final { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; font-weight: 800; }

/* =========================================================================
   Word lists — the learner's own collections
   ========================================================================= */
.listbtn {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%; cursor: pointer;
  background: transparent; border: 1px solid var(--line); color: var(--text-faint);
  font-size: 1rem; line-height: 1; transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.listbtn:hover { background: var(--brand-soft); color: var(--brand); transform: scale(1.06); }
.listbtn.is-on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }

.list-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.list-card { display: flex; align-items: center; gap: 14px; padding: 16px 18px; }
.list-card__ico { font-size: 1.6rem; line-height: 1; }
.list-card__main { flex: 1 1 auto; min-width: 0; display: grid; gap: 2px; }
.list-card__main strong { font-size: 1rem; overflow-wrap: anywhere; }
.list-card__main small { color: var(--text-faint); font-size: .8rem; }
.list-card__go { color: var(--text-faint); font-size: 1.3rem; }

.list-rows { display: grid; gap: 10px; }
.list-row { align-items: center; }
.list-row__from { display: block; color: var(--text-faint); font-size: .76rem; margin-top: 2px; }
.list-row__rm { flex: 0 0 auto; color: var(--text-faint); }
.list-row__rm:hover { color: var(--danger); }
.list-hint { color: var(--text-faint); font-size: .88rem; margin: 14px 0 0; }

/* The add-to-list picker */
.list-pick__word { font-weight: 800; font-size: 1.05rem; margin: 0 0 10px; overflow-wrap: anywhere; }
.list-pick { display: grid; gap: 4px; max-height: 40vh; overflow-y: auto; margin-bottom: 14px; }
.list-pick__row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-sm); }
.list-pick__row:hover { background: var(--surface-3); }
.list-pick__name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.list-pick__n { flex: 0 0 auto; }
.list-pick__none { color: var(--text-faint); font-size: .88rem; margin: 0 0 12px; }
.list-pick__new { display: flex; gap: 8px; }
.list-pick__new input, .dialog-input {
  flex: 1 1 auto; min-width: 0; padding: 10px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface-3); color: var(--text); font: inherit;
}
.dialog-input { width: 100%; }

/* "12/23 languages searchable so far" — the search works from the first book
   that lands, so this says how wide it has got, not that it is unusable. */
.dict-loading {
  margin: 10px 0 0; font-size: .82rem; font-weight: 700; color: var(--text-faint);
  display: flex; align-items: center; gap: 8px;
}
.dict-loading::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid var(--line-strong); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Printing a certificate should yield the certificate — nothing else.

   Two rules govern this block, both learned from looking at the paper rather
   than at the tests. First, every floating layer has to go: the install
   prompt, the confetti still falling from the pass screen and an open dialog
   are all `position: fixed`, so they ride along onto the sheet. Second, the
   printer knows nothing about themes — a learner in dark mode must get the
   same sheet a learner in light mode gets. That means pinning ink colours
   rather than inheriting variables, and forcing white behind everything so
   the page survives "background graphics" being switched on. */
@page { size: A4; margin: 14mm; }

@media print {
  .appbar, .bottomnav, .no-print, .toast, .skip-link,
  .install-fab, .confetti, .modal-backdrop { display: none !important; }

  html, body, .main { background: #fff !important; color: #111 !important; }
  /* On screen the body reserves a viewport-and-a-bit for the bottom nav; on
     paper that reserve is what tips a one-page certificate onto a second. */
  body { min-height: 0 !important; padding-bottom: 0 !important; }
  .main { padding: 0 !important; max-width: none !important; }

  /* One sheet, and the certificate sitting in the middle of it rather than
     clinging to the top edge above a third of a page of nothing. */
  .cert {
    border: none; padding: 0; background: #fff !important;
    display: flex; align-items: center; min-height: 96vh;
    break-inside: avoid; page-break-inside: avoid;
  }
  .cert__inner { width: 100%; border-color: #111; background: #fff !important; }
  .cert__lang, .cert__name, .cert__band, .cert__meta strong, .cert__final { color: #111 !important; }
  .cert__eyebrow, .cert__awarded, .cert__for, .cert__meta small, .cert__foot { color: #444 !important; }
  .cert__can, .cert__can li { color: #222 !important; }

  /* The band is the one fact the certificate exists to state, so it cannot
     depend on a tinted background the printer may refuse to lay down. It
     prints as ink on an outlined badge instead. */
  .cert .chip--band {
    color: #111 !important; background: transparent !important;
    border: 1.2pt solid #111 !important;
  }
}
