/* The Builder — one committed look: a blueprint desk around a sunny window onto the world.
   Layout: top bar, the stage (the bridge site) as large as possible, the toolbar along the bottom. */
:root {
  --night: #0A2240;
  --deep: #10335A;
  --deep-2: #184272;
  --line: rgba(255, 255, 255, 0.1);
  --paper: #F4F8FB;
  --mist: #A9C2DC;
  --ink: #14304A;
  --card: #F7FAFC;
  --card-2: #E5EDF5;
  --sun: #FFC531;
  --sun-d: #D99A00;
  --sun-ink: #4A3300;
  --mint: #3DDC97;
  --mint-d: #1C9D63;
  --mint-ink: #07351F;
  --coral: #FF6B57;
  --coral-d: #C9412D;
  --sky: #5CC8FF;
  --gold: #FFB938;
  --bg1: #154070;
  --bg2: #081B33;
  --font-display: 'Fredoka', 'Rubik', 'Varela Round', 'Arial Rounded MT Bold', system-ui, sans-serif;
  --font-body: 'Rubik', 'Fredoka', 'Segoe UI', system-ui, sans-serif;
  --gut-l: max(16px, env(safe-area-inset-left, 0px));
  --gut-r: max(16px, env(safe-area-inset-right, 0px));
  --mat-w: 88px;
  color-scheme: dark;
}

html { height: 100%; box-sizing: border-box; background: var(--night); }
*, *::before, *::after { box-sizing: inherit; }
body {
  height: 100%; margin: 0; overflow: hidden;
  background: var(--night); color: var(--paper);
  font-family: var(--font-body); font-size: 16px;
  -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; touch-action: manipulation; overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; }
h1, h2, h3 { text-wrap: balance; }

#app { position: relative; height: 100%; overflow: hidden; }
#app[data-world="2"] { --bg1: #3A2F5E; --bg2: #120E26; }
#app[data-world="3"] { --bg1: #2E3A78; --bg2: #0B1030; }
#app[data-world="4"] { --bg1: #5A2C4C; --bg2: #1E0B19; }
#app[data-world="5"] { --bg1: #1B5C8E; --bg2: #08243D; }
#app[data-world="6"] { --bg1: #6B3348; --bg2: #1C0C1A; }

/* ── The desk: blueprint paper with a fine grid ── */
.desk { position: absolute; inset: 0; background: radial-gradient(120% 90% at 50% 35%, var(--bg1), var(--bg2) 78%); transition: background 0.8s; }
.desk .grid {
  position: absolute; inset: 0; opacity: 0.7;
  background-image:
    linear-gradient(rgba(255,255,255,0.07) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.07) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
  mask-image: radial-gradient(85% 75% at 50% 45%, #000 35%, transparent 90%);
  -webkit-mask-image: radial-gradient(85% 75% at 50% 45%, #000 35%, transparent 90%);
}
.desk .marks { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.5; }

.screen { position: absolute; inset: 0; padding-left: var(--gut-l); padding-right: var(--gut-r); }

/* ── Buttons ── */
.btn {
  font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; line-height: 1;
  padding: 0.85em 1.5em; border-radius: 999px; position: relative; min-height: 48px;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.btn:active { transform: translateY(4px); }
.btn-go { background: var(--mint); color: var(--mint-ink); box-shadow: inset 0 2px 0 rgba(255,255,255,0.45), 0 5px 0 var(--mint-d), 0 10px 18px rgba(0,0,0,0.22); }
.btn-go:active { box-shadow: inset 0 2px 0 rgba(255,255,255,0.45), 0 1px 0 var(--mint-d), 0 4px 8px rgba(0,0,0,0.2); }
.btn-soft { background: var(--card-2); color: var(--ink); box-shadow: inset 0 2px 0 rgba(255,255,255,0.7), 0 5px 0 #B6C8D8; }
.btn-soft:active { box-shadow: 0 1px 0 #B6C8D8; }
.btn-danger-soft { background: #FFE6E2; color: #A62E1D; box-shadow: 0 4px 0 #F2B8AF; font-size: 1rem; }
.btn-xl { font-size: clamp(1.4rem, 2.6vw, 1.9rem); padding: 0.7em 1.9em; }

.icon-btn {
  width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: rgba(255,255,255,0.08); border: 1px solid var(--line); color: var(--paper);
  transition: transform 0.1s, background 0.2s, opacity 0.2s, color 0.2s;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn.small { width: 44px; height: 44px; }
.icon-btn.tiny { width: 34px; height: 34px; }
.icon-btn.tiny .ic { width: 18px; height: 18px; }
.icon-btn.light { background: var(--card-2); color: var(--ink); border-color: transparent; }
.icon-btn .ic { width: 24px; height: 24px; }
.icon-btn.off { opacity: 0.35; }
.icon-btn.ready { position: relative; background: rgba(255,226,122,0.18); border-color: rgba(255,226,122,0.6); color: #FFE27A; }
/* Pulsing glows fade a fixed shadow in and out (opacity runs on the GPU; an animated box-shadow repaints every frame). */
.icon-btn.ready::after { content: ''; position: absolute; inset: -1px; border-radius: inherit; pointer-events: none; box-shadow: 0 0 0 6px rgba(255,226,122,0.12), 0 0 22px rgba(255,226,122,0.35); opacity: 0; animation: glow 1.8s ease-in-out infinite; }
@keyframes glow { 50% { opacity: 1; } }
.link-btn { font-family: var(--font-body); font-size: 0.95rem; color: var(--mist); text-decoration: underline; text-underline-offset: 4px; padding: 12px; min-height: 44px; }

/* ── Title ── */
#scr-title { display: grid; place-items: center; padding-block: 24px; }
.title-wrap { display: flex; align-items: center; gap: clamp(16px, 4vw, 56px); max-width: 1100px; width: 100%; justify-content: center; }
.title-hero { width: clamp(280px, 46vw, 560px); max-width: 100%; aspect-ratio: 12.4 / 8.4; position: relative; order: 2; border-radius: 32px; overflow: hidden; box-shadow: 0 30px 60px rgba(0,0,0,0.35), inset 0 0 0 1px rgba(255,255,255,0.12); }
#title-art { width: 100%; height: 100%; display: block; }
.title-text { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; min-width: 0; }
.eyebrow { margin: 0; font-family: var(--font-display); font-weight: 500; color: var(--sky); letter-spacing: 0.04em; font-size: 1.05rem; }
.logo { margin: 0; display: flex; flex-direction: column; line-height: 0.95; }
.logo-main {
  font-family: var(--font-display); font-weight: 700; font-size: clamp(4.4rem, 11vw, 8.2rem); color: var(--sun);
  text-shadow: 0 4px 0 var(--sun-d), 0 8px 0 #8A5B05, 0 18px 30px rgba(0,0,0,0.35);
}
.logo-sub { font-family: var(--font-display); font-weight: 600; font-size: clamp(1.5rem, 3.2vw, 2.4rem); color: var(--paper); margin-top: 0.3em; }
.title-lede { margin: 0 0 10px; color: var(--mist); font-size: clamp(1rem, 1.6vw, 1.2rem); line-height: 1.5; max-width: 30ch; }
.parents-link { position: absolute; bottom: 12px; inset-inline-start: var(--gut-r); }

/* ── Map ── */
#scr-map { display: flex; flex-direction: column; padding-block: 14px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.map-top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.map-title { flex: 1; min-width: 0; }
.map-title h2 { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: clamp(1.5rem, 2.6vw, 2rem); }
.map-title p { margin: 2px 0 0; color: var(--mist); font-size: 0.98rem; }
.worlds { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: clamp(12px, 1.6vw, 20px); flex: 1; min-height: 0; }
.worlds .world-art { min-height: 90px; }
.worlds .world-meta { padding: 8px 18px 0; }
.worlds .world-path { padding: 8px 12px 24px; }
.world {
  border-radius: 28px; overflow: hidden; display: flex; flex-direction: column; position: relative; min-height: 0;
  background: linear-gradient(180deg, var(--w1), var(--w2)); border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 18px 40px rgba(0,0,0,0.28);
}
.world.w1 { --w1: #1F5A80; --w2: #163F5E; --wa: #7FE08A; }
.world.w2 { --w1: #6A3A3A; --w2: #3E2230; --wa: #FFB36B; }
.world.w3 { --w1: #3C4A8E; --w2: #26305F; --wa: #C9B8FF; }
.world.w4 { --w1: #7A3A5E; --w2: #4A1F38; --wa: #FFA3CC; }
.world.w5 { --w1: #2A6FA6; --w2: #194B78; --wa: #9FE0FF; }
.world.w6 { --w1: #8A4552; --w2: #552633; --wa: #FFB27A; }
.world-art { flex: 1; min-height: 150px; position: relative; overflow: hidden; }
.world-art > svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.world-art::after { content: ''; position: absolute; inset: auto 0 0; height: 35%; background: linear-gradient(transparent, var(--w2)); pointer-events: none; }
.world-lock { position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: rgba(8, 22, 40, 0.55); color: var(--paper); font: 600 1.05rem var(--font-display); text-align: center; padding: 10px; }
.world-lock .ic { width: 40px; height: 40px; padding: 12px; box-sizing: content-box; border-radius: 50%; background: rgba(255,255,255,0.12); }
.world-body { display: flex; flex-direction: column; }
.world-meta { padding: 12px 20px 2px; }
.world-num { font-family: var(--font-display); font-weight: 500; font-size: 0.9rem; color: var(--wa); letter-spacing: 0.04em; }
.world-meta h3 { margin: 2px 0 0; font-family: var(--font-display); font-weight: 700; font-size: clamp(1.4rem, 2.2vw, 1.8rem); }
.world-meta p { margin: 2px 0 0; color: var(--mist); font-size: 0.95rem; }
.world-reward { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; padding: 3px 10px 3px 4px; border-radius: 999px; background: rgba(0,0,0,0.2); font-size: 0.85rem; color: var(--paper); }
.world-reward svg { width: 26px; height: 26px; }
.world-path { display: flex; justify-content: center; align-items: flex-start; gap: 8px; padding: 12px 12px 30px; }
.node {
  width: calc((100% - 32px) / 5); max-width: 76px; min-width: 48px; aspect-ratio: 1; border-radius: 50%; position: relative; flex: none;
  background: radial-gradient(circle at 35% 30%, #FFFFFF, #DCE7F0); box-shadow: 0 5px 0 rgba(0,0,0,0.25), inset 0 -4px 0 rgba(0,0,0,0.08);
  display: grid; place-items: center; transition: transform 0.15s;
}
.node:nth-child(even) { margin-top: 24px; }
.node:active { transform: scale(0.94); }
.node svg.portrait { width: 80%; height: 80%; overflow: visible; }
.node .num {
  position: absolute; top: -6px; inset-inline-start: -6px; min-width: 26px; height: 26px; border-radius: 13px; padding: 0 6px;
  background: var(--deep); color: var(--paper); font: 600 0.85rem/26px var(--font-display); text-align: center; border: 2px solid rgba(255,255,255,0.25);
}
.node .mark { position: absolute; bottom: -8px; inset-inline-end: -8px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; }
.node .mark .ic { width: 17px; height: 17px; }
.node .mat-badge { position: absolute; top: -10px; inset-inline-end: -10px; width: 30px; height: 30px; border-radius: 50%; background: #fff; display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0,0,0,0.25); }
.node .mat-badge svg { width: 24px; height: 24px; }
.node.done .mark { background: var(--mint); color: var(--mint-ink); box-shadow: 0 2px 0 var(--mint-d); }
.node.perfect .mark { background: var(--gold); color: #5A3A00; box-shadow: 0 2px 0 #C98A10; }
.node.locked { background: radial-gradient(circle at 35% 30%, #4A6886, #2D4864); box-shadow: 0 4px 0 rgba(0,0,0,0.3); }
.node.locked svg.portrait { filter: brightness(0); opacity: 0.35; }
.node.locked .mark, .node.tomorrow .mark { background: #23405F; color: var(--mist); border: 2px solid rgba(255,255,255,0.2); }
.node.next::after { content: ''; position: absolute; inset: -9px; border-radius: 50%; border: 3px solid var(--wa); animation: ping 1.8s ease-out infinite; }
@keyframes ping { 0% { transform: scale(0.92); opacity: 1; } 100% { transform: scale(1.25); opacity: 0; } }
.world.locked .world-meta { opacity: 0.6; }

/* ── Level ── */
#scr-level {
  display: grid; padding-block: 10px 12px; gap: 10px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.lv-top { display: flex; align-items: center; gap: 12px; min-width: 0; }
.lv-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 0 1 auto; }
.lv-num { font-family: var(--font-display); font-weight: 600; font-size: 1rem; color: var(--bg2); background: #7FE08A; border-radius: 999px; padding: 4px 11px; flex: none; }
#app[data-world="2"] .lv-num { background: #FFB36B; }
#app[data-world="3"] .lv-num { background: #C9B8FF; }
#app[data-world="4"] .lv-num { background: #FFA3CC; }
#app[data-world="5"] .lv-num { background: #9FE0FF; }
#app[data-world="6"] .lv-num { background: #FFB27A; }
.lv-name { font-family: var(--font-display); font-weight: 700; font-size: clamp(1.2rem, 2.1vw, 1.65rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lv-tools { display: flex; gap: 10px; margin-inline-start: auto; }

/* budget meter */
.budget { display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 10px; border-radius: 999px; background: rgba(0,0,0,0.25); border: 1px solid var(--line); margin-inline-start: auto; flex: 0 1 340px; min-width: 0; }
.budget + .lv-tools { margin-inline-start: 0; }
.b-coin { width: 30px; height: 30px; flex: none; }
.b-coin svg, .stat-coin svg { width: 100%; height: 100%; display: block; }
.meter { position: relative; flex: 1; min-width: 70px; height: 14px; border-radius: 7px; background: rgba(255,255,255,0.12); box-shadow: inset 0 2px 3px rgba(0,0,0,0.3); }
.meter .fill { position: absolute; inset-block: 0; inset-inline-start: 0; width: 0; border-radius: 7px; background: linear-gradient(270deg, #3DDC97, #7BEFB8); transition: width 0.35s cubic-bezier(.34,1.56,.64,1), background 0.3s; }
.meter.over-gold .fill { background: linear-gradient(270deg, #FFC531, #FFDD7A); }
.meter.near .fill { background: linear-gradient(270deg, #FF8A3D, #FFB27A); }
.gold-mark { position: absolute; top: 50%; width: 26px; height: 26px; margin-inline-start: -13px; transform: translateY(-50%); border-radius: 50%; display: grid; place-items: center; background: #3A5068; color: #8DA2B8; box-shadow: 0 0 0 2px rgba(0,0,0,0.25); transition: background 0.3s, color 0.3s, transform 0.3s; }
.gold-mark .ic { width: 18px; height: 18px; }
.gold-mark.on { background: var(--gold); color: #5A3A00; box-shadow: 0 0 0 2px rgba(0,0,0,0.2), 0 0 14px rgba(255,197,49,0.6); }
.b-num { font: 600 1.15rem var(--font-display); font-variant-numeric: tabular-nums; white-space: nowrap; direction: ltr; unicode-bidi: isolate; }
.b-num b { color: #fff; }
.b-sep { color: var(--mist); margin: 0 3px; }
.b-num span:last-child { color: var(--mist); }
.budget.bump { animation: bump 0.35s; }
.budget.poor { animation: shake 0.4s; }
@keyframes bump { 40% { transform: scale(1.06); } }
@keyframes shake { 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(2px); } }

/* stage */
.stage { position: relative; min-height: 0; min-width: 0; border-radius: 28px; overflow: hidden; background: #9EDCF5; box-shadow: 0 22px 44px rgba(0,0,0,0.32), inset 0 0 0 1px rgba(255,255,255,0.12); }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
#board.erasing { cursor: pointer; }
#board.testing { cursor: default; }
/* Pulses follow --pulse (0..1), which the stage sets on its scenery frames: a CSS animation inside the board
   would repaint the whole board every frame. */
#board .anchor.free .a-in { transform: scale(calc(1 + 0.18 * var(--pulse, 0))); transform-box: fill-box; transform-origin: center; }
#board .ghost-beam { opacity: calc(1 - 0.55 * var(--pulse, 0)); }
#board .crack { transform: scale(calc(1 + 0.15 * var(--pulse, 0))); transform-box: fill-box; transform-origin: center; }
#board .mark-glow { opacity: calc(0.3 + 0.25 * var(--pulse, 0)); }
#board .l-print { transition: opacity 0.3s; }
#board.erasing .beam { cursor: pointer; }

/* failure note: says what broke, never scolds */
.note {
  position: absolute; top: 14px; inset-inline-end: 14px; z-index: 5;
  display: flex; align-items: center; gap: 10px; width: min(440px, 40%);
  padding: 10px 12px 10px 14px; border-radius: 22px; background: var(--card); color: var(--ink);
  box-shadow: 0 14px 30px rgba(0,0,0,0.28); animation: notein 0.45s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes notein { from { opacity: 0; transform: translateY(-20px) scale(0.92); } }
.note-boni { width: 62px; height: 57px; flex: none; overflow: hidden; }
.note-body { flex: 1; min-width: 0; }
.note-title { margin: 0; font: 600 clamp(1rem, 1.7vw, 1.15rem)/1.35 var(--font-body); }
.note-tip { margin: 3px 0 0; font-size: 0.95rem; color: #476378; line-height: 1.4; }
.note-tip:empty { display: none; }
.note-close { width: 44px; height: 44px; background: var(--card-2); color: var(--ink); border: 0; align-self: flex-start; }

/* toolbar */
.toolbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; min-width: 0;
  border-radius: 26px; background: linear-gradient(180deg, rgba(20,56,96,0.92), rgba(12,36,66,0.92));
  border: 1px solid var(--line); box-shadow: 0 16px 32px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.06);
}
.mats { display: flex; gap: 8px; min-width: 0; }
.mats[data-n="6"], .mats[data-n="7"], .mats[data-n="8"] { --mat-w: 76px; gap: 6px; }
.mats[data-n="7"] .mat-name, .mats[data-n="8"] .mat-name { font-size: 0.86rem; }
.mat {
  position: relative; width: var(--mat-w); height: 74px; flex: none; border-radius: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: rgba(255,255,255,0.07); border: 2px solid transparent; color: var(--paper);
  transition: transform 0.12s cubic-bezier(.34,1.56,.64,1), background 0.2s, box-shadow 0.2s, opacity 0.2s;
}
.mat .swatch { width: 38px; height: 38px; }
.mat-name { font: 600 0.98rem/1 var(--font-display); }
.mat-price { display: flex; align-items: center; gap: 3px; font: 600 0.8rem/1 var(--font-display); color: var(--mist); direction: ltr; margin-top: 3px; }
.mat-price svg { width: 14px; height: 14px; }
.mat:active { transform: scale(0.94); }
.mat[aria-checked="true"] { background: #FFFFFF; color: var(--ink); border-color: var(--sun); box-shadow: 0 4px 0 var(--sun-d), 0 8px 16px rgba(0,0,0,0.25); transform: translateY(-3px); }
.mat[aria-checked="true"] .mat-price { color: #5A7189; }
.mat.locked { opacity: 0.4; }
.mat.locked .swatch { filter: grayscale(1); }
.mat .lock { position: absolute; top: 6px; inset-inline-end: 6px; width: 20px; height: 20px; color: var(--mist); }
.mat .lock .ic { width: 20px; height: 20px; }
.mat.fresh { animation: freshmat 1.4s ease-out 3; }
.mat .new-tag { position: absolute; top: -9px; inset-inline-start: 50%; transform: translateX(50%); background: var(--coral); color: #fff; font: 600 0.72rem/1 var(--font-display); padding: 4px 8px; border-radius: 999px; box-shadow: 0 2px 0 var(--coral-d); white-space: nowrap; }
@keyframes freshmat { 30% { box-shadow: 0 0 0 7px rgba(255,197,49,0.35), 0 4px 0 var(--sun-d); } }
.tools { display: flex; gap: 8px; margin-inline-start: auto; }
.tool { width: 54px; height: 54px; border-radius: 18px; }
.tool[aria-pressed="true"] { background: #FFE2DD; color: #B33A28; border-color: transparent; box-shadow: 0 0 0 3px var(--coral); }
#btn-clear.armed { background: rgba(255,107,87,0.25); color: #FFB2A6; border-color: rgba(255,107,87,0.6); }
.tool:disabled { opacity: 0.35; }
.toolbar .fast { width: 54px; height: 54px; border-radius: 18px; flex: none; }
.toolbar .fast[aria-pressed="true"] { background: rgba(255,197,49,0.22); color: var(--sun); border-color: rgba(255,197,49,0.55); }

/* mini-map of a long level: tap or drag it to look elsewhere */
.minimap {
  position: absolute; bottom: 10px; inset-inline-end: 10px; z-index: 4; width: min(230px, 38%); height: auto;
  border-radius: 12px; overflow: hidden; cursor: pointer; touch-action: none;
  box-shadow: 0 8px 20px rgba(0,0,0,0.3), 0 0 0 2px rgba(255,255,255,0.75);
}

.btn-test {
  display: flex; align-items: center; justify-content: center; gap: 10px; min-width: 168px; height: 66px; padding: 0 22px; flex: none;
  font: 600 clamp(1.25rem, 2vw, 1.45rem)/1 var(--font-display); border-radius: 22px;
  background: var(--mint); color: var(--mint-ink);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.45), 0 6px 0 var(--mint-d), 0 12px 20px rgba(0,0,0,0.25);
  transition: transform 0.08s, box-shadow 0.08s, background 0.2s;
}
.btn-test:active { transform: translateY(5px); box-shadow: inset 0 2px 0 rgba(255,255,255,0.45), 0 1px 0 var(--mint-d); }
.btn-test .t-ic { width: 28px; height: 28px; display: grid; }
.btn-test .t-ic .ic { width: 28px; height: 28px; }
.btn-test.ready, .btn-test.fix { position: relative; }
.btn-test.ready::after, .btn-test.fix::after { content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; box-shadow: 0 0 0 7px rgba(61,220,151,0.22); opacity: 0; animation: readyglow 1.6s ease-in-out infinite; }
.btn-test.fix::after { box-shadow: 0 0 0 8px rgba(255,197,49,0.25); }
@keyframes readyglow { 50% { opacity: 1; } }
.btn-test.stop { background: #E5EDF5; color: var(--ink); box-shadow: inset 0 2px 0 rgba(255,255,255,0.7), 0 6px 0 #9FB3C6; }
.btn-test.fix { background: var(--sun); color: var(--sun-ink); box-shadow: inset 0 2px 0 rgba(255,255,255,0.5), 0 6px 0 var(--sun-d), 0 12px 20px rgba(0,0,0,0.25); }
.btn-test.quiet { opacity: 0.5; pointer-events: none; }
.toolbar.testing .mats, .toolbar.testing .tools { opacity: 0.35; pointer-events: none; }

/* speech bubbles over the board */
.say-layer { position: absolute; inset: 0; pointer-events: none; z-index: 30; }
.say {
  position: absolute; transform: translate(-50%, -100%); max-width: min(300px, 70vw);
  background: #fff; color: var(--ink); border-radius: 20px; padding: 12px 16px;
  font: 600 clamp(1rem, 1.6vw, 1.15rem)/1.35 var(--font-body); text-align: center;
  box-shadow: 0 10px 26px rgba(0,0,0,0.3); animation: sayin 0.35s cubic-bezier(.34,1.56,.64,1) both;
}
.say::after { content: ''; position: absolute; left: var(--tail, 50%); bottom: -9px; width: 20px; height: 20px; background: #fff; transform: translateX(-50%) rotate(45deg); border-radius: 3px; }
.say.warn { background: #FFF1EE; color: #8E2A1C; }
.say.warn::after { background: #FFF1EE; }
.say.out { animation: sayout 0.25s ease-in both; }
@keyframes sayin { from { opacity: 0; transform: translate(-50%, -80%) scale(0.6); } }
@keyframes sayout { to { opacity: 0; transform: translate(-50%, -110%) scale(0.9); } }

/* tutorial hand */
.hand { position: absolute; z-index: 55; width: 64px; height: 64px; pointer-events: none; left: 0; top: 0; filter: drop-shadow(0 6px 10px rgba(0,0,0,0.35)); }
.hand.tap { animation: tap 1.2s ease-in-out infinite; }
@keyframes tap { 0%, 100% { transform: translate(-30%, 10%) scale(1); } 45% { transform: translate(-30%, -4%) scale(0.92); } }

/* ── Overlays & cards ── */
.overlay { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px var(--gut-r) 20px var(--gut-l); background: rgba(5, 16, 30, 0.66); animation: fadein 0.25s both; }
@keyframes fadein { from { opacity: 0; } }
.card {
  position: relative; width: min(100%, 470px); max-height: 100%; overflow-y: auto;
  background: var(--card); color: var(--ink); border-radius: 30px; padding: 28px 28px 24px;
  box-shadow: 0 30px 60px rgba(0,0,0,0.4), inset 0 -6px 0 rgba(20,48,74,0.06);
  animation: cardin 0.45s cubic-bezier(.34,1.56,.64,1) both; text-align: center;
}
@keyframes cardin { from { opacity: 0; transform: translateY(30px) scale(0.92); } }
.card h2 { font-family: var(--font-display); font-weight: 700; margin: 0 0 8px; font-size: clamp(1.6rem, 3vw, 2.1rem); }
.card p { line-height: 1.5; margin: 0 0 14px; color: #3D5866; font-size: 1.05rem; }
.card-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.card-close { position: absolute; top: 14px; inset-inline-end: 14px; }

.win-kicker { font-family: var(--font-display) !important; font-weight: 600; color: var(--mint-d) !important; letter-spacing: 0.04em; margin: 0 0 4px !important; font-size: 1.05rem !important; }
.win-title { font-size: clamp(2rem, 4.4vw, 2.8rem) !important; background: linear-gradient(90deg, #FF4FB0, #FF8A3D, #E8B400, #3DBE6E, #2BB5E8, #8F5BFF); -webkit-background-clip: text; background-clip: text; color: transparent; }
.win-praise { font-weight: 500; color: var(--ink) !important; }
.win-stats { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; }
.stat { display: flex; align-items: center; gap: 6px; background: var(--card-2); border-radius: 16px; padding: 8px 14px; }
.stat-coin { width: 28px; height: 28px; }
.stat b { font: 700 1.6rem var(--font-display); font-variant-numeric: tabular-nums; }
.gear-badge { display: flex; align-items: center; gap: 8px; border-radius: 16px; padding: 8px 14px 8px 10px; background: var(--card-2); font-weight: 500; font-size: 0.98rem; text-align: start; max-width: 270px; }
.gear-badge .gear { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; background: #CBD8E3; color: #8AA0B2; }
.gear-badge .gear .ic { width: 26px; height: 26px; }
.gear-badge.on { background: #FFF2D2; color: #6B4700; }
.gear-badge.on .gear { background: var(--gold); color: #5A3A00; box-shadow: 0 3px 0 #C98A10; animation: gearspin 1.2s cubic-bezier(.34,1.56,.64,1); }
@keyframes gearspin { from { transform: rotate(-200deg) scale(0.3); } }

#ov-dialog { place-items: end center; background: linear-gradient(transparent 40%, rgba(5,16,30,0.55)); -webkit-backdrop-filter: none; backdrop-filter: none; padding-bottom: max(24px, env(safe-area-inset-bottom, 0px)); }
#ov-win { place-items: center start; background: linear-gradient(270deg, rgba(5,16,30,0.6), rgba(5,16,30,0.05) 60%); -webkit-backdrop-filter: none; backdrop-filter: none; }
#ov-win .card { width: min(100%, 420px); }
.dialog { position: relative; width: min(100%, 700px); display: flex; align-items: flex-end; animation: cardin 0.45s cubic-bezier(.34,1.56,.64,1) both; }
.dlg-boni { width: clamp(118px, 17vw, 160px); flex: none; margin-inline-end: -16px; position: relative; z-index: 1; overflow: visible; filter: drop-shadow(0 12px 18px rgba(0,0,0,0.35));
  animation: breathe 2.8s ease-in-out infinite; transform-origin: 50% 100%; } /* breathing moves the whole drawing, so its shadow is not redrawn */
.dlg-body { flex: 1; min-width: 0; background: var(--card); color: var(--ink); border-radius: 28px; padding: 18px 24px 16px; box-shadow: 0 24px 50px rgba(0,0,0,0.4); margin-bottom: 10px; }
@keyframes breathe { 50% { transform: scale(1.015, 0.985); } }
.dlg-who { margin: 0 0 4px; font-family: var(--font-display); font-weight: 600; color: #9A6234; font-size: 0.95rem; }
.dlg-text { margin: 0; font-size: clamp(1.15rem, 2vw, 1.35rem); line-height: 1.5; font-weight: 500; min-height: 2.9em; }
.dlg-art:empty { display: none; }
.dlg-art { display: flex; justify-content: center; margin: 4px 0 10px; }
.dlg-art svg { max-width: 100%; height: auto; overflow: visible; }
.dlg-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.dlg-actions .btn { margin-inline-start: auto; }
.dlg-dots { display: flex; gap: 6px; }
.dlg-dots i { width: 8px; height: 8px; border-radius: 50%; background: #C9D7E2; }
.dlg-dots i.on { background: var(--ink); }

.unlock-art { display: flex; justify-content: center; margin: -6px 0 8px; }
.unlock-art svg { width: min(100%, 320px); height: auto; overflow: visible; }
.sleep-boni { width: 200px; height: auto; margin: -10px auto 0; display: block; overflow: visible; }

/* parents */
.parents-card { text-align: start; width: min(100%, 560px); }
.gate label { display: block; font-size: 1.1rem; margin-bottom: 10px; color: #3D5866; }
.gate-row { display: flex; gap: 10px; }
.gate input { flex: 1; min-width: 0; font: 600 1.4rem var(--font-display); padding: 10px 16px; border-radius: 16px; border: 2px solid #C9D7E2; background: #fff; color: var(--ink); text-align: center; -webkit-user-select: text; user-select: text; }
.gate-err { color: #B33A28 !important; margin-top: 8px !important; }
.par-progress { background: var(--card-2); border-radius: 16px; padding: 12px 16px; font-weight: 500; }
.par-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid #DCE6EE; }
.par-row > div:first-child { min-width: 0; }
.par-row b { display: block; font-family: var(--font-display); font-weight: 600; font-size: 1.08rem; }
.par-row span { display: block; font-size: 0.92rem; color: #5A7482; line-height: 1.4; margin-top: 2px; }
.seg { display: flex; background: var(--card-2); border-radius: 14px; padding: 4px; flex: none; }
.seg button { padding: 10px 12px; min-height: 44px; border-radius: 10px; font: 600 0.95rem var(--font-display); color: #4A6573; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 2px 6px rgba(0,0,0,0.12); }
.toggle { width: 58px; height: 34px; border-radius: 17px; background: #C9D7E2; position: relative; flex: none; transition: background 0.2s; }
.toggle i { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.2); transition: transform 0.2s; }
.toggle[aria-checked="true"] { background: var(--mint); }
.toggle[aria-checked="true"] i { transform: translateX(-24px); }
.par-about { margin: 16px 0; background: var(--card-2); border-radius: 16px; padding: 12px 16px; }
.par-about summary { font-family: var(--font-display); font-weight: 600; cursor: pointer; min-height: 32px; }
.par-about ul { margin: 10px 0 0; padding-inline-start: 20px; color: #3D5866; line-height: 1.5; }
.par-about li { margin-bottom: 4px; }

/* wipe transition & toast */
#wipe { position: absolute; inset: 0; z-index: 80; pointer-events: none; background: var(--bg2); clip-path: circle(0 at 50% 50%); }
.toast {
  position: absolute; z-index: 70; left: 50%; bottom: max(24px, env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 30px);
  background: #fff; color: var(--ink); border-radius: 999px; padding: 12px 22px; font-weight: 600; font-size: 1.05rem;
  box-shadow: 0 12px 30px rgba(0,0,0,0.35); opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none; white-space: nowrap; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
#scr-level .toast-anchor { bottom: 120px; }

/* ── Tall screens ── */
@media (max-aspect-ratio: 1/1) {
  .title-wrap { flex-direction: column; text-align: center; }
  .title-hero { order: 0; width: min(560px, 88vw); }
  .title-text { align-items: center; }
  .worlds { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-auto-rows: minmax(180px, auto); }
  .world { flex-direction: row; }
  .world-art { flex: none; width: 38%; min-height: 0; }
  .world-art::after { inset: 0 auto 0 0; width: 45%; height: auto; background: linear-gradient(270deg, transparent, var(--w2)); }
  .world-body { flex: 1; min-width: 0; justify-content: center; }
  #ov-win { place-items: end center; background: linear-gradient(transparent 35%, rgba(5,16,30,0.6)); }
  #ov-win .card { width: min(100%, 520px); }
  .note { inset-inline-end: 50%; transform: translateX(-50%); width: min(560px, calc(100% - 28px)); }
  @keyframes notein { from { opacity: 0; transform: translate(-50%, -20px) scale(0.92); } }
}
@media (max-width: 1000px) {
  .toolbar:has(.mats[data-n="7"]), .toolbar:has(.mats[data-n="8"]) { flex-wrap: wrap; }
  .toolbar:has(.mats[data-n="7"]) .mats, .toolbar:has(.mats[data-n="8"]) .mats { flex: 1 1 100%; justify-content: center; }
}
@media (max-width: 760px) {
  :root { --mat-w: 76px; }
  .budget { flex-basis: 260px; padding-inline: 8px 10px; gap: 8px; }
  .lv-name { display: none; }
  .btn-test { min-width: 140px; }
}
@media (max-width: 600px) {
  :root { --mat-w: auto; }
  .toolbar { flex-wrap: wrap; gap: 8px; padding: 8px; }
  .mats { flex: 1 1 100%; }
  .mat { flex: 1; height: 66px; min-width: 0; }
  .mats[data-n="7"], .mats[data-n="8"] { flex-wrap: wrap; }
  .mats[data-n="7"] .mat, .mats[data-n="8"] .mat { flex: 1 1 22%; height: 58px; }
  .minimap { width: min(150px, 42%); bottom: 6px; inset-inline-end: 6px; }
  .mat .swatch { width: 32px; height: 32px; }
  .tools { margin-inline-start: 0; }
  .tool { width: 50px; height: 50px; }
  .btn-test { flex: 1; min-width: 0; height: 56px; }
  .lv-top { gap: 8px; }
  .icon-btn { width: 44px; height: 44px; }
  .lv-tools { gap: 6px; }
  .b-coin { display: none; }
  .budget { padding: 5px 10px; }
  .b-num { font-size: 1rem; }
  .worlds .world { flex-direction: column; }
  .worlds .world-art { width: 100%; height: 130px; flex: none; }
  .worlds .world-art::after { inset: auto 0 0; width: auto; height: 40%; background: linear-gradient(transparent, var(--w2)); }
  .dlg-boni { width: 92px; }
  .stage { border-radius: 20px; }
  .note { top: 8px; }
  .note-boni { width: 46px; height: 42px; }
}
@media (max-height: 620px) and (min-aspect-ratio: 1/1) {
  .mat { height: 62px; }
  .mat .swatch { width: 30px; height: 30px; }
  .tool { width: 48px; height: 48px; }
  .btn-test { height: 56px; }
  #scr-level { gap: 8px; padding-block: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
