:root {
  --k: #4a3f55; --w: #fffaf3; --s: #efe4d6; --p: #f7b6c8; --P: #e88aa6; --l: #d9c6f2; --L: #b79be0;
  --b: #bfe3f5; --N: #3f4f7e; --o: #ffc9a3; --m: #c5ecc0; --r: #f28b8b;
  --bg: var(--b);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace;
}
body.dusk { --bg: var(--l); }
body.night { --bg: var(--N); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
body { font-family: var(--mono); color: var(--k); -webkit-text-size-adjust: 100%; }
#app { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 8px 16px; }
#stage { position: relative; flex: none; width: 240px; height: 135px; box-shadow: 0 -4px 0 0 var(--k), 0 4px 0 0 var(--k), -4px 0 0 0 var(--k), 4px 0 0 0 var(--k); }
#world { position: relative; width: 100%; height: 100%; }
canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; image-rendering: pixelated; touch-action: manipulation; }
#hits { position: absolute; inset: 0; }
.hit { position: absolute; left: 0; top: 0; margin: 0; padding: 0; border: 0; background: transparent; cursor: pointer; border-radius: 0; -webkit-tap-highlight-color: transparent; }
.hit:focus-visible { outline: 3px dashed var(--w); outline-offset: 2px; box-shadow: 0 0 0 3px var(--k); }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; padding: 0; margin: -1px; opacity: 0; }

.bubble { position: relative; flex: none; width: min(340px, 100%); background: var(--w); padding: 14px 16px 12px; margin: 4px 4px 0;
  box-shadow: 0 -4px 0 0 var(--k), 0 4px 0 0 var(--k), -4px 0 0 0 var(--k), 4px 0 0 0 var(--k), 0 8px 0 0 rgba(74, 63, 85, .18); }
.bubble[hidden] { display: none; }
.bubble::before { content: ""; position: absolute; left: 50%; top: -16px; margin-left: -8px; width: 16px; height: 8px; background: var(--k);
  clip-path: polygon(0 100%, 50% 0, 100% 100%); }
.bubble::after { content: ""; position: absolute; left: 50%; top: -8px; margin-left: -4px; width: 8px; height: 4px; background: var(--w); }
.bubble label { display: block; font-weight: 700; font-size: 16px; margin-bottom: 8px; }
.row { display: flex; gap: 8px; }
.bubble input[type=password], .bubble select { flex: 1; min-width: 0; font: 700 18px var(--mono); color: var(--k); background: var(--s); border: 0; padding: 8px 10px; border-radius: 0;
  box-shadow: inset 0 0 0 3px var(--k); }
.bubble input:focus-visible, .bubble select:focus-visible { outline: 3px solid var(--P); outline-offset: 2px; }
.bubble button[type=submit] { font: 700 16px var(--mono); color: var(--k); background: var(--p); border: 0; padding: 8px 14px; cursor: pointer; border-radius: 0; box-shadow: inset 0 0 0 3px var(--k), 0 4px 0 0 var(--P); }
.bubble button[type=submit]:active { transform: translateY(2px); }
.bubble button[type=submit]:disabled { background: var(--s); cursor: default; }
.bubble button:focus-visible { outline: 3px solid var(--P); outline-offset: 2px; }
.link { margin-top: 10px; background: none; border: 0; padding: 4px 0; font: 14px var(--mono); color: var(--k); text-decoration: underline; cursor: pointer; }
.plain label { margin-top: 10px; } .plain button { margin-top: 12px; }

#status { min-height: 1.4em; margin: 0; max-width: 340px; text-align: center; font-weight: 700; font-size: 15px; color: var(--k); background: var(--w); padding: 0; }
#status:not(:empty) { padding: 6px 12px; box-shadow: 0 -3px 0 0 var(--k), 0 3px 0 0 var(--k), -3px 0 0 0 var(--k), 3px 0 0 0 var(--k); }
#status.err { background: var(--p); }

#safe { position: fixed; top: 0; left: 0; width: 0; height: 0; visibility: hidden; padding-top: env(safe-area-inset-top); }
.hit, button { touch-action: manipulation; }

/* ---- phones, portrait: full-bleed tall scene, docked thumb-zone panel ---- */
body.portrait #app { display: block; padding: 0; height: 100%; }
body.portrait #world { transition: transform .25s steps(5); }
body.portrait .bubble { position: fixed; left: 0; right: 0; bottom: var(--kb, 0px); width: auto; margin: 0; z-index: 5; padding: 18px 16px calc(14px + env(safe-area-inset-bottom)) ;
  box-shadow: 0 -4px 0 0 var(--k), 0 -8px 0 0 rgba(74, 63, 85, .15); animation: dock .2s steps(4) both; }
body.portrait .bubble::before, body.portrait .bubble::after { display: none; }
body.portrait .bubble label { font-size: 20px; margin-bottom: 12px; }
body.portrait .bubble input[type=password] { font-size: 20px; height: 56px; padding: 0 12px; }
body.portrait .bubble button[type=submit] { font-size: 20px; min-height: 56px; min-width: 104px; }
body.portrait .link { font-size: 16px; min-height: 48px; padding: 10px 8px; margin: 4px 0 0; }
body.portrait #status { position: fixed; left: 12px; right: 12px; bottom: calc(var(--kb, 0px) + var(--panel-h, 0px) + 14px + env(safe-area-inset-bottom)); max-width: none; z-index: 6; font-size: 16px; }
body.portrait #status:empty { display: none; }
@keyframes dock { from { transform: translateY(100%); } to { transform: none; } }

/* ---- phones, landscape: scene left, panel on the right ---- */
body.side #app { display: block; padding: 0; }
body.side .bubble { position: fixed; margin: 0; z-index: 5; padding: 12px 14px 10px; }
body.side .bubble::before, body.side .bubble::after { display: none; }
body.side .bubble label { font-size: 16px; margin-bottom: 8px; }
body.side .bubble input[type=password] { height: 48px; }
body.side .bubble button[type=submit] { min-height: 48px; min-width: 88px; }
body.side .link { min-height: 36px; margin-top: 4px; }
body.side #stage { transition: left .25s steps(5), top .25s steps(5); }
body.side #status { position: fixed; left: 12px; bottom: calc(var(--kb, 0px) + 8px); max-width: 60%; z-index: 6; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
