/* Doopi's Reef Dash — layout and UI. Mobile first; the maze canvas fills the stage. */
:root {
  --ink: #1d1813; --cream: #fffdf5; --deep: #0b4663; --deeper: #062f45; --text: #143c48;
  --teal: #137783; --yellow: #ffd45f; --focus: #e9b83f; --gentle: #20a88a; --challenge: #f0593c;
  --display: "Fredoka Pilot", "Fredoka", ui-rounded, system-ui, sans-serif;
  --body: "Inter Pilot", "Inter", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--deeper); color: var(--text); font-family: var(--body); }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
#app { position: fixed; inset: 0; overflow: hidden; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }
[hidden], .screen[hidden], .overlay[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { width: 1.2em; height: 1.2em; flex: 0 0 auto; }
button { font: inherit; color: inherit; -webkit-touch-callout: none; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px;
  padding: 10px 16px; font: 700 18px/1 var(--display); color: var(--text); background: var(--cream);
  border: 3px solid var(--ink); border-radius: 16px; box-shadow: 0 4px 0 var(--ink); cursor: pointer;
  transition: transform .08s, box-shadow .08s;
}
.btn, .hud-btn { text-decoration: none; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn-big { background: var(--yellow); font-size: 22px; padding: 12px 22px; min-height: 56px; }
.btn-ghost { background: rgba(255, 253, 245, .92); }
.btn-icon { width: 48px; padding: 0; }
.btn-icon svg { width: 26px; height: 26px; }

/* ---------- title ---------- */
#title {
  align-items: center; justify-content: center; gap: clamp(10px, 2.2vh, 22px); padding: 16px 16px max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(255,255,255,.28), transparent 60%),
    linear-gradient(180deg, #7fd3e6 0%, #2e95bd 45%, #0b4663 100%);
}
.title-top { text-align: center; }
.title-cast { display: flex; align-items: flex-end; justify-content: center; gap: 4px; height: clamp(90px, 17vh, 170px); }
.tc { height: 62%; width: auto; filter: drop-shadow(0 4px 0 rgba(0,30,50,.25)); animation: bob 1.6s ease-in-out infinite; }
.tc-doopi { height: 100%; animation-delay: -.4s; }
.tc-pogo { animation-delay: -.8s; }
@keyframes bob { 50% { transform: translateY(-7px); } }
h1 {
  margin: 6px 0 0; font: 700 clamp(38px, 9vw, 72px)/0.95 var(--display); color: #fff;
  -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; letter-spacing: .5px;
  text-shadow: 0 5px 0 var(--ink);
}
h1 .t-small { display: block; font-size: .55em; color: var(--yellow); }
.tagline { margin: 8px 0 0; font: 600 clamp(15px, 2.2vw, 19px)/1.3 var(--body); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.35); }
.modes { display: flex; gap: 16px; width: min(760px, 100%); justify-content: center; }
.mode-card {
  flex: 1 1 0; min-width: 0; display: grid; gap: 10px; align-content: start; text-align: left; padding: 14px 16px 16px;
  border: 3px solid var(--ink); border-radius: 22px; box-shadow: 0 6px 0 var(--ink); cursor: pointer; color: var(--text);
  transition: transform .1s, box-shadow .1s;
}
.mode-card:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.mode-gentle { background: linear-gradient(160deg, #e3fff4, #9fe8cf); }
.mode-challenge { background: linear-gradient(160deg, #fff0e2, #ffb08f); }
.mc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.mc-name { font: 700 30px/1 var(--display); }
.mc-age { font: 700 14px/1 var(--display); padding: 5px 9px; border: 2px solid var(--ink); border-radius: 99px; background: var(--cream); white-space: nowrap; }
.mc-chasers { display: flex; gap: 4px; }
.mc-chasers img { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--ink); background: #fff; }
.mc-facts { display: grid; gap: 6px; font: 600 15px/1.25 var(--body); }
.mc-facts span { display: flex; align-items: center; gap: 8px; }
.mc-facts svg { width: 22px; height: 22px; color: var(--ink); }
.mc-play { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px; border-radius: 14px; font: 700 22px/1 var(--display); color: #fff; }
.mode-gentle .mc-play { background: var(--gentle); box-shadow: inset 0 -4px 0 rgba(0,0,0,.2); }
.mode-challenge .mc-play { background: var(--challenge); box-shadow: inset 0 -4px 0 rgba(0,0,0,.2); }
.title-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.keys-hint { margin: 0; color: rgba(255,255,255,.85); font: 500 13px var(--body); text-align: center; }

/* ---------- level map ---------- */
#map { background: linear-gradient(180deg, #2e95bd, #0b4663); overflow-y: auto; }
.map-head { display: flex; align-items: center; gap: 12px; padding: max(12px, env(safe-area-inset-top)) 16px 12px; flex-wrap: wrap; }
.map-head h2 { flex: 1; margin: 0; font: 700 32px var(--display); color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; }
.seg { display: flex; border: 3px solid var(--ink); border-radius: 16px; overflow: hidden; box-shadow: 0 4px 0 var(--ink); }
.seg button { border: 0; padding: 10px 14px; min-height: 44px; font: 700 17px var(--display); background: var(--cream); cursor: pointer; }
.seg button[aria-checked="true"][data-mode="gentle"] { background: var(--gentle); color: #fff; }
.seg button[aria-checked="true"][data-mode="challenge"] { background: var(--challenge); color: #fff; }
.levels { list-style: none; margin: 0; padding: 4px 16px max(20px, env(safe-area-inset-bottom)); display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.lv {
  width: 100%; display: grid; gap: 6px; justify-items: center; padding: 12px 8px 10px; text-align: center;
  background: var(--cream); border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 5px 0 var(--ink); cursor: pointer;
}
.lv:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.lv img { width: 56px; height: 56px; border-radius: 50%; border: 2px solid var(--ink); background: #fff; }
.lv-num { font: 700 15px var(--display); color: var(--teal); }
.lv-name { font: 700 16px/1.15 var(--display); min-height: 2.3em; display: flex; align-items: center; }
.lv-stars { display: flex; gap: 2px; color: #d7d0bf; }
.lv-stars svg { width: 22px; height: 22px; }
.lv-stars .on { color: var(--yellow); }
.lv[disabled] { opacity: .55; cursor: not-allowed; }
.lv[disabled] img { filter: grayscale(1); }
.lv-lock { color: var(--text); }

/* ---------- play ---------- */
#play { background: var(--deeper); }
.hud {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: max(6px, env(safe-area-inset-top)) 10px 7px;
  background: linear-gradient(180deg, #0f5877, #083a53); border-bottom: 3px solid var(--ink); z-index: 2;
}
.hud-btn {
  width: 42px; height: 42px; flex: 0 0 auto; display: grid; place-items: center; border: 3px solid var(--ink); border-radius: 14px;
  background: var(--cream); box-shadow: 0 3px 0 var(--ink); cursor: pointer; padding: 0;
}
.hud-exit { width: auto; min-width: 65px; padding: 0 7px; font: 700 13px/1 var(--display); color: var(--text); white-space: nowrap; }
.hud-btn svg { width: 24px; height: 24px; }
.hud-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.hud-chip {
  display: flex; align-items: center; gap: 6px; min-height: 40px; padding: 3px 11px; background: var(--cream);
  border: 3px solid var(--ink); border-radius: 999px; box-shadow: 0 3px 0 var(--ink); font: 700 19px/1 var(--display); white-space: nowrap;
}
.hud-chip .hi { width: 24px; height: 24px; color: var(--ink); }
.num { font-variant-numeric: tabular-nums; }
.hud-level { background: var(--yellow); min-width: 40px; justify-content: center; }
.hud-mid { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 8px; }
.hud-lights, .hud-time { flex: 0 1 190px; min-width: 0; }
.bar { flex: 1 1 auto; min-width: 26px; max-width: 120px; height: 10px; border: 2px solid var(--ink); border-radius: 99px; background: #dfe9ea; overflow: hidden; }
.bar b { display: block; height: 100%; width: 100%; background: var(--yellow); transform-origin: left; }
.hud-time .bar b { background: #5fd0a8; }
.hud-time.warn { background: #fff0c2; }
.hud-time.warn .bar b { background: #ffb444; }
.hud-time.hurry { background: #ffd4c8; animation: pulse 1s ease-in-out infinite alternate; }
.hud-time.hurry .bar b { background: #f0593c; }
.hud-time.over { background: #e6e1d4; }
.hud-time.flash { animation: flash .9s ease-out; }
@keyframes pulse { to { transform: scale(1.06); } }
@keyframes flash { 0% { background: #b9f5c9; transform: scale(1.12); } }
.hud-score { min-width: 64px; justify-content: center; background: #e9f6ff; }
.hud-lives { gap: 2px; padding: 3px 8px; }
.hud-lives svg { width: 24px; height: 24px; color: var(--ink); transition: transform .2s, opacity .2s; }
.hud-lives svg.gone { opacity: .25; transform: scale(.7); }
.hud-lives.gentle-lives { font-size: 15px; }
.hud-lives[hidden] { display: none; }

.play-body { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; touch-action: none; }
#board { position: absolute; left: 0; top: 0; display: block; }
.banner {
  position: absolute; left: 50%; top: 6px; transform: translateX(-50%); width: min(94%, 540px);
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 1px 10px;
  padding: 5px 8px; background: rgba(255,253,245,.96); border: 3px solid var(--ink); border-radius: 16px; box-shadow: 0 3px 0 var(--ink);
  pointer-events: none; z-index: 3;
}
.banner img { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--ink); background: #fff; grid-row: 1 / span 2; }
.banner-text { display: grid; min-width: 0; grid-column: 2; grid-row: 1; }
.banner-text b { display: none; }
.banner-text span { font: 700 16px/1.2 var(--display); }
.banner-speak { pointer-events: auto; width: 36px; height: 36px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 11px; background: var(--yellow); cursor: pointer; padding: 0; grid-column: 3; grid-row: 1 / span 2; }
.banner-speak svg { width: 20px; height: 20px; }
.banner-go { grid-column: 2; grid-row: 2; justify-self: start; font: 600 13px/1.2 var(--body); color: var(--teal); animation: pulse 1.6s ease-in-out infinite alternate; transform-origin: left center; }
/* after the first move only the goal line stays (it never disappears during play) */
.banner.mini { padding: 4px 8px; background: rgba(255,253,245,.92); }
.banner.mini img { width: 30px; height: 30px; grid-row: 1; }
.banner.mini .banner-speak { grid-row: 1; }
.banner.mini .banner-go { display: none; }
.banner.mini .banner-text span { font-size: 15px; }
.banner.mini .banner-speak { width: 30px; height: 30px; }
#board:focus { outline: none; }
.powers { position: absolute; left: 8px; bottom: 8px; display: flex; gap: 6px; pointer-events: none; z-index: 3; }
.powers.col { flex-direction: column; align-items: flex-start; }
.pw { display: flex; align-items: center; gap: 5px; padding: 3px 8px 3px 3px; background: var(--cream); border: 3px solid var(--ink); border-radius: 99px; box-shadow: 0 3px 0 var(--ink); }
.pw img, .pw .pw-i { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--ink); background: #fff; display: grid; place-items: center; }
.pw .bar { width: 44px; flex: 0 0 44px; }
.toast {
  position: absolute; left: 50%; top: 60px; transform: translate(-50%, 10px); pointer-events: none; opacity: 0; z-index: 3;
  max-width: calc(100% - 24px); padding: 8px 18px; text-align: center; white-space: nowrap;
  font: 700 clamp(19px, 4.6vw, 28px)/1.15 var(--display); color: var(--text);
  background: rgba(255,253,245,.96); border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 4px 0 var(--ink);
  transition: opacity .35s ease, transform .35s ease;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); } /* held steady for at least 2.2 s, then fades */

.pad {
  --pad: clamp(146px, 44vw, 200px); position: relative; justify-self: center; width: var(--pad); height: var(--pad);
  margin: 8px 0 max(10px, env(safe-area-inset-bottom)); border-radius: 50%; background: rgba(255,253,245,.1);
  border: 3px solid rgba(255,255,255,.22); touch-action: none;
}
.pad-b {
  position: absolute; width: 37%; height: 37%; display: grid; place-items: center; padding: 0; cursor: pointer;
  background: var(--cream); border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 4px 0 var(--ink); touch-action: none;
}
.pad-b svg { width: 62%; height: 62%; color: var(--yellow); pointer-events: none; }
.pad-up { left: 31.5%; top: 1%; } .pad-down { left: 31.5%; bottom: 3%; }
.pad-left { left: 1%; top: 30%; } .pad-right { right: 1%; top: 30%; }
.pad-right svg { transform: rotate(90deg); } .pad-down svg { transform: rotate(180deg); } .pad-left svg { transform: rotate(-90deg); }
.pad-b.on { background: var(--yellow); transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.pad-b.on svg { color: var(--cream); }
.pad-dot { position: absolute; left: 50%; top: 48%; width: 14%; height: 14%; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(255,255,255,.35); }
.no-pad .pad { display: none; }

/* landscape / desktop: pad on the right */
@media (min-aspect-ratio: 5/4) {
  .play-body { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: minmax(0, 1fr); }
  .pad { --pad: clamp(130px, 30vh, 210px); align-self: end; margin: 0 max(16px, env(safe-area-inset-right)) 18px 10px; }
  .no-pad .play-body { grid-template-columns: minmax(0, 1fr); }
}

/* narrow phones: two-row HUD */
@media (max-width: 479px) {
  .hud-mid { display: contents; }
  .hud-lights, .hud-time { flex: none; }
  .hud { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto auto; grid-template-areas: "exit pause time lives mute" "lights lights lights lights score"; gap: 6px; padding-left: 8px; padding-right: 8px; }
  .hud-exit { grid-area: exit; min-width: 58px; font-size: 12px; } #btn-pause { grid-area: pause; } .hud-time { grid-area: time; } .hud-lives { grid-area: lives; }
  .hud .btn-mute { grid-area: mute; } .hud-lights { grid-area: lights; } .hud-score { grid-area: score; }
  .hud-level { display: none; }
  .hud-chip { min-height: 36px; font-size: 17px; padding: 2px 9px; }
  .hud-btn:not(.hud-exit) { width: 38px; height: 38px; }
  .bar { max-width: none; }
  .modes { flex-direction: column; gap: 12px; }
  .mode-card { padding: 11px 13px 12px; gap: 8px; }
  .mc-name { font-size: 25px; }
  .mc-chasers { display: none; }
  .mc-facts { grid-template-columns: 1fr 1fr; gap: 5px 8px; font-size: 13px; }
  .mc-facts svg { width: 18px; height: 18px; }
  .mc-play { font-size: 19px; padding: 8px; }
  .banner-text span { font-size: 14px; }
  .banner img { width: 32px; height: 32px; }
  .banner-go { font-size: 12px; }
  .levels { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
}
@media (max-width: 479px) and (max-height: 700px) {
  .title-cast { height: 70px; }
  .keys-hint, .tagline { display: none; }
  #title { gap: 10px; }
}

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(6,47,69,.74); }
.card {
  width: min(460px, 100%); max-height: 100%; overflow-y: auto; display: grid; gap: 14px; justify-items: center; text-align: center;
  padding: 20px; background: var(--cream); border: 3px solid var(--ink); border-radius: 24px; box-shadow: 0 8px 0 var(--ink);
}
.card h2 { margin: 0; font: 700 30px/1.05 var(--display); }
.card-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.res-face { width: 92px; height: 92px; border-radius: 50%; border: 3px solid var(--ink); background: #fff; }
.stars { display: flex; gap: 10px; }
.star { display: grid; justify-items: center; gap: 2px; color: #d9d2c0; }
.star svg.big { width: 58px; height: 58px; }
.star svg.small { width: 20px; height: 20px; color: var(--text); opacity: .75; }
.star.on svg.big { color: var(--yellow); animation: pop .45s cubic-bezier(.3,1.6,.5,1) both; }
.star:nth-child(2).on svg.big { animation-delay: .15s; } .star:nth-child(3).on svg.big { animation-delay: .3s; }
@keyframes pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
.res-stats { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.res-stats li { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border: 2px solid var(--ink); border-radius: 99px; background: #fff; font: 700 16px var(--display); }
.res-stats svg { width: 20px; height: 20px; }
.grown { text-align: left; justify-items: stretch; width: min(560px, 100%); }
.grown p { margin: 0; font: 500 15px/1.45 var(--body); }
.grown code { font-size: 13px; background: #eef4f4; padding: 1px 4px; border-radius: 4px; word-break: break-all; }
.party { padding: 0; background: #2b2f7a; }
#party-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.party-card { position: absolute; left: 50%; top: max(14px, env(safe-area-inset-top)); transform: translateX(-50%); width: min(460px, calc(100% - 24px)); display: grid; gap: 8px; justify-items: center; text-align: center; padding: 12px 14px; background: rgba(255,253,245,.95); border: 3px solid var(--ink); border-radius: 20px; box-shadow: 0 6px 0 var(--ink); }
.party-card h2 { margin: 0; font: 700 30px var(--display); }
.party-card p { margin: 0; font: 600 15px var(--body); }
.party-card .card-row { flex-wrap: nowrap; }
@media (max-width: 479px) {
  .party-card { gap: 6px; padding: 10px 12px; }
  .party-card h2 { font-size: 26px; }
  .party-card p { font-size: 13.5px; }
  .party-card .btn-big { font-size: 19px; padding: 10px 14px; min-height: 50px; }
}

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