:root { color-scheme: dark; --bg: #000; --fg: #eee; --muted: #9a9a9a; --accent: #8b5cf6; --panel: rgba(18, 12, 8, .95); --rule: #333; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* A game, not a document: no text selection, copy menu or tap flash on a phone, and
   no double-tap zoom. Text fields stay selectable. */
html { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
#app { display: flex; flex-direction: column; min-height: 100dvh; }
#bar { display: flex; align-items: center; gap: .25rem; padding: .35rem .6rem; padding-top: max(.35rem, env(safe-area-inset-top)); }
#bar .title { font-weight: 700; letter-spacing: .06em; text-transform: uppercase; font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.spacer { flex: 1; }
#bar button { background: none; border: 0; color: var(--fg); padding: .3rem .45rem; cursor: pointer; border-radius: .4rem; display: inline-flex; }
#bar button:hover, #bar button:focus-visible { background: #222; outline: none; }
/* A phone held upright: the bar's buttons fit only if they sit closer. */
@media (max-width: 440px) { #bar { gap: 0; padding-left: .3rem; padding-right: .3rem; } #bar button { padding: .3rem .22rem; } }
#bar #rewind { touch-action: none; -webkit-user-select: none; user-select: none; }
#bar #rewind.held { background: #333; opacity: 1; }
#stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .75rem; padding: .25rem 16px max(.5rem, env(safe-area-inset-bottom)); }
/* The LCD: 160 × 144 square pixels. */
#tv { --aspect: 1.1111; position: relative; width: min(100%, calc((100dvh - 4.5rem) * var(--aspect))); aspect-ratio: var(--aspect); background: #000; }
#screen { position: absolute; inset: 0; display: block; width: 100%; height: 100%; image-rendering: pixelated; background: #000; outline: none; touch-action: none; }
#scanlines { position: absolute; inset: 0; pointer-events: none; background: repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,0) 2px, rgba(0,0,0,.28) 2px, rgba(0,0,0,.28) 3px); mix-blend-mode: multiply; }
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.overlay span { background: rgba(0,0,0,.65); color: var(--fg); padding: .4rem .9rem; border-radius: 2rem; font-size: .95rem; }
#hint span { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.notice { position: absolute; left: 0; right: 0; bottom: 0; padding: .25rem .5rem; font-size: .75rem; color: var(--muted); background: rgba(0,0,0,.6); text-align: center; }
.panel { position: absolute; inset: 0; background: var(--panel); padding: 1rem; display: flex; flex-direction: column; gap: .65rem; overflow: auto; z-index: 4; }
.panel h1 { margin: 0; font-size: 1.5rem; letter-spacing: .04em; }
.panel h2 { margin: .25rem 0 .25rem; font-size: .9rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.panel p { margin: 0; }
.drop { display: block; border: 2px dashed #555; border-radius: .6rem; padding: .9rem; text-align: center; cursor: pointer; }
.drop.over { border-color: var(--accent); background: rgba(139,92,246,.12); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row input[type=url] { flex: 1; min-width: 10rem; padding: .5rem .6rem; border-radius: .4rem; border: 1px solid #555; background: #111; color: var(--fg); font: inherit; }
button { font: inherit; padding: .5rem .9rem; border-radius: .4rem; border: 1px solid #555; background: #1c1c24; color: var(--fg); cursor: pointer; }
button.primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
#recent { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: .4rem; }
#recent button { width: 100%; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: .45rem .6rem; }
#recent button:hover { border-color: var(--accent); }
.status { font-size: .9rem; }
.status.bad { color: #ff8a80; }
.status.ok { color: #8be28b; }
.fine { font-size: .78rem; color: var(--muted); }

/* Touch, as touch games draw it (play-md's): a round 8-way d-pad under the left thumb
   B and A under the right, Select and Start between. */
#touch { --dpad: clamp(7.5rem, 38vw, 10rem); --fire: clamp(4rem, 19vw, 5rem); display: none; position: relative; touch-action: none; width: min(100%, 32rem); justify-content: space-between; align-items: flex-end; padding-bottom: 2.6rem; }
#touch button { touch-action: none; user-select: none; -webkit-user-select: none; padding: 0; font-size: 1.1rem; }
#touch button.held { background: #5a5a72; border-color: #9a9ab8; }
.dpad { position: relative; flex: none; width: var(--dpad); height: var(--dpad); border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,.05) 0 60%, rgba(255,255,255,.1) 61%); border: 1px solid rgba(255,255,255,.16); }
.dpad span { position: absolute; display: flex; align-items: center; justify-content: center; background: #2a2a38; color: #8d8da3; font-size: calc(var(--dpad) * .1); pointer-events: none; }
.dpad .up, .dpad .down { left: 34%; width: 32%; height: 27%; }
.dpad .left, .dpad .right { top: 34%; height: 32%; width: 27%; }
.dpad .up { top: 8%; border-radius: .55rem .55rem 0 0; } .dpad .down { bottom: 8%; border-radius: 0 0 .55rem .55rem; }
.dpad .left { left: 8%; border-radius: .55rem 0 0 .55rem; } .dpad .right { right: 8%; border-radius: 0 .55rem .55rem 0; }
.dpad .hub { left: 34%; top: 34%; width: 32%; height: 32%; }
.dpad span.held { background: #5a5a72; color: #fff; }
.middle { position: absolute; left: 50%; bottom: .2rem; transform: translateX(-50%); display: flex; gap: .5rem; }
#touch .small { padding: .3rem .8rem; font-size: .72rem; border-radius: 1rem; text-transform: uppercase; letter-spacing: .06em; }
.face { display: flex; gap: .4rem; align-items: flex-end; flex: none; margin-bottom: calc(var(--fire) * .25); }
@media (pointer: coarse) { #touch { display: flex; margin-top: auto; } #stage { justify-content: flex-start; } #tv { width: min(100%, calc((100dvh - 17rem) * var(--aspect))); } }
/* Choosing a game on a phone: the picture's box is too short for the panel and its
   game list, so the panel takes the page and the pad steps aside until a game starts. */
@media (pointer: coarse) {
  #app:has(#intake:not([hidden])) #touch { display: none; }
  #app:has(#intake:not([hidden])) #tv { width: 100%; aspect-ratio: auto; flex: 1; display: flex; flex-direction: column; }
  #app:has(#intake:not([hidden])) .panel { position: relative; flex: 1; overflow: visible; }
}
/* A phone on its side: the picture takes the whole height, and the bar and the pad
   float over it (and the black at its sides), translucent, as touch games do. */
@media (pointer: coarse) and (orientation: landscape) {
  #bar { position: fixed; top: 0; left: 0; right: 0; z-index: 3; padding: max(.2rem, env(safe-area-inset-top)) max(.6rem, env(safe-area-inset-right)) .2rem max(.6rem, env(safe-area-inset-left)); pointer-events: none; }
  #bar > * { pointer-events: auto; }
  #bar button { opacity: .55; filter: drop-shadow(0 0 2px #000); }
  #bar .title { visibility: hidden; }
  #stage { padding: 0; justify-content: center; }
  #tv { width: min(100vw, calc(100dvh * var(--aspect))); }
  .panel { z-index: 4; }
  #touch { --dpad: min(44dvh, 10.5rem); --fire: min(24dvh, 5.2rem); position: fixed; left: 0; right: 0; bottom: 0; width: auto; margin: 0; z-index: 2; pointer-events: none; padding: 0 max(1.2rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1.2rem, env(safe-area-inset-left)); }
  #touch > * { pointer-events: auto; opacity: .55; }
  /* Select and Start would cover the picture's bottom: they take the corner the title left. */
  #touch .middle { position: fixed; left: max(1.2rem, env(safe-area-inset-left)); top: max(.45rem, env(safe-area-inset-top)); bottom: auto; transform: none; }
  .dpad { background: radial-gradient(circle, rgba(0,0,0,.15) 0 60%, rgba(255,255,255,.12) 61%); }
  .dpad span, #touch button { background: rgba(40, 40, 52, .75); }
  #touch .face .a, #touch .face .b { background: rgba(120, 20, 24, .75); }
  .dpad span.held, #touch button.held { background: rgba(130, 130, 160, .9); }
}
dialog { background: #16120f; color: var(--fg); border: 1px solid #444; border-radius: .8rem; max-width: min(92vw, 32rem); width: 100%; max-height: 92dvh; padding: 1rem 1.1rem; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 .5rem; font-size: 1.1rem; }
dialog form { display: flex; flex-direction: column; gap: .55rem; }
dialog fieldset { border: 1px solid var(--rule); border-radius: .5rem; display: flex; flex-direction: column; gap: .5rem; padding: .5rem .7rem .6rem; margin: 0; }
dialog legend { color: var(--muted); font-size: .85rem; padding: 0 .3rem; }
dialog label { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
dialog label:has(input[type=checkbox]) { justify-content: flex-start; }
dialog select, dialog input[type=range] { max-width: 60%; }
dialog select { font: inherit; padding: .25rem .4rem; background: #111; color: var(--fg); border: 1px solid #555; border-radius: .3rem; }
dialog details { border-top: 1px solid var(--rule); padding-top: .4rem; }
dialog summary { cursor: pointer; }
table.controls { border-collapse: collapse; font-size: .85rem; width: 100%; }
table.controls td, table.controls th { text-align: left; padding: .2rem .3rem; border-bottom: 1px solid var(--rule); }
a { color: var(--accent); }
.panel > footer { margin-top: auto; }
/* B and A, B a little lower as on the pad. */
.face .a, .face .b { width: var(--fire); height: var(--fire); border-radius: 50%; font-weight: 700; font-size: 1rem; background: #6a1418; border-color: #b33; }
.face { gap: .7rem; }
.face .a { margin-bottom: calc(var(--fire) * .45); }
#bar .badge { font-size: .7rem; font-weight: 700; margin-left: .15rem; align-self: center; }
#bar .badge:empty { display: none; }
.sides { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.sides button.inserted { border-color: var(--accent); background: #3a1416; }
