:root {
  --bg: #fff8e7;
  --ink: #2b2340;
  --muted: #6d6585;
  --panel: #ffffff;
  --line: #eadfc4;
  --go: #2fbf71;
  --go-dark: #22995a;
  --accent: #ff8a3d;
  --bad: #e5484d;
  --sand: #f6e3b4;
  --sand-2: #efd598;
  --water: #5ec2ee;
  --rock: #b9b2a6;
  --built: #d9a66b;
  --A: #ffb020; --B: #3fb5e8; --K: #a78bfa; --C: #f2545b; --D: #c47f3b; --E: #1aa37a; --F: #ec4899;
  --G: #8b5cf6; --H: #0ea5b7; --I: #f97316; --J: #64748b; --L: #d4a106;
  --sky1: #8fd3f4; --sky2: #d8f1fb; --sea: #5ec2ee; --ground: #f6e3b4;
  --radius: 18px;
  font-family: "Baloo 2", system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 19px; line-height: 1.45; min-height: 100vh;
  background: linear-gradient(var(--sky1), var(--sky2) 58%, var(--sea) 58% 72%, var(--ground) 72%) fixed; }
body[data-theme="jungle"] { --sky1: #9be3b0; --sky2: #e2f7d9; --sea: #5fb36a; --ground: #3f8f4f; }
body[data-theme="space"] { --sky1: #0b1030; --sky2: #2b2370; --sea: #3b2f8f; --ground: #1a1440; }
body[data-theme="ocean"] { --sky1: #1e88c7; --sky2: #43b5e0; --sea: #2a9fd6; --ground: #e8d29a; }
body[data-theme="candy"] { --sky1: #ffc6e5; --sky2: #fff0f7; --sea: #c8b6ff; --ground: #ffd6a5; }

/* scenery: big emoji around the edges, behind everything */
#scenery { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
#scenery span { position: absolute; line-height: 1; opacity: .9; }
#scenery span:nth-child(1) { top: 70px; left: 3%; font-size: 72px; animation: bob 6s ease-in-out infinite; }
#scenery span:nth-child(2) { top: 90px; left: 30%; font-size: 64px; animation: drift 60s linear infinite; }
#scenery span:nth-child(3) { top: 160px; left: 70%; font-size: 52px; animation: drift 80s linear infinite reverse; }
#scenery span:nth-child(4) { bottom: 2%; left: 1%; font-size: 120px; }
#scenery span:nth-child(5) { bottom: 4%; right: 1%; font-size: 110px; }
#scenery span:nth-child(6) { top: 38%; left: 12%; font-size: 40px; animation: bob 3s ease-in-out infinite; }
#scenery span:nth-child(7) { top: 52%; right: 14%; font-size: 48px; animation: bob 4s ease-in-out infinite; }
#scenery span:nth-child(8) { bottom: 6%; left: 45%; font-size: 40px; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
code { font-family: "JetBrains Mono", monospace; background: #f1ead8; padding: 0 6px; border-radius: 6px; font-size: .88em; }

.btn { border: 0; border-radius: 14px; padding: 10px 18px; background: #efe6d2; color: var(--ink); font-weight: 700; box-shadow: 0 3px 0 #d6c9aa; transition: transform .08s; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #d6c9aa; }
.btn.go { background: var(--go); color: #fff; box-shadow: 0 3px 0 var(--go-dark); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { padding: 6px 12px; font-size: 16px; }
.btn.danger { background: #fde2e2; color: var(--bad); }
.icon-btn { border: 0; background: transparent; font-size: 24px; padding: 4px 8px; border-radius: 10px; }
.icon-btn:hover { background: #0000000d; }

/* ---------- welcome ---------- */
#welcome { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 50% 120%, var(--water) 0 30%, var(--sand) 30.5% 45%, var(--bg) 45.5%); }
.welcome-card { background: var(--panel); border-radius: 28px; padding: 32px 28px; text-align: center; max-width: 420px; width: 100%; box-shadow: 0 10px 40px #2b234022; }
.big-pip { font-size: 84px; animation: bob 2s ease-in-out infinite; }
.welcome-card h1 { margin: 0; font-size: 44px; color: var(--accent); }
.btn.google { display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%; background: #fff; border: 2px solid var(--line); font-size: 20px; }
.btn.google img { width: 24px; height: 24px; }
.welcome-back { font-size: 26px; color: var(--accent); }
.btn.big { width: 100%; font-size: 22px; padding: 12px; }
#name-form { display: flex; flex-direction: column; gap: 12px; }
#name-input { font: inherit; font-size: 26px; text-align: center; padding: 10px; border: 3px solid var(--line); border-radius: 14px; }
#name-input:focus { outline: none; border-color: var(--accent); }

/* ---------- header / path ---------- */
header { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--panel); border-bottom: 2px solid var(--line); }
#captain { font-weight: 800; white-space: nowrap; }
#star-total, #coin-total { font-weight: 800; white-space: nowrap; }
.btn.shop { background: #ffe9a8; box-shadow: 0 3px 0 #e5c76b; }
header .btn { white-space: nowrap; }
@media (max-width: 600px) { #captain, #reset-all { display: none; } header { gap: 6px; padding: 8px 10px; } }
.spacer { flex: 1; }
.part-A { --c: var(--A); } .part-B { --c: var(--B); } .part-K { --c: var(--K); } .part-C { --c: var(--C); }
.part-D { --c: var(--D); } .part-E { --c: var(--E); } .part-F { --c: var(--F); }
.part-G { --c: var(--G); } .part-H { --c: var(--H); } .part-I { --c: var(--I); } .part-J { --c: var(--J); } .part-L { --c: var(--L); }

/* ---------- play area ---------- */
#play { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; padding: 16px; max-width: 1400px; margin: 0 auto; }
@media (max-width: 900px) { #play { grid-template-columns: minmax(0, 1fr); } }
#left, #right { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
#task { background: #fffffff0; border-radius: var(--radius); padding: 14px 18px; box-shadow: 0 2px 0 var(--line); }
.task-head { display: flex; justify-content: space-between; align-items: center; }
#part-name { font-size: 14px; font-weight: 800; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; }
#title { margin: 0; font-size: 28px; line-height: 1.2; }
#text { margin: 6px 0 0; }
.hunt { display: inline-block; margin-top: 6px; font-weight: 800; color: var(--F); }
.hint { margin-top: 10px; background: #fff6d6; border-radius: 12px; padding: 8px 12px; }
.hint pre { font-family: "JetBrains Mono", monospace; font-size: 15px; margin: 6px 0 0; white-space: pre-wrap; }

#stage-wrap { position: relative; background: #ffffffc8; backdrop-filter: blur(6px); border-radius: var(--radius); padding: 10px 8px 14px; min-height: 260px; display: flex; flex-direction: column; align-items: center; box-shadow: 0 2px 0 var(--line); overflow: hidden; }
#bubble { min-height: 2.2em; margin-bottom: 10px; max-width: 92%; background: #fff; border: 3px solid var(--ink); border-radius: 18px; padding: 4px 14px; font-weight: 700; z-index: 3; white-space: pre-wrap; animation: pop .2s; }
#bubble.bad { border-color: var(--bad); }
#bubble.quiet { visibility: hidden; }

/* grid world */
.grid { position: relative; display: grid; gap: 0; align-self: center; }
.cell { position: relative; width: var(--cell); height: var(--cell); display: grid; place-items: center; font-size: calc(var(--cell) * .58); background: var(--sand); box-shadow: inset 0 0 0 1px var(--sand-2); user-select: none; }
.cell.water { background: var(--water) repeating-linear-gradient(-20deg, transparent 0 8px, #ffffff33 8px 10px); box-shadow: none; }
.cell.rock { background: var(--sand); }
.cell.built, .cell.placed { background: var(--built); box-shadow: inset 0 0 0 1px #b88447; }
.cell.ghost { opacity: .45; outline: 3px dashed var(--accent); outline-offset: -5px; }
.cell.guess { box-shadow: inset 0 0 0 4px var(--F); }
.cell.guess::after { content: "🎯"; position: absolute; font-size: calc(var(--cell) * .35); transform: translate(35%, -35%); }
.cell.sparkle { animation: sparkle .4s; }
.predict .cell { cursor: pointer; }
.predict .cell:hover { box-shadow: inset 0 0 0 3px var(--F); }

.pip { position: absolute; top: 0; left: 0; width: var(--cell); height: var(--cell); display: grid; place-items: center; transition: transform .25s ease; z-index: 2; pointer-events: none; }
.av { position: relative; display: inline-block; line-height: 1; }
.av .face { filter: drop-shadow(0 2px 1px #0003); }
.av .hat { position: absolute; top: -.48em; left: 50%; transform: translateX(-50%); font-size: .6em; }
.av .pet { position: absolute; right: -.5em; bottom: -.1em; font-size: .5em; }
.pip .av { font-size: calc(var(--cell) * .6); }
.pip .arrow { position: absolute; inset: 0; transform: rotate(var(--rot, 90deg)); transition: transform .25s; }
.pip .arrow::before { content: ""; position: absolute; top: -2px; left: 50%; transform: translateX(-50%); border: 8px solid transparent; border-bottom: 11px solid var(--accent); border-top: 0; }
.pip.bump .av { animation: shake .4s; }
.pip.happy .av, .talk-pip.happy { animation: hop .5s 2; }

/* talk world */
.talk { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start; gap: 16px; width: 100%; }
.talk-pip { position: relative; font-size: 96px; line-height: 1; flex-basis: 100%; text-align: center; padding-top: 30px; }
.board { background: #fdfaf2; border: 2px solid var(--line); border-radius: 14px; padding: 8px 14px; min-width: 160px; }
.board b { font-size: 14px; color: var(--muted); }
.board pre { margin: 4px 0 0; font-family: inherit; font-size: 22px; line-height: 1.15; white-space: pre; min-height: 1.2em; }

/* editor */
#palette { display: flex; flex-wrap: wrap; gap: 6px; }
#palette button { font-size: 24px; width: 46px; height: 46px; border: 2px solid var(--line); border-radius: 12px; background: #fff; }
#palette button:hover { border-color: var(--accent); }
#palette button.code { width: auto; padding: 0 10px; font: 500 15px "JetBrains Mono", monospace; color: #1d4ed8; }
#editor { border-radius: var(--radius); overflow: hidden; box-shadow: 0 2px 0 var(--line); }
.CodeMirror { height: 340px; font-family: "JetBrains Mono", monospace; font-size: 21px; line-height: 1.5; }
.CodeMirror-gutters { background: #f7f2e6; border-right: 0; }
.CodeMirror-linenumber { color: #b3a988; padding: 0 8px 0 4px; }
.running { background: #d7f5e3 !important; }
.error-line { background: #ffe0e0 !important; }
.cm-s-default .cm-string { color: #c2410c; }
.cm-s-default .cm-builtin, .cm-s-default .cm-variable { color: #1d4ed8; }
.readonly .CodeMirror { background: #faf7ef; }

#controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
#run { font-size: 22px; padding: 10px 26px; }
.speed { display: flex; align-items: center; gap: 4px; margin-left: auto; font-size: 20px; }
.speed input { width: 110px; accent-color: var(--accent); }
#message { min-height: 1.5em; font-weight: 700; padding: 4px 4px; }
#message:not(:empty) { background: #fffffff0; border-radius: 14px; padding: 8px 12px; }
.speed { background: #ffffffd0; border-radius: 12px; padding: 2px 8px; }
#message.bad { color: var(--bad); }
#message.info { color: var(--muted); }
.where { font-size: 14px; background: #ffe0e0; border-radius: 8px; padding: 0 8px; margin-left: 6px; }
.minor { display: flex; gap: 8px; flex-wrap: wrap; }

/* roadmap */
#map { padding: 16px 16px 60px; min-height: calc(100vh - 60px); }
#map-inner { position: relative; max-width: 760px; margin: 0 auto; }
.road { position: absolute; inset: 0; pointer-events: none; }
.road polyline { fill: none; stroke-width: 16; stroke-linecap: round; stroke-linejoin: round; }
.road .base { stroke: #eadcb8; }
.road .walked { stroke: var(--accent); stroke-width: 8; stroke-dasharray: 1 16; }
.zone { position: absolute; left: 50%; transform: translate(-50%, -50%); background: var(--c); color: #fff; padding: 6px 20px; border-radius: 999px; font-size: 21px; font-weight: 800; white-space: nowrap; box-shadow: 0 4px 0 #0002; z-index: 1; }
.zone span { background: #fff3; border-radius: 999px; padding: 0 10px; margin-left: 6px; font-size: 16px; }
.node { position: absolute; width: 66px; height: 66px; margin: -33px 0 0 -33px; border: 4px solid #fff; border-radius: 50%; background: var(--c); color: #fff; font-size: 24px; font-weight: 800; box-shadow: 0 5px 0 #0003; display: grid; place-items: center; padding: 0; z-index: 1; }
.node:not(.done):not(.locked) { background: #fff; color: var(--c); border-color: var(--c); }
.node.locked { background: #e3dac6; border-color: #f3ecdc; box-shadow: 0 5px 0 #cfc4aa; cursor: not-allowed; font-size: 22px; }
.node.next { animation: pulse 1.1s ease-in-out infinite; box-shadow: 0 0 0 8px #ffffffaa, 0 0 24px 6px var(--c); }
.node.goal { width: 100px; height: 100px; margin: -50px 0 0 -50px; font-size: 50px; }
.node.goal:not(.locked) { background: #ffd34d; border-color: #fff; }
.node.goal.locked { background: #e3dac6; font-size: 34px; }
.node .stars { position: absolute; bottom: -22px; font-size: 13px; white-space: nowrap; letter-spacing: -1px; color: #f5b301; }
.node .label { position: absolute; top: 50%; transform: translateY(-50%); max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 700; color: var(--ink); background: #fffe; padding: 1px 10px; border-radius: 10px; }
.node.locked .label { color: var(--muted); }
.label.right { left: 76px; } .label.left { right: 76px; }
.goal .label.right { left: 108px; } .goal .label.left { right: 108px; }
.node.shake { animation: shake .4s; }
.you { position: absolute; transform: translate(-50%, -50%); font-size: 40px; z-index: 2; pointer-events: none; animation: bob 1.4s ease-in-out infinite; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 20px; border-radius: 16px; font-weight: 700; z-index: 20; max-width: calc(100vw - 32px); }
#win-fx { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; }

/* cards */
#card { position: relative; max-width: 680px; margin: 32px auto; background: var(--panel); border-radius: 28px; padding: 28px; text-align: center; box-shadow: 0 6px 30px #2b234018; }
#card-speak { position: absolute; top: 16px; right: 16px; }
.card-emoji { font-size: 64px; }
#card-title { font-size: 32px; margin: 4px 0 12px; }
#card-text { text-align: left; font-size: 21px; margin-bottom: 20px; }
#card-btn { font-size: 22px; padding: 12px 30px; }
.trophies { display: flex; justify-content: center; gap: 16px; margin-bottom: 16px; }
.trophy { background: #fff6d6; border-radius: 16px; padding: 10px 20px; display: flex; flex-direction: column; }
.trophy b { font-size: 28px; }
.mini { display: inline-grid; margin: 4px auto 16px; border-radius: 10px; overflow: hidden; }
.mini span { width: 34px; height: 34px; display: grid; place-items: center; font-size: 20px; background: var(--sand); }
.mini span.built { background: var(--built); }
.mini span.water { background: var(--water); }
pre.art { font-family: inherit; font-size: 26px; line-height: 1.1; margin: 0 0 16px; }

/* dialogs */
dialog { border: 0; border-radius: 28px; padding: 24px 28px; box-shadow: 0 20px 60px #0004; max-width: min(92vw, 720px); }
dialog::backdrop { background: #2b234066; }
#win { text-align: center; }
.win-pip { font-size: 72px; animation: hop .5s 3; }
#win-stars { font-size: 44px; letter-spacing: 4px; color: #f5b301; }
#win-coins { font-size: 26px; font-weight: 800; color: #b7791f; min-height: 1em; }
.win-pip { padding-top: 30px; }

/* shop */
#shop { width: min(92vw, 720px); }
#shop h2 { display: flex; justify-content: space-between; align-items: center; margin: 0; }
#shop-coins { font-size: 24px; color: #b7791f; }
#shop-preview { font-size: 80px; text-align: center; padding: 34px 0 4px; }
#shop-msg { text-align: center; font-weight: 700; min-height: 1.4em; margin: 0; color: var(--accent); }
#shop-items { max-height: 50vh; overflow: auto; }
#shop h3 { margin: 12px 0 6px; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.item { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border: 3px solid var(--line); border-radius: 16px; background: #fff; }
.item b { font-size: 36px; line-height: 1.1; }
.item small { font-size: 12px; color: var(--muted); }
.item span { font-size: 14px; font-weight: 700; color: var(--muted); }
.item:hover { border-color: var(--accent); }
.item.on { border-color: var(--go); background: #e7f9ef; }
.item.on span { color: var(--go-dark); }
#win-title { margin: 4px 0; }
#win-tip { color: var(--muted); min-height: 1em; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
#parent .row { justify-content: flex-start; }
.muted { color: var(--muted); font-size: 15px; }
.table-wrap { max-height: 45vh; overflow: auto; border: 2px solid var(--line); border-radius: 12px; }
#report { border-collapse: collapse; width: 100%; font-size: 15px; }
#report th, #report td { padding: 4px 10px; text-align: left; border-bottom: 1px solid var(--line); }
#report th { position: sticky; top: 0; background: #fbf5e6; }
#report tr[data-i] { cursor: pointer; }
#report tr[data-i]:hover { background: #fff6d6; }
#report tr.current { font-weight: 800; }

@keyframes bob { 50% { translate: 0 -8px; } }
@keyframes pulse { 50% { scale: 1.12; } }
@keyframes hop { 50% { transform: translateY(-14px) scale(1.08); } }
@keyframes shake { 25% { transform: translateX(-6px) rotate(-8deg); } 75% { transform: translateX(6px) rotate(8deg); } }
@keyframes pop { from { transform: scale(.6); } }
@keyframes drift { from { translate: -40vw 0; } to { translate: 60vw 0; } }
@keyframes sparkle { 50% { background: #fff3a8; } }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }
