/* Kenneth's School App. White canvas, chunky blocky game look. No dark mode. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --ink: #1b1f2a;
  --muted: #5b6478;
  --line: #e6e9f0;
  --soft: #f5f7fb;
  --accent: #2f7cf6;
  --accent-dark: #1d5fd0;
  --accent-soft: #e6f0ff;
  --win: #22b35e;
  --win-dark: #178a46;
  --gold: #ffc21a;
  --gold-dark: #d99a00;
  --hint: #ff9f1c;
  --grape: #8b5cf6;
  --radius: 18px;
  --shadow: 0 6px 0 rgba(27, 31, 42, 0.12);
  --font: "Fredoka", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}
body[data-theme="lime"]  { --accent: #3fb618; --accent-dark: #2f8c10; --accent-soft: #eafbe2; }
body[data-theme="grape"] { --accent: #8b5cf6; --accent-dark: #6d3fe0; --accent-soft: #f1ebff; }
body[data-theme="lava"]  { --accent: #f2621f; --accent-dark: #c94a0e; --accent-soft: #fff0e8; }
body[data-theme="ocean"] { --accent: #0ea5b7; --accent-dark: #0a7f8e; --accent-soft: #e2f8fb; }
/* Spooky: haunted purple with pumpkin orange. Still a white canvas. */
body[data-theme="spooky"] { --accent: #5b21b6; --accent-dark: #3b0f80; --accent-soft: #f1eafd; --gold: #f97316; --gold-dark: #c2410c; }
body[data-theme="spooky"] .logo .cube { background: #f97316; box-shadow: inset -5px -5px 0 #5b21b6; }
body[data-theme="spooky"] .avatar-stage { background: linear-gradient(#efe7fb, #fff); }
body[data-theme="spooky"] .xpbar > div { background: repeating-linear-gradient(45deg, #5b21b6, #5b21b6 12px, #f97316 12px, #f97316 24px); }
body[data-theme="spooky"] .question-box { border-style: dashed; }
body[data-theme="spooky"] .topbar::after { content: "🦇"; position: absolute; right: 12px; bottom: -22px; font-size: 18px; animation: flap 3s ease-in-out infinite; pointer-events: none; }
@keyframes flap { 50% { transform: translate(-14px, 4px) rotate(-8deg); } }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { min-height: 100vh; font-size: 18px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.15; letter-spacing: 0.2px; }
h1 { font-size: 30px; } h2 { font-size: 24px; } h3 { font-size: 20px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.hidden { display: none !important; }

.wrap { max-width: 980px; margin: 0 auto; padding: 16px 16px 120px; }

/* Buttons */
.btn {
  font: inherit; font-weight: 700; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; padding: 12px 20px; border-radius: 14px;
  box-shadow: 0 5px 0 var(--accent-dark); transition: transform .06s, box-shadow .06s;
  display: inline-flex; align-items: center; gap: 8px; justify-content: center; min-height: 48px; white-space: nowrap;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn.win { background: var(--win); box-shadow: 0 5px 0 var(--win-dark); }
.btn.gold { background: var(--gold); color: #3a2a00; box-shadow: 0 5px 0 var(--gold-dark); }
.btn.ghost { background: var(--soft); color: var(--ink); box-shadow: 0 5px 0 var(--line); }
.btn.small { min-height: 38px; padding: 6px 14px; font-size: 15px; }
.btn:disabled { opacity: .55; cursor: default; }

/* Cards */
.card { background: #fff; border: 3px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
@media (min-width: 760px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.lobby { grid-template-columns: 300px 1fr; } }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 3px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 5; flex-wrap: wrap; }
.logo { font-weight: 800; font-size: 20px; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.logo .cube { width: 28px; height: 28px; background: var(--accent); border-radius: 7px; box-shadow: inset -5px -5px 0 rgba(0,0,0,.15); }
.spacer { flex: 1; }
.pill { background: var(--soft); border: 2px solid var(--line); border-radius: 999px; padding: 4px 12px; font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.pill.coin::before { content: ""; width: 14px; height: 14px; border-radius: 50%; background: var(--gold); box-shadow: inset -2px -2px 0 var(--gold-dark); }
.pill.fire::before { content: "🔥"; }

/* Login */
.login { max-width: 420px; margin: 8vh auto; text-align: center; }
.login input { width: 100%; }
input, textarea, select {
  font: inherit; border: 3px solid var(--line); border-radius: 14px; padding: 12px 14px; background: #fff; color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { width: 100%; min-height: 140px; resize: vertical; }
label { font-weight: 700; display: block; margin: 10px 0 6px; }

/* Lobby */
.avatar-stage { background: linear-gradient(#e9f3ff, #fff); border-radius: 16px; display: flex; justify-content: center; padding: 10px; }
.xpbar { height: 22px; background: var(--soft); border: 3px solid var(--line); border-radius: 12px; overflow: hidden; }
.xpbar > div { height: 100%; background: repeating-linear-gradient(45deg, var(--accent), var(--accent) 12px, var(--accent-dark) 12px, var(--accent-dark) 24px); transition: width .6s; }
.level-badge { font-size: 42px; font-weight: 800; color: var(--accent); line-height: 1; }
.quest { display: flex; gap: 14px; align-items: center; padding: 14px; border: 3px solid var(--line); border-radius: 16px; margin-bottom: 12px; cursor: pointer; background: #fff; box-shadow: var(--shadow); }
.quest:hover { border-color: var(--accent); }
.quest .icon { width: 54px; height: 54px; border-radius: 12px; display: grid; place-items: center; font-size: 28px; background: var(--accent-soft); flex: none; }
.quest .meta { flex: 1; min-width: 0; }
.quest .title { font-weight: 800; }
.progress { height: 12px; background: var(--soft); border-radius: 8px; overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--win); }
.badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge { background: #fff8e1; border: 3px solid var(--gold); border-radius: 12px; padding: 4px 10px; font-weight: 700; font-size: 14px; }
.badge.locked { background: var(--soft); border-color: var(--line); color: var(--muted); }

/* Quest / coach */
.levels { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 14px; }
.lvl { width: 38px; height: 38px; border-radius: 10px; border: 3px solid var(--line); background: #fff; font-weight: 800; cursor: pointer; font-family: inherit; font-size: 16px; color: var(--ink); }
.lvl.done { background: var(--win); border-color: var(--win-dark); color: #fff; }
.lvl.current { border-color: var(--accent); background: var(--accent-soft); }
.question-box { background: var(--accent-soft); border: 3px solid var(--accent); border-radius: 16px; padding: 14px; font-weight: 700; font-size: 20px; }
.toolbox { background: #fff8e1; border: 3px dashed var(--gold); border-radius: 14px; padding: 10px 14px; margin-top: 10px; font-size: 16px; }
.chat { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.msg { padding: 12px 14px; border-radius: 16px; max-width: 88%; white-space: normal; }
.msg.coach { background: var(--soft); border: 3px solid var(--line); align-self: flex-start; }
.msg.me { background: var(--accent); color: #fff; align-self: flex-end; }
.msg.thinking { color: var(--muted); font-style: italic; }
.composer { position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 3px solid var(--line); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); z-index: 6; }
.composer .row { max-width: 980px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 52px; max-height: 160px; flex: 1; }
.mic { width: 64px; height: 64px; border-radius: 50%; padding: 0; font-size: 28px; flex: none; }
.mic.listening { background: var(--win); box-shadow: 0 5px 0 var(--win-dark); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.chips { display: flex; gap: 8px; flex-wrap: wrap; max-width: 980px; margin: 0 auto 8px; }
.chip { font: inherit; font-size: 14px; font-weight: 700; padding: 6px 12px; border-radius: 999px; border: 2px solid var(--line); background: #fff; cursor: pointer; color: var(--ink); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); }
.timer { font-variant-numeric: tabular-nums; }
.answer-list li { margin-bottom: 10px; }

/* Shop */
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.shop-item { border: 3px solid var(--line); border-radius: 16px; padding: 12px; text-align: center; background: #fff; box-shadow: var(--shadow); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 36px; height: 36px; border-radius: 10px; border: 3px solid #fff; outline: 3px solid var(--line); cursor: pointer; }
.swatch.on { outline-color: var(--ink); }

/* Toasts and confetti */
.toast-zone { position: fixed; top: 76px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #fff; border: 3px solid var(--gold); border-radius: 16px; padding: 10px 18px; font-weight: 800; box-shadow: var(--shadow); animation: pop .35s ease-out; }
.toast.err { border-color: var(--hint); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.confetti { position: fixed; top: -12px; width: 12px; height: 12px; z-index: 60; pointer-events: none; animation: fall 1.6s linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); } }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(27,31,42,.35); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { max-width: 460px; width: 100%; text-align: center; }

/* Parent view */
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { text-align: left; padding: 8px; border-bottom: 2px solid var(--line); vertical-align: top; }
.bars { display: flex; gap: 6px; align-items: flex-end; height: 140px; padding-top: 8px; }
.bars .b { flex: 1; background: var(--accent); border-radius: 6px 6px 0 0; min-height: 2px; position: relative; }
.bars .b span { position: absolute; top: -20px; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--muted); }
.bar-labels { display: flex; gap: 6px; font-size: 11px; color: var(--muted); }
.bar-labels div { flex: 1; text-align: center; }
details { border: 3px solid var(--line); border-radius: 14px; padding: 10px 14px; margin-bottom: 10px; }
summary { cursor: pointer; font-weight: 700; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

body.chatting .wrap { padding-bottom: 200px; }
@media (max-width: 520px) {
  body { font-size: 17px; }
  .logo span { display: none; }
  .topbar { flex-wrap: nowrap; gap: 6px; padding: 10px 12px; }
  .pill { padding: 3px 9px; font-size: 14px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .chip { white-space: nowrap; flex: none; }
  h1 { font-size: 26px; }
  .question-box { font-size: 18px; }
  .mic { width: 58px; height: 58px; }
  .msg { max-width: 94%; }
}

/* Boss battle */
.boss-card { max-width: 640px; margin: 0 auto; text-align: center; }
.boss-face { font-size: 84px; animation: bob 2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-4deg); } }
.taunt { font-style: italic; color: var(--muted); }
.hp { height: 18px; background: var(--soft); border: 3px solid var(--line); border-radius: 10px; overflow: hidden; margin-top: 10px; }
.hp > div { height: 100%; background: linear-gradient(90deg, #f97316, #e11d48); transition: width .4s; }
.opts { display: grid; gap: 10px; }
.opt { justify-content: flex-start; text-align: left; white-space: normal; }
.opt.right { background: var(--win); color: #fff; box-shadow: 0 5px 0 var(--win-dark); }
.opt.nope { background: #fff1e0; box-shadow: 0 5px 0 var(--hint); }
.boss-card.hit { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* Drawing */
.drawpad { max-width: 760px; }
#pad { width: 100%; height: auto; border: 3px solid var(--line); border-radius: 14px; touch-action: none; background: #fff; cursor: crosshair; }
img.drawing { max-width: 100%; width: 320px; border-radius: 12px; border: 3px solid var(--line); background: #fff; display: block; margin: 4px 0; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); }

/* Wins and report */
.wins .win, .win { padding: 6px 0; border-bottom: 2px solid var(--soft); }
.report h3 { margin-top: 14px; }
.report ul { margin: 6px 0; padding-left: 22px; }
@media print {
  .topbar, .tabs, .no-print-hide, .composer, h1, .report ~ h2, .report ~ .card { display: none !important; }
  .report { border: 0; box-shadow: none; }
  .wrap { padding: 0; }
}
.opt.right:disabled, .opt.nope:disabled { opacity: 1; }
#bnext, #fight { min-width: 150px; margin-top: 6px; }
.modal { max-height: 92vh; overflow-y: auto; }

/* Google Classroom board */
.cl-group h3 { margin: 12px 0 6px; font-size: 17px; }
.cl-item { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 3px solid var(--line); border-radius: 14px; margin-bottom: 8px; background: #fff; }
.cl-item .meta { flex: 1; min-width: 0; }
.cl-item .title { font-weight: 800; }
.cl-item.missing { border-color: var(--hint); background: #fff7ee; }
.cl-item.done { opacity: .75; }
.fr { color: var(--accent-dark); font-weight: 700; }

.giftcard { margin: 0 auto 6px; width: 96px; height: 60px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), var(--grape)); color: #fff; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 26px; font-weight: 800; box-shadow: inset -6px -6px 0 rgba(0,0,0,.12); }
.giftcard span { font-size: 20px; }

/* Horror: an original survival-horror look. Dark, blood red, flickering. */
body[data-theme="horror"] {
  color-scheme: dark;
  --bg: #0b0909; --ink: #ece4e4; --muted: #a89a9a; --line: #2e2323; --soft: #171111;
  --accent: #d0102b; --accent-dark: #6e0012; --accent-soft: #2a0c10;
  --win: #2f9e44; --win-dark: #1b5e2a; --gold: #e8c547; --gold-dark: #8f7414; --hint: #ff7a1a;
  --shadow: 0 6px 0 rgba(0,0,0,.6);
  background: var(--bg); color: var(--ink);
}
body[data-theme="horror"]::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(208,16,43,.10), rgba(0,0,0,0) 60%),
    radial-gradient(ellipse at center, rgba(0,0,0,0) 50%, rgba(0,0,0,.65) 100%);
}
body[data-theme="horror"] .wrap, body[data-theme="horror"] .topbar { position: relative; z-index: 1; }
body[data-theme="horror"] .topbar { background: #0b0909; border-bottom: 0; position: sticky; }
body[data-theme="horror"] .topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -14px; height: 16px; pointer-events: none;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='16' viewBox='0 0 120 16'><path d='M0 0h120v4c-6 0-6 9-11 9s-4-9-10-9-5 5-10 5-4-5-9-5-6 11-12 11-5-11-11-11-4 6-9 6-5-6-10-6-6 8-11 8-5-8-10-8-5 4-9 4-5-4-8-4z' fill='%23d0102b'/></svg>") repeat-x;
}
body[data-theme="horror"] h1, body[data-theme="horror"] h2, body[data-theme="horror"] .logo span, body[data-theme="horror"] .level-badge {
  font-family: "Creepster", var(--font); letter-spacing: 1.5px; font-weight: 400; color: var(--accent);
  text-shadow: 0 0 12px rgba(208,16,43,.45);
}
body[data-theme="horror"] h1 { font-size: 36px; animation: flicker 6s infinite; }
body[data-theme="horror"] h2 { font-size: 27px; color: #f3dede; }
@keyframes flicker { 0%, 92%, 96%, 100% { opacity: 1; } 93% { opacity: .3; } 95% { opacity: .75; } }
body[data-theme="horror"] .logo .cube { background: var(--accent); box-shadow: inset -5px -5px 0 #000, 0 0 12px rgba(208,16,43,.6); }

/* Surfaces */
body[data-theme="horror"] .card, body[data-theme="horror"] .quest, body[data-theme="horror"] .shop-item,
body[data-theme="horror"] .cl-item, body[data-theme="horror"] .toast, body[data-theme="horror"] details,
body[data-theme="horror"] .composer, body[data-theme="horror"] .lvl, body[data-theme="horror"] .chip,
body[data-theme="horror"] input, body[data-theme="horror"] textarea, body[data-theme="horror"] select {
  background: #130e0e; color: var(--ink); border-color: var(--line);
}
body[data-theme="horror"] .card { box-shadow: 0 6px 0 rgba(0,0,0,.55), 0 0 0 1px rgba(208,16,43,.08); }
body[data-theme="horror"] .card:nth-child(odd) { transform: rotate(-.25deg); }
body[data-theme="horror"] .composer { border-top-color: #2a1a1a; }
body[data-theme="horror"] .pill { background: #1c1414; border-color: var(--line); color: var(--ink); }
body[data-theme="horror"] .btn.ghost { background: #1c1414; color: var(--ink); box-shadow: 0 5px 0 #000; }
body[data-theme="horror"] .btn.gold { color: #1a1300; }
body[data-theme="horror"] a { color: #ff6b7d; }
body[data-theme="horror"] .muted { color: var(--muted); }
body[data-theme="horror"] input:focus, body[data-theme="horror"] textarea:focus { border-color: var(--accent); }

/* Game pieces */
body[data-theme="horror"] .avatar-stage { background: radial-gradient(ellipse at 50% 30%, #2a1212, #0f0b0b 75%); }
body[data-theme="horror"] .xpbar, body[data-theme="horror"] .progress, body[data-theme="horror"] .hp { background: #1c1414; border-color: var(--line); }
body[data-theme="horror"] .xpbar > div { background: repeating-linear-gradient(45deg, #d0102b, #d0102b 12px, #6e0012 12px, #6e0012 24px); box-shadow: 0 0 10px rgba(208,16,43,.6); }
body[data-theme="horror"] .question-box { background: #1a0c0e; border-style: dashed; color: #fff; }
body[data-theme="horror"] .toolbox { background: #1d1708; border-color: #8f7414; }
body[data-theme="horror"] .msg.coach { background: #1a1313; border-color: #2e2323; }
body[data-theme="horror"] .msg.me { background: #6e0012; }
body[data-theme="horror"] .lvl.current { border-color: var(--accent); background: #2a0c10; }
body[data-theme="horror"] .lvl.done { background: #2f9e44; border-color: #1b5e2a; }
body[data-theme="horror"] .quest:hover { border-color: var(--accent); }
body[data-theme="horror"] .quest .icon { background: #2a0c10; }
body[data-theme="horror"] .badge { border-color: #6e0012; background: #1c0f11; color: var(--ink); }
body[data-theme="horror"] .badge.locked { background: #141010; border-color: #2a2020; color: #6f6363; }
body[data-theme="horror"] .cl-item.missing { border-color: var(--accent); background: #22090d; }
body[data-theme="horror"] .hp > div { background: linear-gradient(90deg, #6e0012, #d0102b); box-shadow: 0 0 10px rgba(208,16,43,.6); }
body[data-theme="horror"] .boss-face { filter: drop-shadow(0 0 14px rgba(208,16,43,.6)); }
body[data-theme="horror"] .opt.nope { background: #2a1606; }
body[data-theme="horror"] .fr { color: #ff8a9a; }
body[data-theme="horror"] .modal-back { background: rgba(0,0,0,.7); }
body[data-theme="horror"] th, body[data-theme="horror"] td { border-bottom-color: var(--line); }
body[data-theme="horror"] .wins .win, body[data-theme="horror"] .win { border-bottom-color: #1c1414; }
/* Drawings stay on white paper so his pen colours show. */
body[data-theme="horror"] #pad, body[data-theme="horror"] img.drawing { background: #fff; }
@media (prefers-reduced-motion: reduce) { body[data-theme="horror"] h1 { animation: none; } }
@media print { body[data-theme="horror"] { background: #fff; color: #000; } }

#btn-msg { position: relative; padding: 6px 12px; }
#btn-msg .dot { position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; border-radius: 10px; background: #e11d48; color: #fff; font-size: 12px; display: grid; place-items: center; padding: 0 5px; }
#msg-send, #q-go { min-width: 150px; }
