/* Zen house look: warm dark ground, Space Grotesk, one green that means "you can act here",
   amber for an action about to waste something. Bars attach to the window edges; the board fills. */

@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 {
  --bg: #262421; --panel: #21201d; --ink: #e4e1dd; --dim: #98948e; --tile: #4b4741; --edge: #221f1c;
  --go: #81b64c; --go-ink: #11160b; --amber: #d9a13b; --red: #d5553f;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
body { font: 500 16px/1.35 "Space Grotesk", system-ui, sans-serif; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; }

#app { position: fixed; inset: 0; }
.screen, #play { position: absolute; inset: 0; display: none; }
#app[data-screen="title"] #title,
#app[data-screen="levels"] #levels,
#app[data-screen="loadout"] #loadout,
#app[data-screen="how"] #how,
#app[data-screen="credits"] #credits { display: flex; }
#app[data-screen="play"] #play,
#app[data-screen="paused"] #play,
#app[data-screen="result"] #play { display: flex; }
#app[data-screen="paused"] #paused,
#app[data-screen="result"] #result { display: flex; }

/* ---------- buttons ---------- */
button { background: var(--tile); border: 0; border-radius: 6px; padding: 12px 16px; min-height: 48px; box-shadow: inset 0 -2px 0 var(--edge); }
button:hover { filter: brightness(1.1); }
button:focus-visible { outline: 3px solid var(--go); outline-offset: 2px; }
button.go { background: var(--go); color: var(--go-ink); font-weight: 700; font-size: 20px; min-height: 56px; }
button.icon { background: none; box-shadow: none; min-width: 48px; padding: 8px; font-size: 18px; color: var(--dim); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > button { flex: 1 1 0; }

/* ---------- bars ---------- */
.bar { display: flex; align-items: center; gap: 8px; background: var(--panel); flex: none; }
.bar.top { height: calc(52px + var(--safe-t)); padding: var(--safe-t) calc(8px + var(--safe-r)) 0 calc(8px + var(--safe-l)); border-bottom: 1px solid var(--edge); }
.bar .lvl { font-weight: 700; font-size: 18px; flex: 1; min-width: 0; }
.bar .lvl #lvlNum { color: var(--dim); }
.chips { display: flex; gap: 6px; align-items: center; }
.chip { font-variant-numeric: tabular-nums; color: var(--dim); padding: 4px 8px; border-radius: 6px; background: var(--edge); }
.chip.keys:empty { display: none; }
.chip.keys img { width: 18px; height: 12px; image-rendering: pixelated; vertical-align: middle; margin: 0 2px; }

/* ---------- play ---------- */
#play { flex-direction: column; }
#board { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #1b1a18; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; touch-action: none; }

/* level briefing: a dialogue bar across the bottom of the board, portrait standing on its left edge */
#brief { position: absolute; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: auto 1fr auto; align-items: end; gap: 14px; padding: 12px calc(14px + var(--safe-r)) 14px calc(8px + var(--safe-l)); background: rgba(20,19,17,.96); border-top: 1px solid var(--edge); }
#brief img { width: clamp(96px, 22vmin, 180px); height: auto; image-rendering: pixelated; display: block; align-self: end; margin: calc(-12px - 3vmin) 0 -14px; border-radius: 4px 4px 0 0; }
#brief .txt { padding-bottom: 4px; min-width: 0; }
#brief .who { color: var(--amber); font-weight: 700; font-size: 15px; margin-bottom: 4px; }
#brief p { margin: 0; font-size: 18px; line-height: 1.35; }
#brief .go { min-width: 96px; }
@media (max-width: 560px) { #brief { grid-template-columns: auto 1fr; } #brief .go { grid-column: 1 / -1; } #brief p { font-size: 16px; } }
#flash { position: absolute; inset: 0; background: rgba(213,85,63,.35); display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 700; pointer-events: none; }
#flash span { background: rgba(20,19,17,.9); padding: 10px 18px; border-radius: 6px; }
#aim { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: rgba(20,19,17,.9); border-top: 1px solid var(--edge); }
#aim span { flex: 1; }
#aim button { min-height: 40px; padding: 6px 14px; }
[hidden] { display: none !important; }

#controls {
  display: grid; gap: 8px; align-items: center;
  padding: 8px calc(10px + var(--safe-r)) calc(8px + var(--safe-b)) calc(10px + var(--safe-l));
  border-top: 1px solid var(--edge);
  grid-template-columns: 1fr auto; grid-template-areas: "tray acts";
}
#dpad { grid-area: dpad; display: none; }
#tray { grid-area: tray; display: flex; gap: 6px; min-width: 0; flex-wrap: wrap; }
#acts { grid-area: acts; display: grid; grid-template-columns: repeat(6, auto); gap: 6px; }

.act { min-width: 72px; padding: 8px 10px; font-weight: 700; color: var(--dim); background: var(--edge); box-shadow: none; }
.act.on { background: var(--go); color: var(--go-ink); }
.act.toggle.active { background: var(--amber); color: var(--go-ink); }
.act.reveal { position: relative; overflow: hidden; }
.act.reveal svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.act.reveal .ring { fill: none; stroke: var(--ink); stroke-width: 3; opacity: 0; transform: rotate(-90deg); transform-origin: 50% 50%; }
.act.reveal.cooling .ring { opacity: .35; }
.act.reveal.showing { background: #7c9fd6; color: #0e1420; }
.act.reveal span { position: relative; }

.item { display: flex; align-items: center; gap: 6px; padding: 6px 10px; min-height: 48px; background: var(--edge); box-shadow: none; color: var(--ink); }
.item img { width: 28px; height: 28px; image-rendering: pixelated; }
.item b { font-variant-numeric: tabular-nums; }
.item.sel { outline: 3px solid var(--go); }
.item.worn { color: var(--amber); }
.item[disabled] { opacity: .45; }

/* touch: d-pad on the left, actions in a block on the right */
.touch #controls { grid-template-columns: auto 1fr; grid-template-areas: "tray tray" "dpad acts"; }
.touch #dpad { display: block; position: relative; width: 150px; height: 150px; border-radius: 50%; background: var(--edge); touch-action: none; }
.touch #acts { grid-template-columns: repeat(3, 1fr); justify-self: end; width: min(100%, 300px); }
.touch .act { min-height: 64px; min-width: 0; font-size: 15px; }
#dpad .arm { position: absolute; width: 50px; height: 50px; background: var(--tile); border-radius: 6px; }
#dpad .arm.n { left: 50px; top: 4px; } #dpad .arm.s { left: 50px; bottom: 4px; }
#dpad .arm.w { top: 50px; left: 4px; } #dpad .arm.e { top: 50px; right: 4px; }
#dpad .hub { position: absolute; left: 50px; top: 50px; width: 50px; height: 50px; background: var(--tile); }
#dpad .arm.lit { background: var(--go); }

/* ---------- screens ---------- */
.screen { flex-direction: column; background: var(--bg); overflow-y: auto; }
.screen.over { background: rgba(20,19,17,.72); align-items: center; justify-content: center; padding: 16px; }
.panel { width: 100%; max-width: 560px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.over .panel { background: var(--panel); border-top: 3px solid var(--go); }
h1, h2 { margin: 0; font-weight: 700; line-height: 1.1; }
h2 { font-size: 28px; }

/* title: the key art fills the window, the wordmark sits in its dark sky, the menu is a bar */
#title { align-items: stretch; justify-content: space-between; background: #0f1418 url(/brand/hero.jpg) center 60% / cover no-repeat; }
@media (orientation: portrait) { #title { background-image: url(/brand/tall.jpg); background-position: center bottom; } }
#title .hero { flex: 1; display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; padding: calc(20px + var(--safe-t)) calc(20px + var(--safe-r)) 0 calc(56px + var(--safe-l)); }
@media (orientation: portrait) { #title .hero { align-items: center; padding-left: calc(16px + var(--safe-l)); } }
#title h1 { margin: 0; line-height: 0; }
#title h1 img { width: min(86vw, 560px); height: auto; filter: drop-shadow(0 6px 0 rgba(0,0,0,.45)); }
#title .menu { background: rgba(33,32,29,.94); border-top: 1px solid var(--edge); padding: 16px calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l)); display: flex; flex-direction: column; gap: 8px; }
#title .menu > * { width: 100%; max-width: 560px; margin: 0 auto; }

.resArt { width: 100%; height: auto; max-height: 30vh; object-fit: cover; display: block; image-rendering: pixelated; border-radius: 4px; }
#flash img { display: block; width: min(70vw, 360px); height: auto; image-rendering: pixelated; margin-bottom: 8px; }
#flash .card { background: rgba(20,19,17,.92); padding: 10px; border-radius: 6px; text-align: center; }

#levelList { list-style: none; margin: 0; padding: 12px calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l)); display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
#levelList button { width: 100%; height: 100%; text-align: left; display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto; gap: 8px; align-items: center; background: var(--panel); padding: 8px 10px 10px; }
#levelList .thumb { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; background: #1b1a18; border-radius: 4px; height: 150px; overflow: hidden; }
#levelList .thumb canvas { max-width: 100%; max-height: 150px; image-rendering: pixelated; }
#levelList .name { font-weight: 700; }
#levelList .n { color: var(--dim); font-variant-numeric: tabular-nums; }
#levelList .best { color: var(--dim); font-variant-numeric: tabular-nums; }
#levelList .best.ghost { color: var(--go); }
#levelList button[disabled] { opacity: .4; cursor: default; }

#loItems { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
#loItems li { display: grid; grid-template-columns: 36px 1fr auto 40px auto; gap: 10px; align-items: center; background: var(--panel); padding: 8px 10px; border-radius: 6px; }
#loItems img { width: 32px; height: 32px; image-rendering: pixelated; }
#loItems b { font-variant-numeric: tabular-nums; text-align: center; font-size: 20px; }
#loItems button { min-width: 48px; padding: 6px; }
#loSlots { color: var(--dim); }

#resRank { font-size: 64px; font-weight: 700; line-height: 1; color: var(--go); }
#resStats { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin: 0; }
#resStats dt { color: var(--dim); }
#resStats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
#resStats .total { color: var(--ink); font-weight: 700; border-top: 1px solid var(--tile); padding-top: 6px; }

.prose p { margin: 0; color: var(--ink); }
.prose h3 { margin: 12px 0 0; font-size: 18px; }
.prose .dim, .keysHelp { color: var(--dim); font-size: 15px; }
.prose ul { margin: 0; padding-left: 20px; }
.prose a { color: var(--go); }
.keysHelp { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; }
.keysHelp kbd { font: inherit; color: var(--ink); }

@media (max-width: 520px) {
  .bar .lvl { font-size: 16px; }
  .touch #dpad { width: 132px; height: 132px; }
  .touch #dpad .arm, .touch #dpad .hub { width: 44px; height: 44px; }
  .touch #dpad .arm.n, .touch #dpad .arm.s, .touch #dpad .hub { left: 44px; }
  .touch #dpad .arm.w, .touch #dpad .arm.e, .touch #dpad .hub { top: 44px; }
}

/* touch, landscape phone: d-pad left of the board, actions right, so the board keeps the height */
@media (orientation: landscape) and (max-height: 540px) {
  html.touch #app #play { display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto 1fr auto; grid-template-areas: "top top top" "dpad board acts" "tray board acts"; }
  html.touch #app:not([data-screen="play"]):not([data-screen="paused"]):not([data-screen="result"]) #play { display: none; }
  .touch #play > .bar.top { grid-area: top; height: calc(44px + var(--safe-t)); }
  .touch #board { grid-area: board; }
  .touch #controls { display: contents; }
  .touch #dpad { grid-area: dpad; align-self: center; margin: 8px 8px 8px calc(44px + var(--safe-l)); }
  .touch #tray { grid-area: tray; flex-direction: column; padding: 0 8px 8px calc(36px + var(--safe-l)); }
  .touch #acts { grid-area: acts; grid-template-columns: repeat(2, 1fr); width: 200px; align-self: center; padding: 8px calc(8px + var(--safe-r)) 8px 8px; }
  .touch .act { min-height: 56px; }
}
.touch #keysHelp { display: none; }
