/* MatKlik — kid-friendly, high-contrast, touch-first. Two fixed colours carry the whole idea:
   --c100 (całość / 100%) and --cx (szukane x). Never swap them. */
:root {
  --bg: #f6f1e7;
  --paper: #fffdf8;
  --ink: #23262d;
  --muted: #6b7280;
  --line: #e6dfd0;
  --c100: #2456c9;      /* całość, 100%  */
  --c100-soft: #dbe5fb;
  --cx: #ff8a1f;        /* szukane x     */
  --cx-soft: #ffe4c7;
  --extra: #1fa971;     /* +VAT, +podwyżka */
  --extra-soft: #d3f4e5;
  --cut: #c9c2b4;       /* odcięty rabat */
  --ok: #1fa971;
  --bad: #e5484d;
  --radius: 18px;
  --shadow: 0 6px 22px rgba(35, 38, 45, .08);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* attribute must beat any display: set below */
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100dvh; display: flex; flex-direction: column; font-size: 17px; line-height: 1.45; }
button, input { font: inherit; }
h1 { font-size: 1.7rem; margin: .2rem 0 .4rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
.muted { color: var(--muted); font-weight: 400; }
.sr { position: absolute; left: -9999px; }
.c100 { color: var(--c100); }
.cx { color: var(--cx); }

.top { display: flex; align-items: center; justify-content: space-between; padding: .7rem 1rem; }
.brand { display: flex; align-items: center; gap: .5rem; background: none; border: 0; font-weight: 800; font-size: 1.25rem; cursor: pointer; color: var(--ink); }
.logo { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 12px; background: var(--c100); color: #fff; font-weight: 900; }
.streak { background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: .3rem .8rem; font-weight: 700; }

main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 0 1rem 2rem; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; }

.hero p { font-size: 1.05rem; }
.modules { display: grid; gap: .8rem; }
.module { text-align: left; background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); cursor: pointer; display: grid; grid-template-columns: 52px 1fr auto; gap: .9rem; align-items: center; transition: transform .12s; }
.module:active { transform: scale(.985); }
.module .letter { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-weight: 900; font-size: 1.4rem; color: #fff; }
.module[data-m="A"] .letter { background: var(--c100); }
.module[data-m="B"] .letter { background: var(--cx); }
.module[data-m="C"] .letter { background: var(--extra); }
.module h3 { margin: 0; font-size: 1.1rem; }
.module p { margin: .15rem 0 0; color: var(--muted); font-size: .92rem; }
.module .prog { font-weight: 800; font-size: .95rem; text-align: right; }
.module.done { border-color: var(--ok); }
.module.done .prog { color: var(--ok); }
.dots { display: flex; gap: 4px; margin-top: 4px; justify-content: flex-end; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--line); display: inline-block; }
.dots i.on { background: var(--ok); }

.syllabus ol { padding-left: 1.3rem; margin: 0; }
.syllabus li { padding: .25rem 0; display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.chip { font-size: .75rem; font-weight: 800; padding: .1rem .5rem; border-radius: 999px; color: #fff; }
.chip[data-m="A"] { background: var(--c100); } .chip[data-m="B"] { background: var(--cx); } .chip[data-m="C"] { background: var(--extra); }
.anchor-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.anchor { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: .4rem .7rem; font-weight: 700; }
.anchor small { color: var(--muted); font-weight: 400; }

.crumbs { display: flex; gap: 1rem; align-items: center; margin: .3rem 0 .8rem; flex-wrap: wrap; }
.link { background: none; border: 0; color: var(--c100); font-weight: 700; cursor: pointer; padding: .3rem 0; }
.progress { margin-left: auto; font-size: .9rem; color: var(--muted); font-weight: 700; }
.badge { display: inline-block; font-size: .8rem; font-weight: 800; padding: .15rem .6rem; border-radius: 999px; background: var(--c100-soft); color: var(--c100); }

.card, .lesson { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; }
.lesson-body { display: grid; gap: 1rem; }
.lesson-body p { margin: 0; }
.lesson-body .box { background: var(--bg); border-radius: 14px; padding: .8rem 1rem; }
.lesson-body .box.warn { background: var(--cx-soft); }
.lesson-actions { margin-top: 1.2rem; display: flex; justify-content: flex-end; }
.demo-controls { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-top: .5rem; }
.demo-controls input[type=range] { flex: 1; min-width: 160px; accent-color: var(--cx); }
.demo-controls output { font-weight: 800; min-width: 3.5rem; }
.demo-table { border-collapse: collapse; margin-top: .3rem; }
.demo-table td { padding: .2rem .8rem .2rem 0; font-weight: 700; }
.demo-table td:first-child { color: var(--c100); }
.demo-table tr.x td { color: var(--cx); }

.btn { border: 2px solid var(--line); background: var(--paper); border-radius: 14px; padding: .55rem .9rem; font-weight: 700; cursor: pointer; color: var(--ink); }
.btn.primary { background: var(--c100); border-color: var(--c100); color: #fff; }
.btn.big { font-size: 1.1rem; padding: .8rem 1.4rem; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }

.task-type { font-size: .8rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.task-text { font-size: 1.25rem; font-weight: 700; margin: .3rem 0 .9rem; }

/* --- visual: grid 10x10 --- */
.grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; max-width: 340px; margin: 0 auto .5rem; touch-action: manipulation; }
.grid b { aspect-ratio: 1; border-radius: 4px; background: #efe9dc; border: 1px solid #e0d8c7; cursor: pointer; }
.grid b.on { background: var(--cx); border-color: var(--cx); }
.grid.readonly b { cursor: default; }
.grid.readonly b.on { background: var(--c100); border-color: var(--c100); }
.grid-count { text-align: center; font-weight: 800; margin-bottom: .6rem; }
.grid-count .cx { font-size: 1.3rem; }
.grid-tools { display: flex; gap: .5rem; justify-content: center; margin-bottom: .8rem; }

/* --- visual: bar --- */
.bar-wrap { margin: .4rem 0 1rem; }
.bar-labels { display: flex; justify-content: space-between; font-size: .85rem; font-weight: 700; margin-bottom: .25rem; }
.bar-labels .l100 { color: var(--c100); } .bar-labels .lx { color: var(--cx); } .bar-labels .lextra { color: var(--extra); }
.bar { position: relative; height: 34px; border-radius: 10px; background: var(--c100-soft); border: 2px solid var(--c100); overflow: visible; }
.bar .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--cx); border-radius: 7px 0 0 7px; transition: width .35s; }
.bar .fill.full { border-radius: 7px; }
.bar .extra { position: absolute; top: -2px; bottom: -2px; left: 100%; background: var(--extra-soft); border: 2px solid var(--extra); border-left: 0; border-radius: 0 10px 10px 0; }
.bar .cut { position: absolute; top: 0; bottom: 0; right: 0; background: repeating-linear-gradient(135deg, var(--cut) 0 6px, #f6f1e7 6px 12px); border-radius: 0 7px 7px 0; }
.bar.unknown { background: repeating-linear-gradient(135deg, var(--cx-soft) 0 8px, #fff 8px 16px); display: grid; place-items: center; }
.bar.unknown .q { font-weight: 900; color: var(--cx); font-size: 1.2rem; }
.bar .tick { position: absolute; top: -6px; bottom: -6px; width: 2px; background: var(--ink); opacity: .35; }
.bar .tick.major { opacity: .7; }
.bar-scale { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: .2rem; }
.bar-over { margin-right: 23%; }   /* leaves room for +extra segment */
.bar-caption { font-size: .9rem; margin-top: .3rem; }

/* --- proportion form --- */
.proportion { margin: .4rem 0 1rem; }
.proportion .title { font-size: .85rem; font-weight: 800; color: var(--muted); margin-bottom: .3rem; }
.prop-grid { display: grid; grid-template-columns: auto auto auto; gap: .35rem .5rem; align-items: center; justify-content: start; }
.prop-grid input { width: 5.2rem; padding: .45rem .5rem; border: 2px solid var(--line); border-radius: 10px; text-align: center; font-weight: 700; }
.prop-grid input.known { border-color: var(--c100-soft); }
.prop-grid input.bad { border-color: var(--bad); background: #fde8e8; }
.prop-grid input.good { border-color: var(--ok); }
.prop-grid .x { display: inline-grid; place-items: center; width: 5.2rem; height: 2.4rem; border: 2px dashed var(--cx); border-radius: 10px; color: var(--cx); font-weight: 900; }
.prop-grid .arrow { color: var(--muted); font-weight: 800; }
.prop-grid .u { font-size: .8rem; color: var(--muted); }
.prop-note { font-size: .85rem; color: var(--muted); margin-top: .35rem; }

.answer-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.answer-row input { flex: 1; min-width: 140px; padding: .7rem .9rem; font-size: 1.2rem; font-weight: 700; border: 2px solid var(--line); border-radius: 14px; }
.answer-row input:focus { outline: none; border-color: var(--cx); }
.unit { font-weight: 800; color: var(--muted); }

.feedback { margin-top: .8rem; padding: .8rem 1rem; border-radius: 14px; font-weight: 600; }
.feedback.ok { background: #d9f5e6; color: #0f6b45; }
.feedback.bad { background: #fde8e8; color: #9b2226; }
.feedback.info { background: var(--cx-soft); color: #7a3f00; }

.tutor { margin-top: .8rem; border: 2px solid var(--c100-soft); border-radius: 14px; padding: .7rem .9rem; background: #fff; }
.tutor-head { font-weight: 800; color: var(--c100); font-size: .9rem; }
.tutor-text { white-space: pre-wrap; }
.tutor-text.loading { color: var(--muted); font-style: italic; }
.tutor-text .src { display: block; margin-top: .3rem; font-size: .75rem; color: var(--muted); font-style: italic; }

.task-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }
.task-actions .ghost { margin-left: auto; }
.ask-row { display: flex; gap: .5rem; margin-top: .6rem; }
.ask-row input { flex: 1; padding: .55rem .8rem; border: 2px solid var(--line); border-radius: 12px; }
.steps { margin-top: .9rem; }
.steps summary { cursor: pointer; font-weight: 700; }
.steps ol { margin: .4rem 0 0; padding-left: 1.3rem; }
.steps li { padding: .15rem 0; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -10px; width: 8px; height: 14px; border-radius: 2px; animation: fall 1.4s linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); opacity: .2; } }

@media (min-width: 640px) {
  .modules { grid-template-columns: 1fr; }
  h1 { font-size: 2rem; }
}

/* --- HUD: XP / level / skin --- */
.hud { display: flex; align-items: center; gap: .6rem; }
.hud .skin { font-size: 1.5rem; line-height: 1; }
.hud .xp { display: flex; align-items: center; gap: .4rem; background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: .3rem .7rem; }
.hud .lvl { font-size: .8rem; font-weight: 800; color: var(--c100); white-space: nowrap; }
.xp-bar { width: 70px; height: 8px; border-radius: 999px; background: var(--c100-soft); overflow: hidden; }
.xp-fill { height: 100%; width: 0; background: var(--cx); transition: width .4s; }
.xp-pop { position: fixed; right: 1rem; top: 3.4rem; background: var(--cx); color: #fff; font-weight: 900; padding: .3rem .7rem; border-radius: 999px; animation: pop 1.2s ease-out forwards; z-index: 5; }
@keyframes pop { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(-30px); opacity: 0; } }

.theme-row { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin: .2rem 0 .9rem; font-size: .9rem; }
.btn.sm { padding: .3rem .6rem; font-size: .85rem; border-radius: 10px; }
.btn.sm.on { background: var(--c100); border-color: var(--c100); color: #fff; }
.module .boss-btn { grid-column: 1 / -1; justify-self: start; }
.boss-btn { border: 2px solid var(--bad); color: var(--bad); background: #fff; border-radius: 12px; padding: .35rem .7rem; font-weight: 800; cursor: pointer; }
.boss-btn.locked { border-color: var(--line); color: var(--muted); }
.boss-btn.beaten { border-color: var(--ok); color: var(--ok); }
.shop-entry { margin-top: .9rem; width: 100%; text-align: left; background: var(--paper); border: 2px dashed var(--cx); border-radius: var(--radius); padding: .8rem 1rem; cursor: pointer; font-size: 1rem; }
.victory { margin-top: .9rem; background: #fff6d6; border: 2px solid #f5c518; border-radius: var(--radius); padding: .8rem 1rem; font-size: 1.05rem; }

/* --- boss --- */
.boss-head { margin-bottom: .8rem; border-color: var(--bad); }
.boss-head .row { display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
.boss-head h2 { margin: 0; font-size: 1.1rem; }
.boss-head .hearts { font-size: 1.2rem; letter-spacing: .1em; }
.boss-head .bar { border-color: var(--bad); background: #fde8e8; }
.boss-head .bar .fill { background: var(--bad); }
.boss-head .bar-labels .l100 { color: var(--bad); }
.boss-shake { animation: shake .4s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.boss-done { text-align: center; padding: 1.4rem 1rem; }
.boss-done h1 { font-size: 1.8rem; }

/* --- shop --- */
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; margin-top: .6rem; }
.shop-item { background: var(--paper); border: 2px solid var(--line); border-radius: 14px; padding: .8rem; text-align: center; cursor: pointer; }
.shop-item .e { font-size: 2.2rem; }
.shop-item .n { font-weight: 800; margin-top: .2rem; }
.shop-item .pr { font-size: .9rem; color: var(--muted); }
.shop-item .pr b { color: var(--bad); }
.shop-item.owned { border-color: var(--ok); background: #eefbf4; }
.shop-item .tag { font-size: .75rem; font-weight: 800; color: var(--ok); }

/* --- method card --- */
.method { margin: .2rem 0 .9rem; background: var(--bg); border-radius: 14px; padding: .8rem 1rem; border-left: 4px solid var(--c100); }
.method h4 { margin: 0 0 .4rem; font-size: 1rem; }
.method .schema { display: grid; grid-template-columns: auto auto auto; gap: .2rem .6rem; font-weight: 800; justify-content: start; margin: .3rem 0 .5rem; font-size: 1.05rem; }
.method .schema .a { color: var(--c100); } .method .schema .x { color: var(--cx); }
.method p { margin: .3rem 0; }
.method .warn { color: #7a3f00; background: var(--cx-soft); border-radius: 10px; padding: .4rem .6rem; }

/* ===================== GAME SKIN (battle-royale vibe, own art) ===================== */
:root {
  --sky1: #8fd3ff; --sky2: #cfeeff; --grass: #7ed957; --storm: #8a3ffc; --gold: #ffd23f; --gold-dark: #d99a00;
  --font-display: "Luckiest Guy", "Bangers", Impact, "Arial Black", sans-serif;
}
body { background: linear-gradient(180deg, var(--sky1) 0%, var(--sky2) 38%, #f6f1e7 100%) fixed; }
h1, .brand span:last-child, .badge, .boss-head h2, .module .letter, .lesson-head h1, .boss-done h1, .victory b {
  font-family: var(--font-display); letter-spacing: .02em; font-weight: 400;
}
h1 { font-size: 2.1rem; color: #1a2b5c; text-shadow: 0 2px 0 #fff, 0 4px 0 rgba(26,43,92,.15); }
.brand span:last-child { font-size: 1.5rem; color: #1a2b5c; text-shadow: 0 2px 0 #fff; }
.logo { background: var(--gold); color: #1a2b5c; box-shadow: 0 3px 0 var(--gold-dark); }
.btn.primary { background: var(--gold); border-color: var(--gold-dark); color: #1a2b5c; box-shadow: 0 4px 0 var(--gold-dark); font-family: var(--font-display); font-weight: 400; letter-spacing: .03em; font-size: 1.05rem; transform: translateY(0); transition: transform .08s, box-shadow .08s; }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-dark); }
.btn { box-shadow: 0 3px 0 var(--line); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.card, .lesson, .module { border-width: 3px; box-shadow: 0 8px 0 rgba(26,43,92,.08), 0 10px 26px rgba(26,43,92,.12); }
.module .letter { font-size: 1.9rem; box-shadow: 0 4px 0 rgba(0,0,0,.18); }

/* hero banner on the map */
.hero { position: relative; border-radius: var(--radius); overflow: hidden; margin: .2rem 0 1rem; min-height: 190px; background: #6bc4ff url("img/hero.jpg") center/cover no-repeat; border: 3px solid #fff; box-shadow: 0 10px 26px rgba(26,43,92,.2); }
.hero .hero-text { position: absolute; inset: auto 0 0 0; padding: 1rem 1.1rem .9rem; background: linear-gradient(180deg, rgba(20,30,70,0) 0%, rgba(20,30,70,.72) 55%, rgba(20,30,70,.85) 100%); color: #fff; }
.hero h1 { color: var(--gold); margin: 0 0 .2rem; font-size: 2.2rem; text-shadow: 0 3px 0 #7a4a00, 0 6px 14px rgba(0,0,0,.4); }
.hero p { margin: 0; font-size: 1rem; color: #eaf4ff; }
.hero p b.c100 { color: #9ec9ff; } .hero p b.cx { color: var(--gold); }
@media (min-width: 640px) { .hero { min-height: 260px; } .hero h1 { font-size: 2.8rem; } }

/* boss screen */
.boss-head { background: #241a4d url("img/storm.jpg") center/cover no-repeat; color: #fff; border-color: var(--storm); position: relative; overflow: hidden; }
.boss-head::before { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(20,10,50,.55), rgba(20,10,50,.85)); }
.boss-head > * { position: relative; }
.boss-head .row { align-items: flex-start; }
.boss-head h2 { color: var(--gold); font-size: 1.5rem; text-shadow: 0 2px 0 #5a2d00; }
.boss-head h2 .muted { color: #cbd5ff; font-family: system-ui, sans-serif; font-size: .8rem; }
.boss-layout { display: grid; grid-template-columns: 96px 1fr; gap: .8rem; align-items: center; }
.boss-portrait { width: 96px; height: 96px; border-radius: 18px; border: 3px solid var(--gold); background: #fff center/cover no-repeat; box-shadow: 0 6px 16px rgba(0,0,0,.4); position: relative; }
.boss-portrait.hit { animation: bosshit .5s; }
@keyframes bosshit { 0% { filter: brightness(3) saturate(0); transform: scale(1); } 30% { transform: scale(.92) rotate(-4deg); } 60% { transform: scale(1.04) rotate(3deg); } 100% { filter: none; transform: none; } }
.dmg { position: absolute; left: 50%; top: 10%; transform: translateX(-50%); font-family: var(--font-display); font-size: 2rem; color: var(--gold); text-shadow: 0 2px 0 #7a1a1a, 0 0 12px #ff3b3b; animation: dmg 1.1s ease-out forwards; pointer-events: none; white-space: nowrap; }
@keyframes dmg { 0% { transform: translate(-50%, 0) scale(.6); opacity: 0; } 20% { transform: translate(-50%, -10px) scale(1.2); opacity: 1; } 100% { transform: translate(-50%, -60px) scale(1); opacity: 0; } }
.boss-head .bar { border-color: #ff5c5c; background: rgba(255,255,255,.15); height: 30px; }
.boss-head .bar .fill { background: linear-gradient(180deg, #ff7b7b, #e02b2b); }
.boss-head .bar-labels .l100, .boss-head .bar-labels .lx { color: #fff; }
.boss-head .bar-scale { color: #cbd5ff; }
.boss-head .hearts { font-size: 1.4rem; }
.flash { position: fixed; inset: 0; pointer-events: none; z-index: 4; animation: flash .45s ease-out forwards; }
.flash.ok { box-shadow: inset 0 0 120px rgba(31,169,113,.55); }
.flash.bad { box-shadow: inset 0 0 120px rgba(229,72,77,.6); }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
.boss-done { background: #241a4d url("img/victory.jpg") center/cover no-repeat; color: #fff; border-color: var(--gold); position: relative; overflow: hidden; }
.boss-done::before { content: ""; position: absolute; inset: 0; background: rgba(20,10,50,.45); }
.boss-done > * { position: relative; }
.boss-done h1 { color: var(--gold); text-shadow: 0 3px 0 #7a4a00; }
.boss-done .btn.primary { margin-top: .6rem; }

/* level-up llama */
.levelup { position: fixed; inset: 0; z-index: 6; display: grid; place-items: center; background: rgba(20,10,50,.55); animation: flash 2.6s ease-in forwards; pointer-events: none; }
.levelup .box { background: #fff; border: 4px solid var(--gold); border-radius: 24px; padding: 1rem 1.4rem; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.4); animation: bounce .6s; }
.levelup img { width: 160px; height: 160px; object-fit: contain; }
.levelup h2 { font-family: var(--font-display); font-size: 1.6rem; margin: .2rem 0 0; color: #1a2b5c; }
@keyframes bounce { 0% { transform: scale(.4); } 60% { transform: scale(1.1); } 100% { transform: scale(1); } }

/* shop header + victory banner */
.shop-hero { display: flex; align-items: center; gap: .8rem; }
.shop-hero img { width: 84px; height: 84px; object-fit: contain; filter: drop-shadow(0 6px 10px rgba(0,0,0,.25)); }
.shop-item .e { font-size: 2.4rem; filter: drop-shadow(0 3px 0 rgba(0,0,0,.15)); }
.victory { background: #241a4d url("img/victory.jpg") center/cover no-repeat; color: #fff; border-color: var(--gold); text-shadow: 0 2px 0 #000; }
.victory b { color: var(--gold); font-size: 1.4rem; }
.mute { background: none; border: 0; cursor: pointer; font-size: 1.1rem; }

/* ===================== BUDDY CHAT ===================== */
.buddy-fab { position: fixed; right: 1rem; bottom: 1rem; z-index: 7; display: flex; align-items: center; gap: .3rem; background: var(--gold); border: 3px solid #fff; color: #1a2b5c; border-radius: 999px; padding: .55rem .9rem; font-family: var(--font-display); font-size: 1.15rem; box-shadow: 0 6px 0 var(--gold-dark), 0 10px 20px rgba(0,0,0,.25); cursor: pointer; }
.buddy-fab:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--gold-dark); }
.buddy-fab.pulse { animation: pulse 1.2s ease-in-out 2; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.buddy { position: fixed; right: .6rem; bottom: .6rem; z-index: 8; width: min(400px, calc(100vw - 1.2rem)); height: min(560px, calc(100dvh - 1.2rem)); background: var(--paper); border: 3px solid #1a2b5c; border-radius: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.35); display: flex; flex-direction: column; overflow: hidden; }
.buddy-head { display: flex; align-items: center; gap: .6rem; padding: .6rem .8rem; background: linear-gradient(90deg, #1a2b5c, #3b2a8a); color: #fff; }
.buddy-head .muted { color: #cbd5ff; font-size: .75rem; }
.buddy-head b { font-family: var(--font-display); font-size: 1.15rem; letter-spacing: .03em; }
.buddy-head .mute { color: #fff; margin-left: auto; }
.buddy-head .mute + .mute { margin-left: 0; }
.buddy-avatar { width: 38px; height: 38px; border-radius: 12px; background: var(--gold); color: #1a2b5c; display: grid; place-items: center; font-size: 1.3rem; box-shadow: 0 3px 0 var(--gold-dark); }
.buddy-log { flex: 1; overflow-y: auto; padding: .7rem; display: flex; flex-direction: column; gap: .45rem; background: linear-gradient(180deg, #eef5ff, #fffdf8); }
.msg { max-width: 85%; padding: .5rem .75rem; border-radius: 16px; line-height: 1.35; font-size: .97rem; white-space: pre-wrap; }
.msg.bot { align-self: flex-start; background: #fff; border: 2px solid var(--c100-soft); border-bottom-left-radius: 6px; }
.msg.me { align-self: flex-end; background: var(--gold); color: #1a2b5c; border-bottom-right-radius: 6px; font-weight: 600; }
.msg.typing { color: var(--muted); font-style: italic; }
.buddy-quick { display: flex; gap: .35rem; padding: .35rem .6rem; overflow-x: auto; border-top: 1px solid var(--line); }
.buddy-quick .btn { white-space: nowrap; }
.buddy-input { display: flex; gap: .4rem; padding: .5rem .6rem .6rem; border-top: 1px solid var(--line); background: var(--paper); }
.buddy-input input { flex: 1; min-width: 0; padding: .55rem .8rem; border: 2px solid var(--line); border-radius: 14px; }
.buddy-input .btn.primary { padding: .45rem .8rem; }
.buddy-input .mute.rec { color: var(--bad); animation: pulse .8s infinite; }
@media (max-width: 480px) { .buddy-fab span { display: none; } }
.exam-timer { margin-top: .4rem; display: inline-block; background: var(--storm); color: #fff; font-weight: 700; padding: .25rem .7rem; border-radius: 999px; font-size: .9rem; box-shadow: 0 3px 0 #5a2aa8; }
.exam-timer b { color: var(--gold); }

/* ===================== D/E visuals: factors, squares, cubes ===================== */
.module[data-m="D"] .letter { background: var(--storm); } .module[data-m="E"] .letter { background: #0ea5a4; }
.chip[data-m="D"] { background: var(--storm); } .chip[data-m="E"] { background: #0ea5a4; }
.factors { margin: .3rem 0 1rem; }
.frow { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem; font-size: 1.15rem; font-weight: 700; }
.fchip { display: inline-grid; place-items: center; min-width: 2rem; height: 2rem; padding: 0 .4rem; border-radius: 8px; color: #fff; }
.fchip.a { background: var(--c100); } .fchip.b { background: var(--cx); }
.fdot { padding: 0 .2rem; color: var(--muted); }
.fgroup { display: inline-flex; gap: .15rem; align-items: center; padding: .2rem .3rem; border: 2px dashed var(--line); border-radius: 10px; }
.chip0 { color: var(--muted); font-weight: 600; }
.fnote { font-size: .9rem; color: var(--muted); margin-top: .35rem; }
.frac { display: inline-block; }
.fline { height: 3px; background: var(--ink); margin: .3rem 0; border-radius: 2px; }
.sq-wrap { margin: .3rem 0 1rem; }
.sq { display: grid; gap: 2px; width: min(220px, 60vw); aspect-ratio: 1; }
.sq i { display: block; background: var(--c100); border-radius: 3px; }
.sq.b i { background: var(--cx); } .sq.c i { background: var(--extra); }
.sq-two { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; }
.sq-two .sq { width: min(160px, 40vw); }
.cube-row { display: flex; gap: .4rem; flex-wrap: wrap; }
.cube-row .sq { width: 70px; }
.sq-hint { background: var(--bg); border-radius: 12px; padding: .6rem .8rem; margin-bottom: .8rem; }

/* ===================== exam ===================== */
.exam-entry { margin-top: .9rem; width: 100%; text-align: left; background: var(--paper); border: 2px dashed var(--c100); border-radius: var(--radius); padding: .8rem 1rem; cursor: pointer; font-size: 1rem; }
.exam-best { margin-left: .5rem; font-size: .85rem; color: var(--ok); font-weight: 700; }
.exam-head { background: linear-gradient(90deg, #1a2b5c, #2456c9) !important; }
.exam-head::before { display: none; }
.exam-fail { background-image: none !important; background: #3b2a8a !important; }
.exam-list { padding-left: 1.2rem; }
.exam-list li { padding: .3rem 0; border-bottom: 1px solid var(--line); }
.exam-list li.bad { background: #fff5f5; }

/* bubbles */
.bubble { position: fixed; right: 1rem; bottom: 4.6rem; z-index: 7; max-width: 240px; background: #fff; color: #1a2b5c; border: 3px solid #1a2b5c; border-radius: 16px 16px 4px 16px; padding: .5rem .8rem; font-weight: 700; box-shadow: 0 8px 20px rgba(0,0,0,.2); cursor: pointer; text-align: left; animation: bubblein .3s ease-out; }
@keyframes bubblein { from { transform: translateY(8px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
.bubble .bx { color: var(--muted); font-weight: 400; margin-left: .3rem; }

/* ===================== BOARD MAP ===================== */
.board { margin: .2rem 0 1rem; }
.board-inner { position: relative; width: 100%; aspect-ratio: 1344 / 768; border-radius: var(--radius); overflow: hidden; border: 3px solid #fff; box-shadow: 0 12px 30px rgba(26,43,92,.25); background: #6bc4ff; }
.board-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.board-nodes { position: absolute; inset: 0; }
.bnode { position: absolute; transform: translate(-50%, -50%); width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; background: var(--gold); box-shadow: 0 4px 0 var(--gold-dark), 0 6px 14px rgba(0,0,0,.35); cursor: pointer; display: grid; place-items: center; padding: 0; font-size: 1rem; transition: transform .15s; z-index: 2; }
.bnode:hover { transform: translate(-50%, -50%) scale(1.15); z-index: 4; }
.bnode.boss { background: #ff5c5c; box-shadow: 0 4px 0 #b91c1c, 0 6px 14px rgba(0,0,0,.35); }
.bnode.exam { width: 44px; height: 44px; font-size: 1.3rem; background: #fff; }
.bnode.shop { background: var(--extra); box-shadow: 0 4px 0 #0f7a4f, 0 6px 14px rgba(0,0,0,.35); }
.bnode.bolt { background: #1a2b5c; color: #fff; }
.bnode.done { background: #d3f4e5; box-shadow: 0 4px 0 #0f7a4f, 0 6px 14px rgba(0,0,0,.25); }
.bnode.locked { background: #cfd3dc; box-shadow: 0 4px 0 #8b90a0; opacity: .9; }
.bnode.open.module, .bnode.open.boss { animation: nodepulse 1.8s ease-in-out infinite; }
@keyframes nodepulse { 0%,100% { box-shadow: 0 4px 0 var(--gold-dark), 0 0 0 0 rgba(255,210,63,.6); } 50% { box-shadow: 0 4px 0 var(--gold-dark), 0 0 0 10px rgba(255,210,63,0); } }
.bnode.boss.open { animation-name: nodepulse-red; }
@keyframes nodepulse-red { 0%,100% { box-shadow: 0 4px 0 #b91c1c, 0 0 0 0 rgba(255,92,92,.6); } 50% { box-shadow: 0 4px 0 #b91c1c, 0 0 0 10px rgba(255,92,92,0); } }
.blabel { position: absolute; top: -34px; left: 50%; transform: translateX(-50%); white-space: nowrap; background: rgba(26,43,92,.92); color: #fff; font-size: .72rem; font-weight: 700; padding: .2rem .5rem; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .15s; }
.bnode:hover .blabel, .bnode:focus .blabel { opacity: 1; }
.pawn { position: absolute; transform: translate(-50%, -100%); z-index: 3; pointer-events: none; }
.pawn-skin { display: block; font-size: 2rem; line-height: 1; filter: drop-shadow(0 4px 4px rgba(0,0,0,.35)); animation: idlebob 2.2s ease-in-out infinite; transform-origin: bottom center; }
.pawn-shadow { display: block; width: 26px; height: 8px; margin: -2px auto 0; border-radius: 50%; background: rgba(0,0,0,.3); filter: blur(1px); }
.pawn.hop .pawn-skin { animation: hop .55s ease-in-out infinite; }
@keyframes idlebob { 0%,100% { transform: translateY(0) scaleX(1); } 50% { transform: translateY(-3px) scaleX(1.03); } }
@keyframes hop { 0%,100% { transform: translateY(0) scale(1, 1); } 40% { transform: translateY(-26px) scale(.95, 1.08); } 100% { transform: translateY(0) scale(1.06, .94); } }
.board-tip { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%) translateY(10px); background: rgba(26,43,92,.92); color: #fff; padding: .35rem .7rem; border-radius: 999px; font-size: .85rem; font-weight: 700; opacity: 0; transition: all .25s; pointer-events: none; white-space: nowrap; max-width: 95%; overflow: hidden; text-overflow: ellipsis; }
.board-tip.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.modules-wrap { margin-top: .6rem; }
.modules-wrap summary { cursor: pointer; font-weight: 700; color: var(--muted); font-size: .9rem; }
.modules-wrap .modules { margin-top: .6rem; }
@media (max-width: 480px) { .bnode { width: 28px; height: 28px; font-size: .85rem; } .bnode.exam { width: 36px; height: 36px; } .pawn-skin { font-size: 1.6rem; } }

/* ===================== FULL-SCREEN BOARD (home) — dark game HUD for a 14-year-old ===================== */
:root { --hud: rgba(12, 16, 40, .82); --hud-line: rgba(140, 170, 255, .35); --neon: #38e8ff; --neon2: #ff4fd8; }
body.is-home { background: radial-gradient(1200px 700px at 50% 30%, #1d2b6b 0%, #0b1030 60%, #06081c 100%) fixed; }
body.is-home main { max-width: none; padding: 0; }
body.is-home .top { position: absolute; left: 0; right: 0; top: 0; z-index: 5; }
body.is-home .brand span:last-child { color: #fff; text-shadow: 0 2px 0 #000; }
body.is-home .hud .xp, body.is-home .streak { background: var(--hud); border-color: var(--hud-line); color: #fff; }
body.is-home .hud .lvl { color: var(--neon); }
body.is-home .mute { color: #fff; }
body.is-home .foot { color: rgba(255,255,255,.45); }
.board { position: relative; height: calc(100dvh - 60px); min-height: 420px; margin: 0; overflow: hidden; }
.board-scroll { position: absolute; inset: 0; overflow: auto; scrollbar-width: none; display: flex; }
.board-scroll::-webkit-scrollbar { display: none; }
.board-inner { position: relative; height: 100%; width: auto; aspect-ratio: 1344 / 768; flex: 0 0 auto; margin: auto; border-radius: 0; border: 0; box-shadow: none; background: transparent; }
.board-img { object-fit: fill; }   /* inner has the exact image ratio, so fill == exact mapping for % coordinates */
@media (min-aspect-ratio: 1344/768) { .board-inner { height: 100%; } }
@media (max-aspect-ratio: 1344/768) { .board-inner { height: 100%; } }
.board-img { filter: saturate(1.08) contrast(1.05); }
.bnode { width: 40px; height: 40px; font-size: 1.15rem; border-width: 3px; }
.bnode.exam { width: 54px; height: 54px; font-size: 1.6rem; }
.blabel { opacity: 1; top: auto; bottom: -26px; font-size: .68rem; padding: .15rem .45rem; background: rgba(12,16,40,.85); border: 1px solid var(--hud-line); letter-spacing: .02em; }

.bnode:hover .blabel { background: #1a2b5c; }
.pawn-skin { font-size: 2.6rem; }
.pawn-shadow { width: 34px; height: 10px; }
.hud-panel { position: absolute; z-index: 4; background: var(--hud); border: 1px solid var(--hud-line); border-radius: 16px; color: #fff; backdrop-filter: blur(6px); box-shadow: 0 10px 30px rgba(0,0,0,.35), inset 0 0 0 1px rgba(255,255,255,.04); }
.hud-tl { left: 1rem; top: 4rem; max-width: min(380px, calc(100vw - 2rem)); padding: .8rem 1rem .9rem; }
.hud-tl h1 { margin: 0; font-size: 1.7rem; color: var(--gold); text-shadow: 0 0 14px rgba(255,210,63,.35), 0 2px 0 #7a4a00; }
.hud-sub { margin: .25rem 0 .4rem; }
.hud-sub .exam-timer { background: linear-gradient(90deg, #7c3aed, #a21caf); box-shadow: 0 0 16px rgba(168,85,247,.5); }
.hud-help { margin: 0; font-size: .85rem; color: #cfd8ff; }
.hud-help b.c100 { color: #8fb4ff; } .hud-help b.cx { color: var(--gold); }
.hud-br { right: 1rem; bottom: 1rem; padding: .5rem .6rem; display: flex; gap: .5rem; align-items: center; }
.hud-br .theme-row { margin: 0; gap: .25rem; }
.hud-br .btn.sm { background: rgba(255,255,255,.08); border-color: var(--hud-line); color: #fff; box-shadow: none; }
.hud-br .btn.sm.on { background: var(--neon); border-color: var(--neon); color: #06081c; box-shadow: 0 0 14px rgba(56,232,255,.6); }
.hud-tr { right: 1rem; top: 4rem; padding: .5rem .8rem; background: linear-gradient(90deg, rgba(122,58,0,.9), rgba(12,16,40,.85)) !important; }
.board-tip { bottom: 1.1rem; left: 1rem; right: auto; transform: translateY(10px); background: var(--hud); border: 1px solid var(--hud-line); }
.board-tip.show { transform: translateY(0); }
.buddy-fab { bottom: 4.6rem; }
body.is-home .buddy-fab { bottom: 4.6rem; right: 1rem; }
/* drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); z-index: 9; background: var(--paper); color: var(--ink); overflow-y: auto; padding: 1rem 1.1rem 2rem; box-shadow: -20px 0 50px rgba(0,0,0,.45); border-left: 3px solid #1a2b5c; animation: drawerin .25s ease-out; }
@keyframes drawerin { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; justify-content: space-between; align-items: center; font-size: 1.1rem; margin-bottom: .5rem; }
.drawer ol { padding-left: 1.3rem; margin: 0; }
.drawer li { padding: .25rem 0; display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.drawer .modules { display: grid; gap: .6rem; }
.drawer-actions { display: flex; gap: .5rem; margin-top: 1rem; }
@media (max-width: 640px) {
  .board { height: calc(100dvh - 60px); }
  .hud-tl { top: 3.6rem; left: .6rem; padding: .6rem .8rem; max-width: calc(100vw - 1.2rem); }
  .hud-tl h1 { font-size: 1.3rem; } .hud-help { display: none; }
  .hud-br { right: .6rem; bottom: .8rem; }
  .blabel { display: none; }
  .bnode { width: 34px; height: 34px; }
  .board-tip { left: .6rem; right: 5.6rem; bottom: .9rem; white-space: normal; font-size: .8rem; }
}

/* nodes sized to the painted tiles */
.board-inner { --tile: 40px; }
.bnode { width: var(--tile); height: var(--tile); font-size: calc(var(--tile) * .5); border-width: 2px; }
.bnode.exam { width: calc(var(--tile) * 1.12); height: calc(var(--tile) * 1.12); font-size: calc(var(--tile) * .6); }
.blabel { bottom: calc(var(--tile) * -0.7); font-size: calc(var(--tile) * .28); }
.pawn-skin { font-size: calc(var(--tile) * 1.15); }
.pawn { transform: translate(-50%, -92%); }
@media (max-width: 640px) { .bnode { width: var(--tile); height: var(--tile); } }

/* declutter: labels only for the pawn's tile and on hover/focus */
.blabel { opacity: 0; transition: opacity .15s; }
.bnode.here .blabel, .bnode:hover .blabel, .bnode:focus-visible .blabel { opacity: 1 !important; }
.bnode .blabel { opacity: 0; }
.bnode.here { box-shadow: 0 0 0 4px rgba(255,255,255,.85), 0 6px 16px rgba(0,0,0,.45); }
.board-tip { opacity: 1; transform: none; }   /* always-on status bar: says where the pawn stands */

/* plain board fields between the content stations */
.bstep { position: absolute; transform: translate(-50%, -50%); width: calc(var(--tile) * .42); height: calc(var(--tile) * .42); border-radius: 50%; background: rgba(255,255,255,.72); box-shadow: 0 2px 0 rgba(0,0,0,.25), inset 0 0 0 2px rgba(26,43,92,.35); pointer-events: none; }

/* the whole board must fit the screen — no horizontal scrolling, every field reachable */
.board-scroll { overflow: hidden; align-items: center; justify-content: center; }
.board-inner { height: auto; width: min(100%, calc((100dvh - 60px) * 1.75)); max-height: 100%; }
.bnode:hover, .bnode.here { z-index: 6; }

/* phones: the board would be too small to tap — make it bigger and pannable, camera follows the pawn */
@media (max-width: 700px) {
  .board-scroll { overflow-x: auto; overflow-y: hidden; justify-content: flex-start; -webkit-overflow-scrolling: touch; }
  .board-inner { width: max(100%, 820px); height: auto; }
  .board-tip { position: fixed; left: .6rem; right: 5.6rem; bottom: .9rem; }
}

/* Bolt has something to say */
.buddy-fab.unread::after { content: ""; position: absolute; top: -3px; right: -3px; width: 14px; height: 14px; border-radius: 50%; background: #e5484d; border: 2px solid #fff; box-shadow: 0 0 10px rgba(229,72,77,.8); animation: pulse 1.4s ease-in-out infinite; }
.buddy-fab { position: fixed; }

/* guided walkthrough */
.guide { margin-top: .9rem; border: 2px solid var(--c100-soft); border-radius: 14px; background: #fff; padding: .7rem .9rem; }
.guide-head { font-weight: 800; color: var(--c100); font-size: .9rem; display: flex; justify-content: space-between; }
.guide-prog { color: var(--muted); font-weight: 600; }
.guide-steps { margin: .5rem 0 0; padding-left: 1.4rem; }
.guide-step { padding: .35rem 0; border-bottom: 1px dashed var(--line); animation: bubblein .25s ease-out; }
.guide-step.loading { color: var(--muted); font-style: italic; }
.guide-actions { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin-top: .6rem; }
.guide-tip { font-size: .8rem; }
