/* Robi and the Weird Lab — one committed look: a night-time toy lab.
   Layout: the board is the stage; the code panel docks on the reading side (right, in Hebrew) and drops below it on tall screens. */
:root {
  --night: #0E2732;
  --deep: #15384A;
  --deep-2: #1C4659;
  --line: rgba(255, 255, 255, 0.1);
  --paper: #F5F8F3;
  --mist: #A6C2CF;
  --ink: #15303D;
  --card: #F6FAFB;
  --card-2: #E4EEF2;
  --sun: #FFC845;
  --sun-d: #D4950F;
  --sun-ink: #4A3300;
  --berry: #DE5BC2;
  --berry-d: #A3368C;
  --mint: #3DDC97;
  --mint-d: #1C9D63;
  --mint-ink: #07351F;
  --coral: #FF6B57;
  --coral-d: #C9412D;
  --sky: #5CE1E6;
  --gold: #FFB938;
  --bg1: #1A4558;
  --bg2: #0C2430;
  --font-display: 'Fredoka', 'Rubik', 'Varela Round', 'Arial Rounded MT Bold', system-ui, sans-serif;
  --font-body: 'Rubik', 'Fredoka', 'Segoe UI', system-ui, sans-serif;
  --chip: clamp(44px, 4.6vw, 58px);
  --key: clamp(50px, 5.2vw, 64px);
  --panel-w: clamp(318px, 33vw, 410px);
  --gut-l: max(16px, env(safe-area-inset-left, 0px));
  --gut-r: max(16px, env(safe-area-inset-right, 0px));
  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: #1B4A3F; --bg2: #0B2620; }
#app[data-world="3"] { --bg1: #33305C; --bg2: #14132B; }
#app[data-world="4"] { --bg1: #4A2238; --bg2: #1C0B16; }
#app[data-world="5"] { --bg1: #124039; --bg2: #061A17; }
#app[data-world="6"] { --bg1: #23286A; --bg2: #0A0C26; }
#app[data-world="6"] .sky .grid {
  opacity: 0.9; background-size: 173px 173px, 257px 257px, 311px 311px;
  background-image: radial-gradient(circle, rgba(255,255,255,0.8) 1px, transparent 1.6px), radial-gradient(circle, rgba(255,255,255,0.55) 1.2px, transparent 2px), radial-gradient(circle, rgba(199,155,255,0.7) 1px, transparent 1.8px);
  background-position: 0 0, 60px 90px, 130px 40px;
}

/* ── Backdrop: blueprint grid and rising bubbles ── */
.sky { position: absolute; inset: 0; background: radial-gradient(120% 90% at 50% 38%, var(--bg1), var(--bg2) 75%); transition: background 0.8s; }
.sky .grid {
  position: absolute; inset: 0; opacity: 0.5;
  background-image: linear-gradient(rgba(255,255,255,0.045) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(80% 70% at 50% 45%, #000 30%, transparent 85%);
  -webkit-mask-image: radial-gradient(80% 70% at 50% 45%, #000 30%, transparent 85%);
}
.bubbles-bg i { position: absolute; bottom: -40px; border-radius: 50%; background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.12); animation: rise linear infinite; }
@keyframes rise { to { transform: translateY(-115vh) translateX(var(--drift, 20px)); } }
/* lite: set by the scene clock when frames run slow; background extras go */
.lite .bubbles-bg { display: none; }

.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;
  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 #B9CCD6; }
.btn-soft:active { box-shadow: 0 1px 0 #B9CCD6; }
.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;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn.small { width: 42px; height: 42px; }
.icon-btn.tiny { width: 32px; height: 32px; }
.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: 10px; }

/* ── Title ── */
#scr-title { display: grid; place-items: center; padding-block: 24px; }
.title-wrap { display: flex; align-items: center; gap: clamp(16px, 5vw, 64px); max-width: 1000px; width: 100%; justify-content: center; }
.title-hero { width: clamp(220px, 34vw, 400px); aspect-ratio: 1; max-width: 100%; position: relative; order: 2; }
.title-hero::before { content: ''; position: absolute; inset: 12% 8% 0; border-radius: 50%; background: radial-gradient(closest-side, rgba(92,225,230,0.22), transparent); }
#title-robi { width: 100%; height: 100%; overflow: visible; position: relative; }
.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.92; }
.logo-main {
  font-family: var(--font-display); font-weight: 700; font-size: clamp(4.6rem, 12vw, 8.5rem); color: var(--sun);
  text-shadow: 0 4px 0 var(--sun-d), 0 8px 0 #8A5B05, 0 18px 30px rgba(0,0,0,0.35);
  letter-spacing: -0.01em;
}
.logo-sub { font-family: var(--font-display); font-weight: 600; font-size: clamp(1.6rem, 3.6vw, 2.6rem); color: var(--paper); margin-top: 0.35em; }
.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: 80px; }
.worlds .world-meta { padding: 10px 18px 2px; }
.worlds .world-path { padding: 10px 12px 26px; }
.world {
  border-radius: 28px; overflow: hidden; display: flex; flex-direction: column; position: relative;
  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: #20586C; --w2: #163D4C; --wa: var(--sky); }
.world.w2 { --w1: #25634F; --w2: #194437; --wa: #9BE84B; }
.world.w3 { --w1: #403B73; --w2: #29264D; --wa: #FF8FAB; }
.world.w4 { --w1: #5A2A45; --w2: #3A1A2D; --wa: #FFD84A; }
.world.w5 { --w1: #1E5A4B; --w2: #12382F; --wa: #7CF0B9; }
.world.w6 { --w1: #2C3380; --w2: #1A1F52; --wa: #C79BFF; }
.world-art { flex: 1; min-height: 130px; 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: 40%; 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(10, 24, 32, 0.55); color: var(--paper); font: 600 1.05rem var(--font-display); }
.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: 14px 20px 4px; }
.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-path { display: flex; justify-content: center; align-items: flex-start; gap: 8px; padding: 14px 14px 34px; flex-wrap: nowrap; }
.node {
  width: calc((100% - 32px) / 5); max-width: 78px; aspect-ratio: 1; border-radius: 50%; position: relative; flex: none;
  background: radial-gradient(circle at 35% 30%, #FFFFFF, #DCE9EF); 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: 26px; }
.node:active { transform: scale(0.94); }
.node svg.portrait { width: 82%; height: 82%; 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.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%, #48687A, #2D4B5A); 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: #23404F; 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; } }
.node.tomorrow { opacity: 0.85; }
.world.locked .world-meta { opacity: 0.6; }

/* ── Level ── */
#scr-level {
  display: grid; padding-block: 10px 14px; gap: 10px 16px;
  grid-template-columns: var(--panel-w) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top" "panel stage";
}
.lv-top { grid-area: top; display: flex; align-items: center; gap: 12px; min-width: 0; }
.lv-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.lv-num { font-family: var(--font-display); font-weight: 600; font-size: 1rem; color: var(--bg2); background: var(--sky); border-radius: 999px; padding: 4px 11px; }
#app[data-world="2"] .lv-num { background: #9BE84B; }
#app[data-world="3"] .lv-num { background: #FF8FAB; }
#app[data-world="4"] .lv-num { background: #FFD84A; }
#app[data-world="5"] .lv-num { background: #7CF0B9; }
#app[data-world="6"] .lv-num { background: #C79BFF; }
.bug-tag { display: flex; align-items: center; gap: 6px; margin-top: 10px; padding: 4px 12px 4px 6px; border-radius: 999px; background: rgba(245,80,90,0.14); color: #FFC2C6; font: 500 0.9rem var(--font-body); width: fit-content; max-width: 100%; }
.bug-tag svg { width: 28px; height: 28px; flex: none; }
.prog-title, .prog-count { white-space: nowrap; }
.bug-tag[hidden] { display: none; }
#btn-restore { margin-inline-start: 4px; }
.lv-name { font-family: var(--font-display); font-weight: 700; font-size: clamp(1.25rem, 2.2vw, 1.7rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lv-goal { display: flex; align-items: center; gap: 6px; margin-inline-start: 6px; padding: 4px 6px 4px 12px; border-radius: 999px; background: rgba(0,0,0,0.2); }
.lv-flasks { display: flex; gap: 4px; }
.goal-arrow { width: 18px; height: 18px; color: var(--mist); }
.goal-animal { width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,0.9); overflow: visible; }
.lv-goal.done .goal-animal { animation: flpop 0.5s cubic-bezier(.34,1.56,.64,1); box-shadow: 0 0 0 3px var(--mint); }
.fl-ic { width: 26px; height: 26px; transition: transform 0.3s cubic-bezier(.34,1.56,.64,1); }
.fl-ic.on { transform: scale(1.15); }
.fl-ic.pop { animation: flpop 0.5s cubic-bezier(.34,1.56,.64,1); }
@keyframes flpop { 0% { transform: scale(0.4); } 60% { transform: scale(1.45); } 100% { transform: scale(1.15); } }
.lv-tools { display: flex; gap: 10px; margin-inline-start: auto; }

.stage { grid-area: stage; position: relative; min-height: 0; min-width: 0; border-radius: 30px; }
.stage::before { content: ''; position: absolute; inset: 4% 6%; border-radius: 50%; background: radial-gradient(closest-side, rgba(255,255,255,0.09), transparent); pointer-events: none; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#board .ent-animal, #board .ent-guard, #board .ent-robi { cursor: pointer; }
.say-layer { position: absolute; inset: 0; pointer-events: none; overflow: visible; }

.say {
  position: fixed; z-index: 30; 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;
  pointer-events: none;
}
.say::after { content: ''; position: absolute; left: 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); } }

/* panel */
.panel {
  grid-area: panel; display: flex; flex-direction: column; gap: 12px; min-height: 0; min-width: 0;
  padding: 14px; border-radius: 30px; overflow-y: auto;
  background: linear-gradient(180deg, rgba(21,56,74,0.92), rgba(14,39,50,0.92));
  border: 1px solid var(--line); box-shadow: 0 20px 40px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.06);
}
.prog { border-radius: 20px; padding: 10px 12px 12px; background: rgba(0,0,0,0.16); border: 2px solid transparent; transition: border-color 0.2s, background 0.2s; }
.prog.sel { border-color: rgba(92,225,230,0.5); background: rgba(92,225,230,0.06); }
.prog-loop { background: rgba(222,91,194,0.08); }
.prog-loop.sel { border-color: rgba(222,91,194,0.75); background: rgba(222,91,194,0.12); }
.prog-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; min-height: 30px; }
.prog-title { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; display: flex; align-items: center; gap: 6px; }
.prog-count { margin-inline-start: auto; font: 500 0.95rem var(--font-display); color: var(--mist); font-variant-numeric: tabular-nums; }
.loop-ic { width: 26px; height: 26px; border-radius: 8px; background: var(--berry); display: inline-grid; place-items: center; color: #fff; }
.loop-ic .ic { width: 18px; height: 18px; }
.stepper { margin-inline-start: auto; display: flex; align-items: center; gap: 6px; }
.step-btn { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,0.12); font: 700 1.3rem/1 var(--font-display); }
.step-btn:active { transform: scale(0.9); }
.step-val { display: flex; align-items: baseline; gap: 4px; min-width: 62px; justify-content: center; direction: rtl; }
.step-val b { font: 700 1.5rem var(--font-display); color: #FFB6EC; font-variant-numeric: tabular-nums; }
.step-val small { font-size: 0.85rem; color: var(--mist); }
.step-val.bump b { animation: bump 0.3s; }
@keyframes bump { 50% { transform: scale(1.35); } }

.slots { display: grid; grid-template-columns: repeat(auto-fill, var(--chip)); gap: 8px; justify-content: start; }
.slot {
  width: var(--chip); height: var(--chip); border-radius: 14px; border: 2px dashed rgba(255,255,255,0.13);
  display: grid; place-items: center; color: rgba(255,255,255,0.2); font: 600 0.85rem var(--font-display);
}
.slot.next { position: relative; border-color: rgba(92,225,230,0.6); color: rgba(92,225,230,0.8); }
.slot.next::before { content: ''; position: absolute; inset: 0; border-radius: 12px; pointer-events: none; background: rgba(92,225,230,0.1); opacity: 0; animation: breathe 1.6s ease-in-out infinite; }
.prog-loop .slot.next { border-color: rgba(255,150,230,0.7); color: rgba(255,170,235,0.9); }
.slot.drop, .chip.drop { box-shadow: 0 0 0 3px var(--sky); }
@keyframes breathe { 50% { opacity: 1; } }

.chip, .key {
  display: grid; place-items: center; position: relative; touch-action: none;
  transition: transform 0.12s cubic-bezier(.34,1.56,.64,1), box-shadow 0.15s, opacity 0.2s;
}
.chip { width: var(--chip); height: var(--chip); border-radius: 14px; }
.chip .ic { width: 58%; height: 58%; }
.chip-m, .key-m { background: var(--sun); color: var(--sun-ink); box-shadow: inset 0 2px 0 rgba(255,255,255,0.55), 0 4px 0 var(--sun-d); }
.chip-o, .key-o { background: var(--berry); color: #fff; box-shadow: inset 0 2px 0 rgba(255,255,255,0.35), 0 4px 0 var(--berry-d); }
[data-d="R"] > .ic { transform: rotate(90deg); }
[data-d="D"] > .ic { transform: rotate(180deg); }
[data-d="L"] > .ic { transform: rotate(-90deg); }
.chip .n {
  position: absolute; bottom: -7px; left: -7px; min-width: 24px; height: 24px; border-radius: 12px; padding: 0 5px;
  background: #fff; color: var(--berry-d); font: 700 0.85rem/24px var(--font-display); text-align: center; box-shadow: 0 2px 0 rgba(0,0,0,0.2);
}
.chip.new { animation: chipin 0.32s cubic-bezier(.34,1.56,.64,1); }
@keyframes chipin { from { transform: scale(0.3) translateY(10px); opacity: 0; } }
.running .chip { opacity: 0.55; }
.running .chip.past { opacity: 0.9; }
.chip.run { opacity: 1 !important; transform: translateY(-5px) scale(1.1); box-shadow: inset 0 2px 0 rgba(255,255,255,0.55), 0 0 0 4px #fff, 0 0 24px rgba(255,255,255,0.75); z-index: 2; }
.chip.err { box-shadow: inset 0 2px 0 rgba(255,255,255,0.55), 0 0 0 4px var(--coral), 0 0 18px rgba(255,107,87,0.7); animation: wiggle 0.45s; }
@keyframes wiggle { 20% { transform: rotate(-9deg); } 40% { transform: rotate(8deg); } 60% { transform: rotate(-5deg); } 80% { transform: rotate(3deg); } }
.chip.lifted { opacity: 0.25; }
.ghost { position: fixed; z-index: 60; pointer-events: none; left: 0; top: 0; transform-origin: 50% 50%; filter: drop-shadow(0 14px 18px rgba(0,0,0,0.35)); }
.ghost.trash { opacity: 0.5; }

.controls { margin-top: auto; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.palette { display: grid; grid-template-columns: repeat(3, var(--key)); grid-template-rows: repeat(3, var(--key)); gap: 7px; flex: none; }
.key { width: var(--key); height: var(--key); border-radius: 18px; }
.key .ic { width: 56%; height: 56%; }
.key-m { box-shadow: inset 0 2px 0 rgba(255,255,255,0.55), 0 6px 0 var(--sun-d), 0 10px 14px rgba(0,0,0,0.22); }
.key-o { box-shadow: inset 0 2px 0 rgba(255,255,255,0.35), 0 6px 0 var(--berry-d), 0 10px 14px rgba(0,0,0,0.22); }
.key:active, .key.press { transform: translateY(5px); }
.key-m:active, .key-m.press { box-shadow: inset 0 2px 0 rgba(255,255,255,0.55), 0 1px 0 var(--sun-d); }
.key-o:active, .key-o.press { box-shadow: inset 0 2px 0 rgba(255,255,255,0.35), 0 1px 0 var(--berry-d); }
.key[data-d="U"] { grid-area: 1 / 2; }
.key[data-d="L"] { grid-area: 2 / 1; }
.key[data-d="R"] { grid-area: 2 / 3; }
.key[data-d="D"] { grid-area: 3 / 2; }
.key[data-d="O"] { grid-area: 2 / 2; }
.key-o.fresh { animation: newtool 1.4s ease-out 2; }
@keyframes newtool { 30% { transform: scale(1.18); box-shadow: 0 0 0 8px rgba(222,91,194,0.35), 0 6px 0 var(--berry-d); } }
.palette.disabled .key { opacity: 0.45; pointer-events: none; }

.actions { display: flex; flex-direction: column; align-items: stretch; gap: 10px; flex: 1; max-width: 170px; min-width: 0; }
.btn-run {
  display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0.8em 0.9em; font-size: clamp(1.15rem, 1.8vw, 1.35rem);
  background: var(--mint); color: var(--mint-ink); border-radius: 22px;
  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);
}
.btn-run:active { box-shadow: inset 0 2px 0 rgba(255,255,255,0.45), 0 1px 0 var(--mint-d); }
.btn-run .ic { width: 26px; height: 26px; }
.btn-run.stop { background: var(--coral); color: #fff; box-shadow: inset 0 2px 0 rgba(255,255,255,0.35), 0 6px 0 var(--coral-d), 0 12px 20px rgba(0,0,0,0.25); }
.btn-run.ready { position: relative; }
.btn-run.ready::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; }
@keyframes readyglow { 50% { opacity: 1; } }
.action-row { display: flex; justify-content: space-between; gap: 8px; }
.action-row .icon-btn { flex: 1; border-radius: 16px; width: auto; }
#btn-fast.on { background: rgba(255,200,69,0.2); color: var(--sun); border-color: rgba(255,200,69,0.5); }
#btn-clear.armed { background: rgba(255,107,87,0.25); color: #FFB2A6; border-color: rgba(255,107,87,0.6); }

/* tutorial hand */
.hand { position: fixed; z-index: 55; width: 64px; height: 64px; pointer-events: none; animation: tap 1.2s ease-in-out infinite; filter: drop-shadow(0 6px 10px rgba(0,0,0,0.35)); }
@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, 18, 26, 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(21,48,61,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: 14px; flex-wrap: wrap; }
.stat { display: flex; align-items: baseline; gap: 6px; background: var(--card-2); border-radius: 16px; padding: 10px 16px; }
.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: 260px; }
.gear-badge .gear { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; background: #CBD8DF; color: #8AA0AC; }
.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,18,26,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,18,26,0.6), rgba(5,18,26,0.05) 60%); -webkit-backdrop-filter: none; backdrop-filter: none; }
#ov-win .card { width: min(100%, calc(var(--panel-w) + 30px)); }
.btn-run.quiet { opacity: 0.5; pointer-events: none; }
.dialog {
  position: relative; width: min(100%, 680px); display: flex; align-items: flex-end; gap: 0;
  animation: cardin 0.45s cubic-bezier(.34,1.56,.64,1) both;
}
.dlg-owl { width: clamp(110px, 16vw, 150px); flex: none; margin-inline-end: -18px; position: relative; z-index: 1; overflow: visible; filter: drop-shadow(0 12px 18px rgba(0,0,0,0.35)); }
.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; }
.dlg-who { margin: 0 0 4px; font-family: var(--font-display); font-weight: 600; color: #8A5A44; 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; }
.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: #C9D7DE; }
.dlg-dots i.on { background: var(--ink); }

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

.sleep-robi { width: 170px; height: auto; margin: -10px auto 0; display: block; overflow: visible; }
.charge { height: 14px; border-radius: 7px; background: var(--card-2); overflow: hidden; margin: 4px auto 0; max-width: 260px; }
.charge-bar { height: 100%; width: 92%; border-radius: 7px; background: linear-gradient(90deg, var(--mint), var(--sky)); transform: scaleX(0.33); transform-origin: right center; animation: charge 4s ease-in-out infinite; }
@keyframes charge { 0% { transform: scaleX(0.2); } 100% { transform: scaleX(1); } }

/* 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 #C9D7DE; 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 #DCE7EC; }
.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: 8px 12px; 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: #C9D7DE; 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; }
.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 */
#wipe { position: absolute; inset: 0; z-index: 80; pointer-events: none; background: var(--bg2); clip-path: circle(0 at 50% 50%); }
#drag-layer { position: absolute; inset: 0; z-index: 60; pointer-events: none; }
.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);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Tall screens: board on top, code below ── */
@media (max-aspect-ratio: 1/1) {
  #scr-level {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "top" "stage" "panel";
  }
  .panel { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto 1fr; align-items: start; gap: 10px 14px; max-height: 58vh; }
  .panel .prog { grid-column: 1; }
  .panel .controls { grid-column: 2; grid-row: 1 / span 3; flex-direction: column; align-items: center; margin-top: 0; }
  .actions { max-width: none; width: 100%; }
  .worlds { grid-template-columns: minmax(0, 1fr); }
  .worlds .world { flex-direction: row; }
  .worlds .world-art { flex: none; width: 36%; }
  .worlds .world-art::after { inset: 0 auto 0 0; width: 45%; height: auto; background: linear-gradient(270deg, transparent, var(--w2)); }
  .worlds .world-body { flex: 1; min-width: 0; justify-content: center; }
  .world { flex-direction: row; }
  .world-art { height: auto; width: 34%; flex: none; }
  .world-body { flex: 1; min-width: 0; }
  .title-wrap { flex-direction: column; text-align: center; }
  .title-hero { order: 0; }
  #ov-win { place-items: end center; background: linear-gradient(transparent 35%, rgba(5,18,26,0.6)); }
  #ov-win .card { width: min(100%, 520px); }
  .worlds { grid-template-rows: none; grid-auto-rows: minmax(170px, auto); }
  .world-art { min-height: 0; }
  .title-text { align-items: center; }
}
@media (max-width: 560px) {
  :root { --chip: 42px; --key: 50px; }
  .panel { grid-template-columns: minmax(0, 1fr); max-height: none; padding: 10px; }
  .panel .controls { grid-column: 1; grid-row: auto; flex-direction: row; align-items: flex-end; }
  .worlds .world { flex-direction: column; }
  .worlds .world-art { width: 100%; height: 120px; }
  .worlds .world-art::after { inset: auto 0 0; width: auto; height: 40%; background: linear-gradient(transparent, var(--w2)); }
  .lv-name { font-size: 1.1rem; }
  .icon-btn { width: 44px; height: 44px; }
  .dlg-owl { width: 90px; }
  .lv-goal { display: none; }
  .world-path { padding-inline: 10px; }
}
@media (max-height: 640px) and (min-aspect-ratio: 1/1) {
  :root { --chip: 42px; --key: 48px; }
  .panel { padding: 10px; gap: 8px; }
  .prog { padding: 8px 10px; }
}

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