/* Doopi games suite — shared visual system.
   Follows the owner-accepted Reef Dash pilot: firm ink contours, cream cards, matte colour,
   Fredoka display type, generous touch targets. Mobile first. */
: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;
  --title-bg: radial-gradient(120% 70% at 50% 0%, rgba(255,255,255,.28), transparent 60%), linear-gradient(180deg, #7fd3e6 0%, #2e95bd 45%, #0b4663 100%);
  --map-bg: linear-gradient(180deg, #2e95bd, #0b4663);
  --play-bg: var(--deeper);
  --hud-bg: linear-gradient(180deg, #0f5877, #083a53);
}
* { 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; }
a { color: inherit; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }
img { -webkit-user-drag: none; user-select: none; }

/* ---------- 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; text-decoration: none;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; box-shadow: 0 4px 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; }
.btn-teal { background: var(--teal); color: #fff; }

/* suite link: always top-left on the title and level screens */
.dk-home {
  position: absolute; left: max(12px, env(safe-area-inset-left)); top: max(12px, env(safe-area-inset-top)); z-index: 4;
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 6px 14px 6px 8px;
  font: 700 16px/1 var(--display); color: var(--text); background: rgba(255,253,245,.94); text-decoration: none;
  border: 3px solid var(--ink); border-radius: 999px; box-shadow: 0 3px 0 var(--ink);
}
.dk-home svg { width: 22px; height: 22px; }
.dk-home:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

/* ---------- title ---------- */
.dk-title {
  align-items: center; justify-content: center; gap: clamp(10px, 2.2vh, 22px); padding: 64px 16px max(16px, env(safe-area-inset-bottom));
  overflow-y: auto; background: var(--title-bg);
}
.title-top { text-align: center; }
.title-cast { display: flex; align-items: flex-end; justify-content: center; gap: 6px; height: clamp(96px, 18vh, 180px); }
.tc { height: 64%; width: auto; filter: drop-shadow(0 4px 0 rgba(0,30,50,.25)); animation: dk-bob 1.7s ease-in-out infinite; }
.tc.lead { height: 100%; animation-delay: -.4s; }
.tc:nth-child(3) { animation-delay: -.8s; }
@keyframes dk-bob { 50% { transform: translateY(-7px); } }
.dk-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);
}
.dk-h1 .t-small { display: block; font-size: .55em; color: var(--yellow); }
.tagline { text-wrap: balance; margin: 8px auto 0; max-width: 34em; 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-faces { display: flex; gap: 4px; }
.mc-faces 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,.88); font: 500 13px var(--body); text-align: center; }

/* ---------- level map ---------- */
.dk-map { background: var(--map-bg); 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 auto; width: 100%; max-width: 1100px; 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 ---------- */
.dk-play { background: var(--play-bg); }
.hud {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: max(6px, env(safe-area-inset-top)) 10px 7px;
  background: var(--hud-bg); border-bottom: 3px solid var(--ink); z-index: 5; position: relative;
}
.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-btn svg { width: 24px; height: 24px; }
.hud-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
/* suite link in the live HUD: a square icon on phones, a labelled pill on wide screens */
.hud-home { text-decoration: none; color: var(--text); }
.hud-home-t { display: none; }
@media (min-width: 900px) and (min-height: 501px) {
  .hud-home { width: 132px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 10px; font: 700 16px/1 var(--display); white-space: nowrap; }
  .hud-home-t { display: inline; }
  .hud::after { content: ""; flex: 0 0 132px; order: 1; } /* balances the pill so the middle stays centred */
  .hud > .btn-mute { order: 2; }
}
.res-home { min-height: 44px; font-size: 16px; }
.hud-mid { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 8px; }
.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 svg { width: 24px; height: 24px; color: var(--ink); }
.hud-chip.lvl { background: var(--yellow); min-width: 40px; justify-content: center; }
.num { font-variant-numeric: tabular-nums; }
.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; transition: transform .25s; }
.lives { gap: 2px; padding: 3px 8px; }
.lives svg { transition: transform .2s, opacity .2s; }
.lives svg.gone { opacity: .25; transform: scale(.7); }
.play-body { flex: 1 1 auto; min-height: 0; position: relative; display: flex; flex-direction: column; }
.stage { position: relative; flex: 1 1 auto; min-width: 0; min-height: 0; overflow: hidden; }

/* goal strip: host portrait, goal, optional read-aloud */
.banner {
  position: absolute; left: 50%; top: 6px; transform: translateX(-50%); width: min(94%, 560px);
  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: 4;
}
.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 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); }
.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; width: 30px; height: 30px; }
.banner.mini .banner-go { display: none; }
.banner.mini .banner-text span { font-size: 15px; }
.banner.static { position: relative; left: auto; top: auto; transform: none; margin: 8px auto 0; flex: 0 0 auto; }

/* calm feedback toast: one short message, readable for at least 2.2 s */
.toast {
  position: absolute; left: 50%; top: 64px; transform: translate(-50%, 10px); pointer-events: none; opacity: 0; z-index: 6;
  max-width: calc(100% - 24px); padding: 8px 18px; text-align: center;
  font: 700 clamp(18px, 4.4vw, 26px)/1.15 var(--display); color: var(--text);
  background: rgba(255,253,245,.97); 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); }

/* hold pad (used by the real-time games) */
.pad {
  --pad: clamp(146px, 42vw, 196px); position: relative; width: var(--pad); height: var(--pad); flex: 0 0 auto;
  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); }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; 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 p { margin: 0; font: 500 16px/1.45 var(--body); }
.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; }
/* batch 5: a living face (a puppet framed like the portrait), used only by games that ask for it */
.res-live { position: relative; display: block; width: 92px; height: 92px; border-radius: 50%; border: 3px solid var(--ink); background: #fff; overflow: hidden; }
.res-live-in { position: absolute; left: 0; top: 0; }
.res-line { font: 600 16px/1.4 var(--body); max-width: 30em; }
.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 small { font: 600 11px/1.1 var(--body); color: var(--text); max-width: 76px; }
.star.on svg.big { color: var(--yellow); animation: dk-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 dk-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(580px, 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; }
.finale { padding: 0; background: linear-gradient(180deg, #2b2f7a 0%, #5a4fb0 60%, #f4a3c8 100%); overflow: hidden; }
.finale-cast { position: absolute; left: 0; right: 0; bottom: 0; height: 58%; display: flex; align-items: flex-end; justify-content: center; gap: 1vw; padding: 0 2vw 3vh; }
.finale-cast img { height: 42%; width: auto; animation: dk-bob 1.1s ease-in-out infinite; filter: drop-shadow(0 5px 0 rgba(0,0,0,.25)); }
.finale-cast img.lead { height: 62%; }
.finale-cast img:nth-child(2n) { animation-delay: -.35s; } .finale-cast img:nth-child(3n) { animation-delay: -.7s; }
.finale-floor { position: absolute; left: -10%; right: -10%; bottom: -24%; height: 44%; border-radius: 50%; background: #f3dcaa; border-top: 3px solid var(--ink); }
.finale-card { position: absolute; left: 50%; top: max(14px, env(safe-area-inset-top)); transform: translateX(-50%); width: min(480px, calc(100% - 24px)); display: grid; gap: 8px; justify-items: center; text-align: center; padding: 14px; background: rgba(255,253,245,.96); border: 3px solid var(--ink); border-radius: 20px; box-shadow: 0 6px 0 var(--ink); z-index: 2; }
.finale-card h2 { margin: 0; font: 700 30px var(--display); }
.finale-card p { margin: 0; font: 600 15px/1.4 var(--body); }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 13px; border-radius: 2px; animation: dk-fall linear infinite; }
@keyframes dk-fall { to { transform: translateY(110vh) rotate(540deg); } }

/* ---------- responsive ---------- */
@media (max-width: 479px) {
  .hud { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .hud-chip { min-height: 36px; font-size: 17px; padding: 2px 9px; }
  .hud-btn { width: 38px; height: 38px; }
  .hud-chip.lvl { display: none; }
  .modes { flex-direction: column; gap: 12px; }
  .mode-card { padding: 11px 13px 12px; gap: 8px; }
  .mc-name { font-size: 25px; }
  .mc-faces { 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; }
  .dk-home { font-size: 14px; min-height: 40px; }
  .finale-card h2 { font-size: 25px; }
  .finale-card p { font-size: 13.5px; }
}
/* very narrow phones: slimmer HUD so Pause, All games, the chips and Sound never touch */
@media (max-width: 359px) {
  .hud { gap: 4px; padding-left: 6px; padding-right: 6px; }
  .hud-btn { width: 34px; height: 34px; border-radius: 12px; }
  .hud-btn svg { width: 21px; height: 21px; }
  .hud-chip { gap: 4px; min-height: 34px; padding: 2px 7px; font-size: 15px; }
  .hud-chip svg { width: 18px; height: 18px; }
  .hud-chip .bar { display: none; }
  .lives { padding: 2px 5px; }
}
@media (max-width: 479px) and (max-height: 700px) {
  .title-cast { height: 70px; }
  .keys-hint, .tagline { display: none; }
  .dk-title { gap: 10px; }
}
/* short landscape screens: slimmer bars so the play area stays large */
@media (max-height: 500px) {
  .hud { padding-top: max(3px, env(safe-area-inset-top)); padding-bottom: 4px; }
  .hud-btn { width: 36px; height: 36px; }
  .hud-chip { min-height: 32px; font-size: 16px; padding: 2px 9px; }
  .hud-chip svg { width: 20px; height: 20px; }
  .banner { top: 4px; padding: 3px 8px; }
  .banner img { width: 28px; height: 28px; }
  .banner-speak { width: 28px; height: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; }
}
