:root {
  --bg: #0d1030;
  --panel: #1b1f4b;
  --panel-edge: #3a3f8f;
  --text: #f4f6ff;
  --muted: #a9b0e8;
  --yellow: #ffd23f;
  --orange: #ff8c1a;
  --green: #4be36b;
  --red: #ff4d6d;
  --blue: #4fc3ff;
  --purple: #b86bff;
  --font: "Baloo 2", "Trebuchet MS", "Segoe UI Rounded", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

canvas#game {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---------- Panels & buttons ---------- */
.panel {
  background: linear-gradient(180deg, #232864, var(--panel));
  border: 3px solid var(--panel-edge);
  border-radius: 22px;
  padding: 22px 26px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), inset 0 2px 0 rgba(255, 255, 255, 0.08);
  text-align: center;
  max-width: min(94vw, 520px);
  width: 100%;
}

.big-btn {
  display: block;
  width: 100%;
  margin: 12px auto 0;
  padding: 14px 18px;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #2a1600;
  background: linear-gradient(180deg, #ffe066, var(--yellow) 50%, var(--orange));
  border: none;
  border-radius: 16px;
  box-shadow: 0 5px 0 #b35c00, 0 8px 18px rgba(0, 0, 0, 0.35);
  transition: transform 0.08s;
}
.big-btn:hover { filter: brightness(1.08); }
.big-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #b35c00; }
.big-btn.secondary {
  color: var(--text);
  background: linear-gradient(180deg, #4a50a8, #343a86);
  box-shadow: 0 5px 0 #20245a, 0 8px 18px rgba(0, 0, 0, 0.35);
  font-size: 1.1rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  font-size: 0.9rem;
}

/* ---------- Screens ---------- */
.screen, .modal {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  z-index: 10;
}
.modal { background: rgba(6, 8, 28, 0.62); backdrop-filter: blur(3px); z-index: 20; }

.logo {
  margin: 0;
  font-size: clamp(2.6rem, 9vw, 5rem);
  font-weight: 900;
  line-height: 1;
  color: var(--blue);
  text-shadow: 0 4px 0 #1b5f99, 0 0 30px rgba(79, 195, 255, 0.5);
  letter-spacing: 0.02em;
}
.logo span {
  color: var(--yellow);
  text-shadow: 0 4px 0 #b35c00, 0 0 30px rgba(255, 210, 63, 0.5);
  margin-left: 0.15em;
}
.tagline { margin: 8px 0 18px; color: var(--muted); font-size: 1.15rem; }

.skill-now { min-height: 1.4em; color: var(--muted); font-size: 1.05rem; line-height: 1.5; }
.skill-now b { color: var(--yellow); }

.howto {
  margin-top: 18px;
  max-width: 520px;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.55;
  text-align: left;
}
.howto b { color: var(--text); }
.small-links { margin-top: 12px; display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: 0.9rem; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
.hud-left { position: absolute; top: 12px; left: 12px; width: min(46vw, 320px); }
.hud-right { position: absolute; top: 10px; right: 12px; text-align: right; }
.bar {
  position: relative;
  height: 22px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 6px;
}
.bar .fill { height: 100%; width: 0; transition: width 0.12s; }
.bar.hp .fill { background: linear-gradient(90deg, #ff4d6d, #ff8fa3); }
.bar.xp .fill { background: linear-gradient(90deg, #36b9ff, #7fe3ff); }
.bar.boss .fill { background: linear-gradient(90deg, #8b3dff, #d38bff); }
.bar span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 800;
  text-shadow: 0 1px 2px #000;
}
.skill-pill {
  display: inline-block;
  font-size: 0.8rem;
  padding: 2px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.45);
  color: var(--muted);
}
.stat { font-size: 1.6rem; font-weight: 900; text-shadow: 0 2px 3px #000; }
.stat.small { font-size: 0.95rem; font-weight: 700; color: var(--muted); }
.hud-buttons { margin-top: 6px; display: flex; gap: 6px; justify-content: flex-end; pointer-events: auto; }
.icon-btn {
  width: 42px; height: 42px;
  font-size: 1.2rem;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.45);
  color: var(--text);
}
#bossBar {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: min(80vw, 520px);
  text-align: center;
}
.boss-name { font-weight: 900; color: #e4c2ff; text-shadow: 0 2px 3px #000; margin-bottom: 4px; }

/* ---------- Math panel ---------- */
.math-panel { max-width: min(94vw, 420px); padding: 18px 20px; }
.math-title {
  font-size: 2rem;
  font-weight: 900;
  color: var(--yellow);
  text-shadow: 0 3px 0 #b35c00;
  line-height: 1.1;
}
.math-sub { color: var(--muted); margin: 4px 0 8px; }
.skill-tag {
  display: inline-block;
  font-size: 0.8rem;
  padding: 2px 10px;
  border-radius: 10px;
  background: #2d3380;
  color: #c8ceff;
}
.question {
  font-size: clamp(2.2rem, 10vw, 3.2rem);
  font-weight: 900;
  margin: 10px 0 2px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.prompt { color: var(--muted); min-height: 1.4em; }
.prompt.hint { color: #ffe680; }
.answer-box {
  margin: 8px auto 12px;
  width: 70%;
  min-height: 62px;
  font-size: 2.4rem;
  font-weight: 900;
  line-height: 58px;
  background: #0b0e2a;
  border: 3px solid var(--blue);
  border-radius: 16px;
  color: #fff;
}
.answer-box.empty { border-style: dashed; }
.answer-box.shake { animation: shake 0.3s; }
@keyframes shake {
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.keypad button {
  padding: 10px 0;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  background: linear-gradient(180deg, #3d439c, #2d3380);
  border: none;
  border-radius: 14px;
  box-shadow: 0 4px 0 #1a1e55;
}
.keypad button:active { transform: translateY(3px); box-shadow: 0 1px 0 #1a1e55; }
.keypad button.soft { background: linear-gradient(180deg, #2a2f70, #22265e); }
.keypad .hint-btn { font-size: 1.1rem; background: linear-gradient(180deg, #6d5a12, #4f4110); }
.keypad .hint-btn:disabled { opacity: 0.4; }
.keypad .go-btn {
  grid-column: span 2;
  font-size: 1.3rem;
  color: #0b3315;
  background: linear-gradient(180deg, #8dffa4, var(--green));
  box-shadow: 0 4px 0 #1f8a37;
}

.feedback { margin-top: 10px; }
.fb-title { font-size: 1.8rem; font-weight: 900; }
.feedback.good .fb-title { color: var(--green); }
.feedback.bad .fb-title { color: #ffb36b; }
.fb-body { margin-top: 6px; font-size: 1.08rem; line-height: 1.45; }
.fb-body .eq { font-size: 1.6rem; font-weight: 900; display: block; margin: 4px 0; }
.fb-body .note { display: block; margin-top: 8px; color: var(--yellow); font-weight: 700; }

/* ---------- Upgrade cards ---------- */
.up-panel { max-width: min(96vw, 760px); }
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.card {
  position: relative;
  padding: 14px 10px 12px;
  background: linear-gradient(180deg, #2f3590, #252a72);
  border: 3px solid #5960c9;
  border-radius: 18px;
  color: var(--text);
  text-align: center;
  transition: transform 0.1s, border-color 0.1s;
  animation: pop 0.25s ease-out backwards;
}
.card:hover, .card:focus { transform: translateY(-4px) scale(1.03); border-color: var(--yellow); outline: none; }
.card .icon { font-size: 2.4rem; }
.card .name { font-size: 1.15rem; font-weight: 900; margin-top: 4px; }
.card .lvl { font-size: 0.8rem; color: var(--yellow); font-weight: 800; }
.card .desc { font-size: 0.92rem; color: #cfd4ff; margin-top: 6px; }
.card .key {
  position: absolute; top: 6px; left: 8px;
  font-size: 0.75rem; color: var(--muted);
}
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }

.pause-powers, .go-stats { margin: 10px 0 4px; line-height: 1.6; }
.go-stats { display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; text-align: left; font-size: 1.1rem; }
.go-stats .v { font-weight: 900; color: var(--yellow); text-align: right; }
.go-stats .full { grid-column: span 2; text-align: center; margin-top: 8px; color: var(--green); font-weight: 800; }
.pause-powers span {
  display: inline-block;
  margin: 3px;
  padding: 3px 9px;
  border-radius: 10px;
  background: #2d3380;
  font-size: 0.9rem;
}

/* ---------- Power Check ---------- */
.check-progress {
  height: 8px;
  margin: 6px auto 4px;
  width: 70%;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 6px;
  overflow: hidden;
}
.check-progress div { height: 100%; background: linear-gradient(90deg, var(--green), #b9ffc6); transition: width 0.2s; }
.keypad .skip-btn { font-size: 0.95rem; background: linear-gradient(180deg, #4a5068, #363b52); }

/* ---------- Parent panel ---------- */
.parent-panel { max-width: min(96vw, 980px); max-height: 94vh; overflow-y: auto; text-align: left; user-select: text; }
.pin-gate { text-align: center; max-width: 340px; margin: 0 auto; }
.pin-gate input {
  font-family: inherit;
  font-size: 2rem;
  letter-spacing: 0.5em;
  text-align: center;
  width: 190px;
  padding: 8px 0 8px 0.5em;
  border-radius: 14px;
  border: 3px solid var(--blue);
  background: #0b0e2a;
  color: #fff;
}
.pin-error { color: var(--red); min-height: 1.3em; margin-top: 6px; }
.parent-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.parent-head .close-btn { width: auto; margin: 0; padding: 8px 22px; }
.sum-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 12px 0; }
.sum-card { background: #2a2f78; border-radius: 12px; padding: 8px; text-align: center; }
.sum-v { font-size: 1.5rem; font-weight: 900; color: var(--yellow); }
.sum-k { font-size: 0.8rem; color: var(--muted); }
.parent-help { color: var(--muted); font-size: 0.92rem; line-height: 1.5; }
.parent-help b { color: var(--text); }
.strand h3 { margin: 16px 0 4px; color: var(--blue); }
.strand-note { color: var(--muted); font-size: 0.85rem; margin-bottom: 4px; }
.table-wrap { overflow-x: auto; }
.strand table { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 640px; }
.strand th { text-align: left; color: var(--muted); font-weight: 700; font-size: 0.78rem; padding: 4px 6px; }
.strand td { padding: 7px 6px; border-top: 1px solid rgba(255, 255, 255, 0.08); vertical-align: top; }
.st { font-weight: 800; }
.st-mastered { color: var(--yellow); }
.st-ready { color: var(--green); }
.st-notyet { color: #ffb36b; }
.st-unassessed { color: var(--muted); }
.st-sub { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }
.st-sub.force { color: var(--blue); font-weight: 700; }
.dots { white-space: nowrap; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 2px; }
.dot.y { background: var(--green); }
.dot.n { background: var(--red); }
.strand select {
  font-family: inherit;
  background: #2d3380;
  color: var(--text);
  border: 2px solid #444bb0;
  border-radius: 8px;
  padding: 3px 4px;
}
.mini-btn {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
  padding: 3px 8px;
  border-radius: 8px;
  border: 1px solid #5960c9;
  background: transparent;
  color: var(--text);
}
.parent-foot { margin-top: 16px; display: flex; justify-content: space-between; }
.link-btn.danger { color: #ff8fa3; }

@media (max-height: 640px) {
  .question { margin: 4px 0 0; }
  .answer-box { min-height: 48px; line-height: 44px; font-size: 2rem; margin: 4px auto 8px; }
  .keypad button { padding: 6px 0; font-size: 1.3rem; }
  .howto { display: none; }
}

/* ---------- Accounts & players ---------- */
.auth-panel, .kid-panel { max-width: min(94vw, 460px); }
.kid-panel { max-width: min(96vw, 640px); }
.auth-note { color: var(--muted); line-height: 1.45; margin: 6px 0 12px; }
.auth-panel input:not([type="checkbox"]), .add-kid input:not([type="checkbox"]), .delete-form input {
  display: block;
  width: 100%;
  font-family: inherit;
  font-size: 1.15rem;
  margin: 8px 0;
  padding: 10px 14px;
  border-radius: 12px;
  border: 3px solid var(--panel-edge);
  background: #0b0e2a;
  color: #fff;
  user-select: text;
}
.auth-panel input:focus, .add-kid input:focus { outline: none; border-color: var(--blue); }
.auth-panel .link-btn { margin-top: 10px; }
.kid-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-top: 10px; }
.kid-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 14px 8px; border-radius: 18px; border: 3px solid var(--panel-edge);
  background: #2a2f78; color: var(--text); transition: transform 0.1s, border-color 0.1s;
}
.kid-card:hover, .kid-card:focus { transform: translateY(-3px); border-color: var(--yellow); outline: none; }
.kid-card.add { background: transparent; border-style: dashed; }
.kid-face {
  width: 62px; height: 62px; border-radius: 50%; display: grid; place-items: center;
  font-size: 2rem; font-weight: 900; color: #1b1f4b; background: #3a3f8f;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2);
}
.kid-card.add .kid-face { color: var(--muted); }
.kid-name { font-size: 1.15rem; font-weight: 900; }
.kid-sub { font-size: 0.8rem; color: var(--muted); }
.kid-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.who-row { margin-bottom: 6px; font-size: 1.1rem; }
.who-row .link-btn { font-size: 0.9rem; }

/* ---------- Live co-op games ---------- */
.live-games { margin-top: 12px; text-align: left; }
.live-head { color: var(--muted); font-size: 0.85rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
.live-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #2a2f78; border-radius: 12px; padding: 8px 12px; margin-top: 6px;
}
.live-row small { color: var(--muted); }
.join-btn { font-size: 1rem; padding: 6px 16px; }
.wait-panel { max-width: min(94vw, 420px); }
.wait-text { font-size: 1.15rem; line-height: 1.5; }
.wait-dots { display: flex; gap: 8px; justify-content: center; }
.wait-dots i { width: 12px; height: 12px; border-radius: 50%; background: var(--blue); animation: blink 1.2s infinite; }
.wait-dots i:nth-child(2) { animation-delay: 0.2s; }
.wait-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
.team-list { margin-top: 6px; display: flex; flex-direction: column; gap: 3px; }
.mate { font-size: 0.85rem; font-weight: 800; text-shadow: 0 1px 2px #000; display: flex; align-items: center; gap: 4px; }
.mate small { color: #ffb36b; }
.mate-bar { display: inline-block; width: 70px; height: 6px; border-radius: 3px; background: rgba(0, 0, 0, 0.5); overflow: hidden; margin-left: 4px; }
.mate-bar span { display: block; height: 100%; background: #ff4d6d; }
.go-stats .note-line { color: #ffb36b; margin: 0 0 8px; }

/* ---------- Grown-ups: family view ---------- */
.parent-account { color: var(--muted); font-size: 0.9rem; margin: 4px 0 8px; }
.parent-panel h3 { margin: 16px 0 6px; }
.family-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; min-width: 640px; }
.family-table th { text-align: left; color: var(--muted); font-weight: 700; font-size: 0.78rem; padding: 4px 6px; }
.family-table td { padding: 7px 6px; border-top: 1px solid rgba(255, 255, 255, 0.08); cursor: pointer; }
.family-table tr.on td { background: rgba(79, 195, 255, 0.12); }
.kid-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 4px; }
.kid-tab {
  border: 2px solid var(--panel-edge); background: #22265e; color: var(--text);
  border-radius: 999px; padding: 6px 14px; font-weight: 800; font-size: 0.95rem;
}
.kid-tab.on { border-color: var(--yellow); background: #2a2f78; }
.kid-tab.add { border-style: dashed; color: var(--muted); }
.add-kid { max-width: 420px; margin: 8px auto; text-align: center; }
.kid-colors { display: flex; gap: 10px; justify-content: center; margin: 8px 0; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent; }
.swatch.on { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25); }
.import-row { display: block; color: var(--muted); font-size: 0.9rem; margin: 6px 0; }
.parent-foot span { display: flex; gap: 14px; }

/* ---------- Skill trees (tabbed talent view) ---------- */
.tree-panel { max-width: min(98vw, 860px); max-height: 96vh; overflow-y: auto; padding: 14px 16px; }
.tree-panel .cards { display: block; }
.tree-tabs { display: flex; gap: 6px; border-bottom: 3px solid #3a3f8f; margin-bottom: 8px; }
.tree-tab {
  position: relative; flex: 1; padding: 8px 6px 6px; border-radius: 12px 12px 0 0; border: 3px solid #3a3f8f; border-bottom: 0;
  background: #1c2050; color: var(--muted); display: flex; flex-direction: column; align-items: center; margin-bottom: -3px;
}
.tree-tab.active { background: #2f3590; color: var(--text); border-color: var(--yellow); }
.tree-tab .tt-icon { font-size: 1.5rem; }
.tree-tab .tt-name { font-weight: 900; }
.tree-tab .tt-role { font-size: 0.72rem; }
.tree-tab .tt-pts { font-size: 0.75rem; color: var(--yellow); font-weight: 800; }
.tree-tab .tt-dot { position: absolute; top: 6px; right: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
.tree-mastery { font-size: 0.85rem; color: #cfd4ff; margin: 4px 0 8px; }
.tree-mastery b { color: var(--blue); }
.talent { position: relative; display: flex; flex-direction: column; gap: 22px; padding: 4px 0 8px; }
.talent-lines { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
.talent-lines path { fill: none; stroke-width: 3; }
.talent-lines path.on { stroke: #ffd23f; }
.talent-lines path.off { stroke: #4a4f8f; stroke-dasharray: 5 4; }
.talent-lines text { font-size: 11px; font-weight: 900; }
.talent-lines text.on { fill: #ffd23f; } .talent-lines text.off { fill: #7d84c9; }
.t-row { display: grid; grid-template-columns: 58px repeat(4, 1fr); gap: 10px; align-items: stretch; position: relative; }
.t-row.closed .t-label { color: #5a5fa0; }
.t-label {
  font-size: 0.7rem; font-weight: 800; color: var(--muted); text-transform: uppercase;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; border-right: 2px dashed #3a3f8f;
}
.t-label small { text-transform: none; font-size: 0.68rem; }
.t-cell.empty { min-height: 10px; }
.node {
  position: relative; z-index: 1; padding: 6px 5px; border-radius: 12px; text-align: center;
  border: 3px solid #3a3f8f; background: #22265e; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 1px; transition: transform 0.1s;
}
.node.primary { border-style: double; border-width: 4px; }
.node.available { border-color: var(--yellow); background: #2f3590; box-shadow: 0 0 14px rgba(255, 210, 63, 0.3); cursor: pointer; }
.node.available:hover, .node.available:focus { transform: translateY(-3px) scale(1.04); outline: none; }
.node.locked { opacity: 0.5; cursor: default; }
.node.locked.owned { opacity: 0.85; }
.node.maxed { border-color: var(--green); cursor: default; }
.node .n-icon { font-size: 1.5rem; }
.node .n-name { font-weight: 900; font-size: 0.82rem; line-height: 1.1; }
.node .n-lvl { font-size: 0.7rem; color: var(--yellow); font-weight: 800; }
.node.maxed .n-lvl { color: var(--green); }
.node .n-desc { font-size: 0.68rem; color: #cfd4ff; line-height: 1.2; }
.node .needs { font-size: 0.64rem; color: #ffb36b; margin-top: 2px; }
.node .key {
  position: absolute; top: 3px; left: 5px; font-size: 0.66rem; color: var(--muted);
  border: 1px solid var(--muted); border-radius: 5px; padding: 0 3px;
}
.tree-snack { margin-top: 8px; display: flex; gap: 10px; align-items: center; justify-content: center; }
.tree-snack .node { width: 160px; }
.last-game { margin-top: 6px; font-size: 0.92rem; color: var(--muted); }
.pause-class { font-size: 1.15rem; font-weight: 900; margin-bottom: 6px; }
@media (max-width: 640px) {
  .t-row { grid-template-columns: 34px repeat(4, 1fr); gap: 5px; }
  .t-label small { display: none; }
  .node .n-desc { display: none; }
  .node .n-name { font-size: 0.7rem; }
  .tree-tab .tt-role { display: none; }
}

/* ---------- Boss word problems ---------- */
.question.word { white-space: normal; letter-spacing: 0; font-size: 1.2rem; font-weight: 700; line-height: 1.45; text-align: left; margin: 8px 0; }
.math-panel.boss { border-color: #b86bff; box-shadow: 0 0 30px rgba(184, 107, 255, 0.45), 0 12px 40px rgba(0, 0, 0, 0.5); }
.math-panel.boss .math-title { color: #d9b8ff; }

/* ---------- Wardrobe ---------- */
.ward-panel { max-width: min(96vw, 720px); max-height: 94vh; overflow-y: auto; }
.ward-top { display: flex; gap: 14px; align-items: center; margin: 6px 0 10px; text-align: left; }
#wardPreview { background: radial-gradient(circle, #2f3590, #1c2050); border-radius: 16px; flex: 0 0 auto; }
.ward-count { font-weight: 900; font-size: 1.1rem; color: var(--yellow); }
.ward-slot { margin-bottom: 10px; text-align: left; }
.ward-slot-name { font-size: 0.75rem; font-weight: 800; color: var(--muted); text-transform: uppercase; margin-bottom: 4px; }
.ward-items { display: flex; flex-wrap: wrap; gap: 8px; }
.ward-item { width: 112px; padding: 6px; border-radius: 12px; border: 3px solid #3a3f8f; background: #22265e; color: var(--text); display: flex; flex-direction: column; align-items: center; }
.ward-item.owned { cursor: pointer; border-color: #6f78d8; }
.ward-item.owned:hover { transform: translateY(-2px); }
.ward-item.worn { border-color: var(--yellow); background: #2f3590; box-shadow: 0 0 12px rgba(255, 210, 63, 0.3); }
.ward-item.locked { opacity: 0.5; }
.ward-item .wi-icon { font-size: 1.7rem; }
.ward-item .wi-name { font-weight: 900; font-size: 0.8rem; }
.ward-item .wi-how { font-size: 0.66rem; color: #cfd4ff; }
.ward-item.worn .wi-how { color: var(--yellow); font-weight: 800; }

/* ---------- Parent progress charts ---------- */
.pc-title { margin: 18px 0 6px; color: var(--blue); font-size: 1.05rem; }
.pc-filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 4px; }
.pc-filters label { font-size: 0.8rem; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.pc-filters select { font: inherit; font-size: 0.92rem; padding: 5px 8px; border-radius: 8px; background: #22265e; color: var(--text); border: 2px solid var(--panel-edge); }
.pc-card { background: #1a1d4a; border: 2px solid #2c3175; border-radius: 14px; padding: 10px 12px; margin: 10px 0; }
.pc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.pc-sub { font-size: 0.78rem; color: var(--muted); }
.pc-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.8rem; color: #c3c2b7; margin: 6px 0 2px; }
.pc-legend i, .pc-tip i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.pc-plot { position: relative; margin-top: 8px; }
.pc-svg { width: 100%; height: auto; display: block; }
.pc-grid { stroke: rgba(255, 255, 255, 0.08); stroke-width: 1; }
.pc-tick { fill: #9aa0d8; font-size: 11px; }
.pc-axis { fill: #9aa0d8; font-size: 11px; }
.pc-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.pc-dot { stroke: #1a1d4a; stroke-width: 2; }
.pc-bar { fill: #3987e5; }
.pc-cross { stroke: rgba(255, 255, 255, 0.35); stroke-width: 1; }
.pc-tip { position: absolute; pointer-events: none; background: #0f1130; border: 1px solid #3a3f8f; border-radius: 8px; padding: 6px 9px; font-size: 0.8rem; min-width: 130px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4); }
.pc-tip div { display: flex; align-items: center; gap: 2px; }
.pc-tip span { margin-left: auto; padding-left: 10px; font-weight: 800; }
.pc-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.pc-table th, .pc-table td { padding: 4px 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); text-align: right; }
.pc-table th:first-child, .pc-table td:first-child { text-align: left; }
.pc-empty { color: var(--muted); padding: 14px 0; }

/* ---------- Level-up skill pick (3 random skills) ---------- */
.pick-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 8px 0; }
.pick-card {
  position: relative; flex: 1 1 200px; max-width: 250px; padding: 14px 12px 12px; border-radius: 18px; text-align: center;
  border: 3px solid var(--yellow); background: #2a2f78; color: var(--text); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; transition: transform 0.1s;
  box-shadow: 0 0 16px rgba(255, 210, 63, 0.2);
}
.pick-card:hover, .pick-card:focus { transform: translateY(-4px) scale(1.03); outline: none; }
.pick-card.primary { border-style: double; border-width: 5px; }
.pick-card.master { background: linear-gradient(180deg, #4a3a8f, #2a2f78); box-shadow: 0 0 22px rgba(255, 210, 63, 0.45); }
.pick-card[data-tree="sharp"] .pk-tree { background: #1f4f7a; }
.pick-card[data-tree="storm"] .pk-tree { background: #4b2f86; }
.pick-card[data-tree="guard"] .pk-tree { background: #2f6b46; }
.pick-card .pk-tree { font-size: 0.75rem; font-weight: 800; padding: 2px 10px; border-radius: 999px; background: #3a3f8f; }
.pick-card .pk-icon { font-size: 2.4rem; margin-top: 4px; }
.pick-card .pk-name { font-size: 1.15rem; font-weight: 900; }
.pick-card .pk-lvl { font-size: 0.78rem; color: var(--yellow); font-weight: 800; }
.pick-card .pk-desc { font-size: 0.86rem; color: #cfd4ff; line-height: 1.3; }
.pick-card .key { position: absolute; top: 8px; left: 10px; font-size: 0.75rem; color: var(--muted); border: 1px solid var(--muted); border-radius: 6px; padding: 0 5px; }
.pick-foot { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.pick-foot b { color: var(--yellow); }

/* ---------- Jokes and boss cut scenes ---------- */
.joke-box {
  position: fixed; left: 50%; top: 96px; transform: translateX(-50%); z-index: 30; pointer-events: none;
  width: min(92vw, 520px); padding: 10px 16px 11px; border-radius: 18px; text-align: center;
  background: #ffd23f; color: #1b1f4b; border: 3px solid #1b1f4b; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transition: opacity 0.3s, transform 0.3s;
}
.joke-box.hidden { display: block; opacity: 0; transform: translate(-50%, -12px); }
.joke-box .jk-q { font-weight: 800; font-size: 1rem; }
.joke-box .jk-q::before { content: "😄 "; }
.joke-box .jk-a { font-weight: 900; font-size: 1.05rem; color: #a8256a; margin-top: 4px; opacity: 0; max-height: 0; transition: opacity 0.4s; }
.joke-box .jk-a.show { opacity: 1; max-height: 4em; }
body.cutscene #hud, body.cutscene .joke-box { opacity: 0; }
@media (max-width: 640px) { .joke-box { top: 118px; } .joke-box .jk-q { font-size: 0.9rem; } }

/* While a level-up problem or the skill pick is open, the joke moves to the bottom, on top of the popup. */
body:has(#upgradeModal:not(.hidden)) .joke-box, body:has(#mathModal:not(.hidden)) .joke-box, body:has(#waitModal:not(.hidden)) .joke-box {
  top: auto; bottom: 14px;
}

/* ---------- Multiple-choice answers (civics) ---------- */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.choices button {
  display: flex; align-items: center; gap: 8px; text-align: left; padding: 10px 12px; min-height: 52px; border-radius: 14px;
  border: 3px solid var(--panel-edge); background: #2a2f78; color: var(--text); font: inherit; font-weight: 800; font-size: 0.98rem; cursor: pointer;
}
.choices button:hover, .choices button:focus { border-color: var(--yellow); outline: none; transform: translateY(-2px); }
.choices .ck { flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%; background: var(--yellow); color: #1b1f4b; display: grid; place-items: center; font-weight: 900; font-size: 0.85rem; }
#choiceWrap .hint-btn, #choiceWrap .skip-btn { width: 100%; padding: 10px; border-radius: 12px; border: 0; color: var(--text); font: inherit; font-weight: 800; background: linear-gradient(180deg, #6d5a12, #4f4110); }
#choiceWrap .skip-btn { background: linear-gradient(180deg, #4a5068, #363b52); }
#choiceWrap .hint-btn:disabled { opacity: 0.4; }
@media (max-width: 520px) { .choices { grid-template-columns: 1fr; } }

/* ---------- World picker ---------- */
.world-pick { display: flex; gap: 10px; margin: 10px 0 6px; }
.world-card {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 8px; border-radius: 16px; cursor: pointer;
  border: 3px solid var(--panel-edge); background: #22265e; color: var(--text); font: inherit; transition: transform 0.1s;
}
.world-card:hover { transform: translateY(-2px); }
.world-card.on { border-color: var(--yellow); background: #2f3590; box-shadow: 0 0 14px rgba(255, 210, 63, 0.3); }
.world-card .wc-icon { font-size: 1.8rem; }
.world-card .wc-name { font-weight: 900; font-size: 1.05rem; }
.world-card .wc-tag { font-size: 0.75rem; color: #cfd4ff; line-height: 1.25; }
.world-card .wc-best { font-size: 0.72rem; color: var(--yellow); font-weight: 800; }
@media (max-width: 520px) { .world-card .wc-tag { display: none; } }

/* ---------- Knowledge Knights ---------- */
.rpg-panel { max-width: min(96vw, 860px); max-height: 92vh; overflow-y: auto; text-align: left; }
.rpg-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.rpg-head .math-title { font-size: 1.5rem; }
.rpg-panel h4 { margin: 14px 0 6px; color: var(--blue); }
.rpg-help, .rpg-hello { color: #cfd4ff; line-height: 1.45; }
.rpg-hello { font-size: 1.05rem; font-style: italic; }
.rpg-dim { color: var(--muted); font-size: 0.82rem; }
.rpg-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.rpg-note { min-height: 1.3em; margin-top: 8px; color: var(--green); font-weight: 800; }
.rpg-note.bad { color: #ff8fa3; }
.rpg-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.rpg-item { display: grid; grid-template-columns: 34px 1fr; grid-template-rows: auto auto auto; column-gap: 8px; padding: 8px; border-radius: 12px; background: #22265e; border: 2px solid var(--panel-edge); }
.rpg-item.rare { border-color: var(--yellow); }
.rpg-item.eq { background: #2a2f78; }
.rpg-item .ri-icon { grid-row: 1 / span 3; font-size: 1.6rem; display: grid; place-items: center; }
.rpg-item .ri-slot { grid-column: 2; font-size: 0.68rem; color: var(--muted); text-transform: uppercase; font-weight: 800; }
.rpg-item .ri-name { grid-column: 2; font-weight: 900; font-size: 0.9rem; }
.rpg-item .ri-desc { grid-column: 2; font-size: 0.75rem; color: #cfd4ff; }
.rpg-item .mini-btn { grid-column: 2; justify-self: start; margin-top: 4px; }
.rpg-stats { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 8px 10px; border-radius: 12px; background: #1a1d4a; font-weight: 800; font-size: 0.9rem; }
.rpg-quest { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; background: #22265e; margin: 6px 0; }
.rpg-reward { font-size: 0.8rem; color: var(--yellow); margin-top: 3px; }
.rpg-prog { font-weight: 900; color: var(--blue); white-space: nowrap; }
.rpg-done { color: var(--green); font-weight: 900; white-space: nowrap; }
.rpg-ready { color: var(--yellow); font-weight: 800; margin: -2px 0 6px 10px; }
.mini-btn.go { border-color: var(--yellow); }
.mini-btn.danger { border-color: #ff4d6d; color: #ff8fa3; }
.rpg-chars, .rpg-classes { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.rpg-char { display: flex; flex-direction: column; gap: 4px; }
.rpg-char-main, .rpg-class {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 12px; border-radius: 16px; cursor: pointer; text-align: center;
  border: 3px solid var(--panel-edge); background: #22265e; color: var(--text); font: inherit;
}
.rpg-char-main:hover, .rpg-class:hover { border-color: var(--yellow); transform: translateY(-2px); }
.rc-icon { font-size: 2rem; }
.rc-name { font-weight: 900; font-size: 1.1rem; }
.rc-sub { font-size: 0.78rem; color: #cfd4ff; }
.rpg-class span { font-size: 0.82rem; color: #cfd4ff; }
.rc-del { align-self: center; font-size: 0.8rem; }
#rpgNewName { font: inherit; font-size: 1rem; padding: 8px 10px; border-radius: 10px; border: 2px solid var(--panel-edge); background: #1a1d4a; color: var(--text); margin-bottom: 10px; width: min(100%, 280px); }
.rpg-prompt {
  position: fixed; left: 50%; bottom: 86px; transform: translateX(-50%); z-index: 7; padding: 10px 18px; border-radius: 14px;
  background: #ffd23f; color: #1b1f4b; font: inherit; font-weight: 900; border: 3px solid #1b1f4b; cursor: pointer; box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}
.rpg-bar { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 7; display: none; gap: 8px; }
body.rpg .rpg-bar { display: flex; }
body.rpg.cutscene .rpg-bar, body.cutscene .rpg-prompt { display: none; }
.rpg-bar button { width: 58px; height: 58px; border-radius: 16px; border: 3px solid var(--panel-edge); background: rgba(27,31,75,0.9); color: var(--text); font-size: 1.5rem; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; }
.rpg-bar button small { font-size: 0.62rem; color: var(--muted); font-weight: 800; }
.tree-panel-inner .cards { display: block; }

/* ---------- Knowledge Knights: energy and skill buttons ---------- */
.rpg-only { display: none; }
body.rpg .rpg-only { display: block; }
.bar.energy .fill { background: linear-gradient(90deg, #2f8fd8, #7fd4ff); }
.skill-bar { position: fixed; right: 14px; bottom: 14px; z-index: 7; display: none; gap: 8px; flex-wrap: wrap-reverse; justify-content: flex-end; max-width: 46vw; }
body.rpg .skill-bar { display: flex; }
body.rpg.cutscene .skill-bar { display: none; }
.sk-btn { position: relative; width: 64px; height: 64px; border-radius: 50%; border: 3px solid var(--panel-edge); background: rgba(27,31,75,0.92); color: var(--text); cursor: pointer; overflow: hidden; touch-action: manipulation; }
.sk-btn.ready { border-color: var(--yellow); box-shadow: 0 0 12px rgba(255, 210, 63, 0.45); }
.sk-btn.low .sk-icon { opacity: 0.4; }
.sk-btn.low .sk-cost { color: #ff8fa3; }
.sk-icon { font-size: 1.7rem; position: relative; z-index: 1; }
.sk-key { position: absolute; top: 4px; left: 8px; font-size: 0.65rem; font-weight: 900; color: var(--muted); z-index: 3; }
.sk-cost { position: absolute; bottom: 3px; left: 0; right: 0; text-align: center; font-size: 0.62rem; font-weight: 900; color: #7fd4ff; z-index: 3; }
.sk-cd { position: absolute; inset: 0; border-radius: 50%; z-index: 2; display: grid; place-items: center; font-weight: 900; font-size: 1.1rem; color: #fff; text-shadow: 0 1px 3px #000; }
@media (max-width: 640px) { .sk-btn { width: 56px; height: 56px; } .rpg-bar button { width: 48px; height: 48px; } .rpg-bar { left: 12px; transform: none; } }

/* ---------- Knowledge Knights: shoot button ---------- */
.shoot-btn { position: fixed; right: 14px; bottom: 92px; z-index: 7; display: none; width: 78px; height: 78px; border-radius: 50%; border: 3px solid #ff4d6d; background: rgba(120,20,40,0.85); color: #fff; font-size: 1.9rem; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; touch-action: none; user-select: none; }
.shoot-btn small { font-size: 0.62rem; font-weight: 900; }
.shoot-btn:active { transform: scale(0.94); background: rgba(160,30,60,0.95); }
body.rpg .shoot-btn { display: flex; }
body.rpg.cutscene .shoot-btn { display: none; }
body.rpg canvas { cursor: crosshair; }

/* Knowledge Knights: the game draws a big reticle, so hide the small cursor over the game */
body.aiming canvas { cursor: none; }

.rpg-bar button.on { border-color: #4be36b; background: rgba(30,90,50,0.92); box-shadow: 0 0 12px rgba(75,227,107,0.45); }
.rpg-bar button.on small { color: #7be37b; }

/* Friends (parents add other families so kids can join each other's games) */
.friends-box { margin-top: 14px; }
.friend-form { display: flex; gap: 8px; flex-wrap: wrap; }
.friend-form input { flex: 1 1 220px; min-width: 0; padding: 8px 10px; border-radius: 8px; border: 2px solid #2c3550;
  background: rgba(0,0,0,0.25); color: var(--text); font: inherit; }
.friend-form input:focus { outline: none; border-color: var(--blue); }
.friend-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06); }
.friend-row small { color: var(--muted); }
.friend-row { flex-wrap: wrap; }
.friend-row > span:last-child { display: flex; gap: 6px; margin-left: auto; }
.friend-row > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.friends-box .live-head { margin-top: 10px; }
.friend-row .mini-btn, .friend-form .mini-btn { display: inline-block; margin-top: 0; font-size: 0.85rem; padding: 5px 10px; }
.friend-row .mini-btn:not(.secondary), .friend-form .mini-btn { background: #2d3380; }
.friend-row .mini-btn.secondary { border-color: #3a4060; color: var(--muted); }
.friend-tag { font-style: normal; font-size: 0.72rem; font-weight: 800; color: #10131f; background: #4be36b;
  border-radius: 6px; padding: 1px 6px; vertical-align: 1px; }
.friend-news { margin: 8px 0; padding: 8px 10px; border-radius: 8px; background: rgba(75,227,107,0.14);
  border: 1px solid rgba(75,227,107,0.5); font-size: 0.92rem; }

/* Parent report card by grade level */
.report-view { margin: 4px 0 10px; }
.grade-report { width: 100%; }
.grade-report .grade-row th { text-align: left; padding: 12px 6px 6px; color: var(--blue); font-size: 1rem; border-bottom: 1px solid rgba(255,255,255,0.12); }
.grade-report .grade-row th span { float: right; color: var(--muted); font-size: 0.82rem; font-weight: 600; }
.grade-report .grade-cell { color: var(--muted); font-weight: 800; white-space: nowrap; }

/* Privacy: consent box, family data */
.consent-row { display: flex; gap: 8px; align-items: flex-start; text-align: left; color: var(--muted); font-size: 0.9rem; line-height: 1.4; margin: 8px 0; }
.consent-row input { margin-top: 3px; flex: none; }
.consent-row a, .auth-note a, .parent-help a { color: var(--text); }
.data-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.delete-form { margin-top: 8px; }
.delete-form input { width: 100%; max-width: 320px; }
