:root {
  --bg: #051C55; --board: #0A2A75; --text: #F2F6FF; --muted: #9DB4E0; --accent: #FFC23D; --onAccent: #2A1A00;
  --danger: #FF4B3E; --good: #5BE07A; --panel: #0E3384; --panelBorder: #2F5BB5; --key: #12398F; --navy: #131B45;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, "SF Pro Rounded", "SF Pro Display", system-ui, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: radial-gradient(120% 80% at 50% 20%, #1C4FAE 0%, #0A2A66 55%, #051C55 100%);
  user-select: none; -webkit-user-select: none; touch-action: none;
}
#app { position: relative; height: 100%; max-width: 520px; margin: 0 auto; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

.screen { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; padding: max(14px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom)); }
.screen.active { display: flex; }

/* Title */
#title { justify-content: center; gap: 10px; text-align: center; }
.logo { width: min(78%, 340px); max-height: 24vh; object-fit: contain; display: block; }
.logo.small { width: min(52%, 220px); max-height: 13vh; }
.titleFlaggy img { width: min(46vw, 210px, 26vh); margin: 4px 0 -6px; }
.kicker { font-size: 12px; font-weight: 800; letter-spacing: 2.4px; color: #9FB6EA; }
.blurb { color: var(--muted); font-size: 15px; line-height: 1.4; margin-bottom: 10px; }
.big { background: var(--accent); color: var(--onAccent); font-weight: 900; font-size: 19px; border-radius: 16px; padding: 14px 0; width: min(100%, 300px);
  box-shadow: 0 5px 0 #B7861C, 0 10px 24px rgba(0,0,0,.35); }
.big:active { transform: translateY(3px); box-shadow: 0 2px 0 #B7861C; }
.ghost { color: var(--muted); font-weight: 700; font-size: 15px; padding: 10px 18px; }

/* Speech bubble (white, navy outline, red bold lead) */
.bubble { background: #fff; color: #15151f; border: 3px solid var(--navy); border-radius: 16px; padding: 10px 14px; font-size: 15px; line-height: 1.3; font-weight: 600; }
.bubble b { color: #D8262A; font-weight: 800; }

/* Boot camp */
#boot { gap: 8px; }
.dots { display: flex; gap: 6px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: #2F5BB5; }
.dots i.on { background: var(--accent); }
#bootBubble { width: min(100%, 420px); min-height: 64px; flex-shrink: 0; }
.bootStage { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
.bootInner { position: relative; padding-top: var(--peek, 110px); }
.bootInner .peek { position: absolute; left: 0; top: 0; width: var(--peekW, 150px); pointer-events: none; z-index: 2; }
.bootBoard { display: grid; gap: 3px; background: var(--board); padding: 5px; border-radius: 12px; position: relative; z-index: 1; }
.bootBoard .cell { width: var(--cell, 54px); height: var(--cell, 54px); border-radius: 8px; display: grid; place-items: center; font-weight: 900; font-size: calc(var(--cell, 54px) * .5); cursor: pointer; }
.cell.hid { background: linear-gradient(#6C93E0, #3A62B8); box-shadow: inset 0 -4px 0 #24448F, inset 0 2px 0 rgba(255,255,255,.35); }
.cell.open { background: #D6E2F2; }
.cell.lit { outline: 3px solid var(--accent); outline-offset: -1px; box-shadow: 0 0 16px rgba(255,194,61,.8); }
.cell.dash { outline: 2px dashed var(--accent); outline-offset: -4px; }
#bootNext { margin-bottom: 6px; flex-shrink: 0; }
#boot > * { flex-shrink: 0; }
#boot > .bootStage { flex-shrink: 1; }
#bootNext[hidden] { display: block; visibility: hidden; }

/* Game */
#game { padding-left: 10px; padding-right: 10px; }
.hud { width: 100%; }
.hudTop { display: flex; justify-content: space-between; align-items: center; }
#hudTitle { font-size: 12px; font-weight: 800; letter-spacing: 1.8px; color: #9FB6EA; }
#hudTitle.tough { color: #FF6A5E; }
.iconBtn { background: var(--key); border: 1px solid var(--panelBorder); border-radius: 9px; width: 34px; height: 30px; display: grid; place-items: center; }
.iconBtn i { width: 10px; height: 12px; border-left: 3.5px solid #fff; border-right: 3.5px solid #fff; }
.hudStats { display: grid; grid-template-columns: 1fr 1fr 1fr; text-align: center; margin: 6px 0 2px; }
.hudStats span { display: block; font-size: 10px; letter-spacing: 1.6px; color: var(--muted); font-weight: 700; }
.hudStats b { font-size: 22px; font-weight: 800; display: inline-flex; gap: 3px; align-items: center; min-height: 28px; }
.hudStats b i { width: 18px; height: 18px; border-radius: 4px; background: #C4CFE1; display: inline-block; position: relative; }
.hudStats b i::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: #1E2030; box-shadow: 0 0 0 1.5px #1E2030; }
.hudStats b i.gone { opacity: .25; }

.boardWrap { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; min-height: 0; }
.stage { position: relative; padding-top: var(--peek, 112px); }
.stage .peek { position: absolute; width: 150px; top: 0; left: 6%; pointer-events: none; z-index: 2; }
#board { display: block; border-radius: 12px; touch-action: none; }
.hint { position: absolute; top: 4px; left: calc(6% + var(--peekW, 150px) - 14px); width: max(calc(94% - var(--peekW, 150px) + 14px), 230px); max-width: calc(100vw - 32px - 6% - var(--peekW, 150px)); font-size: 13.5px; padding: 8px 11px; z-index: 3; }
.hint:empty { display: none; }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; margin-top: 12px; }
.ctl { display: flex; align-items: center; gap: 10px; background: var(--key); border: 2px solid var(--panelBorder); border-radius: 16px; padding: 12px 14px; text-align: left; }
.ctl b { display: block; font-size: 16px; letter-spacing: .5px; }
.ctl small { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.ctl.on { background: #1C4FB8; border-color: var(--accent); }
.ctl[disabled] { opacity: .35; }
.flagIcon { width: 18px; height: 24px; position: relative; }
.flagIcon::before { content: ""; position: absolute; left: 3px; top: 1px; width: 3px; height: 22px; border-radius: 2px; background: #E4E8EF; }
.flagIcon::after { content: ""; position: absolute; left: 6px; top: 1px; border-left: 13px solid #E2200C; border-top: 6px solid transparent; border-bottom: 6px solid transparent; }
.pushIcon { font-style: normal; font-size: 26px; color: var(--accent); transform: rotate(90deg); font-weight: 900; line-height: 1; }

/* Overlays */
.overlay { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; padding: 16px; background: rgba(4,22,69,.9); z-index: 10; }
.overlay.show { display: flex; }
.panel { width: min(100%, 400px); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.panel .flaggy { width: min(190px, 24vh); }
.panel h2 { font-size: 40px; font-weight: 900; color: var(--accent); letter-spacing: .5px; text-shadow: 0 3px 0 rgba(0,0,0,.25); line-height: 1; }
.panel h2.bad { color: var(--danger); }
.panel .small { font-size: 12px; font-weight: 800; letter-spacing: 2.2px; color: #9FB6EA; }
.panel p { color: var(--muted); font-size: 15px; line-height: 1.4; }
.panel .row { display: flex; gap: 10px; width: 100%; justify-content: center; }
.tileBtn { background: var(--panel); border: 2px solid var(--panelBorder); border-radius: 16px; padding: 12px 10px; min-width: 120px; font-weight: 800; }
.tileBtn.primary { background: var(--accent); color: var(--onAccent); border-color: #FFD77A; box-shadow: 0 0 24px rgba(255,194,61,.35); }
.tileBtn small { display: block; font-size: 11px; font-weight: 700; opacity: .75; }
.storyArt { width: 100%; max-width: min(330px, 42vh); border-radius: 18px; -webkit-mask-image: radial-gradient(closest-side, #000 70%, transparent); mask-image: radial-gradient(closest-side, #000 70%, transparent); }
.panel .bubble { text-align: left; width: 100%; font-size: 16px; position: relative; }
.carry { background: var(--accent); color: var(--onAccent); font-weight: 900; border-radius: 999px; padding: 6px 14px; font-size: 14px; border: 2px solid var(--navy); align-self: flex-end; margin-top: -24px; margin-right: 8px; position: relative; z-index: 2; }
.store { display: inline-block; background: #000; color: #fff; border-radius: 12px; padding: 10px 18px; font-weight: 700; text-decoration: none; border: 1px solid #555; }
.store small { display: block; font-size: 10px; font-weight: 600; opacity: .8; }
.store b { font-size: 19px; }
.levelGrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; width: 100%; }
.levelGrid button { aspect-ratio: 1; border-radius: 9px; background: var(--key); border: 1px solid var(--panelBorder); font-weight: 800; }
.levelGrid button.done { background: #D6E2F2; color: #0050FD; }
.levelGrid button.next { background: var(--accent); color: var(--onAccent); }
.levelGrid button[disabled] { opacity: .3; }

/* Short frames: a smaller hint so it stays clear of the stats */
@media (max-height: 640px) { .hint { font-size: 11.5px; padding: 6px 9px; border-width: 2px; } .hudStats b { font-size: 18px; min-height: 22px; } .ctl { padding: 8px 12px; } }
