@font-face { font-family: "Space Grotesk"; src: url(/fonts/space-grotesk-400.woff2) format("woff2"); font-weight: 400; font-display: swap }
@font-face { font-family: "Space Grotesk"; src: url(/fonts/space-grotesk-500.woff2) format("woff2"); font-weight: 500; font-display: swap }
@font-face { font-family: "Space Grotesk"; src: url(/fonts/space-grotesk-700.woff2) format("woff2"); font-weight: 700; font-display: swap }

:root {
  --field: hsl(345, 72%, 30%);
  --deep: hsl(345, 78%, 16%);
  --btn: #ff7a3d;
  --btn-ink: #2b0e00;
  --ink: #f1fdff;
  --soft: rgba(241, 253, 255, 0.72);
  --chrome: rgba(10, 0, 20, 0.36);
  --chrome-hi: rgba(255, 255, 255, 0.12);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --bar: 52px; --statush: 40px; --pal: 60px; --toolh: 48px; --subh: 58px; --gap: 8px;
  --fixed: calc(var(--bar) + var(--statush) + var(--pal) + var(--toolh) + var(--subh) + 5 * var(--gap) + 20px);
  color-scheme: dark;
}

* { box-sizing: border-box; touch-action: manipulation; -webkit-tap-highlight-color: transparent }
html, body { margin: 0; height: 100%; overflow: hidden }
body {
  background: var(--field);
  color: var(--ink);
  font: 500 16px/1.35 "Space Grotesk", system-ui, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0 }
button:disabled { cursor: default; opacity: 0.45 }
h2, h3, p { margin: 0 }
[hidden] { display: none !important }

#bg { position: fixed; inset: 0; width: 100%; height: 100%; display: block }
#app { position: fixed; inset: 0 }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; padding: calc(var(--sat) + 10px) 12px calc(var(--sab) + 10px) }

/* ---- buttons ---------------------------------------------------------------------------------------- */
.big {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  height: var(--subh); padding: 0 28px; border-radius: 16px;
  background: var(--btn); color: var(--btn-ink);
  font-weight: 700; font-size: 22px; letter-spacing: 0.02em; white-space: nowrap;
  box-shadow: 0 5px 0 #b84311, 0 10px 24px rgba(0, 0, 0, 0.25);
  transition: transform 0.08s, box-shadow 0.08s;
}
.big:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 #b84311 }
.big.alt { background: var(--ink); color: var(--deep); box-shadow: 0 5px 0 rgba(255, 255, 255, 0.55), 0 10px 24px rgba(0, 0, 0, 0.25) }
.big.alt:active { box-shadow: 0 1px 0 rgba(255, 255, 255, 0.55) }
.ghost { height: 48px; padding: 0 20px; border-radius: 14px; background: var(--chrome-hi); font-weight: 700; font-size: 18px; white-space: nowrap }
.textlink { font-weight: 700; font-size: 14px; letter-spacing: 0.12em; padding: 12px 10px; color: var(--soft) }
.icon { width: 48px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; background: var(--chrome); gap: 4px }
.count { min-width: 1.6em; padding: 0 8px; border-radius: 10px; background: rgba(0, 0, 0, 0.16); font-size: 18px; text-align: center }
kbd.key { display: none; font: 700 12px/1 "Space Grotesk", sans-serif; padding: 4px 6px; border-radius: 6px; background: rgba(0, 0, 0, 0.22); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25) }
@media (hover: hover) and (pointer: fine) {
  kbd.key { display: inline-block }
  .big:hover:not(:disabled) { filter: brightness(1.06) }
  .tools button:hover:not(:disabled), .ghost:hover, .icon:hover:not(:disabled) { background: rgba(255, 255, 255, 0.18) }
}

/* ---- home ------------------------------------------------------------------------------------------- */
#home { justify-content: center; overflow: hidden; background:
  radial-gradient(60% 50% at 20% 15%, rgba(255, 255, 255, 0.10), transparent 70%),
  radial-gradient(70% 60% at 85% 90%, rgba(0, 0, 0, 0.25), transparent 70%) }
#homeBoard { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-8deg); opacity: 0.75; pointer-events: none }
.home-ui { position: relative; display: flex; flex-direction: column; align-items: center; gap: 18px; width: 100%; max-height: 100%; overflow-y: auto; padding: 8px 0 }
.logo { width: min(86vw, 540px); height: auto; filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.35)); animation: breathe 4s ease-in-out infinite }
@keyframes breathe { 50% { transform: scale(1.03); filter: drop-shadow(0 8px 36px rgba(255, 220, 140, 0.45)) } }
.doors { display: flex; flex-direction: column; align-items: stretch; gap: 14px; width: min(86vw, 360px) }
.doors .big { width: 100%; height: 64px; font-size: 24px }
.door-line { text-align: center; font-size: 15px; color: var(--ink); background: var(--chrome); border-radius: 10px; padding: 6px 10px }
.feet { display: flex; gap: 6px; justify-content: center; background: var(--chrome); border-radius: 14px; padding: 0 8px }
.gad-shelf { width: min(100%, 720px); min-height: 0 }
.reduced .logo { animation: none }

/* ---- bars ------------------------------------------------------------------------------------------- */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: var(--bar); width: 100% }
.bar h2 { font-size: 22px; font-weight: 700; white-space: nowrap; letter-spacing: 0.01em }

/* ---- play ------------------------------------------------------------------------------------------- */
#play { gap: var(--gap); justify-content: space-between; background: radial-gradient(90% 60% at 50% 45%, rgba(0, 0, 0, 0.22), transparent 70%) }
.rail { display: flex; flex-direction: column; gap: var(--gap); width: min(100%, var(--board, 360px)); flex: none }
.status { height: var(--statush); display: flex; align-items: center; gap: 12px; padding: 0 12px; border-radius: 12px; background: var(--chrome) }
.pips { display: flex; gap: 6px; flex: none }
.pip { width: 12px; height: 12px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.55) }
.pip.used { background: rgba(255, 255, 255, 0.55); border-color: transparent }
.pip.now { border-color: var(--btn); background: var(--btn); box-shadow: 0 0 10px var(--btn) }
.status-line { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; font-size: 16px; font-weight: 500 }
.board-wrap { position: relative; width: var(--board); height: var(--board); flex: none }
#board { display: block; touch-action: none }
.chip {
  position: absolute; width: 52px; height: 44px; border-radius: 22px; font-weight: 700; font-size: 18px;
  background: var(--deep); color: #fff; border: 3px solid var(--c, #fff); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  animation: nudge 1.2s ease-in-out infinite;
}
.chip.armed { background: var(--c); color: #072a30; animation: none }
@keyframes nudge { 50% { transform: translateY(-3px) scale(1.06) } }
.tip { position: absolute; padding: 6px 10px; border-radius: 10px; background: rgba(0, 20, 24, 0.92); font-weight: 700; font-size: 15px; white-space: nowrap; pointer-events: none }
.palette { height: var(--pal); display: flex; justify-content: center; align-items: center; gap: 10px }
.sw { position: relative; width: 52px; height: 52px; border-radius: 14px; background: var(--c); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25); transition: transform 0.1s; display: flex; align-items: center; justify-content: center }
.sw.on { transform: translateY(-4px); box-shadow: 0 0 0 3px var(--field), 0 0 0 6px #fff, 0 8px 18px rgba(0, 0, 0, 0.35) }
.sw.dim { opacity: 0.5 }
.sw .unseen { display: none; position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: #fff }
.sw.dim .unseen { display: block }
.sw kbd.key { position: absolute; bottom: -8px; right: -6px }
.sw i { display: block; width: 18px; height: 18px; color: rgba(0, 20, 25, 0.6) }
.g-dot { border-radius: 50%; background: currentColor }
.g-ring { border-radius: 50%; border: 5px solid currentColor }
.g-bar { height: 6px !important; width: 22px !important; border-radius: 3px; background: currentColor }
.g-cross { background: linear-gradient(currentColor, currentColor) center/6px 100% no-repeat, linear-gradient(currentColor, currentColor) center/100% 6px no-repeat }
.g-diamond { background: currentColor; transform: rotate(45deg) scale(0.85) }
.tools { height: var(--toolh); display: flex; gap: 8px }
.tools button { flex: 1; border-radius: 12px; background: var(--chrome); font-weight: 700; font-size: 16px; display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap }
#nums.on { background: rgba(255, 255, 255, 0.2) }
#submit { width: 100% }

/* side by side when the window is wider than tall: board left, the rest in a column beside it */
.side #play { display: grid; grid-template-columns: var(--board) minmax(260px, 360px); grid-template-rows: 1fr 1fr; column-gap: 28px; row-gap: 14px; justify-content: center; align-content: center }
.side #play .rail { width: 100% }
.side #play .rail-top { grid-column: 2; grid-row: 1; align-self: end }
.side #play .board-wrap { grid-column: 1; grid-row: 1 / span 2; align-self: center }
.side #play .rail-bottom { grid-column: 2; grid-row: 2; align-self: start }

/* ---- levels ---------------------------------------------------------------------------------------- */
#levels { gap: 10px }
#levels .bar { width: min(100%, 640px) }
.level-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; width: min(100%, 640px, calc(100svh - 120px)); }
.lv { aspect-ratio: 1; border-radius: 10px; background: var(--deep); display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; font-size: clamp(12px, 3.4vw, 20px); line-height: 1 }
.lv-s { font-size: 0.5em; color: #ffd84a; letter-spacing: -0.1em }
.lv.gold { background: linear-gradient(#ffe48a, #ffb93d); color: #3a2200 }
.lv.gold .lv-s { color: #7a4a00 }
.lv.next { background: var(--btn); color: var(--btn-ink); box-shadow: 0 0 0 3px #fff; animation: nudge 1.4s ease-in-out infinite }
.lv.locked { opacity: 0.4 }

/* ---- sheets ---------------------------------------------------------------------------------------- */
.sheet { position: absolute; z-index: 10 }
.card {
  left: 0; right: 0; bottom: 0; padding: 22px 18px calc(var(--sab) + 18px);
  background: linear-gradient(rgba(6, 40, 46, 0.86), rgba(4, 30, 35, 0.97));
  border-top: 2px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; max-height: 70%; overflow-y: auto;
}
.card.rise { animation: rise 0.5s cubic-bezier(0.2, 1.3, 0.4, 1) }
@keyframes rise { from { transform: translateY(100%) } }
.card-head { font-size: 18px; font-weight: 700; color: var(--btn); letter-spacing: 0.06em; text-transform: uppercase }
.card-rule { font-size: clamp(22px, 5.6vw, 32px); font-weight: 700; line-height: 1.2 }
.card-note { font-size: 16px; color: var(--soft); font-variant-numeric: tabular-nums }
.card-stars { font-size: 26px; color: #ffd84a; letter-spacing: 0.1em; min-height: 1.2em }
.card-buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; margin-top: 4px }
.card-buttons .big { height: 52px; font-size: 19px; padding: 0 20px }
.card-buttons .ghost { height: 48px; padding: 0 16px }
.card-buttons { flex-wrap: nowrap }
.gad-end { width: 100% }
.side .card { left: auto; right: 0; top: 0; width: min(440px, 45vw); border-top: 0; border-left: 2px solid rgba(255, 255, 255, 0.2); max-height: none; justify-content: center }
.side .card.rise { animation-name: slide }
@keyframes slide { from { transform: translateX(100%) } }
.panel { inset: 0; background: var(--deep); display: flex; flex-direction: column; align-items: center; padding: calc(var(--sat) + 10px) 16px 16px }
.panel .bar { width: min(100%, 560px) }
.list { width: min(100%, 560px); display: flex; flex-direction: column; gap: 10px; overflow-y: auto; padding: 8px 0 }
.toggle { height: 56px; border-radius: 14px; background: var(--chrome); font-weight: 700; font-size: 18px; text-align: left; padding: 0 18px }
.toggle.on { background: rgba(255, 255, 255, 0.16) }
.credits h3 { font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--soft); margin-top: 10px }
.credits p { font-size: 16px }
.credits a { color: var(--ink); font-weight: 700 }

#toast { position: absolute; left: 50%; top: calc(var(--sat) + 64px); transform: translate(-50%, -20px); opacity: 0; pointer-events: none; z-index: 30;
  padding: 10px 16px; border-radius: 12px; background: rgba(0, 20, 24, 0.94); font-weight: 700; white-space: nowrap; transition: 0.2s }
#toast.on { opacity: 1; transform: translate(-50%, 0) }
.tweaks { position: absolute; right: 8px; bottom: 8px; z-index: 40; display: flex; flex-wrap: wrap; gap: 6px; max-width: 260px; padding: 10px; border-radius: 12px; background: rgba(0, 0, 0, 0.75); font-size: 13px }
.tweaks b { width: 100% }
.tweaks button { padding: 6px 10px; border-radius: 8px; background: rgba(255, 255, 255, 0.12) }
.tweaks button.on { background: var(--btn); color: var(--btn-ink) }
.side .card-buttons { flex-wrap: wrap }

/* a big window gets a big rail beside a big board, so the controls don't look lost next to it */
@media (min-height: 640px) and (min-width: 1000px) {
  :root { --bar: 64px; --statush: 54px; --pal: 84px; --toolh: 60px; --subh: 74px }
  .side #play { grid-template-columns: var(--board) minmax(300px, 420px); column-gap: 40px }
  .bar h2 { font-size: 28px }
  .status-line { font-size: 19px }
  .pip { width: 15px; height: 15px }
  .sw { width: 68px; height: 68px; border-radius: 18px }
  .sw i { width: 24px; height: 24px }
  .tools button { font-size: 18px }
  .big { font-size: 26px }
  .doors { width: 440px }
  .doors .big { height: 78px; font-size: 30px }
  .door-line { font-size: 17px }
  .textlink { font-size: 16px }
  .card-rule { font-size: 34px }
}
.logo { max-height: 26svh; width: auto; max-width: min(86vw, 540px) }
#submit.coach { animation: nudge 1s ease-in-out infinite }
@media (max-width: 520px) { .card { gap: 6px; padding-top: 16px } .card-rule { font-size: 21px } .card-stars { font-size: 22px } .card-buttons .ghost { padding: 0 12px } }

/* a disabled primary stays in the family: never orange-over-teal mud */
.big:disabled { background: rgba(255, 255, 255, 0.14); color: rgba(241, 253, 255, 0.55); box-shadow: none; opacity: 1 }
#safe { position: fixed; top: 0; left: 0; width: 0; height: 0; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); pointer-events: none; visibility: hidden }
#play.ended .rail-bottom { visibility: hidden }
.level-next { width: min(100%, 640px); text-align: center; font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; padding: 10px; border-radius: 12px; background: var(--chrome) }
