/* Spelling Star - styles. Plain CSS, no build step, works offline. */
:root {
  --bg: #f3f6ff;
  --card: #ffffff;
  --ink: #1e1b4b;
  --muted: #5b5f86;
  --line: #dfe3f5;
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --green: #059669;
  --green-bg: #d1fae5;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --blue: #2563eb;
  --orange: #ea580c;
  --purple: #9333ea;
  --yellow: #facc15;
  --radius: 22px;
  --shadow: 0 6px 0 rgba(30, 27, 75, .12), 0 12px 28px rgba(30, 27, 75, .08);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  background-image: radial-gradient(circle at 10% 0%, #e0e7ff 0, transparent 40%), radial-gradient(circle at 90% 10%, #fae8ff 0, transparent 35%);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  font-size: 18px;
  line-height: 1.4;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--primary); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--primary); color: #fff;
  box-shadow: 0 4px 0 var(--primary-dark);
}
.brand { color: #fff; text-decoration: none; font-weight: 800; font-size: 1.35rem; display: flex; align-items: center; gap: 6px; }
.brand-star { display: inline-block; animation: spin 6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.topbar-stats { display: flex; gap: 8px; align-items: center; }
.pill { display: inline-flex; align-items: center; gap: 4px; background: rgba(255,255,255,.18); padding: 6px 12px; border-radius: 999px; font-size: 1rem; }
.pill-btn { border: 0; cursor: pointer; color: #fff; min-height: 40px; }

.container { max-width: 960px; margin: 0 auto; padding: 20px 16px 60px; outline: none; }

/* ---------- Generic UI ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.center { text-align: center; }
.muted { color: var(--muted); }
h1 { font-size: 2rem; margin: 0 0 8px; }
h2 { font-size: 1.5rem; margin: 0 0 8px; }
h3 { font-size: 1.2rem; margin: 0 0 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 12px 22px; border-radius: 16px; border: 0;
  background: var(--primary); color: #fff; font-weight: 800; font-size: 1.1rem;
  box-shadow: 0 5px 0 var(--primary-dark); cursor: pointer; text-decoration: none;
  transition: transform .08s, box-shadow .08s; user-select: none; -webkit-user-select: none;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--primary-dark); }
.btn:focus-visible { outline: 4px solid var(--yellow); outline-offset: 3px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-green { background: var(--green); box-shadow: 0 5px 0 #065f46; }
.btn-green:active { box-shadow: 0 1px 0 #065f46; }
.btn-orange { background: var(--orange); box-shadow: 0 5px 0 #9a3412; }
.btn-orange:active { box-shadow: 0 1px 0 #9a3412; }
.btn-red { background: var(--red); box-shadow: 0 5px 0 #991b1b; }
.btn-red:active { box-shadow: 0 1px 0 #991b1b; }
.btn-light { background: #fff; color: var(--ink); box-shadow: 0 5px 0 var(--line); border: 2px solid var(--line); }
.btn-light:active { box-shadow: 0 1px 0 var(--line); }
.btn-big { min-height: 72px; font-size: 1.35rem; padding: 14px 28px; border-radius: 20px; }
.btn-sm { min-height: 40px; padding: 6px 14px; font-size: .95rem; border-radius: 12px; box-shadow: 0 3px 0 var(--primary-dark); }
.btn-sm.btn-light { box-shadow: 0 3px 0 var(--line); }
.btn-sm.btn-red { box-shadow: 0 3px 0 #991b1b; }
.btn-sm.btn-green { box-shadow: 0 3px 0 #065f46; }
.icon-btn { font-size: 1.6rem; }
.back-link { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; text-decoration: none; margin-bottom: 12px; min-height: 44px; }

/* ---------- Home ---------- */
.hello { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.hello h1 { font-size: 2.2rem; }
.week-picker { display: flex; flex-direction: column; gap: 4px; font-weight: 700; color: var(--muted); }
.week-picker select { min-height: 52px; padding: 8px 14px; border-radius: 14px; border: 3px solid var(--line); background: #fff; font-weight: 700; color: var(--ink); max-width: 100%; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
@media (max-width: 560px) { .tiles { grid-template-columns: 1fr; } }
.tile {
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
  min-height: 170px; padding: 22px; border-radius: 26px; color: #fff; text-decoration: none;
  position: relative; overflow: hidden; transition: transform .12s;
}
.tile:hover { transform: translateY(-3px) rotate(-.5deg); }
.tile:active { transform: translateY(3px); }
.tile:focus-visible { outline: 5px solid var(--yellow); outline-offset: 4px; }
.tile .emoji { font-size: 3rem; line-height: 1; }
.tile .t-title { font-size: 1.7rem; font-weight: 900; }
.tile .t-sub { font-size: 1rem; opacity: .95; }
.tile::after { content: ""; position: absolute; right: -30px; bottom: -30px; width: 130px; height: 130px; border-radius: 50%; background: rgba(255,255,255,.15); }
.tile-practice { background: linear-gradient(135deg, #10b981, #047857); box-shadow: 0 7px 0 #065f46; }
.tile-test { background: linear-gradient(135deg, #3b82f6, #1d4ed8); box-shadow: 0 7px 0 #1e3a8a; }
.tile-games { background: linear-gradient(135deg, #f97316, #c2410c); box-shadow: 0 7px 0 #7c2d12; }
.tile-rewards { background: linear-gradient(135deg, #a855f7, #7e22ce); box-shadow: 0 7px 0 #581c87; }

.parent-link { display: block; text-align: center; margin-top: 36px; color: var(--muted); font-weight: 700; text-decoration: none; padding: 12px; }

.empty-state { text-align: center; padding: 40px 20px; }
.empty-state .big { font-size: 4rem; }

/* ---------- Spelling card ---------- */
.spell-card { text-align: center; padding: 28px 22px; }
.progress { height: 14px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 6px 0 18px; }
.progress > div { height: 100%; background: linear-gradient(90deg, #22c55e, #10b981); border-radius: 999px; transition: width .4s; }
.progress-label { font-weight: 800; color: var(--muted); }
.listen-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 10px 0 18px; }
.listen-big {
  width: 120px; height: 120px; border-radius: 50%; border: 0; cursor: pointer; font-size: 3.2rem;
  background: var(--yellow); box-shadow: 0 7px 0 #ca8a04; transition: transform .08s;
}
.listen-big:active { transform: translateY(5px); box-shadow: 0 2px 0 #ca8a04; }
.listen-big.speaking { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }

.spell-input {
  width: 100%; max-width: 560px; display: block; margin: 0 auto;
  font-size: 2.4rem; font-weight: 800; text-align: center; letter-spacing: .08em;
  padding: 14px 16px; border-radius: 20px; border: 4px solid var(--line); background: #fff; outline: none;
}
.spell-input:focus { border-color: var(--primary); box-shadow: 0 0 0 5px #c7d2fe; }
.spell-input.good { border-color: var(--green); background: var(--green-bg); }
.spell-input.bad { border-color: var(--red); background: var(--red-bg); }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }

.hint-box { margin: 14px auto 0; max-width: 560px; background: #fef9c3; border: 3px dashed #eab308; border-radius: 16px; padding: 12px 16px; font-size: 1.2rem; }
.hint-letters { font-size: 2rem; letter-spacing: .25em; font-weight: 800; }
.feedback { min-height: 64px; margin-top: 14px; font-size: 1.5rem; font-weight: 900; }
.feedback.good { color: var(--green); }
.feedback.bad { color: var(--red); }
.answer-reveal { font-size: 2.2rem; font-weight: 900; letter-spacing: .06em; }
.answer-reveal .ok { color: var(--green); }
.answer-reveal .miss { color: var(--red); text-decoration: underline wavy; text-underline-offset: 6px; background: var(--red-bg); border-radius: 6px; }
.small-diff { font-weight: 800; letter-spacing: .04em; }
.small-diff .ok { color: var(--green); }
.small-diff .miss { color: var(--red); background: var(--red-bg); border-radius: 4px; text-decoration: underline; }

/* ---------- Choice cards ---------- */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.choice {
  border: 4px solid var(--line); background: #fff; border-radius: 22px; padding: 22px; text-align: left; cursor: pointer;
  box-shadow: 0 5px 0 var(--line); transition: transform .08s;
}
.choice:hover { border-color: var(--primary); }
.choice:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--line); }
.choice:disabled { opacity: .45; cursor: default; }
.choice .emoji { font-size: 2.4rem; }
.choice .c-title { font-size: 1.3rem; font-weight: 900; margin-top: 4px; }
.choice .c-sub { color: var(--muted); }

/* ---------- Results ---------- */
.score-big { font-size: 4.5rem; font-weight: 900; line-height: 1; }
.stars-row { font-size: 3rem; letter-spacing: .1em; margin: 8px 0; }
.stars-row .off { filter: grayscale(1); opacity: .3; }
.result-list { list-style: none; padding: 0; margin: 0; text-align: left; }
.result-list li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 2px solid var(--line); flex-wrap: wrap; }
.result-list li:last-child { border-bottom: 0; }
.result-list .num { width: 28px; color: var(--muted); font-weight: 800; }
.result-list .mark { font-size: 1.4rem; }
.result-list .word { font-weight: 900; font-size: 1.25rem; min-width: 150px; }
.result-list .typed { color: var(--muted); }

/* ---------- Rewards ---------- */
.reward-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.stat-box { background: #fff; border-radius: 20px; padding: 18px; text-align: center; box-shadow: var(--shadow); }
.stat-box .v { font-size: 2.6rem; font-weight: 900; }
.stat-box .l { color: var(--muted); font-weight: 700; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.badge { background: #fff; border-radius: 20px; padding: 16px 12px; text-align: center; border: 4px solid var(--yellow); box-shadow: 0 5px 0 #ca8a04; }
.badge .b-icon { font-size: 3rem; }
.badge .b-name { font-weight: 900; }
.badge .b-desc { font-size: .9rem; color: var(--muted); }
.badge.locked { border-color: var(--line); box-shadow: 0 5px 0 var(--line); }
.badge.locked .b-icon { filter: grayscale(1); opacity: .3; }

.prizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.prize { background: #fff; border-radius: 20px; padding: 16px; text-align: center; border: 4px solid var(--line); box-shadow: 0 5px 0 var(--line); display: flex; flex-direction: column; align-items: center; }
.prize.ready { border-color: var(--green); box-shadow: 0 5px 0 #065f46; animation: glow 1.6s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 5px 0 #065f46, 0 0 0 6px rgba(34,197,94,.25); } }
.prize .p-icon { font-size: 3rem; }
.prize .p-name { font-weight: 900; min-height: 2.6em; display: grid; place-items: center; }
.prize .p-cost { font-weight: 900; color: var(--orange); font-size: 1.2rem; }
.prize .progress { width: 100%; }
.stat-spend { border: 4px solid var(--yellow); }
.next-prize { display: inline-block; margin-top: 8px; background: #fff; border: 3px solid var(--yellow); border-radius: 999px; padding: 6px 14px; color: var(--ink); text-decoration: none; font-weight: 700; }
.pending-box { border: 4px solid var(--yellow); }

/* ---------- Modal + toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(30, 27, 75, .55); display: grid; place-items: center; z-index: 60; padding: 16px; animation: fade .2s; }
.modal { background: #fff; border-radius: 28px; padding: 28px; max-width: 460px; width: 100%; text-align: center; animation: pop .35s cubic-bezier(.2, 1.6, .5, 1); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.modal .m-icon { font-size: 4.5rem; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120px); background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 999px; font-weight: 800; z-index: 70; transition: transform .3s; max-width: 90vw; text-align: center; }
#toast.show { transform: translateX(-50%) translateY(0); }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

/* ---------- Scramble game ---------- */
.game-hud { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-weight: 900; font-size: 1.2rem; margin-bottom: 12px; }
.game-hud span { background: #fff; padding: 8px 14px; border-radius: 14px; box-shadow: 0 3px 0 var(--line); }
.timer { height: 12px; background: var(--line); border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
.timer > div { height: 100%; background: linear-gradient(90deg, #f97316, #facc15); transition: width .25s linear; }
.slots, .tiles-row { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.slot, .ltile {
  width: 56px; height: 64px; border-radius: 14px; font-size: 2rem; font-weight: 900; display: grid; place-items: center; text-transform: lowercase;
}
.slot { border: 4px dashed #c7d2fe; background: #eef2ff; cursor: pointer; }
.slot.filled { border-style: solid; border-color: var(--primary); background: #fff; }
.ltile { border: 0; background: var(--orange); color: #fff; box-shadow: 0 5px 0 #9a3412; cursor: pointer; transition: transform .08s; }
.ltile:active { transform: translateY(4px); box-shadow: 0 1px 0 #9a3412; }
.ltile.used { visibility: hidden; }
@media (max-width: 560px) { .slot, .ltile { width: 42px; height: 50px; font-size: 1.5rem; } }

/* ---------- Blaster game ---------- */
.blaster-wrap { position: relative; border-radius: 24px; overflow: hidden; background: #0b1026; box-shadow: var(--shadow); }
#blaster-canvas { display: block; width: 100%; height: 52vh; min-height: 300px; touch-action: manipulation; }
.blaster-input-row { display: flex; gap: 10px; margin-top: 12px; }
.blaster-input-row input { flex: 1; font-size: 1.8rem; font-weight: 800; padding: 10px 16px; border-radius: 16px; border: 4px solid var(--line); text-align: center; letter-spacing: .06em; outline: none; min-width: 0; }
.blaster-input-row input:focus { border-color: var(--orange); }
.blaster-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(11,16,38,.75); color: #fff; text-align: center; padding: 20px; }

/* ---------- Admin ---------- */
.admin h1 { font-size: 1.7rem; }
.tabs { display: flex; gap: 8px; margin: 12px 0 18px; flex-wrap: wrap; }
.tab { border: 0; background: #fff; border-radius: 14px; padding: 10px 18px; font-weight: 800; cursor: pointer; box-shadow: 0 3px 0 var(--line); min-height: 48px; }
.tab.active { background: var(--primary); color: #fff; box-shadow: 0 3px 0 var(--primary-dark); }
.admin .card { padding: 20px; }
.admin label { font-weight: 800; display: block; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.input, .admin textarea, .admin select {
  width: 100%; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); background: #fff; font-size: 1rem; outline: none;
}
.input:focus, .admin textarea:focus, .admin select:focus { border-color: var(--primary); }
.admin textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .95rem; }
.week-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 2px solid var(--line); flex-wrap: wrap; }
.week-item:last-child { border-bottom: 0; }
.week-item .w-title { font-weight: 900; font-size: 1.1rem; }
.tag { display: inline-block; background: var(--green-bg); color: var(--green); font-weight: 900; padding: 2px 10px; border-radius: 999px; font-size: .85rem; margin-left: 6px; }
.word-table { width: 100%; border-collapse: collapse; }
.word-table th { text-align: left; font-size: .85rem; color: var(--muted); padding: 6px; }
.word-table td { padding: 4px; vertical-align: middle; }
.word-table td.n { color: var(--muted); font-weight: 800; width: 30px; text-align: right; }
.word-table td.w { width: 26%; }
.word-table td.act { white-space: nowrap; width: 1%; }
.word-table .input { padding: 8px 10px; }
.mini { border: 0; background: #eef2ff; border-radius: 10px; min-width: 40px; height: 40px; cursor: pointer; font-size: 1.05rem; }
.mini.has { background: var(--green-bg); }
.mini.del { background: var(--red-bg); }
@media (max-width: 680px) {
  .word-table, .word-table tbody, .word-table tr, .word-table td { display: block; width: 100% !important; }
  .word-table thead { display: none; }
  .word-table tr { border-bottom: 2px solid var(--line); padding: 8px 0; }
  .word-table td.n { text-align: left; }
}
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 8px; display: flex; gap: 10px; flex-wrap: wrap; }
.data-table { width: 100%; border-collapse: collapse; font-size: .98rem; }
.data-table th, .data-table td { text-align: left; padding: 8px 6px; border-bottom: 2px solid var(--line); }
.data-table th { color: var(--muted); font-size: .85rem; }
.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > div { height: 100%; background: var(--red); }
.pinpad { display: grid; grid-template-columns: repeat(3, 76px); gap: 12px; justify-content: center; margin: 18px 0; }
.pinpad button { height: 76px; border-radius: 20px; border: 0; background: #fff; font-size: 1.8rem; font-weight: 900; box-shadow: 0 5px 0 var(--line); cursor: pointer; }
.pinpad button:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--line); }
.pin-dots { font-size: 2rem; letter-spacing: .4em; min-height: 48px; }
details.test-detail summary { cursor: pointer; font-weight: 800; padding: 6px 0; }
.url-list code { display: inline-block; background: #eef2ff; padding: 6px 10px; border-radius: 10px; font-size: 1.05rem; margin: 3px 0; }

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