:root {
  --bg: #f3f0e8; --panel: #fff; --panel2: #f7f5ef; --ink: #1d1c19; --muted: #6e695f; --line: #e1dccf;
  --accent: #2f7d4a; --accent-ink: #fff; --accent2: #e0a526;
  --good: #2f7d4a; --good-bg: #e6f3e9; --bad: #b23b2e; --bad-bg: #fbe8e5; --warn: #8a5a00; --warn-bg: #fff3d6; --info-bg: #efece5;
  --inacc: #d4a017; --mist: #e07b24; --blun: #c8372d; --best: #1f8f5f;
  --top-h: 56px; --tab-h: 64px; --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141513; --panel: #1e201d; --panel2: #252722; --ink: #ecebe5; --muted: #a29d91; --line: #34362f;
    --accent: #52b07a; --accent-ink: #0c1a11; --good: #7fd19a; --good-bg: #1a2c20; --bad: #ff8a7a; --bad-bg: #3a1e1a;
    --warn: #f2c46b; --warn-bg: #33290f; --info-bg: #262823;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; }
body { padding-top: calc(var(--top-h) + env(safe-area-inset-top)); padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); overflow-x: hidden; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 24px; margin: 4px 0 6px; line-height: 1.2; }
h2 { font-size: 18px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 14px 0 6px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .mt { margin-top: 8px; } .center { text-align: center; justify-content: center; }
.hidden { display: none !important; }
.bad { color: var(--bad); }

/* top + tab bars */
.topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 20; height: calc(var(--top-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 14px 0; display: flex; align-items: center; justify-content: space-between; background: #1f2a22; color: #fff; }
.logo { color: #fff; font-weight: 800; font-size: 18px; white-space: nowrap; }
.stats { display: flex; align-items: center; gap: 8px; }
.chip { background: rgba(255,255,255,.12); border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.lvl { display: flex; align-items: center; gap: 6px; color: #fff; }
.lvlNum { background: var(--accent2); color: #2a1d00; font-weight: 900; border-radius: 50%; width: 28px; height: 28px; display: grid; place-items: center; font-size: 13px; }
.lvlBar { width: 56px; height: 8px; background: rgba(255,255,255,.18); border-radius: 99px; overflow: hidden; display: block; }
.lvlBar.wide { width: 100%; background: var(--info-bg); height: 10px; margin: 6px 0; }
.lvlFill { display: block; height: 100%; background: var(--accent2); border-radius: 99px; transition: width .5s; }
@media (max-width: 420px) { .logo span { display: none; } }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--panel); border-top: 1px solid var(--line); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.tabbar a span { font-size: 22px; line-height: 1; filter: grayscale(.6); }
.tabbar a.active { color: var(--accent); }
.tabbar a.active span { filter: none; transform: scale(1.1); }

.view { max-width: 1180px; margin: 0 auto; }
.page { padding: 16px; max-width: 760px; margin: 0 auto; }
.page.wide { max-width: 1180px; }
.crumb { margin-bottom: 6px; font-size: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 10px 0; }
.card.center { text-align: center; padding: 28px 18px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.lead { font-size: 16.5px; }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--panel); padding: 10px 14px; border-radius: 11px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; color: var(--ink); }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.big { padding: 13px 22px; font-size: 16.5px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.seg { display: flex; background: var(--info-bg); border-radius: 11px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 8px; border-radius: 8px; cursor: pointer; font-weight: 700; color: var(--muted); min-height: 40px; }
.seg button.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.seg.small button { padding: 6px 10px; min-height: 34px; }
input, select, textarea { border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; padding: 10px 12px; min-height: 44px; }
input { flex: 1; min-width: 0; }
textarea { width: 100%; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.toggle { display: flex; gap: 10px; align-items: center; margin: 10px 0; cursor: pointer; }
.toggle input { width: 20px; height: 20px; min-height: 0; flex: none; accent-color: var(--accent); }
.pill { font-size: 12px; font-weight: 800; padding: 3px 9px; border-radius: 99px; background: var(--info-bg); vertical-align: middle; }
.pill.good { background: var(--good-bg); color: var(--good); } .pill.bad { background: var(--bad-bg); color: var(--bad); }

/* feedback */
.feedback, .pzFeedback { border-radius: 12px; padding: 12px 14px; border-left: 4px solid var(--line); background: var(--info-bg); min-height: 46px; }
.feedback.good, .pzFeedback.good { background: var(--good-bg); border-color: var(--good); }
.feedback.bad, .pzFeedback.bad { background: var(--bad-bg); border-color: var(--bad); }
.feedback.warn { background: var(--warn-bg); border-color: var(--warn); }
.pzFeedback:empty { display: none; }
.feedback ul { margin: 6px 0 0; padding-left: 20px; }
.feedback .prev { font-size: 13px; margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }

/* board */
.board { position: relative; width: 100%; aspect-ratio: 1; overflow: hidden; }
.cgHost { width: 100%; height: 100%; }
.promo { position: absolute; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 10; }
.promoCard { background: var(--panel); border-radius: 14px; padding: 14px; text-align: center; font-weight: 700; }
.promoRow { display: flex; gap: 6px; margin: 10px 0; }
.promoRow button { width: 60px; height: 60px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); cursor: pointer; position: relative; }
.promoRow piece { position: absolute; inset: 4px; background-size: cover; display: block; }
.promoCancel { border: 0; background: none; color: var(--muted); cursor: pointer; }

/* puzzle + lesson layout */
.pzWrap, .lesson, .gameGrid, .reviewGrid, .introGrid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
@media (min-width: 900px) {
  .pzWrap, .lesson, .gameGrid, .reviewGrid { grid-template-columns: minmax(0, 560px) minmax(300px, 1fr); align-items: start; }
  .introGrid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
}
.pzSide, .lSide, .rvSide { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.pzStatus { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid #888; display: inline-block; flex: none; }
.pzTheme { font-weight: 700; color: var(--muted); }
.pzNote { background: var(--warn-bg); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.lIdea { background: var(--info-bg); border-radius: 12px; padding: 10px 14px; }
.lIdea summary { font-weight: 800; cursor: pointer; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.lIdea ol { margin: 8px 0 0; padding-left: 20px; } .lIdea li { margin: 4px 0; }
.lLevel { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.moves { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 2px 8px; font: 14px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace; max-height: 220px; overflow: auto; }
.moves .n { color: var(--muted); }
.moves .mv { cursor: pointer; border-radius: 4px; padding: 0 4px; }
.moves .mv.cur { background: var(--accent); color: var(--accent-ink); }
.c-inacc { color: var(--inacc); font-weight: 700; } .c-mist { color: var(--mist); font-weight: 700; } .c-blun { color: var(--blun); font-weight: 800; }

/* drills */
.drillHead { display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 10px; font-size: 16px; }
.dots { display: flex; gap: 5px; flex: 1; justify-content: center; }
.dots span { width: 22px; height: 8px; border-radius: 99px; background: var(--line); }
.dots span.ok { background: var(--good); } .dots span.miss { background: var(--bad); }
.nextRow { justify-content: center; position: sticky; bottom: calc(var(--tab-h) + 8px); }
.bigIcon { font-size: 52px; line-height: 1.1; }
.bigStars { font-size: 34px; margin: 6px 0; }
.stars { color: var(--accent2); letter-spacing: 1px; } .stars .off { color: var(--line); }
.learnCard .spot li { margin: 6px 0; }
.rushScore { font-size: 22px; } .rushClock { font-size: 22px; font-variant-numeric: tabular-nums; } .rushStrikes { color: var(--bad); font-size: 18px; letter-spacing: 2px; }

/* home */
.hero { display: flex; gap: 14px; align-items: flex-start; background: linear-gradient(135deg, #24372b, #1f2a22); color: #f1efe6; border: 0; }
.hero p { margin: 4px 0 0; } .hero .muted { color: #b8c4b9; }
.coachAv { font-size: 34px; background: var(--accent2); color: #2a1d00; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.goalRow { display: flex; gap: 16px; align-items: center; }
.ring { --p: 0; width: 84px; height: 84px; border-radius: 50%; flex: none; display: grid; place-items: center; background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--info-bg) 0); position: relative; }
.ring::before { content: ''; position: absolute; inset: 9px; background: var(--panel); border-radius: 50%; }
.ring span { position: relative; font-weight: 900; font-size: 18px; text-align: center; line-height: 1; }
.ring small { display: block; font-size: 10px; color: var(--muted); font-weight: 600; }
.plan { display: flex; flex-direction: column; gap: 8px; }
.planItem, .gameRow { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; color: var(--ink); text-align: left; width: 100%; cursor: pointer; }
.planItem > span:nth-child(2), .gameRow > span:nth-child(2) { flex: 1; min-width: 0; }
.planItem:hover, .gameRow:hover { border-color: var(--accent); }
.planItem.done { opacity: .55; }
.pIcon { font-size: 26px; width: 36px; text-align: center; }
.rule { border-left: 4px solid var(--accent2); }
.rule p { margin: 4px 0 0; }
.gameList { display: flex; flex-direction: column; gap: 8px; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile, .themeTile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 2px; color: var(--ink); }
.tile:hover, .themeTile:hover { border-color: var(--accent); }
.tile.hot { border-color: var(--accent2); box-shadow: inset 0 0 0 1px var(--accent2); }
.tile span:last-child { color: var(--muted); font-size: 13px; }
.tIcon { font-size: 26px; }
.wideTile { margin-bottom: 10px; }
.themeGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.themeTile.weak { border-color: var(--bad); background: var(--bad-bg); }

/* path */
.unit { margin: 18px 0 26px; }
.unitHead { display: flex; justify-content: space-between; align-items: center; background: var(--u); color: #fff; border-radius: var(--radius); padding: 12px 16px; }
.unitHead h2 { margin: 0; color: #fff; } .unitHead .muted { color: rgba(255,255,255,.8); }
.unitProg { font-weight: 900; font-size: 18px; }
.nodes { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 16px 0; }
.node { display: flex; align-items: center; gap: 12px; transform: translateX(calc((var(--off) - 1) * 50px)); color: var(--ink); width: 230px; }
.nodeIcon { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-size: 28px; background: var(--panel); border: 3px solid var(--line); box-shadow: 0 4px 0 var(--line); flex: none; transition: transform .1s; }
.node.open .nodeIcon { border-color: var(--u); box-shadow: 0 4px 0 var(--u); animation: pulse 1.6s infinite; }
.node.done .nodeIcon { background: var(--u); border-color: var(--u); box-shadow: 0 4px 0 rgba(0,0,0,.25); }
.node.locked { opacity: .5; }
.node:active .nodeIcon { transform: translateY(3px); box-shadow: none; }
.nodeLabel { font-weight: 700; font-size: 14px; line-height: 1.3; }
.node.boss .nodeIcon { width: 76px; height: 76px; font-size: 34px; }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* play */
.bots { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.bot { background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 2px; text-align: left; cursor: pointer; color: var(--ink); }
.bot.sel { border-color: var(--accent); background: var(--good-bg); }
.botEmoji { font-size: 26px; }
.player { display: flex; align-items: center; gap: 8px; padding: 6px 2px; }
.player .botEmoji { font-size: 22px; }
.thinking { color: var(--muted); font-size: 13px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.gSide { display: flex; flex-direction: column; gap: 10px; margin: 0; }

/* review */
.rvNav { margin-top: 8px; }
.evalGraph { width: 100%; height: 70px; border-radius: 10px; overflow: hidden; margin-top: 6px; cursor: pointer; border: 1px solid var(--line); display: block; }
.gWhiteBg { fill: #f4f2ec; } .gBlackBg { fill: #3a3a36; }
.gLine { fill: none; stroke: var(--accent2); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.gCursor { stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.gm-mist { fill: var(--mist); } .gm-blun { fill: var(--blun); }
.accBig { font-size: 44px; font-weight: 900; line-height: 1; }
.accBig small { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.cls { font-size: 12.5px; font-weight: 800; padding: 3px 8px; border-radius: 8px; background: var(--info-bg); }
.cls.best, .cls.good { color: var(--best); } .cls.inacc { color: var(--inacc); } .cls.mist { color: var(--mist); } .cls.blun { color: #fff; background: var(--blun); }
.advice p { margin: 8px 0; }
.coachCard { margin: 0; }
.keyList { display: flex; flex-direction: column; gap: 6px; }
.keyM { text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 10px 12px; cursor: pointer; font-weight: 600; color: var(--ink); min-height: 44px; }
.keyM:hover { border-color: var(--accent); }
.progress { height: 10px; background: var(--info-bg); border-radius: 99px; overflow: hidden; margin: 16px 0 8px; }
.pFill { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.impList { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

/* me */
.meHead { display: flex; gap: 16px; align-items: center; }
.bigLvl { width: 72px; height: 72px; border-radius: 50%; background: var(--accent2); color: #2a1d00; display: grid; place-items: center; font-size: 30px; font-weight: 900; flex: none; }
.meHead > div:last-child { flex: 1; }
.statGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 8px; text-align: center; display: flex; flex-direction: column; }
.stat b { font-size: 22px; } .stat span { font-size: 12px; color: var(--muted); }
.twoCol { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.twoCol .card { margin: 0; }
@media (max-width: 520px) { .twoCol { grid-template-columns: 1fr; } }
.bar { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); color: var(--ink); font-size: 14px; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.badge { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 6px; text-align: center; display: flex; flex-direction: column; gap: 2px; opacity: .38; filter: grayscale(1); }
.badge.got { opacity: 1; filter: none; border-color: var(--accent2); }
.badge span { font-size: 26px; } .badge b { font-size: 12.5px; } .badge small { font-size: 11px; color: var(--muted); }
.settings label { display: flex; align-items: center; gap: 8px; margin: 8px 0; }

/* toasts + confetti */
.toasts { position: fixed; top: calc(var(--top-h) + env(safe-area-inset-top) + 8px); left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: max-content; max-width: 92vw; }
.toast { background: #1f2a22; color: #fff; padding: 9px 16px; border-radius: 99px; font-weight: 700; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: tin .25s ease-out; transition: opacity .4s, transform .4s; }
.toast.xp { background: var(--accent2); color: #2a1d00; }
.toast.big { font-size: 16px; padding: 12px 20px; }
.toast.bad { background: var(--bad); }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes tin { from { opacity: 0; transform: translateY(-10px) scale(.95); } }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti span { position: absolute; top: -30px; animation: fall 1.8s ease-in forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); opacity: .8; } }

@media (min-width: 900px) { .page { padding: 22px; } }
.opCard .opHead { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; margin-bottom: 4px; }
.tabbar a { font-size: 11px; }
@media (max-width: 380px) { .tabbar a { font-size: 10px; } .tabbar a span { font-size: 20px; } }
.promoRow.cg-wrap { width: auto; height: auto; position: static; }
.promoRow.cg-wrap piece { position: absolute; top: 4px; left: 4px; right: 4px; bottom: 4px; width: auto !important; height: auto !important; transform: none !important; background-size: cover; pointer-events: none; }

/* agent fix box */
.fixBox input, .fixBox textarea { width: 100%; box-sizing: border-box; border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; background: var(--bg, transparent); resize: vertical; min-height: 76px; margin-bottom: 8px; }
.fixBox .row { align-items: center; gap: 10px; flex-wrap: wrap; }
.fixItem { border-top: 1px solid var(--line); padding: 8px 0 2px; margin-top: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.fixBox input { min-height: 44px; resize: none; }
.opCard.feature { border: 2px solid var(--accent); }
