:root {
  --bg: #1b3156;
  --panel: #22406b;
  --edge: #29c8ff;
  --ink: #e8f1ff;
  --muted: #a9bfdf;
  --gold: #ffd23f;
  --pink: #ff7aa8;
  --shark: #97caeb;
  --font: ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { overscroll-behavior: none; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }

#app { height: 100dvh; display: flex; flex-direction: column; max-width: 1200px; margin: 0 auto; padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom); }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 2px; }
.home-link { display: block; flex: none; line-height: 0; border-radius: 50%; }
.home-link:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.brand-logo { height: 52px; width: auto; flex: none; }
.titles { flex: 1; min-width: 0; }
.titles h1 { margin: 0; font-size: 26px; letter-spacing: 1px; color: var(--shark); text-shadow: 0 0 12px rgba(41, 200, 255, 0.55); font-family: var(--mono); text-transform: uppercase; }
.level-title { margin: 2px 0 0; color: var(--gold); font-weight: 700; font-size: 14px; }
.top-stats { display: flex; gap: 16px; }
.stat { display: flex; flex-direction: column; align-items: flex-end; }
.stat-label { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: 1px; }
.stat b { font-family: var(--mono); font-size: 22px; color: #fff; }
.lives { display: flex; gap: 4px; height: 24px; align-items: center; }
.lives svg { width: 28px; height: 20px; }
.lives img { width: 26px; height: 26px; object-fit: contain; }
.lives .lost { opacity: 0.18; }
.top-buttons { display: flex; gap: 8px; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 2px solid var(--edge); background: var(--panel); font-size: 15px; }
.icon-btn.off { opacity: 0.45; }

/* Stage */
.stage { flex: 1; min-height: 0; display: flex; gap: 14px; }
.game { flex: 1; min-width: 0; min-height: 0; position: relative; }
.game canvas { border-radius: 12px; box-shadow: 0 0 0 2px #17305a, 0 0 30px rgba(41, 200, 255, 0.15); touch-action: none; }

.panel { width: 290px; flex: none; background: var(--panel); border: 2px solid #3a5f94; border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 12px; align-self: flex-start; }
.recipe-head { display: flex; gap: 12px; align-items: center; padding-bottom: 14px; }
.recipe-head h2 { margin: 0; font-size: 18px; color: var(--gold); text-transform: uppercase; letter-spacing: 1px; font-family: var(--mono); }
.recipe-sub { margin: 4px 0 0; font-size: 12px; color: var(--muted); line-height: 1.35; }
.bar-thumb { width: 120px; flex: none; }
.bar-build { position: relative; aspect-ratio: 900 / 733; }
.bar-build img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.bar-build .ghost { filter: grayscale(1) brightness(0.6); opacity: 0.22; }
.bar-build .layer { transition: clip-path 0.35s ease-out; filter: drop-shadow(0 0 6px rgba(255, 210, 63, 0.25)); }
.bar-build.complete .layer { animation: barglow 1.4s ease-in-out infinite alternate; }
@keyframes barglow { to { filter: drop-shadow(0 0 10px rgba(255, 210, 63, 0.8)); } }
.bar-pct { position: absolute; left: 0; right: 0; bottom: -16px; text-align: center; font: 700 11px var(--mono); color: var(--gold); }
.recipe { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.recipe li { display: grid; grid-template-columns: 30px 1fr auto; grid-template-rows: auto 6px; column-gap: 8px; row-gap: 4px; align-items: center; }
.recipe li svg { grid-row: 1 / 3; width: 30px; height: 30px; }
.recipe .name { font-size: 13px; font-weight: 600; }
.recipe .count { font-family: var(--mono); font-weight: 700; font-size: 14px; }
.recipe .bar { grid-column: 2 / 4; height: 6px; border-radius: 3px; background: #142a4d; overflow: hidden; }
.recipe .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--edge), var(--shark)); transition: width 0.2s; }
.recipe li.done .count { color: #6dffb0; }
.recipe li.done .bar i { background: #6dffb0; }
.recipe li.bump { animation: bump 0.25s; }
@keyframes bump { 50% { transform: scale(1.06); } }

.lighthouse { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; font-weight: 700; font-size: 14px; }
.lighthouse.locked { background: #2c4d80; color: var(--muted); }
.lighthouse.unlocked { background: #3b2f05; color: var(--gold); box-shadow: 0 0 0 2px var(--gold), 0 0 18px rgba(255, 210, 63, 0.5); animation: glow 1.2s ease-in-out infinite alternate; }
@keyframes glow { to { box-shadow: 0 0 0 2px var(--gold), 0 0 28px rgba(255, 210, 63, 0.85); } }
.lh-icon { width: 22px; height: 22px; flex: none; background: center / contain no-repeat; }
.locked .lh-icon { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 11V8a5 5 0 0 1 10 0v3' fill='none' stroke='%238fa6c8' stroke-width='3'/%3E%3Crect x='4' y='11' width='16' height='11' rx='2' fill='%238fa6c8'/%3E%3C/svg%3E"); }
.unlocked .lh-icon { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 22h6l-1-14h-4z' fill='%23fff'/%3E%3Crect x='9' y='4' width='6' height='4' fill='%23ffd23f'/%3E%3Cpath d='M15 6l8-3v6zM9 6L1 3v6z' fill='%23ffd23f' opacity='.6'/%3E%3C/svg%3E"); }

/* D-pad */
.dpad { display: none; }
.has-touch .dpad { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(2, 54px); gap: 6px; justify-content: center; padding: 10px 0 6px; }
.d { border-radius: 14px; border: 2px solid var(--edge); background: var(--panel); font-size: 22px; color: var(--shark); touch-action: none; }
.d.up { grid-column: 2; grid-row: 1; }
.d.left { grid-column: 1; grid-row: 2; }
.d.down { grid-column: 2; grid-row: 2; }
.d.right { grid-column: 3; grid-row: 2; }
.d.pressed { background: #1d3a6b; }

/* Overlay screens */
.overlay { position: fixed; inset: 0; background: rgba(5, 8, 18, 0.78); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; backdrop-filter: blur(3px); }
.overlay[hidden] { display: none; }
.card { background: var(--panel); border: 2px solid var(--edge); border-radius: 18px; padding: 22px; max-width: 520px; width: 100%; max-height: 100%; overflow: auto; text-align: center; box-shadow: 0 0 40px rgba(41, 200, 255, 0.3); }
.card .logo { height: 84px; width: auto; }
.card h1 { font-family: var(--mono); color: var(--shark); text-transform: uppercase; letter-spacing: 2px; margin: 10px 0 2px; font-size: 32px; text-shadow: 0 0 14px rgba(41, 200, 255, 0.6); }
.card h2 { color: var(--gold); margin: 0 0 12px; font-size: 18px; }
.card p { color: #cdd9ee; line-height: 1.45; margin: 8px 0; }
.card .bar-img { max-width: 80%; max-height: 170px; border-radius: 12px; margin: 8px auto; display: block; }
.victory-stage { position: relative; width: min(300px, 78%); margin: 10px auto 4px; overflow: visible; }
.victory-stage .bar-img { max-width: 100%; max-height: none; width: 100%; margin: 0; }
.card.victory { overflow: visible; }
.victory-shark { position: absolute; left: -49%; top: -4%; width: 69%; z-index: 2; opacity: 0; pointer-events: none; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5)); }
.victory-shark svg { width: 100%; height: auto; }
.tagline { font-family: var(--mono); font-weight: 800; font-size: 20px; color: var(--gold) !important; letter-spacing: 1px; margin: 14px 0 0 !important; opacity: 0; transform: translateY(6px); transition: opacity 0.5s, transform 0.5s; }
.tagline.show { opacity: 1; transform: none; }
.crumb { position: absolute; width: 6px; height: 5px; border-radius: 2px; background: #b07a3c; pointer-events: none; }
.crumb:nth-child(3n) { background: #3b1f0e; width: 4px; height: 4px; }
.card .mini-recipe { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; text-align: left; margin: 12px auto; max-width: 380px; font-size: 14px; }
.card .mini-recipe span { display: flex; align-items: center; gap: 8px; }
.card .mini-recipe svg { width: 24px; height: 24px; flex: none; }
.card .keys { font-size: 13px; color: var(--muted); }
.card .big { font-family: var(--mono); font-size: 34px; color: #fff; margin: 4px 0; }
.btn { display: inline-block; margin: 14px 6px 0; padding: 12px 26px; border-radius: 12px; border: 0; background: var(--gold); color: #2a1d00; font-weight: 800; font-size: 17px; letter-spacing: 0.5px; box-shadow: 0 4px 0 #b38a00; }
.btn.secondary { background: transparent; color: var(--ink); border: 2px solid var(--edge); box-shadow: none; }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #b38a00; }
.pick { display: flex; justify-content: center; gap: 10px; margin: 10px 0 4px; }
.pick button { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 132px; padding: 8px 6px 6px; border-radius: 14px; border: 2px solid #3a5f94; background: #1b3156; font-weight: 800; font-size: 15px; }
.pick button img { width: 72px; height: 70px; object-fit: contain; }
.pick button[aria-pressed='true'] { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold), 0 0 16px rgba(255, 210, 63, 0.45); }
.pick button[data-character='ms'][aria-pressed='true'] { border-color: #ff8fbd; box-shadow: 0 0 0 2px #ff8fbd, 0 0 16px rgba(255, 143, 189, 0.5); }
.placeholder-note { font-size: 11px; color: #ffb36b; margin-top: 10px; }

.toast { position: fixed; left: 50%; top: 84px; transform: translateX(-50%) translateY(-10px); background: #1d2a4d; border: 2px solid var(--gold); color: var(--gold); padding: 10px 16px; border-radius: 12px; font-weight: 700; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 5; text-align: center; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Phones & narrow windows: recipe becomes a compact strip above the map. */
@media (max-width: 820px), (max-aspect-ratio: 4/5) {
  #app { padding-left: 8px; padding-right: 8px; }
  .topbar { padding: 6px 0; gap: 8px; }
  .brand-logo { height: 38px; }
  .titles h1 { font-size: 20px; white-space: nowrap; }
  .level-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .stat-label { font-size: 13px; }
  .top-stats { gap: 10px; }
  .stat b { font-size: 20px; }
  .lives svg { width: 20px; height: 15px; }
  .lives img { width: 22px; height: 22px; }
  .icon-btn { width: 34px; height: 34px; }
  .stage { flex-direction: column; gap: 6px; }
  .panel { width: 100%; padding: 8px; gap: 6px; border-radius: 12px; align-self: stretch; }
  .panel { display: grid; grid-template-columns: 76px 1fr; grid-template-areas: 'bar recipe' 'bar light'; column-gap: 8px; }
  .recipe-head { grid-area: bar; padding-bottom: 12px; align-self: center; }
  .recipe-head > div:last-child { display: none; }
  .bar-thumb { width: 76px; }
  .bar-pct { font-size: 11px; bottom: -14px; }
  .recipe { grid-area: recipe; flex-direction: row; gap: 6px; }
  .lighthouse { grid-area: light; }
  .recipe li { flex: 1; grid-template-columns: 22px 1fr; grid-template-rows: auto 5px; column-gap: 4px; }
  .recipe li svg { width: 22px; height: 22px; }
  .recipe .name { display: none; }
  .recipe .count { font-size: 15px; }
  .recipe .bar { grid-column: 1 / 3; height: 5px; }
  .lighthouse { padding: 5px 8px; font-size: 14px; }
  .lh-icon { width: 16px; height: 16px; }
  .toast { top: 60px; font-size: 18px; }
  /* Phone text a step bigger (Mitch, 2026-11-17); smaller pictures so the cards still fit. */
  .card { padding: 14px; }
  .card .logo { display: none; } /* the header behind already shows it */
  .card h1 { margin-top: 2px; }
  .card h2 { font-size: 21px; }
  .card p { font-size: 18px; line-height: 1.35; }
  .card .bar-img { max-height: 110px; }
  .card .mini-recipe { font-size: 16px; }
  .card .keys { font-size: 15px; }
  .btn { font-size: 19px; }
  .pick button { font-size: 17px; }
  .pick button img { width: 56px; height: 54px; }
  .victory-stage .bar-img { max-height: none; } /* the win card's picture keeps its size */
}
/* Short phone screens (e.g. iPhone SE). */
@media (max-width: 820px) and (max-height: 760px) {
  .card .bar-img { max-height: 80px; }
  .card p { margin: 6px 0; }
  .victory-stage .bar-img { max-height: none; }
}
@media (max-width: 560px) {
  .topbar { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: 'logo titles buttons' 'stats stats stats'; row-gap: 4px; }
  .home-link { grid-area: logo; }
  .brand-logo { height: 34px; }
  .titles { grid-area: titles; }
  .top-buttons { grid-area: buttons; }
  .top-stats { grid-area: stats; justify-content: space-between; padding: 0 4px; }
  .stat { flex-direction: row; align-items: center; gap: 8px; }
  .toast { top: 42vh; }
}

/* Touch screens: the map gets the space; the pad sits in Nantucket Sound and the sound & pause
   buttons in the empty corner above the jail, see-through (Mitch, 2026-11-17). trackMap() keeps
   the --map-* variables in step with the map's on-screen box. */
.has-touch .dpad { position: fixed; z-index: 4; display: flex; gap: 8px; padding: 0;
  left: var(--map-cx, 50%); top: calc(var(--map-bottom, 100vh) - var(--pad-h) - 3px); transform: translateX(-50%);
  --pad-h: clamp(26px, calc(var(--map-h, 500px) * 0.078), 40px); }
.has-touch .d { width: calc(var(--pad-h) * 1.5); height: var(--pad-h); padding: 0; border-width: 1.5px; border-radius: 10px;
  font-size: calc(var(--pad-h) * 0.45); background: rgba(27, 49, 86, 0.6); border-color: rgba(41, 200, 255, 0.75); }
.has-touch .d.left { order: 1; } .has-touch .d.up { order: 2; } .has-touch .d.down { order: 3; } .has-touch .d.right { order: 4; }
.has-touch .d.pressed { background: rgba(41, 200, 255, 0.45); }
.has-touch .top-buttons { position: fixed; z-index: 4; gap: 6px; left: calc(var(--map-left, 8px) + 6px); top: calc(var(--map-top, 0px) + 6px); }
.has-touch .icon-btn { width: 32px; height: 32px; font-size: 13px; border-width: 1.5px; background: rgba(27, 49, 86, 0.6); border-color: rgba(41, 200, 255, 0.75); }
@media (max-width: 560px) {
  /* With the buttons on the map, the header fits on one line: logo, title, score & lives. */
  .has-touch .topbar { display: flex; padding: 4px 0; gap: 10px; }
  .has-touch .top-stats { gap: 12px; padding: 0; }
  .has-touch .stat { flex-direction: column; align-items: flex-end; gap: 0; }
  .has-touch .stat-label { font-size: 11px; }
  .has-touch .stat b { font-size: 20px; line-height: 1.1; }
}
