:root {
  --bg: #0d102d;
  --panel: #171a46;
  --panel-2: #20245d;
  --text: #f7f7ff;
  --muted: #b9bee8;
  --line: rgba(255,255,255,.12);
  --gold: #ffd166;
  --pink: #ef5da8;
  --cyan: #4cc9f0;
  --green: #7bd88f;
  --danger: #ff6b6b;
  --soft: #fff5d6;
  --shadow: 0 18px 45px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
html { max-width: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; overflow-x: hidden; }
body { margin: 0; min-height: 100vh; max-width: 100%; overflow-x: hidden; background: radial-gradient(circle at top left, #33216f 0, transparent 34rem), linear-gradient(180deg, #0d102d, #111434 58%, #0d102d); padding-bottom: 5.8rem; }
body.word-dictionary-page { height: 100vh; height: 100dvh; overflow: hidden; padding-bottom: 0; }
body.theme-soft-night {
  --bg: #111827;
  --panel: #1f2937;
  --panel-2: #273449;
  --text: #f4f7fb;
  --muted: #cbd5e1;
  --line: rgba(226,232,240,.16);
  --gold: #f6d58f;
  --pink: #d98bb7;
  --cyan: #8bd3dd;
  --green: #9ee6b7;
  --danger: #fca5a5;
  --soft: #fff2c7;
  background: linear-gradient(180deg, #101827, #162033 56%, #101827);
}
body.theme-warm-paper {
  --bg: #f3ead8;
  --panel: #fff8e8;
  --panel-2: #eadfca;
  --text: #2d261b;
  --muted: #665c4d;
  --line: rgba(69,55,35,.18);
  --gold: #8b5e12;
  --pink: #9b4668;
  --cyan: #1b6a73;
  --green: #2f6f4f;
  --danger: #9b2f2f;
  --soft: #3a2d14;
  --shadow: 0 14px 34px rgba(91,70,38,.16);
  background: linear-gradient(180deg, #f3ead8, #fbf4e6 45%, #efe2cb);
}
body.theme-green-comfort {
  --bg: #102018;
  --panel: #1b3027;
  --panel-2: #263c31;
  --text: #f2fbf5;
  --muted: #c3d8cb;
  --line: rgba(213,232,220,.16);
  --gold: #f2d58a;
  --pink: #d98d9f;
  --cyan: #8ed7c5;
  --green: #98e6a8;
  --danger: #f4a3a3;
  --soft: #fff2c0;
  background: linear-gradient(180deg, #102018, #173326 58%, #102018);
}
body.theme-ink-black {
  --bg: #050505; --panel: #111111; --panel-2: #1c1c1c; --text: #f5f5f5; --muted: #b9b9b9; --line: rgba(255,255,255,.14);
  --gold: #f8d66d; --pink: #d76ea8; --cyan: #7ed8ff; --green: #91e8a8; --danger: #ff8f8f; --soft: #fff1bf;
  background: #050505;
}
body.theme-ocean-calm {
  --bg: #071b25; --panel: #102c38; --panel-2: #173d4b; --text: #eefcff; --muted: #b7d5dc; --line: rgba(191,236,245,.16);
  --gold: #f5d77a; --pink: #d98bb0; --cyan: #72d7e8; --green: #8ce5bd; --danger: #ffa5a5; --soft: #e9fff8;
  background: linear-gradient(180deg, #071b25, #0e2d39 58%, #071b25);
}
body.theme-lavender-mist {
  --bg: #171426; --panel: #25203a; --panel-2: #312a4a; --text: #fbf7ff; --muted: #d5cce7; --line: rgba(232,220,255,.16);
  --gold: #f4d176; --pink: #df8cc4; --cyan: #a8d8ff; --green: #a6e6ba; --danger: #ffa5b8; --soft: #fff0d0;
  background: linear-gradient(180deg, #171426, #25203a 55%, #171426);
}
body.theme-rose-dim {
  --bg: #21131a; --panel: #321f29; --panel-2: #412936; --text: #fff8fb; --muted: #dec4cf; --line: rgba(255,224,235,.15);
  --gold: #f7cf7a; --pink: #f08ab7; --cyan: #93d7e7; --green: #9de2aa; --danger: #ff9a9a; --soft: #fff0c9;
  background: linear-gradient(180deg, #21131a, #33202a 55%, #21131a);
}
body.theme-sepia-book {
  --bg: #e7d7b9; --panel: #f8ecd3; --panel-2: #e5d3b1; --text: #352818; --muted: #6f614e; --line: rgba(80,55,25,.2);
  --gold: #8d5f18; --pink: #9d5f6c; --cyan: #3d7f87; --green: #517d42; --danger: #9b2f2f; --soft: #3b2a16;
  --shadow: 0 14px 34px rgba(91,70,38,.16);
  background: linear-gradient(180deg, #e7d7b9, #f3e5c9 58%, #e3d1ae);
}
body.theme-mint-paper {
  --bg: #e4f3e9; --panel: #f6fff8; --panel-2: #d4eadc; --text: #173125; --muted: #536b5d; --line: rgba(30,72,49,.18);
  --gold: #806016; --pink: #9b5c7c; --cyan: #247987; --green: #2e7c4d; --danger: #9b2f2f; --soft: #173125;
  --shadow: 0 14px 34px rgba(30,72,49,.14);
  background: linear-gradient(180deg, #e4f3e9, #f6fff8 58%, #dceee4);
}
body.theme-slate-focus {
  --bg: #111827; --panel: #202938; --panel-2: #2d3849; --text: #f8fafc; --muted: #c8d1dd; --line: rgba(226,232,240,.16);
  --gold: #e8c66d; --pink: #c989ad; --cyan: #8ecde5; --green: #9bddb4; --danger: #fca5a5; --soft: #fff2c2;
  background: linear-gradient(180deg, #111827, #1c2736 58%, #111827);
}
body.theme-high-contrast {
  --bg: #000814; --panel: #001d3d; --panel-2: #003566; --text: #ffffff; --muted: #dbeafe; --line: rgba(255,255,255,.28);
  --gold: #ffd60a; --pink: #ff70a6; --cyan: #7dd3fc; --green: #a7f3d0; --danger: #ff8c8c; --soft: #fff7b0;
  background: #000814;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem 1rem; background: rgba(13,16,45,.86); backdrop-filter: blur(16px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.brand span { display: grid; place-items: center; width: 2.35rem; height: 2.35rem; border-radius: .65rem; color: #10122e; background: linear-gradient(135deg, var(--gold), var(--cyan)); font-weight: 900; }
.brand strong { font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ghost { color: var(--muted); font-size: .9rem; }
.word-dictionary-page .topbar { width: 100vw; max-width: 100vw; padding: .55rem .7rem; background: linear-gradient(135deg, rgba(255,95,170,.92), rgba(85,224,255,.88)); border-bottom: 0; box-shadow: 0 14px 34px rgba(0,0,0,.28); }
.word-dictionary-page .brand { width: 100%; justify-content: center; min-height: 3.15rem; }
.word-dictionary-page .brand strong { width: 100%; text-align: center; color: #ffffff; font-size: clamp(1.35rem, 6vw, 2.35rem); font-weight: 1000; letter-spacing: .04em; text-shadow: 0 2px 16px rgba(0,0,0,.28); }
.floating-settings { position: fixed; left: calc(min(390px, 100vw) - 4rem); bottom: calc(4.55rem + env(safe-area-inset-bottom)); z-index: 14; display: inline-flex; align-items: center; justify-content: center; width: 3.1rem; height: 3.1rem; padding: 0; border-radius: 999px; background: linear-gradient(135deg, var(--cyan), var(--pink)); color: white; font-size: 1.15rem; font-weight: 900; box-shadow: 0 16px 36px rgba(0,0,0,.38); border: 1px solid rgba(255,255,255,.22); }
.prompt-modal { position: fixed; inset: 0; z-index: 30; display: none; align-items: end; justify-content: center; padding: 1rem; background: rgba(0,0,0,.64); }
.prompt-modal.is-open { display: flex; }
.prompt-modal-card { width: min(42rem, 100%); max-height: 86vh; overflow: auto; padding: 1rem; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.prompt-modal-card textarea { min-height: 15rem; margin: .75rem 0; line-height: 1.45; }
.prompt-modal-card [data-prompt-close] { background: var(--panel-2); border: 1px solid var(--line); padding: .55rem .75rem; }
.paste-image-box { display: grid; gap: .45rem; margin: .75rem 0; padding: .85rem; border: 1px dashed var(--line); border-radius: 8px; background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
.paste-image-box:focus { outline: 3px solid rgba(85,224,255,.18); border-color: var(--cyan); }
.paste-image-box.has-image { border-color: var(--green); background: color-mix(in srgb, var(--green) 12%, var(--panel-2)); }
.paste-image-box b { color: var(--gold); }
.paste-image-box span, .paste-image-box small { color: var(--muted); }
.selected-hook-line { padding: .55rem .7rem; border-radius: 8px; border: 1px solid var(--line); background: color-mix(in srgb, var(--gold) 10%, var(--panel-2)); color: var(--gold); font-weight: 800; }

.page { width: min(1050px, 100%); margin: 0 auto; padding: 1rem; }
.hero { padding: 1.2rem 0 1rem; }
.hero p { margin: 0 0 .35rem; color: var(--cyan); font-weight: 700; letter-spacing: 0; }
.hero h1 { margin: 0; font-size: clamp(2rem, 9vw, 4.2rem); line-height: 1; }
.top-learning-buttons { display: flex; gap: .16rem; margin: 0 0 1rem; overflow: hidden; }
.top-filter-btn { flex: 1 1 0; min-width: 0; display: grid; place-items: center; align-content: center; min-height: 3.2rem; padding: .38rem .12rem; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 10px 22px rgba(0,0,0,.16); text-align: center; }
.bi { display: block; width: 1em; height: 1em; fill: currentColor; }
.top-filter-btn .bi { color: var(--cyan); font-size: 1.05rem; margin-bottom: .1rem; }
.top-filter-btn b { display: block; color: var(--gold); font-size: .78rem; line-height: 1.05; }
.top-filter-btn span { display: block; margin-top: .16rem; color: var(--muted); font-size: .62rem; line-height: 1.15; }
.top-filter-btn.active { border-color: rgba(255,209,102,.62); background: color-mix(in srgb, var(--gold) 14%, var(--panel)); }
.word-dictionary-page .page { display: flex; flex-direction: column; width: min(390px, 100vw); max-width: min(390px, 100vw); height: calc(100vh - 5.35rem); height: calc(100dvh - 5.35rem); margin: 0; padding: .45rem .35rem .3rem; overflow: hidden; }
.word-dictionary-page .top-learning-buttons { flex: 0 0 auto; position: relative; top: auto; z-index: 9; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .14rem; width: 100%; max-width: 100%; margin: 0 0 .75rem; padding: .38rem .18rem; border-radius: 0; background: rgba(7,8,31,.94); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); overflow: hidden; }
.word-dictionary-page .top-learning-buttons > * { min-width: 0; }
.word-dictionary-page .top-filter-btn { width: auto; min-width: 0; min-height: 3.38rem; padding: .24rem .06rem; box-shadow: none; border-radius: 8px; }
.word-dictionary-page .top-filter-btn .bi { font-size: .95rem; margin-bottom: .06rem; }
.word-dictionary-page .top-filter-btn b { display: block; width: 100%; color: var(--text); font-size: clamp(.58rem, 2.7vw, .82rem); line-height: 1.1; white-space: normal; overflow-wrap: anywhere; }
.word-dictionary-page .top-filter-btn span { display: block; margin-top: .13rem; color: var(--muted); font-size: clamp(.5rem, 2.35vw, .62rem); line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dic-search { flex: 0 0 auto; position: relative; top: auto; z-index: 8; display: grid; grid-template-columns: minmax(0, 1fr) 3.05rem 3.05rem; gap: .16rem; width: 100%; max-width: 100%; margin: -.35rem 0 .7rem; padding: .42rem .2rem; background: rgba(7,8,31,.92); border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); overflow: hidden; }
.dic-search input { min-width: 0; min-height: 2.65rem; padding: .65rem .75rem; border-radius: 8px; }
.dic-search button, .dic-search a { display: inline-flex; align-items: center; justify-content: center; min-width: 0; min-height: 2.65rem; padding: .55rem .2rem; border-radius: 8px; font-size: .62rem; font-weight: 900; white-space: nowrap; }
.dic-search a { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); }
.dic-total-line { flex: 0 0 auto; display: flex; align-items: center; gap: .35rem; margin: -.35rem 0 .55rem; padding: .42rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: color-mix(in srgb, var(--panel-2) 72%, var(--bg)); color: var(--muted); font-size: .82rem; font-weight: 900; }
.dic-total-line strong { color: var(--gold); font-size: 1rem; }
.dic-total-line em { margin-left: auto; color: var(--cyan); font-style: normal; font-size: .74rem; }
.dic-filter-panel { flex: 0 0 auto; position: relative; top: auto; z-index: 7; width: 100%; max-width: 100%; max-height: 38vh; overflow: auto; margin: -.7rem 0 .75rem; border-radius: 0; border-left: 0; border-right: 0; background: rgba(18,20,59,.97); backdrop-filter: blur(14px); }
.dic-filter-panel[hidden] { display: none; }
.dic-filter-panel .link-button { min-height: 2.7rem; }
.mode-filter-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .45rem; padding: .65rem; }
.mode-filter-panel .mode-choice { display: grid; place-items: center; gap: .18rem; min-height: 3.2rem; padding: .6rem .45rem; border: 1px solid var(--line); border-radius: 8px; background: color-mix(in srgb, var(--panel-2) 82%, transparent); color: var(--text); text-align: center; }
.mode-filter-panel .mode-choice b { font-size: .92rem; color: var(--gold); }
.mode-filter-panel .mode-choice span { color: var(--muted); font-size: .74rem; font-weight: 900; }
.mode-filter-panel .mode-choice.active { border-color: rgba(255,209,102,.72); background: color-mix(in srgb, var(--gold) 16%, var(--panel)); box-shadow: 0 0 0 3px rgba(255,209,102,.1); }
.mode-filter-panel .muted-line { grid-column: 1 / -1; margin: .05rem 0 0; font-size: .74rem; line-height: 1.35; }

.panel, .word-card, .stat, .era-card, .flashcard { background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.panel { padding: 1rem; margin-bottom: 1rem; }
.notice { margin: 0 0 1rem; padding: .85rem 1rem; border-radius: 8px; background: rgba(76,201,240,.14); border: 1px solid rgba(76,201,240,.35); color: #eaffff; }
.empty, .hint { color: var(--muted); }
.big { font-size: 1.5rem; font-weight: 800; color: var(--gold); }
.journey { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .2rem; }
.journey span { flex: 0 0 auto; padding: .7rem .8rem; border-radius: 999px; background: rgba(255,209,102,.13); border: 1px solid rgba(255,209,102,.3); color: var(--soft); font-weight: 900; }

.home-top { display: grid; gap: 1rem; align-items: start; margin-bottom: 1rem; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
.home-top .stats-grid { margin-bottom: 0; }
.dictionary-home { order: -1; margin-bottom: 0; }
.mini-dictionary-list { display: grid; gap: .45rem; max-height: 31rem; overflow: auto; padding-right: .15rem; }
.mini-dict-row { display: grid; gap: .18rem; padding: .7rem; border-radius: 8px; background: color-mix(in srgb, var(--panel-2) 72%, var(--bg)); border: 1px solid var(--line); }
.mini-dict-row b { color: var(--gold); font-size: 1.08rem; }
.mini-dict-row span { color: var(--muted); font-size: .88rem; line-height: 1.35; }
.stat { padding: 1rem; }
.stat span, .status-row span { display: block; color: var(--muted); font-size: .88rem; }
.stat strong { display: block; margin-top: .35rem; font-size: 1.75rem; color: var(--gold); }
.status-row { display: flex; justify-content: space-between; gap: 1rem; padding: .75rem 0; border-top: 1px solid var(--line); }
.status-row:first-of-type { border-top: 0; }
.section-title, .word-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.section-title h2, .panel h2 { margin: 0 0 .85rem; }
.section-title a, .link-button, .quick-links a { display: inline-flex; align-items: center; justify-content: center; min-height: 2.55rem; padding: .65rem .9rem; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); font-weight: 700; }
.quick-links a.active { border-color: rgba(255,209,102,.55); background: rgba(255,209,102,.14); color: var(--gold); }

.word-list, .root-grid, .timeline, .cards-stack, .dictionary-list { display: grid; gap: .85rem; }
.word-only-list { display: grid; gap: .35rem; }
.word-dictionary-page .word-only-list { display: block; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: calc(5.7rem + env(safe-area-inset-bottom)); scroll-padding-bottom: calc(5.7rem + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
.word-dictionary-page .word-only-list .word-row-card { margin-bottom: .35rem; }
.word-card { display: block; padding: 1rem; }
.word-card strong { color: var(--gold); font-size: 1.2rem; }
.word-card p { margin: .45rem 0; }
.word-card small, .word-card span { color: var(--muted); }
.dictionary-top { display: grid; gap: 1rem; align-items: center; }
.list-summary { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.dictionary-top h2 { margin: .1rem 0 .35rem; }
.eyebrow { margin: 0; color: var(--cyan); font-size: .84rem; font-weight: 900; text-transform: uppercase; }
.muted-line { color: var(--muted); }
.dictionary-totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
.dictionary-totals div { padding: .85rem; border-radius: 8px; background: color-mix(in srgb, var(--panel-2) 72%, var(--bg)); border: 1px solid var(--line); }
.dictionary-totals span { display: block; color: var(--muted); font-size: .78rem; }
.dictionary-totals strong { display: block; margin-top: .25rem; color: var(--gold); font-size: 1.45rem; }
.dictionary-card .word-head h2 { margin: 0; color: var(--gold); }
.count-badge { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; padding: .34rem .58rem; border-radius: 999px; border: 1px solid rgba(76,201,240,.38); background: rgba(76,201,240,.12); color: var(--cyan); font-weight: 900; font-size: .78rem; }
.related-title { margin-top: .85rem; color: var(--gold); font-weight: 900; }
.related-word-grid { display: flex; flex-wrap: wrap; gap: .45rem; max-height: 16rem; overflow: auto; padding: .65rem 0 .1rem; }
.word-pill { display: inline-flex; align-items: center; min-height: 2rem; padding: .38rem .58rem; border-radius: 999px; background: rgba(255,255,255,.07); border: 1px solid var(--line); color: var(--text); font-size: .86rem; font-weight: 800; }
.word-pill:hover { border-color: rgba(255,209,102,.55); color: var(--gold); }
.word-row-card { border: 1px solid color-mix(in srgb, var(--green) 24%, var(--line)); border-radius: 8px; background: color-mix(in srgb, var(--panel) 70%, rgba(107, 226, 154, .16)); overflow: hidden; }
.word-row-toggle { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .82rem .9rem; border: 0; border-radius: 0; background: transparent; color: var(--text); text-align: left; }
.word-row-toggle strong { color: var(--gold); font-size: 1.08rem; }
.word-row-meta { flex: 0 0 auto; max-width: 46%; display: inline-flex; align-items: center; justify-content: flex-end; gap: .35rem; overflow: hidden; color: var(--muted); font-size: .82rem; }
.word-row-meta small { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .78rem; }
.word-row-meta em { flex: 0 0 auto; min-width: 2.2rem; padding: .2rem .34rem; border-radius: 999px; border: 1px solid rgba(255,255,255,.16); background: rgba(255,255,255,.08); color: var(--muted); font-style: normal; font-size: .67rem; font-weight: 1000; text-align: center; }
.word-row-card.is-open .word-row-toggle { background: color-mix(in srgb, var(--gold) 10%, transparent); }
.word-row-card.is-transferred { border-color: rgba(76,201,240,.36); background: color-mix(in srgb, var(--panel) 74%, rgba(76,201,240,.18)); }
.word-row-card.is-transferred .word-row-toggle strong { color: var(--cyan); }
.word-row-card.stage-night,
.word-row-card.stage-summary-5-min,
.word-row-card.stage-one-hour,
.word-row-card.stage-day-1,
.word-row-card.stage-day-3,
.word-row-card.stage-day-7,
.word-row-card.stage-day-30 {
  border-color: rgba(91, 152, 255, .58);
  background: linear-gradient(135deg, color-mix(in srgb, var(--panel) 74%, rgba(67,111,255,.24)), color-mix(in srgb, var(--panel) 78%, rgba(154,95,255,.22)));
}
.word-row-card.stage-night .word-row-toggle strong,
.word-row-card.stage-summary-5-min .word-row-toggle strong,
.word-row-card.stage-one-hour .word-row-toggle strong,
.word-row-card.stage-day-1 .word-row-toggle strong,
.word-row-card.stage-day-3 .word-row-toggle strong,
.word-row-card.stage-day-7 .word-row-toggle strong,
.word-row-card.stage-day-30 .word-row-toggle strong { color: #bfe6ff; }
.word-row-card.stage-night .word-row-meta em,
.word-row-card.stage-summary-5-min .word-row-meta em,
.word-row-card.stage-one-hour .word-row-meta em,
.word-row-card.stage-day-1 .word-row-meta em,
.word-row-card.stage-day-3 .word-row-meta em,
.word-row-card.stage-day-7 .word-row-meta em,
.word-row-card.stage-day-30 .word-row-meta em { background: rgba(85,224,255,.18); border-color: rgba(85,224,255,.45); color: var(--cyan); }
.word-row-card.stage-king { border-color: rgba(255,209,102,.78); background: linear-gradient(135deg, color-mix(in srgb, var(--panel) 56%, rgba(255,209,102,.34)), color-mix(in srgb, var(--panel) 70%, rgba(255,164,64,.28))); }
.word-row-card.stage-king .word-row-toggle strong { color: var(--gold); }
.word-row-card.stage-king .word-row-meta em { background: rgba(255,209,102,.24); border-color: rgba(255,209,102,.62); color: var(--gold); }
.word-dictionary-page .word-row-toggle { gap: .45rem; padding: .78rem .75rem .78rem .85rem; }
.word-dictionary-page .word-row-toggle strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.1rem; }
.word-dictionary-page .word-row-meta { max-width: 3.1rem; gap: 0; }
.word-dictionary-page .word-row-meta small { display: none; }
.word-dictionary-page .word-row-card.stage-not-started .word-row-meta { display: none; }
.word-dictionary-page .word-hidden-detail { padding-left: .75rem; padding-right: .75rem; }
.word-row-tools { display: flex; align-items: center; justify-content: space-between; gap: .45rem; padding: 0 .75rem .72rem .85rem; }
.word-row-tools small { color: var(--muted); font-size: .7rem; font-weight: 800; }
.back-stage-btn { min-height: 2.25rem; padding: .48rem .72rem; border: 1px solid rgba(255,209,102,.48); border-radius: 8px; background: rgba(255,209,102,.16); color: var(--gold); font-size: .78rem; font-weight: 1000; }
.word-row-tools { display: flex; align-items: center; gap: .5rem; padding: 0 .75rem .75rem; }
.word-row-tools button { min-height: 2.25rem; padding: .45rem .7rem; border-radius: 999px; font-size: .78rem; background: linear-gradient(135deg, var(--cyan), var(--pink)); color: #fff; }
.word-row-tools small { color: var(--muted); font-size: .78rem; }
.success-text { color: var(--green) !important; }
.word-row-image { display: block; width: calc(100% - 1.5rem); max-height: 12rem; object-fit: cover; margin: 0 .75rem .65rem; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); }
.word-row-image.in-detail { width: 100%; margin: .35rem 0 0; max-height: 18rem; }
.word-hidden-detail { padding: 0 .9rem .95rem; border-top: 1px solid var(--line); }
.word-hidden-detail p { margin: .55rem 0; }
.kid-detail { display: grid; gap: .8rem; padding-top: .8rem; }
.kid-hero { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .75rem; border-radius: 8px; background: linear-gradient(135deg, rgba(85,224,255,.15), rgba(255,95,170,.12)); border: 1px solid var(--line); }
.kid-hero h2 { margin: .12rem 0 0; color: var(--gold); font-size: clamp(1.8rem, 8vw, 3rem); line-height: 1; }
.kid-label { display: block; color: var(--cyan); font-size: .72rem; font-weight: 1000; text-transform: uppercase; letter-spacing: .03em; }
.kid-grid { display: grid; gap: .6rem; }
.kid-grid section, .kid-mini-row > div, .story-box { padding: .75rem; border-radius: 8px; background: color-mix(in srgb, var(--panel-2) 68%, transparent); border: 1px solid var(--line); }
.kid-big { color: var(--gold); font-size: 1.22rem; font-weight: 900; }
.pos-badge { display: inline-flex; align-items: center; justify-content: center; margin-right: .35rem; padding: .2rem .45rem; border-radius: 999px; background: rgba(255,211,110,.16); border: 1px solid rgba(255,211,110,.38); color: var(--gold); font-size: .72rem; text-transform: uppercase; }
.sound-btn { flex: 0 0 auto; min-width: 5rem; min-height: 2.7rem; padding: .55rem .75rem; border-radius: 999px; background: linear-gradient(135deg, var(--cyan), var(--pink)); color: #fff; box-shadow: 0 10px 22px rgba(0,0,0,.18); }
.memory-strip { padding: .75rem; border-radius: 8px; background: rgba(255,211,110,.13); border: 1px solid rgba(255,211,110,.34); color: var(--soft); }
.kid-mini-row { display: grid; gap: .6rem; }
.story-box p { line-height: 1.5; }
.remember-steps { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .1rem; }
.remember-steps span { flex: 0 0 auto; padding: .48rem .62rem; border-radius: 999px; background: rgba(255,255,255,.08); border: 1px solid var(--line); color: var(--text); font-size: .78rem; font-weight: 900; }
.word-image { width: 100%; max-height: 15rem; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); margin: .75rem 0; background: #10143a; }
.word-image.thumb { max-height: 9rem; }
.chips { display: flex; flex-wrap: wrap; gap: .45rem; margin: .65rem 0; }
.chip { border-radius: 999px; padding: .38rem .6rem; font-weight: 900; color: #10122e; font-size: .82rem; }
.chip.prefix { background: #75d7ff; }
.chip.root { background: #ffd166; }
.chip.suffix { background: #7bd88f; }
.progress { height: 1rem; background: #10143a; border-radius: 999px; overflow: hidden; border: 1px solid var(--line); margin: 1rem 0; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg,var(--cyan),var(--gold)); }
.error-text { color: var(--danger); }
.simple-line { padding: .7rem; border-radius: 8px; background: rgba(255,255,255,.06); }
.king-badge { display: inline-flex; width: fit-content; align-items: center; gap: .35rem; padding: .4rem .65rem; border-radius: 999px; background: rgba(255,209,102,.18); border: 1px solid rgba(255,209,102,.45); color: var(--gold); font-weight: 900; margin: .5rem 0; }
.king-card { border-color: rgba(255,209,102,.45); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; align-items: center; }
.actions form, .review-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.memory-process { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-top: .75rem; padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 8px; background: color-mix(in srgb, var(--panel-2) 70%, var(--bg)); color: var(--text); }
.memory-process small { color: var(--muted); font-weight: 800; text-align: right; }
.stage-btn { background: linear-gradient(135deg, var(--gold), var(--pink)) !important; color: #160e1c !important; border: 0 !important; box-shadow: 0 10px 20px rgba(255, 209, 102, .16); }
.moved-badge { display: inline-flex; align-items: center; min-height: 2.55rem; padding: .55rem .85rem; border-radius: 999px; border: 1px solid rgba(76,201,240,.38); background: rgba(76,201,240,.14); color: var(--cyan); font-weight: 1000; }
.icon-btn { width: 2.4rem; height: 2.4rem; padding: 0; display: inline-grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.icon-btn.active { color: var(--gold); }
.form-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1rem; }
.secondary { background: var(--panel-2); border: 1px solid var(--line); }
.ajax-message { min-height: 1.25rem; margin-top: .75rem; color: var(--muted); }
.ajax-message.success { color: var(--green); }
.ajax-message.error { color: var(--danger); }

.memory-image-box { display: grid; gap: .75rem; margin: 0 0 1rem; padding: 1rem; background: rgba(16,20,58,.78); border: 1px solid var(--line); border-radius: 8px; }
.memory-image-box.compact { margin: .8rem 0; padding: .75rem; }
.memory-image-box img, .flash-image { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #10143a; }
.memory-image-box.compact img { max-height: 15rem; }
.image-placeholder { display: grid; place-items: center; min-height: 10rem; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); background: color-mix(in srgb, var(--panel-2) 45%, transparent); text-align: center; padding: 1rem; }
.image-status { min-height: 1.2rem; color: var(--muted); font-size: .9rem; }
.image-status.success { color: var(--green); }
.image-status.error { color: var(--danger); }
.generate-image-btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; width: 100%; }
.generate-image-btn:disabled { opacity: .76; cursor: wait; }
.spinner { display: none; width: 1rem; height: 1rem; border: 2px solid rgba(255,255,255,.42); border-top-color: white; border-radius: 50%; animation: spin .8s linear infinite; }
.generate-image-btn.is-loading .spinner { display: inline-block; }
.flash-image { max-height: 9.5rem; margin-bottom: .4rem; }
@keyframes spin { to { transform: rotate(360deg); } }

label { display: grid; gap: .35rem; color: var(--muted); font-weight: 700; }
input, select, textarea { width: 100%; color: var(--text); background: color-mix(in srgb, var(--panel-2) 62%, var(--bg)); border: 1px solid var(--line); border-radius: 8px; padding: .8rem .85rem; outline: none; }
body.theme-soft-night input, body.theme-soft-night select, body.theme-soft-night textarea,
body.theme-green-comfort input, body.theme-green-comfort select, body.theme-green-comfort textarea,
body.theme-ink-black input, body.theme-ink-black select, body.theme-ink-black textarea,
body.theme-ocean-calm input, body.theme-ocean-calm select, body.theme-ocean-calm textarea,
body.theme-lavender-mist input, body.theme-lavender-mist select, body.theme-lavender-mist textarea,
body.theme-rose-dim input, body.theme-rose-dim select, body.theme-rose-dim textarea,
body.theme-slate-focus input, body.theme-slate-focus select, body.theme-slate-focus textarea,
body.theme-high-contrast input, body.theme-high-contrast select, body.theme-high-contrast textarea { background: rgba(8,14,24,.72); }
body.theme-warm-paper input, body.theme-warm-paper select, body.theme-warm-paper textarea,
body.theme-sepia-book input, body.theme-sepia-book select, body.theme-sepia-book textarea,
body.theme-mint-paper input, body.theme-mint-paper select, body.theme-mint-paper textarea { background: color-mix(in srgb, var(--panel) 86%, white); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(76,201,240,.15); }
.form-grid, .filters, .quiz-form, .build-form { display: grid; gap: .85rem; }
.wide { grid-column: 1 / -1; }
.check { display: flex; grid-auto-flow: column; align-items: center; justify-content: start; }
.check input { width: auto; }

button, .primary { border: 0; border-radius: 8px; padding: .78rem 1rem; background: linear-gradient(135deg, var(--cyan), var(--pink)); color: white; font-weight: 900; cursor: pointer; }
.danger { background: var(--danger); margin-top: .75rem; }
.actions button, .review-actions button { background: var(--panel-2); border: 1px solid var(--line); padding: .55rem .7rem; }
.edit-image-panel { margin-bottom: 1rem; }
.edit-image-panel .section-title span { color: var(--gold); font-weight: 900; }
.image-tools { margin-top: .75rem; }
.image-tools .danger { margin-top: 0; }

.flashcard { position: relative; min-height: 23rem; padding: 1rem; transform-style: preserve-3d; transition: transform .35s ease; cursor: pointer; }
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard .front, .flashcard .back { position: absolute; inset: 0; padding: 1rem; backface-visibility: hidden; display: grid; align-content: center; gap: .65rem; }
.flashcard .front strong { font-size: 2.4rem; color: var(--gold); }
.flashcard .front span { color: var(--muted); }
.flashcard .back { transform: rotateY(180deg); align-content: start; overflow: auto; }

.review-card h2 { font-size: 2.7rem; margin: .5rem 0; color: var(--gold); }
.review-card.summary-focus p:not(.hint):not(.big) { display: none; }
.review-card.summary-focus .big, .review-card.summary-focus .hint { display: block; }
.pill { display: inline-flex; width: fit-content; padding: .32rem .6rem; border-radius: 999px; background: rgba(255,209,102,.16); color: var(--gold); border: 1px solid rgba(255,209,102,.35); font-weight: 800; }
.era-card { position: relative; padding: 1rem 1rem 1rem 1.25rem; }
.era-card::before { content: ""; position: absolute; left: .35rem; top: 1rem; bottom: 1rem; width: 3px; background: var(--cyan); border-radius: 1rem; }
.era-card.locked { filter: grayscale(.7); opacity: .62; }
.tree { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: .6rem; }
.tree a { display: grid; gap: .2rem; padding: .75rem; background: color-mix(in srgb, var(--panel-2) 72%, var(--bg)); border: 1px solid var(--line); border-radius: 8px; }
.tree small { color: var(--muted); }
.quick-links { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
.theme-settings { display: grid; gap: 1rem; }
.theme-grid { display: grid; grid-template-columns: 1fr; gap: .75rem; }
.theme-choice { position: relative; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: .75rem; min-height: 5rem; padding: .85rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); cursor: pointer; }
.theme-choice input { width: 1.15rem; height: 1.15rem; accent-color: var(--cyan); }
.theme-choice b { display: block; font-size: 1rem; color: var(--text); }
.theme-choice small { display: block; margin-top: .2rem; color: var(--muted); line-height: 1.35; }
.theme-choice:has(input:checked) { border-color: rgba(255,209,102,.72); box-shadow: 0 0 0 3px rgba(255,209,102,.12); }
.theme-preview-time-dark { background: linear-gradient(135deg, #171a46, #20245d); }
.theme-preview-soft-night { background: linear-gradient(135deg, #1f2937, #273449); }
.theme-preview-warm-paper { background: linear-gradient(135deg, #fff8e8, #eadfca); color: #2d261b; }
.theme-preview-warm-paper b { color: #2d261b; }
.theme-preview-warm-paper small { color: #665c4d; }
.theme-preview-green-comfort { background: linear-gradient(135deg, #1b3027, #263c31); }
.theme-preview-ink-black { background: linear-gradient(135deg, #050505, #1c1c1c); }
.theme-preview-ocean-calm { background: linear-gradient(135deg, #102c38, #173d4b); }
.theme-preview-lavender-mist { background: linear-gradient(135deg, #25203a, #3b3156); }
.theme-preview-rose-dim { background: linear-gradient(135deg, #321f29, #4a2d3a); }
.theme-preview-sepia-book { background: linear-gradient(135deg, #f8ecd3, #d8c199); color: #352818; }
.theme-preview-mint-paper { background: linear-gradient(135deg, #f6fff8, #cbe6d6); color: #173125; }
.theme-preview-slate-focus { background: linear-gradient(135deg, #202938, #354157); }
.theme-preview-high-contrast { background: linear-gradient(135deg, #000814, #003566); }
.theme-preview-sepia-book b, .theme-preview-mint-paper b { color: inherit; }
.theme-preview-sepia-book small, .theme-preview-mint-paper small { color: color-mix(in srgb, currentColor 72%, transparent); }
.settings-grid { margin-top: .35rem; }

@media (max-width: 719px) {
  .page { width: min(390px, 100vw); max-width: min(390px, 100vw); margin: 0; padding: .75rem .55rem 5.3rem; }
  .word-dictionary-page .page { width: min(390px, 100vw); max-width: min(390px, 100vw); padding: .45rem .35rem .3rem; }
  .section-title { align-items: flex-start; }
  .section-title .pill { flex: 0 0 auto; font-size: .74rem; padding: .26rem .48rem; }
  .theme-choice { min-height: 4.85rem; padding: .78rem; }
  .theme-choice small { overflow-wrap: anywhere; }
}

@supports (-webkit-touch-callout: none) {
  .word-dictionary-page .page { width: 100vw; max-width: 100vw; }
}

.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .08rem; width: 100vw; max-width: 100vw; padding: .38rem .18rem calc(.38rem + env(safe-area-inset-bottom)); background: rgba(10,12,34,.94); backdrop-filter: blur(18px); border-top: 1px solid var(--line); overflow: hidden; }
.bottom-nav a { display: grid; place-items: center; gap: .12rem; min-width: 0; min-height: 3.2rem; color: var(--muted); border-radius: 8px; font-size: clamp(.52rem, 2.25vw, .66rem); overflow: hidden; }
.bottom-nav b { display: grid; place-items: center; width: 1.42rem; height: 1.42rem; border-radius: 50%; background: var(--panel-2); color: var(--text); font-size: .78rem; line-height: 1; font-weight: 1000; }
.bottom-nav a.active { color: var(--gold); background: rgba(255,209,102,.1); }

@media (min-width: 720px) {
  .page { padding: 1.5rem; }
  .top-learning-buttons { gap: .75rem; }
  .top-filter-btn { min-height: 4.4rem; padding: .7rem .5rem; }
  .top-filter-btn b { font-size: .98rem; }
  .top-filter-btn span { font-size: .76rem; }
  .word-dictionary-page .top-learning-buttons { top: 0; gap: .65rem; margin-left: 0; margin-right: 0; padding: .55rem; }
  .word-dictionary-page .top-filter-btn { min-height: 3.45rem; }
  .word-dictionary-page .top-filter-btn b { font-size: .94rem; }
  .dic-search { top: 4.25rem; margin-left: 0; margin-right: 0; padding: .55rem; }
  .dic-filter-panel { top: 7.85rem; margin-left: 0; margin-right: 0; padding: 1rem; }
  .kid-grid, .kid-mini-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .home-top { grid-template-columns: minmax(18rem, 23rem) 1fr; }
  .stats-grid { grid-template-columns: repeat(6, 1fr); }
  .home-top .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .word-list, .timeline, .root-grid, .dictionary-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dictionary-top { grid-template-columns: 1fr minmax(16rem, 22rem); }
  .form-grid, .filters, .build-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards-stack { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards-stack.single-card { grid-template-columns: minmax(0, 32rem); justify-content: center; }
  .quick-links { grid-template-columns: repeat(4, 1fr); }
  .bottom-nav { right: 0; width: 100%; max-width: 100vw; }
}

/* === Additions: streak, SM-2, loading, shortcuts, heatmap, mistakes === */

/* Loading bar at top */
.global-loading-bar { position: fixed; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, transparent, var(--gold, #ffd166), transparent); transform: translateX(-100%); transition: transform .3s; z-index: 9999; pointer-events: none; opacity: 0; }
.global-loading-bar.is-active { animation: loading-bar 1s ease-in-out infinite; opacity: 1; }
@keyframes loading-bar { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

/* Skeleton loader */
.skeleton { display: block; background: linear-gradient(90deg, rgba(255,255,255,.05) 0%, rgba(255,255,255,.12) 50%, rgba(255,255,255,.05) 100%); background-size: 200% 100%; animation: skeleton-shimmer 1.4s ease infinite; border-radius: 6px; min-height: 1rem; }
@keyframes skeleton-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Streak chip */
.streak-chip { display: inline-flex; align-items: center; gap: .35rem; padding: .35rem .65rem; border-radius: 999px; background: rgba(255,153,51,.18); color: #ffb454; font-weight: 700; font-size: .85rem; }
.streak-chip.is-active { background: rgba(255,103,31,.25); color: #ff8a3d; box-shadow: 0 0 12px rgba(255,103,31,.35); }
.streak-chip .streak-flame { font-size: 1.05rem; }
.streak-broken { opacity: .55; }

/* SM-2 grade buttons */
.sm2-grades { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: .5rem; margin-top: 1rem; }
.sm2-grades button { padding: .85rem .5rem; border-radius: 10px; border: 1px solid var(--line, #28284a); background: var(--panel-2, #16183a); color: var(--text, #fff); font-weight: 700; cursor: pointer; transition: transform .12s, background .15s; }
.sm2-grades button:hover { transform: translateY(-1px); }
.sm2-grade-again { background: rgba(220,53,69,.18) !important; color: #ff8a95 !important; }
.sm2-grade-hard  { background: rgba(255,143,28,.18) !important; color: #ffb454 !important; }
.sm2-grade-good  { background: rgba(48,209,88,.18) !important; color: #6ee598 !important; }
.sm2-grade-easy  { background: rgba(64,156,255,.18) !important; color: #6ab4ff !important; }
.sm2-grades small { display: block; font-weight: 400; font-size: .68rem; opacity: .75; margin-top: .2rem; }

/* Keyboard shortcut help overlay */
.shortcut-help { position: fixed; bottom: 5rem; right: 1rem; background: rgba(10,12,34,.96); color: var(--text, #fff); padding: 1rem 1.2rem; border-radius: 10px; border: 1px solid var(--line, #28284a); font-size: .8rem; line-height: 1.7; max-width: 22rem; box-shadow: 0 10px 40px rgba(0,0,0,.45); z-index: 100; }

/* Review heatmap */
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 12px); gap: 3px; padding: .75rem; overflow-x: auto; }
.heatmap-cell { width: 12px; height: 12px; border-radius: 2px; background: rgba(255,255,255,.06); }
.heatmap-cell.lvl-1 { background: rgba(110,229,152,.25); }
.heatmap-cell.lvl-2 { background: rgba(110,229,152,.45); }
.heatmap-cell.lvl-3 { background: rgba(110,229,152,.70); }
.heatmap-cell.lvl-4 { background: rgba(110,229,152,.95); }
.heatmap-legend { display: flex; gap: .35rem; align-items: center; font-size: .72rem; color: var(--muted); padding: 0 .75rem .5rem; }

/* Mistake review page */
.mistake-list { display: grid; gap: .65rem; }
.mistake-row { display: flex; justify-content: space-between; gap: 1rem; padding: .85rem 1rem; background: var(--panel, #14163b); border-radius: 10px; border-left: 4px solid #ff8a95; }
.mistake-row .accuracy { font-weight: 700; color: #ff8a95; }
.mistake-row .accuracy.warn { color: #ffb454; border-color: #ffb454; }

/* Notice variants */
.notice.error { background: rgba(220,53,69,.15); border-left: 3px solid #ff8a95; color: #ff8a95; }

/* Lazy image fade-in */
img[loading="lazy"] { transition: opacity .25s; }
img[loading="lazy"]:not([src]), img[loading="lazy"][src=""] { opacity: 0; }

/* === Pronunciation checker === */
.pron-status { margin-top: .5rem; padding: .55rem .8rem; border-radius: 8px; font-size: .82rem; background: rgba(255,255,255,.04); }
.pron-status.listening { background: rgba(255,103,31,.18); color: #ff8a3d; animation: pulse 1.5s ease infinite; }
.pron-status.checking { background: rgba(64,156,255,.18); color: #6ab4ff; }
.pron-status.grade-great { background: rgba(48,209,88,.22); color: #6ee598; }
.pron-status.grade-good { background: rgba(255,193,7,.22); color: #ffd166; }
.pron-status.grade-retry { background: rgba(220,53,69,.18); color: #ff8a95; }
.pron-status.error { background: rgba(220,53,69,.18); color: #ff8a95; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

/* === AI lab page === */
.ai-lab-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin-top: 1rem; }
.ai-card { padding: 1.2rem; border-radius: 12px; background: var(--panel, #14163b); border: 1px solid var(--line, #28284a); }
.ai-card h3 { margin: 0 0 .5rem; font-size: 1rem; }
.ai-card p { color: var(--muted); font-size: .85rem; margin: .25rem 0; }
.ai-card .ai-actions { margin-top: .8rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.ai-card .ai-status { margin-top: .6rem; font-size: .78rem; color: var(--muted); }
.ai-card .ai-progress-bar { width: 100%; height: 6px; background: rgba(255,255,255,.06); border-radius: 3px; overflow: hidden; margin-top: .5rem; }
.ai-card .ai-progress-bar > div { height: 100%; background: linear-gradient(90deg, #6ee598, #6ab4ff); transition: width .3s; }

/* Bottom nav now has 8 items (added AI Lab) */
.bottom-nav { grid-template-columns: repeat(8, minmax(0, 1fr)) !important; }

/* === Daily challenges === */
.challenge-list { display: grid; gap: .75rem; }
.challenge-row { display: flex; gap: 1rem; padding: .8rem 1rem; background: rgba(255,255,255,.03); border-radius: 10px; border-left: 4px solid var(--gold, #ffd166); }
.challenge-row.is-done { border-left-color: #6ee598; background: rgba(110,229,152,.08); }

/* === Confetti === */
.confetti-container { position: fixed; top: 0; left: 0; right: 0; bottom: 0; pointer-events: none; z-index: 10000; overflow: hidden; }
.confetti-piece { position: absolute; width: 10px; height: 14px; top: -20px; opacity: 0; animation: confetti-fall 2.2s ease-out forwards; }
.confetti-piece.c1 { background: #ffd166; }
.confetti-piece.c2 { background: #6ee598; }
.confetti-piece.c3 { background: #6ab4ff; }
.confetti-piece.c4 { background: #ff8a95; }
.confetti-piece.c5 { background: #c39dff; }
@keyframes confetti-fall {
  0%   { opacity: 0; transform: translateY(0) rotate(0); }
  10%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(110vh) rotate(720deg); }
}

/* === Badge unlock toast === */
.badge-toast { position: fixed; top: 1.5rem; right: 1.5rem; max-width: 22rem; background: rgba(20,22,59,.97); color: var(--text); padding: 1rem 1.25rem; border-radius: 12px; border: 2px solid var(--gold, #ffd166); box-shadow: 0 20px 60px rgba(0,0,0,.45); z-index: 9999; display: flex; gap: .75rem; align-items: center; transform: translateX(120%); transition: transform .35s cubic-bezier(.5,1.7,.5,1); }
.badge-toast.is-show { transform: translateX(0); }
.badge-toast .badge-icon { font-size: 2.4rem; line-height: 1; }
.badge-toast h4 { margin: 0; font-size: .92rem; color: var(--gold, #ffd166); }
.badge-toast p { margin: .12rem 0 0; font-size: .78rem; color: var(--muted); }

/* === Badge cards on achievements page === */
.badge-earned { border-color: rgba(255,209,102,.4); background: linear-gradient(135deg, rgba(255,209,102,.05), rgba(20,22,59,.6)); }
.badge-locked { opacity: .65; }

/* ==========================================================================
   Responsive Utility System
   Breakpoints:
     - Mobile:     < 480px
     - Phablet:    480px – 719px
     - Tablet:     720px – 1023px
     - Laptop:     1024px – 1279px
     - Desktop:    1280px+
   ========================================================================== */

/* --- Base box-sizing & overflow guards --- */
*, *::before, *::after { box-sizing: border-box; }
html, body { max-width: 100vw; overflow-x: hidden; }
img, video, svg, canvas { max-width: 100%; height: auto; }

/* --- Flex utilities --- */
.u-flex      { display: flex; }
.u-flex-col  { display: flex; flex-direction: column; }
.u-flex-wrap { flex-wrap: wrap; }
.u-flex-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.u-flex-center  { display: flex; justify-content: center; align-items: center; }
.u-flex-1 { flex: 1; min-width: 0; }
.u-items-center { align-items: center; }
.u-items-start  { align-items: flex-start; }

.u-gap-xs { gap: .25rem; }
.u-gap-sm { gap: .5rem; }
.u-gap    { gap: 1rem; }
.u-gap-lg { gap: 1.5rem; }

/* --- Spacing --- */
.u-m-0   { margin: 0; }
.u-mt-xs { margin-top: .25rem; }
.u-mt-sm { margin-top: .5rem; }
.u-mt    { margin-top: 1rem; }
.u-mt-lg { margin-top: 1.5rem; }
.u-mb    { margin-bottom: 1rem; }
.u-p-sm  { padding: .5rem; }
.u-p     { padding: 1rem; }
.u-p-lg  { padding: 1.5rem; }

/* --- Text --- */
.u-text-center { text-align: center; }
.u-text-left   { text-align: left; }
.u-text-right  { text-align: right; }
.u-text-xs  { font-size: .72rem; }
.u-text-sm  { font-size: .82rem; }
.u-text-md  { font-size: .95rem; }
.u-text-lg  { font-size: 1.1rem; }
.u-text-xl  { font-size: 1.4rem; }
.u-text-2xl { font-size: 1.8rem; }
.u-text-3xl { font-size: 2rem; }
.u-text-4xl { font-size: 2.4rem; }
.u-text-muted { color: var(--muted); }
.u-text-gold  { color: var(--gold, #ffd166); }
.u-text-good  { color: #6ee598; }
.u-text-warn  { color: #ffb454; }
.u-text-bad   { color: #ff8a95; }

/* --- Width --- */
.u-w-full       { width: 100%; }
.u-max-w-sm     { max-width: 480px; margin-inline: auto; }
.u-max-w-md     { max-width: 640px; margin-inline: auto; }
.u-max-w-lg     { max-width: 800px; margin-inline: auto; }
.u-max-w-xl     { max-width: 1100px; margin-inline: auto; }
.u-min-w-200    { min-width: 200px; }

/* --- Grid --- */
.u-grid      { display: grid; gap: 1rem; }
.u-grid-1    { grid-template-columns: 1fr; }
.u-grid-auto-sm { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.u-grid-auto-md { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.u-grid-auto-lg { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

/* --- Filters / states --- */
.u-grayscale     { filter: grayscale(1); opacity: .35; }
.u-divider-gold  { border-left: 4px solid var(--gold, #ffd166); }
.u-divider-good  { border-left: 4px solid #6ee598; }
.u-no-underline  { text-decoration: none; }

/* --- Touch-friendly buttons (mobile) --- */
@media (max-width: 719px) {
  button, .link-button, .top-filter-btn, .bottom-nav a,
  input[type="submit"], input[type="button"] {
    min-height: 44px;            /* WCAG touch target */
    font-size: 1rem;
  }
  input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], textarea, select {
    font-size: 16px !important;  /* prevents iOS Safari zoom */
    min-height: 44px;
  }
  .u-text-4xl { font-size: 1.8rem; }
  .u-text-3xl { font-size: 1.6rem; }
  .u-text-2xl { font-size: 1.4rem; }
  .panel { padding: 1rem; margin-inline: 0; }
}

/* --- Phablet --- */
@media (min-width: 480px) and (max-width: 719px) {
  .u-grid-auto-sm { grid-template-columns: repeat(2, 1fr); }
}

/* --- Tablet --- */
@media (min-width: 720px) and (max-width: 1023px) {
  .u-max-w-xl { max-width: 95vw; }
  .ai-lab-grid { grid-template-columns: repeat(2, 1fr); }
  .home-top    { grid-template-columns: 1fr; }
  .stats-grid  { grid-template-columns: repeat(4, 1fr); }
  .heatmap     { grid-template-rows: repeat(7, 14px); gap: 4px; }
}

/* --- Laptop --- */
@media (min-width: 1024px) {
  .page { max-width: 1200px; margin: 0 auto; padding: 1.5rem 2rem 6rem; }
  .ai-lab-grid { grid-template-columns: repeat(3, 1fr); }
  .home-top    { grid-template-columns: minmax(20rem, 25rem) 1fr; }
  .stats-grid  { grid-template-columns: repeat(6, 1fr); }
  .home-top .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .word-list, .timeline, .root-grid, .dictionary-list { grid-template-columns: repeat(3, 1fr); }
  .cards-stack { grid-template-columns: repeat(3, 1fr); }
  .cards-stack.single-card { grid-template-columns: minmax(0, 36rem); justify-content: center; }
  .heatmap { grid-template-rows: repeat(7, 16px); gap: 5px; }
  .heatmap-cell { width: 16px; height: 16px; }
}

/* --- Desktop --- */
@media (min-width: 1280px) {
  .page { max-width: 1400px; padding: 2rem 3rem 6rem; }
  .ai-lab-grid { grid-template-columns: repeat(4, 1fr); }
  .word-list, .timeline, .root-grid, .dictionary-list { grid-template-columns: repeat(4, 1fr); }
  .cards-stack { grid-template-columns: repeat(4, 1fr); }
  .stats-grid { grid-template-columns: repeat(6, 1fr); }
  .home-top .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

/* --- Mobile-specific overrides for new components --- */
@media (max-width: 479px) {
  /* Streak / XP / badge chips wrap below header */
  .streak-chip { font-size: .78rem; padding: .25rem .5rem; }

  /* Word-of-the-day card on mobile: stack vertically */
  .wotd-card { flex-direction: column; align-items: flex-start; }
  .wotd-card .wotd-actions { flex-direction: row; width: 100%; }
  .wotd-card .wotd-actions > * { flex: 1; }

  /* AI Lab cards: stack 1 column */
  .ai-lab-grid { grid-template-columns: 1fr; }

  /* Stats grid: 2 cols on phone */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: .5rem; }
  .stat { padding: .65rem; }
  .stat strong { font-size: 1.1rem; }

  /* SM-2 buttons: 2x2 grid */
  .sm2-grades { grid-template-columns: repeat(2, 1fr); }
  .sm2-grades button { padding: 1rem .5rem; min-height: 56px; }

  /* Bottom nav: smaller icons on 8-item grid */
  .bottom-nav b { width: 1.25rem; height: 1.25rem; font-size: .7rem; }
  .bottom-nav a { min-height: 3rem; padding: .25rem; }
  .bottom-nav span { font-size: .58rem; }

  /* Confetti / toast positioning */
  .badge-toast { right: .75rem; left: .75rem; max-width: calc(100vw - 1.5rem); top: 1rem; }

  /* Heatmap: more compact */
  .heatmap { grid-template-rows: repeat(7, 9px); gap: 2px; }
  .heatmap-cell { width: 9px; height: 9px; }

  /* Hide non-essential page hero */
  .hero { padding: .5rem 0; }
  .hero h1 { font-size: 1.4rem; }

  /* Flashcard front/back proper sizing */
  .flashcard { min-height: 22rem; }
  .flashcard .front strong { font-size: 1.8rem; }
  .flashcard .back h2 { font-size: 1.4rem; }

  /* Cloze/Reverse/Spelling: full width content */
  .quiz-panel { padding: 1rem !important; }
}

/* --- Print --- */
@media print {
  .bottom-nav, .topbar, .global-loading-bar, .shortcut-help, .badge-toast, .confetti-container { display: none !important; }
  body { background: white; color: black; }
}

/* --- Accessibility: reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .confetti-piece, .skeleton, .global-loading-bar.is-active, .pron-status.listening { animation: none !important; }
}

/* --- Focus visible for keyboard navigation --- */
:focus-visible {
  outline: 2px solid var(--gold, #ffd166);
  outline-offset: 2px;
  border-radius: 6px;
}
button:focus-visible, a:focus-visible { outline-offset: 3px; }

/* --- High contrast: better readability --- */
@media (prefers-contrast: more) {
  .muted-line, .u-text-muted { color: rgba(255,255,255,.9); }
  .panel { border: 2px solid var(--line, #28284a); }
}

/* ==========================================================================
   Component classes for refactored pages
   ========================================================================== */

/* Dashboard streak chips */
.xp-chip      { background: rgba(110,229,152,.18); color: #6ee598; }
.badges-chip  { background: rgba(255,209,102,.18); color: #ffd166; }

/* Recent badges pill */
.badge-pill {
  text-align: center;
  padding: .5rem .75rem;
  background: rgba(255,209,102,.08);
  border-radius: 8px;
  min-width: 70px;
}

/* Large badge icon (achievements page) */
.badge-icon-lg {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: .25rem;
}

/* Quiz options (cloze, reverse) */
.quiz-options {
  grid-template-columns: 1fr;
  gap: .65rem;
}
.quiz-option-btn {
  padding: 1rem;
  font-size: .95rem;
  border-radius: 10px;
  border: 1px solid var(--line, #28284a);
  background: var(--panel-2, #16183a);
  color: var(--text, #fff);
  cursor: pointer;
  transition: background .15s, transform .12s;
  text-align: left;
}
.quiz-option-btn:hover { transform: translateY(-1px); background: rgba(255,255,255,.06); }
.quiz-option-btn:disabled { cursor: default; transform: none; }
.quiz-option-btn.option-correct { background: rgba(110,229,152,.3) !important; border-color: #6ee598; }
.quiz-option-btn.option-wrong   { background: rgba(220,53,69,.25) !important; border-color: #ff8a95; }

@media (min-width: 480px) {
  .quiz-options { grid-template-columns: repeat(2, 1fr); }
}

/* Quiz question text — large, readable */
.quiz-question-text {
  line-height: 1.5;
  font-weight: 500;
  margin: .5rem 0;
}

/* Spelling drill input */
.spell-input {
  width: 100%;
  font-size: 1.4rem;
  text-align: center;
  padding: 1rem;
  border-radius: 10px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line, #28284a);
  color: var(--text);
  font-family: 'SF Mono', Menlo, monospace;
  letter-spacing: .04em;
}
.spell-input:focus {
  outline: 2px solid var(--gold, #ffd166);
  outline-offset: 2px;
}

@media (max-width: 479px) {
  .spell-input { font-size: 1.15rem; padding: .85rem; }
  .quiz-question-text { font-size: 1.1rem; }
  .badge-icon-lg { font-size: 2.4rem; }
}

/* Section title — fix wrap on tiny screens */
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .75rem;
}
.section-title h2 { margin: 0; font-size: 1rem; flex: 1 1 auto; }
.section-title small,
.section-title a { font-size: .78rem; }

/* Panel default tightening on mobile */
@media (max-width: 479px) {
  .section-title h2 { font-size: .95rem; }
  .panel { padding: .85rem; border-radius: 10px; }
  .word-card { padding: .75rem; }
  .word-card strong { font-size: .95rem; }
}

/* Make heatmap horizontally scrollable on small screens */
.heatmap { overflow-x: auto; padding-bottom: .25rem; }

/* AI lab cards — fix code block overflow */
.ai-card code {
  display: block;
  background: rgba(0,0,0,.3);
  padding: .4rem .55rem;
  border-radius: 6px;
  font-size: .72rem;
  word-break: break-all;
  margin-top: .5rem;
}

/* Pronunciation row spacing */
.pron-row {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
.pron-row .sound-btn { flex: 1; min-width: 0; }

/* ==========================================================================
   VISUAL POLISH PASS — Make it MAST
   ========================================================================== */

/* === Smooth global transitions === */
button, a, .word-card, .ai-card, .panel, .stat, input, select, textarea, .top-filter-btn, .badge-pill {
  transition: transform .18s ease, box-shadow .22s ease, background-color .22s ease, border-color .22s ease;
}

/* === Page-level polish: subtle gradient backdrop === */
body {
  background-attachment: fixed;
  background-image: radial-gradient(ellipse at top, rgba(67, 56, 202, .08) 0%, transparent 50%),
                    radial-gradient(ellipse at bottom right, rgba(255, 209, 102, .04) 0%, transparent 50%);
}

/* === Mobile hero — compact, less wasted space === */
@media (max-width: 719px) {
  .hero { padding: .4rem 0 .6rem; }
  .hero p { font-size: .65rem; margin-bottom: .15rem; opacity: .7; }
  .hero h1 { font-size: 1.5rem; }
}

@media (min-width: 720px) and (max-width: 1023px) {
  .hero h1 { font-size: 2rem; }
}

/* === Better panels: subtle inner glow + lift on hover === */
.panel {
  background: linear-gradient(180deg, rgba(255,255,255,.025), transparent 50%), var(--panel, #14163b);
  box-shadow: 0 2px 8px rgba(0,0,0,.18), inset 0 1px 0 rgba(255,255,255,.05);
}

/* === Better cards: lift on hover === */
.word-card, .ai-card {
  background: linear-gradient(180deg, rgba(255,255,255,.04), transparent 50%), var(--panel, #14163b);
  box-shadow: 0 4px 14px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.05);
}
.word-card:hover, .ai-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,.32), inset 0 1px 0 rgba(255,255,255,.08);
}

/* === Stat cards polished === */
.stat {
  background: linear-gradient(135deg, rgba(85,224,255,.04), rgba(255,209,102,.02));
  border: 1px solid rgba(255,255,255,.04);
  border-radius: 10px;
  padding: .85rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.stat span { font-size: .68rem; color: var(--muted); letter-spacing: .03em; text-transform: uppercase; font-weight: 700; }
.stat strong { font-size: 1.4rem; color: var(--gold, #ffd166); font-weight: 800; letter-spacing: -.02em; }
.stat:hover { border-color: rgba(255,209,102,.2); transform: translateY(-2px); }

@media (max-width: 479px) {
  .stat { padding: .55rem; }
  .stat span { font-size: .58rem; }
  .stat strong { font-size: 1.05rem; }
}

/* === Streak chip glow when active === */
.streak-chip.is-active {
  animation: streak-glow 2.5s ease infinite;
}
@keyframes streak-glow {
  0%, 100% { box-shadow: 0 0 14px rgba(255,103,31,.4); }
  50%      { box-shadow: 0 0 22px rgba(255,103,31,.6); }
}

/* === Better buttons: subtle gradient + lift === */
button, .link-button {
  background: linear-gradient(180deg, var(--panel-2, #16183a), rgba(20,22,59,.8));
  border: 1px solid var(--line, #28284a);
  border-radius: 10px;
  padding: .65rem 1rem;
  color: var(--text, #fff);
  font-weight: 600;
  cursor: pointer;
}
button:hover, .link-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
  border-color: rgba(255,209,102,.3);
}
button:active, .link-button:active { transform: translateY(0); }
button:disabled { opacity: .55; cursor: not-allowed; transform: none !important; }

button.primary, .primary {
  background: linear-gradient(135deg, var(--gold, #ffd166), #ff9a3d);
  color: #0a0c22 !important;
  border-color: transparent;
  font-weight: 800;
}
button.primary:hover, .primary:hover {
  box-shadow: 0 6px 22px rgba(255,209,102,.35);
  filter: brightness(1.06);
}

button.secondary, .secondary {
  background: linear-gradient(180deg, rgba(85,224,255,.12), rgba(85,224,255,.04));
  border-color: rgba(85,224,255,.3);
  color: var(--cyan, #55e0ff);
}

/* === Sound / pronunciation buttons === */
.sound-btn {
  background: linear-gradient(135deg, rgba(195,157,255,.18), rgba(110,180,255,.12));
  border-color: rgba(195,157,255,.35);
  color: #c39dff;
  padding: .55rem .85rem;
  font-weight: 700;
}

/* === Top stats nav better === */
.top-filter-btn {
  background: linear-gradient(180deg, rgba(255,255,255,.04), transparent 50%), var(--panel, #14163b);
  position: relative;
  overflow: hidden;
}
.top-filter-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 60%, rgba(255,209,102,.04) 100%);
  pointer-events: none;
}
.top-filter-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,.28);
  border-color: rgba(85,224,255,.25);
}
.top-filter-btn.active::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--gold, #ffd166);
  border-radius: 0 0 2px 2px;
}

/* === Bottom nav active state with indicator === */
.bottom-nav a.active {
  position: relative;
  background: rgba(255,209,102,.1);
}
.bottom-nav a.active::before {
  content: '';
  position: absolute;
  top: 4px; left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background: var(--gold, #ffd166);
  border-radius: 0 0 3px 3px;
}
.bottom-nav b { transition: transform .15s; }
.bottom-nav a:hover b { transform: translateY(-2px); }
.bottom-nav a.active b {
  background: var(--gold, #ffd166);
  color: #0a0c22;
}

/* === Flashcard full-width on mobile === */
@media (max-width: 719px) {
  .cards-stack.single-card {
    grid-template-columns: 1fr !important;
    width: 100%;
  }
  .flashcard {
    width: 100%;
    margin: 0;
  }
}

/* === Flashcard: nicer surface === */
.flashcard {
  background: linear-gradient(135deg, var(--panel, #14163b), rgba(67,56,202,.08));
  box-shadow: 0 12px 40px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 14px;
}

/* === Word card details === */
.word-card { border-radius: 12px; }
.word-card strong { color: var(--gold, #ffd166); }

/* === Form inputs polish === */
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], textarea, select {
  background: rgba(0,0,0,.18);
  border: 1px solid var(--line, #28284a);
  border-radius: 9px;
  padding: .65rem .85rem;
  color: var(--text, #fff);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--cyan, #55e0ff);
  box-shadow: 0 0 0 3px rgba(85,224,255,.18);
}

/* === Chip-style buttons (for filters, tags) === */
.chip {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .28rem .6rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.08);
}
.chip.prefix { background: rgba(255,103,31,.12); color: #ff8a3d; border-color: rgba(255,103,31,.25); }
.chip.root   { background: rgba(110,229,152,.12); color: #6ee598; border-color: rgba(110,229,152,.25); }
.chip.suffix { background: rgba(85,224,255,.12); color: #55e0ff; border-color: rgba(85,224,255,.25); }

/* === Progress bars polish === */
.ai-progress-bar {
  height: 8px;
  border-radius: 4px;
  background: rgba(0,0,0,.3);
  box-shadow: inset 0 1px 2px rgba(0,0,0,.3);
}
.ai-progress-bar > div {
  background: linear-gradient(90deg, #6ee598, #55e0ff, #c39dff);
  box-shadow: 0 0 8px rgba(110,229,152,.35);
}

/* === Empty state styling === */
.empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
  font-style: italic;
  border: 1px dashed var(--line, #28284a);
  border-radius: 12px;
  background: rgba(255,255,255,.02);
}
.empty::before {
  content: '🌱';
  display: block;
  font-size: 2.5rem;
  margin-bottom: .5rem;
}

/* === Section title polish === */
.section-title h2 {
  background: linear-gradient(135deg, var(--text, #fff) 0%, var(--gold, #ffd166) 70%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* === Notices polish === */
.notice {
  background: linear-gradient(135deg, rgba(85,224,255,.08), rgba(110,229,152,.05));
  border-left: 4px solid var(--cyan, #55e0ff);
  padding: .85rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}
.notice.error {
  background: linear-gradient(135deg, rgba(220,53,69,.12), rgba(220,53,69,.04));
  border-left-color: #ff8a95;
  color: #ffb5bd;
}

/* === Laptop sidebar for richer layouts === */
@media (min-width: 1280px) {
  .page-with-sidebar {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 1.5rem;
    align-items: start;
  }
  .page-sidebar {
    position: sticky;
    top: 5.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
}

/* === Ripple effect on buttons === */
button, .link-button { position: relative; overflow: hidden; }
button::after, .link-button::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255,255,255,.25) 0%, transparent 70%);
  opacity: 0;
  transform: scale(0.5);
  transition: opacity .4s, transform .4s;
  pointer-events: none;
}
button:active::after, .link-button:active::after {
  opacity: 1;
  transform: scale(2);
  transition: 0s;
}

/* === Page entry animation === */
.page > section,
.page > .home-top,
.page > .panel {
  animation: fade-in-up .45s ease both;
}
.page > section:nth-child(1) { animation-delay: .02s; }
.page > section:nth-child(2) { animation-delay: .08s; }
.page > section:nth-child(3) { animation-delay: .14s; }
.page > section:nth-child(4) { animation-delay: .2s; }
.page > section:nth-child(5) { animation-delay: .26s; }
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* === Better topbar === */
.topbar {
  backdrop-filter: blur(14px);
  background: linear-gradient(180deg, rgba(10,12,34,.92), rgba(10,12,34,.7));
  border-bottom: 1px solid rgba(255,255,255,.05);
  box-shadow: 0 2px 18px rgba(0,0,0,.18);
}
.topbar .brand span {
  background: linear-gradient(135deg, #6ee598, #55e0ff);
  color: #0a0c22 !important;
  font-weight: 900;
  border-radius: 8px;
  padding: .35rem .55rem;
  box-shadow: 0 4px 12px rgba(85,224,255,.25);
}

/* === Mistake rows lift === */
.mistake-row:hover { transform: translateX(4px); border-left-width: 6px; }

/* === Challenge row hover === */
.challenge-row:hover { background: rgba(255,255,255,.05); border-left-width: 6px; }

/* === Badge pill hover === */
.badge-pill:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 8px 18px rgba(255,209,102,.18);
}

/* === Better word-of-the-day card === */
.wotd-card {
  background:
    radial-gradient(circle at top right, rgba(255,209,102,.08), transparent 60%),
    var(--panel, #14163b);
  position: relative;
  overflow: hidden;
}
.wotd-card::before {
  content: '📅';
  position: absolute;
  top: -10px; right: -10px;
  font-size: 8rem;
  opacity: .03;
  pointer-events: none;
}

/* === Scrollbar polish === */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,.2); }
::-webkit-scrollbar-thumb { background: rgba(85,224,255,.18); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: rgba(85,224,255,.3); }

/* === Selection color === */
::selection { background: rgba(255,209,102,.4); color: #fff; }

/* === Better SM-2 grade buttons === */
.sm2-grades button {
  position: relative;
  overflow: hidden;
}
.sm2-grades button::before {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .25s ease;
}
.sm2-grades button:hover::before { transform: scaleX(1); }


/* ==========================================================================
   ANALYTICS / CHARTS
   ========================================================================== */

/* Metric cards (top of analytics) */
.metric-grid {
  display: grid;
  gap: .85rem;
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 720px) { .metric-grid { grid-template-columns: repeat(4, 1fr); } }

.metric-card {
  background: linear-gradient(135deg, rgba(85,224,255,.06), rgba(255,209,102,.03));
  border: 1px solid rgba(255,255,255,.05);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.metric-card small { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.metric-card strong { font-size: 2rem; color: var(--gold, #ffd166); line-height: 1; margin: .15rem 0; font-weight: 800; letter-spacing: -.02em; }
.metric-card span { font-size: .72rem; color: var(--muted); display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }

/* SVG chart base */
.chart-svg { width: 100%; height: auto; display: block; max-height: 220px; }
.chart-line { fill: none; stroke: var(--cyan, #55e0ff); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; filter: drop-shadow(0 0 4px rgba(85,224,255,.4)); }
.chart-dot { fill: var(--gold, #ffd166); stroke: var(--cyan, #55e0ff); stroke-width: 1; }
.chart-dot:hover { r: 4; cursor: pointer; }
.chart-gridline { stroke: rgba(255,255,255,.06); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tick { fill: var(--muted); font-size: 11px; }

/* Sparkline */
.chart-sparkline { width: 80px; height: 24px; display: inline-block; vertical-align: middle; }
.chart-sparkline polyline { fill: none; stroke: var(--cyan, #55e0ff); stroke-width: 1.5; }

/* Horizontal bars */
.chart-bars-h { display: grid; gap: .75rem; }
.chart-bar-row { display: grid; grid-template-columns: minmax(120px, 30%) 1fr; gap: 1rem; align-items: center; }
.chart-bar-label { display: flex; flex-direction: column; }
.chart-bar-label strong { font-size: .9rem; color: var(--gold, #ffd166); }
.chart-bar-label small { color: var(--muted); font-size: .72rem; }
.chart-bar-track { height: 18px; background: rgba(0,0,0,.25); border-radius: 9px; overflow: hidden; }
.chart-bar-fill { height: 100%; background: linear-gradient(90deg, #ff8a3d, #ff8a95); border-radius: 9px; transition: width .8s ease; }

@media (max-width: 479px) {
  .chart-bar-row { grid-template-columns: 1fr; gap: .35rem; }
  .chart-bar-track { height: 14px; }
}

/* Vertical bars (24-hour) */
.chart-bars-v {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 3px;
  align-items: end;
  height: 140px;
  padding: 0 .5rem;
}
.chart-bar-col { display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; gap: 2px; justify-content: flex-end; }
.chart-bar-vfill {
  width: 100%;
  background: linear-gradient(180deg, #6ee598, #55e0ff);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: height 1s cubic-bezier(.5,1.5,.5,1);
}
.chart-bar-col small { font-size: 9px; color: var(--muted); transform: rotate(-45deg); transform-origin: top right; white-space: nowrap; }
.chart-bar-col:hover .chart-bar-vfill { background: linear-gradient(180deg, #ffd166, #ff8a3d); }

/* Funnel chart */
.chart-funnel { display: grid; gap: .55rem; }
.funnel-row { display: grid; grid-template-columns: 70px 1fr; gap: .75rem; align-items: center; }
.funnel-label { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.funnel-label b { color: var(--gold, #ffd166); font-size: .82rem; }
.funnel-label small { color: var(--muted); font-size: .7rem; }
.funnel-bar { height: 22px; background: rgba(0,0,0,.25); border-radius: 6px; overflow: hidden; }
.funnel-fill {
  height: 100%;
  background: linear-gradient(90deg, rgba(110,229,152,.85), rgba(85,224,255,.85), rgba(195,157,255,.85), rgba(255,209,102,.85));
  border-radius: 6px;
  transition: width 1s ease;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.15);
}

/* Insight box */
.insight {
  margin-top: 1rem;
  padding: .75rem 1rem;
  background: linear-gradient(135deg, rgba(110,229,152,.08), rgba(85,224,255,.04));
  border-left: 3px solid var(--cyan, #55e0ff);
  border-radius: 8px;
  font-size: .85rem;
  line-height: 1.5;
}
.insight a { color: var(--cyan, #55e0ff); }

.insights-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .65rem; }
.insights-list li {
  padding: .75rem 1rem;
  background: rgba(255,255,255,.025);
  border-radius: 8px;
  border-left: 3px solid var(--gold, #ffd166);
  font-size: .88rem;
  line-height: 1.5;
}

/* Delta badges */
.chart-delta { font-weight: 800; font-size: .78rem; padding: .12rem .4rem; border-radius: 4px; }
.delta-up   { background: rgba(110,229,152,.15); color: #6ee598; }
.delta-down { background: rgba(220,53,69,.15); color: #ff8a95; }
.delta-flat { background: rgba(255,255,255,.06); color: var(--muted); }

/* Retention risk cards */
.risk-grid {
  display: grid;
  gap: .65rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.risk-card {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  padding: .75rem 1rem;
  background: rgba(255,209,102,.04);
  border-left: 3px solid var(--gold, #ffd166);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
}
.risk-card:hover { background: rgba(255,209,102,.08); transform: translateX(3px); }
.risk-card strong { color: var(--gold, #ffd166); font-size: .95rem; }
.risk-card small { color: var(--muted); font-size: .75rem; }
.risk-badge {
  display: inline-block;
  margin-top: .25rem;
  padding: .2rem .55rem;
  border-radius: 4px;
  font-size: .68rem;
  font-weight: 700;
  width: max-content;
}
.risk-high { background: rgba(220,53,69,.2); color: #ff8a95; }
.risk-medium { background: rgba(255,143,28,.18); color: #ffb454; }

/* ==========================================================================
   ONBOARDING + INSTALL PROMPT + HELP
   ========================================================================== */

/* Onboarding card */
.onboard-card {
  text-align: center;
  background: linear-gradient(180deg, rgba(85,224,255,.04), var(--panel, #14163b));
  padding: 2rem 1.5rem;
}
.onboard-illustration {
  font-size: 5rem;
  line-height: 1;
  margin: 1rem 0;
  animation: float-bob 3s ease-in-out infinite;
}
@keyframes float-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}
.onboard-body {
  color: var(--muted);
  line-height: 1.65;
  font-size: 1rem;
  margin: 1rem auto;
  max-width: 480px;
}
.onboard-body b { color: var(--gold, #ffd166); }
.onboard-progress {
  height: 6px;
  background: rgba(0,0,0,.25);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 1rem;
}
.onboard-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #6ee598, #55e0ff, #c39dff);
  transition: width .55s cubic-bezier(.5,1.7,.5,1);
}
.onboard-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  margin: 0 2px;
  transition: background .3s;
}
.onboard-dot.is-done { background: var(--gold, #ffd166); }

@media (max-width: 479px) {
  .onboard-illustration { font-size: 4rem; }
  .onboard-card { padding: 1.5rem 1rem; }
}

/* Install Banner */
.install-banner {
  position: fixed;
  bottom: 5rem;
  left: 1rem;
  right: 1rem;
  background: linear-gradient(135deg, var(--panel, #14163b), rgba(67,56,202,.15));
  border: 2px solid var(--cyan, #55e0ff);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  z-index: 9999;
  padding: 1rem 1.25rem;
  transform: translateY(150%);
  transition: transform .4s cubic-bezier(.5,1.5,.5,1);
  max-width: 480px;
  margin-inline: auto;
}
.install-banner.is-show { transform: translateY(0); }
.install-banner-content { display: flex; gap: 1rem; align-items: center; }
.install-icon { font-size: 2.5rem; line-height: 1; flex-shrink: 0; }
.install-text { flex: 1; min-width: 0; }
.install-text strong { display: block; font-size: .95rem; color: var(--cyan, #55e0ff); }
.install-text small { color: var(--muted); font-size: .78rem; }
.install-actions { display: flex; gap: .5rem; flex-shrink: 0; }
.install-banner.ios button[data-install-no] {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 1.2rem;
  border-radius: 50%;
}

@media (min-width: 1024px) {
  .install-banner {
    left: auto;
    right: 1.5rem;
    bottom: 1.5rem;
    max-width: 380px;
  }
}

@media (max-width: 479px) {
  .install-banner { padding: .85rem; }
  .install-banner-content { flex-wrap: wrap; }
  .install-actions { width: 100%; justify-content: flex-end; }
}

/* Help page <kbd> styling */
kbd {
  display: inline-block;
  padding: .15rem .45rem;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: .82rem;
  font-weight: 700;
  color: var(--gold, #ffd166);
  min-width: 1.5rem;
  text-align: center;
}

/* Help link blocks */
.insights-list a {
  color: var(--cyan, #55e0ff);
  text-decoration: none;
  font-weight: 600;
}
.insights-list a:hover { text-decoration: underline; }

/* Hindi-pending fallback (when meaning is missing) */
.hindi-pending {
  color: var(--cyan, #55e0ff);
  font-style: italic;
  opacity: .9;
}
.muted-line + .hindi-pending,
.hindi-pending + .muted-line {
  color: var(--muted);
  font-size: .72rem;
  margin-left: .25rem;
}

/* Backup page */
.backup-list { display: grid; gap: .65rem; }
.backup-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .85rem 1rem;
  background: rgba(255,255,255,.025);
  border-radius: 10px;
  border-left: 3px solid var(--cyan, #55e0ff);
  flex-wrap: wrap;
}
.backup-row code { font-size: .78rem; }
.backup-row pre { margin: 0; font-size: .8rem; }

/* === Multi-user UI === */
.topbar-user { display: flex; gap: .35rem; align-items: center; }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .35rem .75rem;
  background: linear-gradient(135deg, rgba(110,229,152,.15), rgba(85,224,255,.1));
  border: 1px solid rgba(110,229,152,.25);
  border-radius: 999px;
  color: #6ee598 !important;
  font-weight: 700;
  font-size: .85rem;
  text-decoration: none !important;
}
.user-chip:hover { background: linear-gradient(135deg, rgba(110,229,152,.25), rgba(85,224,255,.18)); }
.logout-link {
  display: inline-grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  background: rgba(220,53,69,.12);
  border: 1px solid rgba(220,53,69,.25);
  border-radius: 50%;
  color: #ff8a95 !important;
  font-size: 1.05rem;
  text-decoration: none !important;
  font-weight: 800;
}
.logout-link:hover { background: rgba(220,53,69,.22); }

@media (max-width: 479px) {
  .user-chip { font-size: .75rem; padding: .25rem .55rem; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .logout-link { width: 1.9rem; height: 1.9rem; font-size: .9rem; }
}

/* ==========================================================================
   FIXED VIEWPORT — Prevent zoom on tap/click/pinch
   ========================================================================== */

html {
  /* Prevent iOS Safari from auto-adjusting text size on orientation change */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Disable touch-callout (long-press menu) on iOS */
  -webkit-touch-callout: none;
  /* Smooth scrolling */
  scroll-behavior: smooth;
  /* Lock font size */
  -webkit-text-size-adjust: none;
}

body {
  /* Prevent double-tap zoom on every interactive element */
  touch-action: manipulation;
  /* Prevent user from selecting text via long-press (still allow on inputs) */
  -webkit-user-select: none;
  user-select: none;
  /* Prevent overscroll bounce */
  overscroll-behavior: none;
  /* Disable pull-to-refresh on mobile */
  overscroll-behavior-y: contain;
}

/* Re-enable text selection in places where it's needed */
input, textarea, [contenteditable="true"],
.word-row-card strong, .word-row-card p,
.kid-big, .kid-grid section p,
.flashcard h2, .flashcard p,
p, span, h1, h2, h3, h4, code, pre {
  -webkit-user-select: text;
  user-select: text;
}

/* All clickable elements: lock touch behavior */
button, a, input, select, textarea, label,
.flashcard, .word-card, .ai-card, .badge-pill,
.top-filter-btn, .bottom-nav a, .stat,
.auth-tab, .auth-submit, .pin-input,
[data-review-action], [data-sm2-grade], [data-cloze-answer],
[data-reverse-answer], [data-spell-check], [data-spell-hint],
[data-word-toggle], [data-speak-word], [data-check-pronunciation],
[data-copy-image-prompt], [data-delete-word], [data-favorite],
[data-image-action], [data-image-run], [data-quiz-form] button {
  touch-action: manipulation !important;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
}

/* Prevent zoom via wheel + ctrl */
html, body {
  zoom: 1;
}

/* iOS Safari: disable zoom when focusing inputs */
input, select, textarea {
  font-size: 16px !important;
  -webkit-appearance: none;
  appearance: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation !important;
}

/* Special: PIN input keeps larger but still no-zoom */
.pin-input {
  font-size: 1.5rem !important;
}

/* Spelling drill input */
.spell-input {
  font-size: 16px !important;
}

@media (min-width: 480px) {
  .spell-input { font-size: 1.4rem !important; }
}

/* Disable double-tap zoom on the whole page */
* {
  touch-action: manipulation;
}

/* Allow scroll inside scrollable containers */
.heatmap, .chart-bars-v, pre, [data-scrollable],
.mini-dictionary-list, .word-list, .word-only-list,
.ai-lab-grid, .insights-list, .backup-list,
.risk-grid, .funnel-row, .auth-features,
.metric-grid, .stats-grid, .home-top {
  touch-action: pan-x pan-y;
}

/* Disable iOS rubber-band scrolling at body level */
@supports (-webkit-touch-callout: none) {
  body { position: relative; overscroll-behavior: none; }
}

/* Tap highlight removal */
* {
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}

/* Prevent select on doubletap */
.bottom-nav a, .topbar a, .auth-tab,
.streak-chip, .stat, .badge-pill,
.top-filter-btn, .chip {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Stop accidental drag on images */
img {
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: auto;
}

/* Focus rings: stay subtle (no growth that looks like zoom) */
button:focus, a:focus, input:focus, select:focus, textarea:focus {
  outline-offset: 1px;
}

/* Buttons: prevent layout shift on tap */
button, a.link-button, .auth-submit, .primary, .secondary, .sound-btn,
.top-filter-btn, .sm2-grades button, .quiz-option-btn,
input[type="submit"], input[type="button"] {
  -webkit-tap-highlight-color: transparent;
  transform-origin: center;
}

/* iOS Safari: 100vh fix using safe areas */
.auth-wrap, .install-wrap, .page {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* === My Angel brand icon === */
.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 3px 12px rgba(255,209,102,.4), 0 0 0 2px rgba(255,209,102,.25);
  vertical-align: middle;
}
.brand-fallback {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #6ee598, #55e0ff);
  color: #0a0c22; font-weight: 900;
  border-radius: 8px;
  box-shadow: 0 3px 12px rgba(85,224,255,.3);
}
.topbar .brand { display: flex; align-items: center; gap: .6rem; }
.topbar .brand strong {
  background: linear-gradient(135deg, #ffd166 0%, #ff9a3d 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 900;
  letter-spacing: -.01em;
}

@media (max-width: 479px) {
  .brand-icon, .brand-fallback { width: 30px; height: 30px; }
  .topbar .brand strong { font-size: .95rem; }
}
