@font-face { font-family: 'Tiny5'; src: url('../fonts/tiny5-latin.woff2') format('woff2'); font-display: block; }
@font-face { font-family: 'Jersey20'; src: url('../fonts/jersey20-latin.woff2') format('woff2'); font-display: block; size-adjust: 112%; }

:root {
  --px: 4px;             /* one art pixel on screen, set by js/main.js */
  --ink: #1a1622;
  --paper: #f4ecd6;
  --paper-2: #e2d6b4;
  --amber: #f2b545;
  --cyan: #5fe0d2;
  --red: #e2574c;
  --deck: #221d2e;
  --deck-2: #2f2840;
  --text-scale: 1;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #14121c; color: var(--paper); overflow: hidden; overscroll-behavior: none; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
body { font-family: 'Jersey20', system-ui, sans-serif; }
button { font: inherit; color: inherit; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#stage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; background: #0d0c12; }
body.portrait #stage { flex: 0 0 auto; }
#screen { position: relative; width: calc(var(--px) * 192); height: calc(var(--px) * 144); overflow: hidden; background: #000; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; }

/* ---------- HUD ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; height: calc(var(--px) * 14); display: flex; justify-content: space-between; align-items: center; padding: 0 calc(var(--px) * 3); pointer-events: none; }
#hud[hidden] { display: none; }
#hp { display: flex; gap: calc(var(--px) * 1); }
#hp b { width: calc(var(--px) * 7); height: calc(var(--px) * 7); background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 7 7" shape-rendering="crispEdges"><path d="M3 0h1v1h1v1h1v1h1v1h-1v1h-1v1h-1v1h-1v-1h-1v-1h-1v-1h-1v-1h1v-1h1v-1h1z" fill="%231a1622"/><path d="M3 1h1v1h1v1h1v1h-1v1h-1v1h-1v-1h-1v-1h-1v-1h1v-1h1z" fill="%235fe0d2"/><path d="M3 2h1v1h-1z" fill="%23d8fff9"/></svg>') center/100% 100% no-repeat; image-rendering: pixelated; }
#hp b.half { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 7 7" shape-rendering="crispEdges"><path d="M3 0h1v1h1v1h1v1h1v1h-1v1h-1v1h-1v1h-1v-1h-1v-1h-1v-1h-1v-1h1v-1h1v-1h1z" fill="%231a1622"/><path d="M3 1h1v5h-1v-1h-1v-1h-1v-1h1v-1h1z" fill="%235fe0d2"/><path d="M4 1v5h1v-1h1v-1h0v-1h-1v-1h-1z" fill="%23463c5c"/></svg>'); }
#hp b.empty { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 7 7" shape-rendering="crispEdges"><path d="M3 0h1v1h1v1h1v1h1v1h-1v1h-1v1h-1v1h-1v-1h-1v-1h-1v-1h-1v-1h1v-1h1v-1h1z" fill="%231a1622"/><path d="M3 1h1v1h1v1h1v1h-1v1h-1v1h-1v-1h-1v-1h-1v-1h1v-1h1z" fill="%23463c5c"/></svg>'); }
#hp.hit b { animation: shake 0.25s steps(3) 1; }
#tool { display: flex; align-items: center; gap: calc(var(--px) * 1); background: rgba(20, 18, 28, 0.82); border: calc(var(--px) * 1) solid var(--ink); box-shadow: inset 0 0 0 calc(var(--px) * 0.5) #4d4466; padding: calc(var(--px) * 0.5) calc(var(--px) * 1.5); }
#tool .k { font-family: 'Tiny5', monospace; font-size: calc(var(--px) * 6); line-height: 1; color: var(--amber); }
#tool i { width: calc(var(--px) * 10); height: calc(var(--px) * 10); background-size: 100% 100%; image-rendering: pixelated; }
#tool[hidden] { display: none; }
.hud-r { display: flex; gap: calc(var(--px) * 2); align-items: center; }
#mute { pointer-events: auto; width: calc(var(--px) * 12); height: calc(var(--px) * 12); border: calc(var(--px) * 1) solid var(--ink); background: rgba(20,18,28,0.82) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" shape-rendering="crispEdges"><path d="M1 4h2l2-2v6l-2-2h-2z" fill="%23f4ecd6"/><path d="M6 3h1v1h-1zM7 4h1v2h-1zM6 6h1v1h-1z" fill="%235fe0d2"/></svg>') center/70% no-repeat; padding: 0; image-rendering: pixelated; cursor: pointer; }
#mute.off { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" shape-rendering="crispEdges"><path d="M1 4h2l2-2v6l-2-2h-2z" fill="%238a80a6"/><path d="M6 3h1v1h-1zM8 3h1v1h-1zM7 4h1v1h-1zM6 5h1v1h-1zM8 5h1v1h-1z" fill="%23e2574c"/></svg>'); }
#keys { display: none; }
body.keyhints #keys { display: flex; justify-content: center; gap: 18px; flex: none; padding: 6px 10px; background: #14121c; color: #b7add0; font-size: 18px; }
#keys b { color: var(--amber); font-family: 'Tiny5', monospace; font-weight: normal; font-size: 13px; background: #2f2840; padding: 1px 6px; border-radius: 3px; }
#boot { position: fixed; inset: 0; background: #0d0c12; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 50; }
.boot-logo { font-family: 'Tiny5', monospace; color: var(--paper); font-size: 22px; letter-spacing: 0.1em; }
.boot-track { width: 180px; height: 6px; background: #2f2840; } .boot-track i { display: block; height: 100%; width: 0; background: var(--cyan); }
.board { position: relative; flex: none; width: calc(var(--px) * 180); height: calc(var(--px) * 64); align-self: center; background: #a8814e; border: calc(var(--px) * 1.5) solid #6b4a2f; box-shadow: inset 0 0 0 calc(var(--px) * 1) #c9a46a; overflow: hidden; }
.board svg { position: absolute; left: 0; top: 0; width: calc(var(--px) * 180); height: calc(var(--px) * 64); }
.board .card { position: absolute; width: calc(var(--px) * 41); height: calc(var(--px) * 15); overflow: hidden; background: #f4ecd6; color: var(--ink); font-size: calc(var(--px) * 5.6); line-height: 1; padding: calc(var(--px) * 1); display: flex; gap: calc(var(--px) * 1); align-items: center; box-shadow: calc(var(--px) * 0.5) calc(var(--px) * 0.5) 0 rgba(0,0,0,0.3); }
.board .card i { flex: none; width: calc(var(--px) * 9); height: calc(var(--px) * 9); background-size: 100%; image-rendering: pixelated; }
.board .card::before { content: ''; position: absolute; top: calc(var(--px) * -1); left: 45%; width: calc(var(--px) * 3); height: calc(var(--px) * 3); border-radius: 50%; background: #e2574c; }
.board-sum { margin-top: calc(var(--px) * 2); font-size: calc(var(--px) * 7 * var(--text-scale)); line-height: 1.1; }
.board-sum b { color: var(--amber); font-family: 'Tiny5', monospace; font-weight: normal; font-size: calc(var(--px) * 5); margin-right: calc(var(--px) * 1); }
#tool.off i { opacity: 0.35; }
@keyframes shake { 0% { transform: translateX(calc(var(--px) * -1)); } 50% { transform: translateX(var(--px)); } 100% { transform: none; } }

#objective { position: absolute; left: 50%; top: calc(var(--px) * 16); transform: translateX(-50%); max-width: 90%; text-align: center; background: rgba(20, 18, 28, 0.85); border: calc(var(--px) * 1) solid var(--amber); color: var(--paper); font-size: calc(var(--px) * 7 * var(--text-scale)); line-height: 1.05; padding: calc(var(--px) * 1) calc(var(--px) * 3); pointer-events: none; transition: opacity 0.4s; }
#objective small { display: block; color: var(--amber); font-family: 'Tiny5', monospace; font-size: calc(var(--px) * 5); letter-spacing: 0.05em; }
#objective[hidden] { display: block; opacity: 0; }

#prompt { position: absolute; right: calc(var(--px) * 3); bottom: calc(var(--px) * 3); background: var(--paper); color: var(--ink); border: calc(var(--px) * 1) solid var(--ink); font-size: calc(var(--px) * 8 * var(--text-scale)); line-height: 1; padding: calc(var(--px) * 1) calc(var(--px) * 2.5); pointer-events: none; }
#prompt b { font-family: 'Tiny5', monospace; font-size: calc(var(--px) * 6); color: #fff; background: var(--red); padding: 0 calc(var(--px) * 1); margin-right: calc(var(--px) * 1.5); border-radius: 50%; }
#prompt[hidden] { display: none; }

#toast { position: absolute; left: 50%; bottom: calc(var(--px) * 4); transform: translateX(-50%); background: rgba(20, 18, 28, 0.9); border: calc(var(--px) * 1) solid var(--cyan); font-size: calc(var(--px) * 8 * var(--text-scale)); line-height: 1; padding: calc(var(--px) * 1.5) calc(var(--px) * 3); white-space: nowrap; opacity: 0; transition: opacity 0.25s; pointer-events: none; }
#toast.on { opacity: 1; }
#toast.gold { border-color: var(--amber); }

/* ---------- dialog ---------- */
#dialog { position: absolute; left: calc(var(--px) * 3); right: calc(var(--px) * 3); bottom: calc(var(--px) * 3); min-height: calc(var(--px) * 40); background: var(--paper); color: var(--ink); border: calc(var(--px) * 1) solid var(--ink); box-shadow: inset 0 0 0 calc(var(--px) * 1) var(--paper-2), 0 calc(var(--px) * 1) 0 rgba(0,0,0,0.4); padding: calc(var(--px) * 3) calc(var(--px) * 4); font-size: calc(var(--px) * 9.5 * var(--text-scale)); line-height: 1.02; }
#dialog[hidden] { display: none; }
#dialog { z-index: 5; } #sheet, #title { z-index: 3; } #toast { z-index: 6; }
#dialog .who { position: absolute; top: calc(var(--px) * -6); left: calc(var(--px) * 4); background: var(--ink); color: var(--amber); font-size: calc(var(--px) * 8 * var(--text-scale)); line-height: 1; padding: calc(var(--px) * 1) calc(var(--px) * 3); }
#dialog .who:empty { display: none; }
#dialog .more { position: absolute; right: calc(var(--px) * 3); bottom: calc(var(--px) * 1); font-size: calc(var(--px) * 6); animation: bob 0.7s steps(2) infinite; }
#dialog.typing .more { visibility: hidden; }
#dialog .choices { margin-top: calc(var(--px) * 2); display: flex; flex-direction: column; gap: calc(var(--px) * 1); }
#dialog .choices div { padding-left: calc(var(--px) * 6); position: relative; }
#dialog .choices div.on::before { content: '▶'; position: absolute; left: 0; color: var(--red); }
@keyframes bob { 50% { transform: translateY(calc(var(--px) * 1)); } }

/* ---------- menus (title + pause) ---------- */
#sheet, #title { position: absolute; inset: 0; background: rgba(14, 12, 20, 0.94); display: flex; flex-direction: column; padding: calc(var(--px) * 5); font-size: calc(var(--px) * 9 * var(--text-scale)); line-height: 1.05; overflow: hidden; }
#sheet[hidden], #title[hidden] { display: none; }
#sheet h2, #title h2 { margin: 0 0 calc(var(--px) * 3); font-family: 'Tiny5', monospace; font-weight: normal; font-size: calc(var(--px) * 8); color: var(--amber); letter-spacing: 0.04em; }
.tabs { display: flex; gap: calc(var(--px) * 2); margin-bottom: calc(var(--px) * 4); flex-wrap: wrap; }
.tabs span { font-family: 'Tiny5', monospace; font-size: calc(var(--px) * 6); padding: calc(var(--px) * 1) calc(var(--px) * 2); border: calc(var(--px) * 0.75) solid #4d4466; color: #b7add0; }
.tabs span.on { background: var(--amber); color: var(--ink); border-color: var(--amber); }
.list { display: flex; flex-direction: column; gap: calc(var(--px) * 1.5); overflow: hidden; flex: 1; min-height: 0; }
.list .row { padding: calc(var(--px) * 1) calc(var(--px) * 3) calc(var(--px) * 1) calc(var(--px) * 7); position: relative; border: calc(var(--px) * 0.75) solid transparent; }
.list .row.on { border-color: var(--amber); background: rgba(242, 181, 69, 0.08); }
.list .row.on::before { content: '▶'; position: absolute; left: calc(var(--px) * 2); color: var(--amber); }
.list .row small, .note { display: block; color: #b7add0; font-size: 0.8em; }
.list .row .val { float: right; color: var(--cyan); }
.list .row.dim { opacity: 0.45; }
.hint { margin-top: auto; padding-top: calc(var(--px) * 2); font-family: 'Tiny5', monospace; font-size: calc(var(--px) * 5); color: #8a80a6; }
.ev { display: flex; gap: calc(var(--px) * 3); align-items: flex-start; }
.ev i { flex: none; width: calc(var(--px) * 12); height: calc(var(--px) * 12); background-size: 100% 100%; image-rendering: pixelated; }

#title { background: #0d0c12; align-items: center; justify-content: center; text-align: center; }
#title .logo { font-family: 'Tiny5', monospace; font-size: calc(var(--px) * 13); line-height: 0.95; color: var(--paper); text-shadow: calc(var(--px) * 1) calc(var(--px) * 1) 0 #3b2f5c; }
#title .logo em { display: block; font-style: normal; color: var(--cyan); font-size: 0.55em; letter-spacing: 0.3em; margin-bottom: calc(var(--px) * 2); }
#title .list { flex: none; margin-top: calc(var(--px) * 8); align-items: center; }
#title .list .row { min-width: calc(var(--px) * 70); text-align: left; }
#title .foot { position: absolute; bottom: calc(var(--px) * 3); left: 0; right: 0; font-family: 'Tiny5', monospace; font-size: calc(var(--px) * 4.5); color: #6d6488; }

/* ---------- control deck ---------- */
#deck { flex: 1 1 auto; display: flex; align-items: center; justify-content: space-between; padding: 12px 18px 18px; background: var(--deck); gap: 10px; min-height: 0; }
body.portrait #deck { border-top: 3px solid #0d0c12; }
body.landscape.touch #deck { position: absolute; inset: 0; background: none; pointer-events: none; padding: 12px max(14px, env(safe-area-inset-right)) 14px max(14px, env(safe-area-inset-left)); align-items: flex-end; }
body.landscape.touch #deck > * { pointer-events: auto; }
body:not(.touch) #deck, body.hide-touch #deck { display: none; }
#pad-zone, #btn-zone { position: relative; display: flex; align-items: center; justify-content: center; }
#btn-zone { flex-direction: column; gap: 14px; }
body.left-hand #deck { flex-direction: row-reverse; }
#dpad { position: relative; width: calc(168px * var(--ctl, 1)); height: calc(168px * var(--ctl, 1)); touch-action: none; }
#dpad span { position: absolute; width: 35%; height: 35%; background: var(--deck-2); box-shadow: inset 0 3px 0 rgba(255,255,255,0.08), 0 3px 0 #0d0c12; }
#dpad span::after { content: ''; position: absolute; left: 50%; top: 50%; border: 9px solid transparent; transform: translate(-50%, -50%); }
#dpad .u { left: 32.5%; top: 0; } #dpad .u::after { border-bottom-color: #8f86ad; margin-top: -5px; }
#dpad .d { left: 32.5%; bottom: 0; } #dpad .d::after { border-top-color: #8f86ad; margin-top: 5px; }
#dpad .l { left: 0; top: 32.5%; } #dpad .l::after { border-right-color: #8f86ad; margin-left: -5px; }
#dpad .r { right: 0; top: 32.5%; } #dpad .r::after { border-left-color: #8f86ad; margin-left: 5px; }
#dpad i { position: absolute; left: 32.5%; top: 32.5%; width: 35%; height: 35%; background: var(--deck-2); }
#dpad i::after { content: ''; position: absolute; inset: 30%; border-radius: 50%; background: #1a1622; }
#dpad[data-dir="up"] .u, #dpad[data-dir="down"] .d, #dpad[data-dir="left"] .l, #dpad[data-dir="right"] .r { background: #574a7e; transform: translateY(2px); }
#ab { display: flex; gap: 16px; align-items: center; transform: rotate(-18deg); }
.round { width: calc(74px * var(--ctl, 1)); height: calc(74px * var(--ctl, 1)); border-radius: 50%; border: 0; font-family: 'Tiny5', monospace; font-size: 24px; color: #fff; touch-action: none; box-shadow: inset 0 -5px 0 rgba(0,0,0,0.3), 0 4px 0 #0d0c12; }
.round.a { background: #c9463f; margin-top: -30px; }
.round.b { background: #3f7bc9; margin-top: 30px; }
.round.on { transform: translateY(3px); filter: brightness(1.2); box-shadow: inset 0 -2px 0 rgba(0,0,0,0.3), 0 1px 0 #0d0c12; }
.pill { align-self: center; background: var(--deck-2); border: 0; padding: 8px 18px; border-radius: 99px; font-family: 'Tiny5', monospace; font-size: 13px; color: #b7add0; letter-spacing: 0.1em; touch-action: none; box-shadow: 0 3px 0 #0d0c12; }
.pill.on { background: #574a7e; color: #fff; }
body.landscape.touch #btn-zone { flex-direction: column-reverse; }
body.landscape.touch .pill { position: fixed; top: max(10px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); }
body.left-hand.landscape.touch .pill { right: auto; left: max(12px, env(safe-area-inset-left)); }

/* handheld screen: the HTML parts on the screen take the same four shades */
body[data-screen="green"] { --ink: #13261c; --paper: #e3f2c4; --paper-2: #97c46f; --amber: #e3f2c4; --cyan: #97c46f; --red: #3f7350; }
body[data-screen="olive"] { --ink: #24221a; --paper: #f2ecbf; --paper-2: #c2b46a; --amber: #f2ecbf; --cyan: #c2b46a; --red: #6e6a3a; }
body[data-screen="gray"] { --ink: #161616; --paper: #eeeeee; --paper-2: #a8a8a8; --amber: #eeeeee; --cyan: #a8a8a8; --red: #5a5a5a; }
body[data-screen] #screen #objective, body[data-screen] #screen #toast, body[data-screen] #screen #tool, body[data-screen] #screen #mute { background-color: var(--ink); }
body[data-screen] #sheet, body[data-screen] #title { background: var(--ink); }
body[data-screen] #hp b { filter: grayscale(1) brightness(1.1) sepia(1) hue-rotate(40deg) saturate(0.6); }
body[data-screen="gray"] #hp b { filter: grayscale(1); }
