:root {
  --bg: #0d1030;
  --bg2: #1a1f55;
  --panel: #232a6b;
  --panel2: #2d3580;
  --line: #3d47a3;
  --text: #f4f6ff;
  --muted: #aab2e6;
  --gold: #ffd23f;
  --good: #2ee87a;
  --bad: #ff4d6d;
  --xp: #4cc9f0;
  --accent: #ff9f1c;
  --radius: 18px;
  --font: 'Fredoka', 'Nunito', 'Noto Sans SC', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(ellipse at top, var(--bg2), var(--bg) 70%) fixed;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
#stars { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
#stars i { position: absolute; width: 2px; height: 2px; background: #fff; border-radius: 50%; opacity: .5; animation: twinkle 3s infinite ease-in-out; }
@keyframes twinkle { 50% { opacity: .1; } }
#app { position: relative; z-index: 1; max-width: 1180px; margin: 0 auto; padding: 18px 24px 60px; }

button { font-family: inherit; cursor: pointer; border: 0; color: inherit; }
input, select { font-family: inherit; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: .3px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 22px; border-radius: 14px; font-size: 18px; font-weight: 600;
  background: var(--accent); color: #2a1600;
  box-shadow: 0 5px 0 rgba(0,0,0,.35); transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.btn.secondary { background: var(--panel2); color: var(--text); }
.btn.good { background: var(--good); color: #003015; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.small { padding: 8px 14px; font-size: 15px; border-radius: 11px; }
.btn.big { padding: 16px 32px; font-size: 22px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.iconbtn { background: var(--panel); border-radius: 12px; padding: 8px 12px; font-size: 18px; box-shadow: 0 4px 0 rgba(0,0,0,.3); }
.iconbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.3); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px; margin-bottom: 16px;
  background: rgba(35, 42, 107, .85); border: 2px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(6px);
}
.topbar .avatar { font-size: 40px; width: 58px; height: 58px; display: grid; place-items: center; background: var(--bg); border-radius: 50%; border: 3px solid var(--gold); }
.topbar .who { flex: 1; min-width: 0; }
.topbar .name { font-size: 20px; font-weight: 700; }
.lvl { display: inline-block; background: var(--gold); color: #3a2a00; font-weight: 700; border-radius: 8px; padding: 1px 8px; font-size: 14px; margin-left: 6px; }
.xpbar { height: 12px; background: var(--bg); border-radius: 8px; overflow: hidden; margin-top: 6px; max-width: 340px; border: 1px solid var(--line); }
.xpbar > div { height: 100%; background: linear-gradient(90deg, var(--xp), #80ffdb); border-radius: 8px; transition: width .6s; }
.xptext { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat { display: flex; align-items: center; gap: 6px; font-size: 20px; font-weight: 700; background: var(--bg); padding: 6px 12px; border-radius: 12px; }

/* ---------- profile select ---------- */
.title-hero { text-align: center; margin: 30px 0 26px; }
.title-hero h1 { font-size: 64px; background: linear-gradient(180deg, #fff3b0, var(--gold) 60%, #ff9f1c); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 4px 0 rgba(0,0,0,.4)); }
.title-hero p { color: var(--muted); font-size: 20px; margin: 6px 0 0; }
.grid { display: grid; gap: 18px; }
.heroes { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.hero-card {
  background: var(--panel); border: 3px solid var(--line); border-radius: var(--radius); padding: 20px 14px; text-align: center;
  box-shadow: 0 6px 0 rgba(0,0,0,.3); transition: transform .15s, border-color .15s;
}
.hero-card:hover { transform: translateY(-4px); border-color: var(--gold); }
.hero-card .face { font-size: 64px; }
.hero-card .n { font-size: 22px; font-weight: 700; margin-top: 4px; }
.hero-card.new { border-style: dashed; color: var(--muted); display: grid; place-items: center; min-height: 190px; font-size: 20px; }

/* ---------- hub ---------- */
.hub { grid-template-columns: 2fr 1fr; align-items: start; }
.portals { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.mtportal { --c: #3a86ff; outline: 3px dashed rgba(255,255,255,.8); outline-offset: -8px; animation: mtpulse 1.8s ease-in-out infinite; }
@keyframes mtpulse { 50% { box-shadow: 0 0 0 7px rgba(58,134,255,.4); } }
.mtbar { width: 100%; margin-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-radius: 16px; border: 2px solid rgba(58,134,255,.6); background: rgba(58,134,255,.18); color: inherit; font: inherit; font-size: 17px; cursor: pointer; text-align: left; }
.hwpanel { margin-bottom: 18px; border: 2px solid #ffd23f; }
.hwgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.hwitem { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; border: 2px solid rgba(255,255,255,.15); background: rgba(255,255,255,.06); color: inherit; font: inherit; cursor: pointer; text-align: left; }
.hwitem:hover { background: rgba(255,255,255,.12); }
.hwitem.done { border-color: #2ee87a; background: rgba(46,232,122,.12); }
.hwi { font-size: 30px; } .hwgo { margin-left: auto; font-weight: 700; white-space: nowrap; }
.okc2 { color: #2ee87a; }
.portal {
  position: relative; border-radius: 22px; padding: 22px 18px 18px; text-align: left; min-height: 210px;
  background: linear-gradient(160deg, var(--c), color-mix(in srgb, var(--c) 40%, #120a30));
  box-shadow: 0 8px 0 rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.25); overflow: hidden;
  transition: transform .15s;
}
.portal:hover { transform: translateY(-5px) rotate(-.5deg); }
.portal .ico { font-size: 62px; filter: drop-shadow(0 4px 0 rgba(0,0,0,.3)); }
.portal h3 { font-size: 24px; margin-top: 8px; text-shadow: 0 2px 0 rgba(0,0,0,.3); }
.portal .sub { font-size: 15px; opacity: .9; }
.portal .prog { margin-top: 12px; height: 10px; background: rgba(0,0,0,.3); border-radius: 6px; overflow: hidden; }
.portal .prog > div { height: 100%; background: #fff; border-radius: 6px; }
.raid {
  margin-top: 18px; display: flex; align-items: center; gap: 18px; padding: 20px 22px; border-radius: 22px; width: 100%; text-align: left;
  background: linear-gradient(120deg, #6a0d2e, #c9184a 60%, #ff4d6d); box-shadow: 0 8px 0 rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.2);
  transition: transform .15s;
}
.raid:hover { transform: translateY(-4px); }
.raid .ico { font-size: 64px; animation: bob 2s infinite ease-in-out; }
.raid h3 { font-size: 26px; }
@keyframes bob { 50% { transform: translateY(-6px); } }
.panel { background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.panel h3 { font-size: 19px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.side { display: grid; gap: 16px; }
.quest { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.quest:last-child { border: 0; }
.quest .q { flex: 1; font-size: 15px; }
.quest .mini { height: 6px; background: var(--bg); border-radius: 4px; margin-top: 4px; overflow: hidden; }
.quest .mini > div { height: 100%; background: var(--good); }
.quest .rw { font-size: 14px; color: var(--gold); white-space: nowrap; }
.quest.done .q { text-decoration: line-through; opacity: .6; }
.badges { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.badge { aspect-ratio: 1; display: grid; place-items: center; font-size: 26px; background: var(--bg); border-radius: 12px; filter: grayscale(1); opacity: .3; }
.badge.on { filter: none; opacity: 1; background: color-mix(in srgb, var(--gold) 25%, var(--bg)); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.lb { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 16px; }
.lb .rk { width: 26px; font-weight: 700; color: var(--gold); }
.lb .xp { margin-left: auto; color: var(--muted); }

/* ---------- map ---------- */
.maphead { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.maphead h2 { font-size: 32px; flex: 1; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.tab { padding: 8px 16px; border-radius: 12px; background: var(--panel); font-size: 17px; font-weight: 600; border: 2px solid transparent; }
.tab.on { background: var(--c, var(--accent)); color: #1b0f00; }
.tab.mine::after { content: ' ★'; }
.path { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.node {
  position: relative; text-align: left; padding: 18px; border-radius: 20px; background: var(--panel); border: 3px solid var(--line);
  box-shadow: 0 6px 0 rgba(0,0,0,.3); transition: transform .15s, border-color .15s; min-height: 150px; display: flex; flex-direction: column;
}
.node:hover { transform: translateY(-4px); border-color: var(--c); }
.node .num { position: absolute; top: 10px; right: 14px; color: var(--muted); font-weight: 700; }
.node .ico { font-size: 40px; }
.node .t { font-size: 19px; font-weight: 600; margin-top: 6px; flex: 1; }
.node .stars { font-size: 20px; letter-spacing: 2px; margin-top: 8px; }
.node.next { border-color: var(--c); animation: glow 1.6s infinite; }
.node .tag { position: absolute; top: -10px; left: 14px; background: var(--good); color: #002a12; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 8px; }
.node .tag.taught { background: var(--xp); color: #00263a; }
@keyframes glow { 50% { box-shadow: 0 6px 0 rgba(0,0,0,.3), 0 0 26px var(--c); } }
.s-on { color: var(--gold); }
.s-off { color: #4a5299; }

/* ---------- learn ---------- */
.learn { max-width: 760px; margin: 0 auto; }
.lcard { background: #fffdf5; color: #26205a; border-radius: 24px; padding: 34px 38px; font-family: 'Nunito', var(--font); font-size: 24px; line-height: 1.55; box-shadow: 0 10px 0 rgba(0,0,0,.35); min-height: 300px; position: relative; }
.lcard h2 { font-family: var(--font); font-size: 30px; color: #5a3fd1; margin-bottom: 14px; }
.lcard b { color: #d6336c; }
.lcard .read { position: absolute; top: 18px; right: 18px; background: #efeaff; color: #5a3fd1; }
.dots { display: flex; gap: 8px; justify-content: center; margin: 18px 0; }
.dots i { width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--gold); }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; line-height: 1; font-size: .85em; margin: 0 2px; }
.frac sup { border-bottom: 2px solid currentColor; padding: 0 3px 1px; }
.frac sub { padding: 1px 3px 0; }

/* ---------- battle ---------- */
.arena { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 20px; margin-bottom: 14px; }
.fighter { text-align: center; }
.fighter .sprite { font-size: 76px; line-height: 1.1; display: inline-block; filter: drop-shadow(0 8px 0 rgba(0,0,0,.35)); }
.fighter .label { font-weight: 600; font-size: 17px; margin-top: 4px; }
.hp { height: 18px; background: var(--bg); border: 2px solid var(--line); border-radius: 10px; overflow: hidden; max-width: 280px; margin: 8px auto 0; }
.hp > div { height: 100%; background: linear-gradient(90deg, #ff4d6d, #ff8fa3); transition: width .4s; }
.hearts { font-size: 26px; letter-spacing: 3px; margin-top: 6px; }
.vs { font-size: 34px; font-weight: 700; color: var(--gold); text-align: center; }
.combo { font-size: 16px; color: var(--gold); min-height: 22px; }
.hitme { animation: shake .4s; }
.hitfoe { animation: hit .45s; }
.lunge { animation: lunge .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
@keyframes hit { 30% { transform: scale(.85) rotate(8deg); filter: brightness(3) drop-shadow(0 0 0 #fff); } }
@keyframes lunge { 50% { transform: translateX(40px) scale(1.1); } }
.dmg { position: absolute; font-size: 34px; font-weight: 700; color: var(--gold); pointer-events: none; animation: rise 1s forwards; text-shadow: 0 3px 0 #000; }
@keyframes rise { to { transform: translateY(-70px); opacity: 0; } }
.qbox { background: #fffdf5; color: #221c55; border-radius: 24px; padding: 20px 28px; box-shadow: 0 10px 0 rgba(0,0,0,.35); font-family: 'Nunito', var(--font); }
.qmeta { display: flex; justify-content: space-between; color: #7a74b8; font-size: 15px; font-weight: 700; margin-bottom: 8px; font-family: var(--font); }
.qtext { font-size: 26px; line-height: 1.45; font-weight: 700; min-height: 40px; }
.qtext .big { font-size: 38px; line-height: 1.4; margin: 10px 0; letter-spacing: 3px; }
.qtext .blank { display: inline-block; min-width: 70px; border-bottom: 3px solid #5a3fd1; color: #5a3fd1; text-align: center; }
.qtext .hint { font-size: 16px; color: #7a74b8; font-weight: 600; }
.coin { display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff2a8, #e0a800); color: #4a3500; font-size: 16px; font-weight: 800; border: 3px solid #b88a00; letter-spacing: 0; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.choice {
  display: flex; align-items: center; gap: 12px; text-align: left; padding: 16px 18px; border-radius: 16px; font-size: 21px; font-weight: 700;
  background: #efeaff; color: #2a2266; border: 3px solid #d6ccff; box-shadow: 0 5px 0 #b9acf0; font-family: 'Nunito', var(--font);
  transition: transform .08s;
}
.choice:hover { background: #e3dbff; }
.choice:active { transform: translateY(3px); box-shadow: 0 2px 0 #b9acf0; }
.choice .k { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: #5a3fd1; color: #fff; font-size: 16px; flex: none; }
.choice.right { background: #c9ffdf; border-color: #2ee87a; box-shadow: 0 5px 0 #1fb35c; }
.choice.wrong { background: #ffd6de; border-color: #ff4d6d; box-shadow: 0 5px 0 #c9184a; }
.choice[disabled] { pointer-events: none; }
.answer-input { display: flex; gap: 12px; margin-top: 20px; }
.answer-input input { flex: 1; min-width: 0; font-size: 28px; padding: 12px 18px; border-radius: 14px; border: 3px solid #d6ccff; font-weight: 700; color: #221c55; }
.answer-input input:focus { outline: none; border-color: #5a3fd1; }
.feedback { margin-top: 18px; padding: 14px 18px; border-radius: 14px; font-size: 19px; font-weight: 700; display: flex; align-items: center; gap: 14px; }
.feedback.ok { background: #c9ffdf; color: #00592a; }
.feedback.no { background: #ffe3e8; color: #8a0021; }
.feedback .ex { flex: 1; font-weight: 600; }

/* ---------- results ---------- */
.result { max-width: 640px; margin: 20px auto; text-align: center; }
.result h1 { font-size: 54px; }
.bigstars { font-size: 76px; letter-spacing: 8px; margin: 10px 0; }
.bigstars span { display: inline-block; animation: pop .5s backwards; }
.bigstars span:nth-child(2) { animation-delay: .25s; }
.bigstars span:nth-child(3) { animation-delay: .5s; }
@keyframes pop { 0% { transform: scale(0) rotate(-60deg); } 80% { transform: scale(1.25); } }
.rewards { display: flex; justify-content: center; gap: 16px; margin: 16px 0 24px; flex-wrap: wrap; }
.reward { background: var(--panel); border: 2px solid var(--line); border-radius: 16px; padding: 14px 22px; font-size: 22px; font-weight: 700; }
.reward small { display: block; color: var(--muted); font-size: 13px; font-weight: 600; }
.levelup { font-size: 30px; color: var(--gold); animation: pop .6s; margin-bottom: 10px; }

/* ---------- modal / toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(5, 6, 25, .75); z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal .box { background: var(--panel); border: 3px solid var(--line); border-radius: 24px; padding: 26px; width: min(560px, 100%); max-height: 90vh; overflow: auto; animation: fadeup .25s; }
@keyframes fadeup { from { opacity: 0; transform: translateY(14px); } }
.modal .box.wide { width: min(1000px, 100%); }
.modal h2 { font-size: 28px; margin-bottom: 12px; }
#toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(120px); background: var(--gold); color: #3a2a00; font-weight: 700; padding: 12px 22px; border-radius: 14px; z-index: 60; transition: transform .3s; box-shadow: 0 6px 0 rgba(0,0,0,.35); font-size: 18px; }
#toast.on { transform: translateX(-50%) translateY(0); }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 600; color: var(--muted); }
.field input, .field select { font-size: 20px; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); color: var(--text); }
.pick { display: flex; flex-wrap: wrap; gap: 8px; }
.pick button { font-size: 30px; width: 58px; height: 58px; border-radius: 14px; background: var(--bg); border: 3px solid transparent; }
.pick button.on { border-color: var(--gold); background: var(--panel2); }
.pick.text button { font-size: 18px; width: auto; height: auto; padding: 8px 16px; font-weight: 600; }
.shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; }
.item { background: var(--bg); border: 2px solid var(--line); border-radius: 16px; padding: 12px; text-align: center; }
.item .f { font-size: 44px; }
.item .p { color: var(--gold); font-weight: 700; margin: 4px 0 6px; }

/* ---------- teacher ---------- */
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--bg); margin-bottom: 6px; cursor: pointer; font-size: 16px; }
.check input { width: 20px; height: 20px; accent-color: var(--good); }
.cols3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 8px; background: var(--bg); margin: 2px 2px 0 0; }
.pill.weak { background: #5c1630; color: #ffb3c1; }

.confetti { position: fixed; top: -20px; width: 10px; height: 14px; z-index: 70; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 600px) {
  .answer-input input { font-size: 22px; padding: 10px 12px; }
  .answer-input .btn { flex: none; padding: 10px 14px; font-size: 16px; }
  .qbox { padding: 16px 16px; }
  .qtext { font-size: 22px; }
  .qmeta { flex-wrap: wrap; gap: 6px; }
  .ans-short input { width: 100%; min-width: 0; }
}
@media (max-width: 900px) {
  .hub { grid-template-columns: 1fr; }
  .portals { grid-template-columns: repeat(2, 1fr); }
  .choices { grid-template-columns: 1fr; }
  .cols3 { grid-template-columns: 1fr; }
  .arena .fighter .sprite { font-size: 64px; }
  .title-hero h1 { font-size: 44px; }
  #app { padding: 14px 16px 50px; }
}
.hwgrid.plan { grid-template-columns: 1fr; }
/* daily homework cards: Start sits on its own row so it never overlaps the subject name */
.hwgrid:not(.plan) .hwitem { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 10px; row-gap: 8px; }
.hwgrid:not(.plan) .hwgo { grid-column: 1 / -1; margin: 0; text-align: center; padding: 6px 8px; border-radius: 10px; background: rgba(255,255,255,.1); }
.hwgrid:not(.plan) .hwitem.done .hwgo { background: rgba(46,232,122,.15); }
.hwitem > span:nth-child(2) { min-width: 0; overflow-wrap: anywhere; }

/* practices */
.node .pbar { height: 6px; background: rgba(255,255,255,.12); border-radius: 4px; overflow: hidden; margin: 8px 0 4px; }
.node .pbar > div { height: 100%; background: var(--c, #ffd23f); border-radius: 4px; }
.pgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 12px; }
.pbtn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; border-radius: 12px; border: 2px solid rgba(255,255,255,.15); background: rgba(255,255,255,.06); color: inherit; font: inherit; font-size: 14px; cursor: pointer; }
.pbtn span { color: #ffd23f; letter-spacing: 1px; font-size: 13px; }
.pbtn.done { border-color: rgba(46,232,122,.6); background: rgba(46,232,122,.12); }
.pbtn.next { border-color: #ffd23f; animation: glow 1.6s infinite; }
.pbtn:hover { background: rgba(255,255,255,.14); }
@media (max-width: 520px) { .pgrid { grid-template-columns: repeat(2, 1fr); } }

/* iPad portrait and phones: subject worlds two to a row, compact; one to a row on phones */
@media (max-width: 900px) { .portal { padding: 16px; } .portal .ico { font-size: 46px; } .portal h3 { font-size: 21px; } }
@media (max-width: 520px) { .portals { grid-template-columns: 1fr; } }
.xptext { font-size: 13px; }
/* keyboard users can always see where they are */
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible { outline: 3px solid #ffd23f; outline-offset: 3px; }
/* a topic with all 10 practices done */
.node .tag.master { background: linear-gradient(90deg, #ffd23f, #ff9f1c); color: #3a2400; }
.node.mastered { border-color: #ffd23f; }
/* children who get dizzy from motion (system setting): calm everything down */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .confetti, #stars i { display: none !important; }
}

/* ---------- battle effects (js/fx.js) ---------- */
#fxlayer { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.fx-slash { position: fixed; border-radius: 50%; transform-origin: left center;
  background: linear-gradient(90deg, transparent, var(--sc, #fff) 30%, #fff 50%, var(--sc, #fff) 70%, transparent);
  box-shadow: 0 0 14px var(--sc, #fff), 0 0 30px var(--sc, #fff); }
.fx-spark { position: fixed; width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 10px currentColor; }
.fx-flash { position: fixed; inset: 0; }
.fx-ghost { position: fixed; transform: translate(-50%, -50%); filter: blur(1px) brightness(1.6); line-height: 1.1; }
.fx-half { position: fixed; display: grid; place-items: center; filter: drop-shadow(0 8px 0 rgba(0,0,0,.35)); }
.fx-pop { position: fixed; font-family: var(--font); font-weight: 700; font-size: 34px; white-space: nowrap; color: #fff;
  text-shadow: 0 3px 0 #000, 0 0 16px rgba(0,0,0,.6); -webkit-text-stroke: 1px rgba(0,0,0,.4); }
.fx-pop.good { color: #2ee87a; }
.fx-pop.gold { color: #ffd23f; font-size: 30px; }
.fx-pop.ko { color: #ff4d6d; font-size: 64px; letter-spacing: 2px; }

/* ---------- phones and tablets (20 Oct 2026) ---------- */
/* grid and flex children may shrink below their content, so nothing pushes the page wider than the screen */
.grid > *, .hub > *, .side > *, .portals > *, .hwgrid > *, .builder > * { min-width: 0; }
.hub { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
img, video, canvas, svg { max-width: 100%; }
.panel, .qbox, .modal .box { overflow-wrap: anywhere; }
@media (max-width: 900px) {
  .hub { grid-template-columns: minmax(0, 1fr); }
  /* tablets: the hero card, quests and trophies sit side by side under the worlds */
  .side { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); align-items: start; }
}
@media (max-width: 640px) {
  #app { padding: 10px 10px 40px; }
  /* top bar: hero + name on the first row, streak / coins / buttons on the second */
  .topbar { flex-wrap: wrap; gap: 8px 10px; padding: 10px 12px; }
  .topbar .avatar { width: 48px; height: 48px; font-size: 32px; }
  .topbar .who { flex: 1 1 calc(100% - 70px); }
  .topbar .name { font-size: 18px; line-height: 1.25; }
  .topbar .xpbar { max-width: none; }
  .topbar .stat { font-size: 16px; padding: 6px 10px; }
  .topbar .iconbtn { padding: 8px 10px; min-width: 44px; min-height: 44px; }
  .topbar .stat:first-of-type { margin-left: auto; }
  .panel { padding: 14px 12px; }
  .btn { padding: 11px 16px; font-size: 17px; }
  .btn.big { padding: 14px 22px; font-size: 19px; }
  .modal { padding: 10px; align-items: end; }
  .modal .box { padding: 18px 14px; max-height: 92vh; border-radius: 20px; }
  .modal h2 { font-size: 23px; }
  .title-hero h1 { font-size: 36px; }
  .title-hero p { font-size: 16px; }
  .heroes { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .hero-card { padding: 14px 8px; }
  .hero-card .face { font-size: 48px; }
  .maphead { flex-wrap: wrap; gap: 8px; }
  .maphead h2 { font-size: 22px; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .arena { gap: 8px; }
  .vs { font-size: 20px; }
  .fighter .label { font-size: 14px; }
  .hp { max-width: 140px; }
  .raid { flex-wrap: wrap; gap: 10px; }
  .mtbar { flex-wrap: wrap; gap: 8px; }
  table { font-size: 14px; }
}
@media (max-width: 520px) {
  /* subject worlds become compact rows: icon on the left, name and progress on the right */
  .portal { display: grid; grid-template-columns: 52px minmax(0, 1fr); column-gap: 12px; align-items: center; text-align: left; padding: 14px; }
  .portal .ico { grid-row: 1 / span 4; font-size: 40px; margin: 0; }
  .portal h3 { font-size: 19px; }
  .portal .prog { margin-top: 6px; }
  .raid .ico { font-size: 44px; }
  .raid h3 { font-size: 21px; }
}
/* fingers, not mice: every button is at least 40px tall on touch screens */
@media (pointer: coarse) {
  /* children's fingers: 44px is the smallest comfortable tap (Apple HIG) */
  .btn, .btn.small, .iconbtn, .tab, .pick button, .btabs button, .choice, .pbtn, .pad-bar button, .enav-g button, .calc-keys button { min-height: 44px; }
  .iconbtn { min-width: 44px; }
}
/* iPhone notch and home bar: keep content out from under them */
#app { padding-left: max(var(--gutter, 24px), env(safe-area-inset-left)); padding-right: max(var(--gutter, 24px), env(safe-area-inset-right)); padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
.modal { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
@media (max-width: 900px) { #app { --gutter: 16px; } }
@media (max-width: 640px) { #app { --gutter: 10px; } }
/* on iPad and wider phones, long reading text keeps a comfortable line length */
.lcard > div, .qtext .passage, .pbody { max-width: 72ch; }
/* hero builder labels readable on small screens */
.bitem .pr { font-size: 13px; }
.bitem .rar { font-size: 11px; }
@media (max-width: 520px) {
  .portal { min-height: 0; }
  /* topic map: two quests to a row */
  .path { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .node { min-height: 0; padding: 12px 10px; border-radius: 16px; }
  .node .ico { font-size: 30px; }
  .node .t { font-size: 15px; line-height: 1.25; }
  .node .tag { font-size: 11px; }
}
@media (max-width: 640px) {
  /* in a battle the question matters most: slim top bar, short header, smaller arena */
  #app:has(.arena) .topbar { padding: 6px 10px; margin-bottom: 8px; }
  #app:has(.arena) .topbar .avatar { width: 38px; height: 38px; font-size: 24px; }
  #app:has(.arena) .topbar .who { flex: 1 1 0; }
  #app:has(.arena) .topbar .xpbar, #app:has(.arena) .topbar .xptext, #app:has(.arena) .topbar .stat, #app:has(.arena) .topbar .lvl ~ span { display: none; }
  #app:has(.arena) .maphead { flex-wrap: nowrap; margin-bottom: 8px; }
  #app:has(.arena) .maphead h2 { font-size: 17px !important; line-height: 1.25; }
  .arena.themed, .arena { padding: 8px 6px; margin-bottom: 8px; }
  .arena .herofig { width: 92px; height: 84px; }
  .arena .herofig .sprite, .arena .fighter .sprite { font-size: 52px; }
  .arena .herofig .pet { font-size: 28px; }
  .fighter .hearts { font-size: 15px; }
  .qbox { padding: 12px; }
  .qtext { font-size: 20px; }
}

/* ---------- Hanyu Pinyin over Chinese characters (js/pinyin.js) ---------- */
.pyw ruby { ruby-position: over; ruby-align: center; }
.pyw rt { font-family: 'Nunito', system-ui, sans-serif; font-size: .52em; font-weight: 700; color: #6a5acd; letter-spacing: 0; line-height: 1; user-select: none; }
.pyw rp { display: none; }
.py-hide rt { display: none; }
/* leave room above each line for the pinyin */
.qtext:not(.py-hide) .pyw, .choices:not(.py-hide) .pyw, .equestion:not(.py-hide) .pyw, .passage:not(.py-hide) .pyw, .lcard:not(.py-hide) .pyw { line-height: 2.1; }
.pybtn { background: #efeaff !important; color: #5a3fd1 !important; font: 700 15px 'Noto Sans SC', var(--font) !important; padding: 4px 10px !important; box-shadow: none !important; margin-right: 6px; border: 2px solid transparent !important; }
.pybtn.on { background: #5a3fd1 !important; color: #fff !important; }
.exam-top .pybtn { margin: 0; }
.lcard .pybtn.lpy { position: absolute; top: 14px; right: 70px; }
.trackbar { margin: 0 0 14px; }
