/* stf.css -- the browser shell.
 *
 * Two rules held the whole file together:
 *
 *   1. THE PICTURE IS THE PAGE. 496x384 (or 684x384 widescreen) of arcade
 *      output, presented with square pixels, centred, never distorted. Every
 *      layout decision below is downstream of "do not stretch the game".
 *
 *   2. NOTHING THE THUMB TOUCHES MOVES. On a phone the browser's own
 *      gestures -- double-tap zoom, pull-to-refresh, text selection, the
 *      long-press callout -- are all ways for a fighting game to eat an
 *      input. They are turned off on the stage and only on the stage.
 *
 * No external assets: no web fonts, no images, no icon sets. The page is
 * cross-origin isolated (COOP/COEP), so anything third-party would need
 * CORP headers it will not have -- and a 40 KB icon font to draw three
 * glyphs would be a poor trade in any case.
 */

:root {
  --bg:      #07090d;
  --panel:   #11141b;
  --panel2:  #171b24;
  --line:    #262c39;
  --ink:     #e8ecf4;
  --dim:     #98a1b3;
  --accent:  #4ea3ff;
  --accent2: #ffc247;
  --bad:     #ff6b6b;
  --good:    #56d38a;
  --pad-size: 1;          /* set from settings */
  --pad-alpha: 0.55;
  --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);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;          /* no pull-to-refresh over the game */
  -webkit-text-size-adjust: 100%;
}

body { overflow: hidden; }
body.scroll { overflow: auto; }        /* set while a screen is up */

h1 { font-size: 1.5rem; margin: 0 0 .2em; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin: 1.6em 0 .6em; color: var(--accent2);
     text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
p  { margin: 0 0 1em; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
code { background: #0d1017; padding: .1em .35em; border-radius: 3px;
       font-size: .9em; }

/* ---------------------------------------------------------------- stage -- */

#stage {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #000;
  /* The whole reason this element exists as a separate layer: these four
   * properties are what stop a phone browser from treating a fighting game
   * as a document. */
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#stage[hidden] { display: none; }

#frame {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}

#canvas {
  display: block;
  background: #000;
  image-rendering: pixelated;
  max-width: 100%; max-height: 100%;
  outline: none;
  /* width/height in CSS pixels are set by stf_layout.js -- the aspect the
   * engine is presenting is a runtime fact, not a stylesheet one. */
}

/* Portrait on a phone: the picture sits high so the controls below it have
 * somewhere to be, instead of being centred behind them. */
body.portrait #frame { align-items: flex-start; padding-top: calc(var(--safe-t) + 6px); }

/* ------------------------------------------------------------------ hud -- */

#hud {
  position: absolute;
  top: calc(var(--safe-t) + 8px);
  right: calc(var(--safe-r) + 8px);
  display: flex; gap: 6px;
  z-index: 30;
  transition: opacity .35s;
}
#hud.faded { opacity: .18; }
#hud.faded:hover { opacity: 1; }

.hudbtn {
  font: 600 12px/1 system-ui, sans-serif;
  letter-spacing: .06em;
  min-width: 44px; min-height: 44px;      /* the accessibility floor, and
                                             also the thumb floor */
  padding: 0 10px;
  color: var(--ink);
  background: rgba(10,13,19,.72);
  border: 1px solid rgba(120,140,180,.35);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  cursor: pointer;
  touch-action: manipulation;
}
.hudbtn:active { background: rgba(78,163,255,.35); }

/* ---------------------------------------------------- the online readout -- *
 *
 * Top LEFT, opposite the HUD, because the HUD fades to 18% on its own and this
 * must not: a link that has gone quiet is exactly when a player looks up. */
#netbar {
  position: absolute;
  top: calc(var(--safe-t) + 8px);
  left: calc(var(--safe-l) + 8px);
  z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: 0 8px 0 12px;
  min-height: 44px;
  font: 600 12px/1 system-ui, sans-serif;
  letter-spacing: .04em;
  color: var(--ink);
  background: rgba(10,13,19,.78);
  border: 1px solid rgba(120,140,180,.35);
  border-radius: 12px;
  backdrop-filter: blur(6px);
  max-width: calc(100% - 24px);
}
/* `display: flex` on an id beats the user agent's `[hidden] { display: none }`,
 * so the bar appeared over the game with nothing connected. Restated at the
 * same specificity. */
#netbar[hidden] { display: none; }
#netbar .hudbtn { min-height: 34px; min-width: 34px; font-size: 11px; padding: 0 8px; }
#netbar .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #d2a24c;                      /* connecting                    */
  box-shadow: 0 0 8px currentColor;
  flex: none;
}
#netbar.live  .dot { background: #4ec98a; }
#netbar.relay .dot { background: #4ea3ff; }
#netbar.bad   .dot { background: #e2585c; }
#netbar-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#netdetail {
  position: absolute;
  top: calc(var(--safe-t) + 58px);
  left: calc(var(--safe-l) + 8px);
  z-index: 30;
  max-width: min(92vw, 460px);
  padding: 10px 12px;
  font: 11px/1.7 ui-monospace, Consolas, monospace;
  white-space: pre-wrap;
  color: var(--dim);
  background: rgba(10,13,19,.92);
  border: 1px solid rgba(120,140,180,.3);
  border-radius: 12px;
}

#toast {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 16px);
  max-width: min(90vw, 460px);
  padding: 10px 14px;
  background: rgba(10,13,19,.9);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px; color: var(--ink);
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
  z-index: 40;
  text-align: center;
}
#toast.show { opacity: 1; }

/* --------------------------------------------------------------- screens -- */

.screen {
  position: fixed; inset: 0;
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 16px)
           calc(var(--safe-b) + 16px) calc(var(--safe-l) + 16px);
  background:
    radial-gradient(1200px 700px at 50% -10%, #131a2b 0%, transparent 60%),
    var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen[hidden] { display: none; }

.card {
  width: 100%; max-width: 560px;
  margin: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px 26px 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
}
.card.wide { max-width: 720px; }

.sub  { color: var(--dim); margin-top: -.2em; }
.status { font-size: 14px; color: var(--ink); margin: 12px 0 4px; }
.detail { font: 12px/1.6 ui-monospace, Consolas, monospace; color: var(--dim);
          white-space: pre-wrap; word-break: break-word; }
.fineprint { font-size: 12.5px; color: var(--dim); }

/* the capability check ------------------------------------------------------
 *
 * A list, not a paragraph, because the five gates behind it fail
 * independently: the reader has to be able to see WHICH line is the ✗ without
 * parsing prose. The failing line is the only one that gets a background and
 * a border, for the same reason.
 *
 * `pre-wrap` on the body text is load-bearing -- the findings in stf_caps.js
 * contain newlines and an indented list of candidate causes, and reflowing
 * them into a wall would undo the point of writing them out. */
.checks { list-style: none; margin: 14px 0 10px; padding: 0;
          display: grid; gap: 8px; }
.chk { display: grid; grid-template-columns: 1.2em 1fr; gap: 8px;
       align-items: start; font-size: 13.5px; line-height: 1.5; }
.chk .mark { font-weight: 700; text-align: center; line-height: 1.5; }
.chk-label { color: var(--ink); }
.chk-text  { color: var(--dim); font-size: 12.5px; margin-top: 4px;
             white-space: pre-wrap; }
.chk.ok   { color: var(--dim); }
.chk.ok .mark { color: var(--good); }
.chk.ok .chk-label { color: var(--dim); }
.chk.warn .mark { color: var(--accent2); }
.chk.warn .chk-label { color: var(--accent2); }
.chk.fail { border: 1px solid #5a2a30; background: #1a1013; border-radius: 10px;
            padding: 10px 12px 11px; grid-template-columns: 1.2em 1fr; }
.chk.fail .mark { color: var(--bad); }
.chk.fail .chk-label { color: var(--bad); font-weight: 600; }
.chk.fail .chk-text { color: #d7ccc9; }

.detail.raw { margin-top: 10px; padding: 10px 12px; background: #0c0f16;
              border: 1px solid var(--line); border-radius: 10px;
              max-height: 40vh; overflow: auto; white-space: pre;
              user-select: all; -webkit-user-select: all; }

.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

button {
  font: 600 14px/1 system-ui, sans-serif;
  min-height: 44px; padding: 0 18px;
  border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink);
  touch-action: manipulation;
}
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent);
                 color: #06101d; }
button.primary:disabled { background: #2b3a4d; border-color: #2b3a4d;
                          color: #7d8ba0; }
button.danger  { background: transparent; border-color: #63333a; color: #ff9b9b; }
button.ghost   { background: transparent; }
button.small   { min-height: 34px; padding: 0 12px; font-size: 13px; }
button.link {
  background: none; border: none; padding: 0; min-height: 0;
  color: var(--accent); text-decoration: underline; font-size: inherit;
  font-weight: 500;
}

/* agreement ---------------------------------------------------------------- */

ol.terms { margin: 18px 0; padding-left: 1.1em; }
ol.terms li { margin-bottom: 14px; color: var(--dim); }
ol.terms strong { color: var(--ink); display: block; margin-bottom: 2px; }

.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 18px;
         padding: 14px; border: 1px solid var(--line); border-radius: 10px;
         background: var(--panel2); cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 0; flex: none;
               accent-color: var(--accent); }

/* rom ---------------------------------------------------------------------- */

#drop {
  margin: 18px 0;
  border: 2px dashed #2f3a4d; border-radius: 14px;
  background: #0c0f16;
  padding: 30px 18px;
  text-align: center;
  transition: border-color .15s, background .15s;
  cursor: pointer;
}
#drop.over { border-color: var(--accent); background: #101a2a; }
#drop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropicon { font-size: 30px; color: var(--accent); line-height: 1; }
.dropmain { font-size: 16px; font-weight: 600; margin: 10px 0 6px; }
.dropalt  { font-size: 13.5px; color: var(--dim); }
.dropnote { font-size: 12px; color: var(--dim); margin-top: 10px; }

.bar { height: 8px; background: #0c0f16; border: 1px solid var(--line);
       border-radius: 99px; overflow: hidden; }
#rom-bar { height: 100%; width: 0; background: var(--accent);
           transition: width .18s linear; }

ul.log { list-style: none; margin: 10px 0 0; padding: 0;
         font: 12px/1.7 ui-monospace, Consolas, monospace;
         max-height: 220px; overflow-y: auto; }
ul.log li { display: flex; gap: 8px; color: var(--dim); }
ul.log li .ok  { color: var(--good); }
ul.log li .bad { color: var(--bad); }

.error { border: 1px solid #5a2a30; background: #1a1013; border-radius: 12px;
         padding: 16px; margin-top: 16px; }
.error h2 { margin: 0 0 8px; color: var(--bad); text-transform: none;
            letter-spacing: 0; font-size: 15px; }
/* Prose wraps; a `pre` block does not -- its alignment is the message. It
 * scrolls sideways inside its own box so it can never widen the page. */
#rom-error-body { margin: 0; }
#rom-error-body p { margin: 0 0 .8em; font-size: 13.5px; line-height: 1.55;
                    color: #edd6d6; }
#rom-error-body p:last-child { margin-bottom: 0; }
#rom-error-body pre { margin: 0 0 .8em; padding: 8px 10px; overflow-x: auto;
                      background: #120b0d; border: 1px solid #40232a;
                      border-radius: 8px; font-size: 12px; line-height: 1.6;
                      color: #ffd7d7; white-space: pre; }

.have { border: 1px solid #244b36; background: #0e1713; border-radius: 12px;
        padding: 16px; margin-top: 16px; }
.have h2 { margin: 0 0 10px; color: var(--good); font-size: 15px;
           text-transform: none; letter-spacing: 0; }
.have dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px;
           margin: 0; font-size: 13px; }
.have dt { color: var(--dim); }
.have dd { margin: 0; font-family: ui-monospace, Consolas, monospace; }

details.why { margin-top: 14px; border-top: 1px solid var(--line);
              padding-top: 12px; }
details.why summary { cursor: pointer; color: var(--accent); font-size: 14px;
                      font-weight: 600; }
details.why p { font-size: 13px; color: var(--dim); margin: 10px 0 0; }

/* settings ----------------------------------------------------------------- */

.settings { display: grid; gap: 8px; }
/* Flex rather than a fixed grid: on a 390-point phone a three-column grid
 * squeezed "On-screen controls" into three wrapped lines next to a wide
 * select. Wrapping puts the control on its own line instead, which is what
 * the space actually allows. */
.set { display: flex; flex-wrap: wrap; align-items: center;
       justify-content: space-between; gap: 8px 12px;
       padding: 9px 12px; background: var(--panel2);
       border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.set > span { flex: 1 1 8em; }
.set select, .set input[type=range] { min-height: 32px; flex: 0 1 auto; }
.set input[type=range] { min-width: 140px; }
.set select { background: #0c0f16; color: var(--ink); border: 1px solid var(--line);
              border-radius: 7px; padding: 5px 8px; font-size: 13px; }
.set input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.set output { font: 12px ui-monospace, Consolas, monospace; color: var(--dim);
              min-width: 3.2em; text-align: right; margin-left: auto; }

.padlist { font: 13px/1.7 ui-monospace, Consolas, monospace; color: var(--dim);
           background: var(--panel2); border: 1px solid var(--line);
           border-radius: 10px; padding: 10px 12px; }
.padlist .on { color: var(--good); }
.binds { margin-top: 10px; display: grid; gap: 6px; }
.bindrow { display: grid; grid-template-columns: 1fr auto auto; gap: 10px;
           align-items: center; background: var(--panel2);
           border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
           font-size: 13px; }
.bindrow .what { font-family: ui-monospace, Consolas, monospace; color: var(--dim); }
.bindrow.listening { border-color: var(--accent2); }

/* ------------------------------------------------------------ touch pad -- */

#pad {
  position: absolute; inset: 0;
  z-index: 20;
  /* The surface takes every pointer and hit-tests them itself. A touch
   * pointer is implicitly captured by the element it went down on, so
   * per-element listeners would keep sending `pointermove` to the button the
   * thumb has already slid off -- see the note at the top of stf_touch.js. */
  pointer-events: auto;
  opacity: var(--pad-alpha);
  touch-action: none;
}
#pad[hidden] { display: none; }
#pad.arranging { opacity: .95; }

.tc {                                /* a touch control */
  position: absolute;
  pointer-events: auto;
  display: flex; align-items: center; justify-content: center;
  font: 700 13px/1 system-ui, sans-serif;
  letter-spacing: .05em;
  color: #dfe7f5;
  border: 2px solid rgba(190,210,240,.55);
  background: rgba(18,24,36,.5);
  border-radius: 999px;
  transform: translate(-50%, -50%);
  transition: background .06s, border-color .06s;
  will-change: transform;
}
.tc.down { background: rgba(78,163,255,.55); border-color: #cfe4ff; }

/* the stick */
#tc-stick { border-width: 2px; }
#tc-knob {
  position: absolute; pointer-events: none;
  border-radius: 999px;
  background: rgba(190,210,240,.5);
  border: 2px solid rgba(230,240,255,.75);
  transform: translate(-50%, -50%);
}
/* the fixed d-pad's four arms */
.tc.arm { border-radius: 14px; }

/* the three action buttons keep the arcade panel's own names */
#tc-punch   { border-color: rgba(255,140,140,.7); }
#tc-kick    { border-color: rgba(140,220,255,.7); }
#tc-barrier { border-color: rgba(255,220,140,.7); }

.tc.sys { font-size: 11px; border-radius: 10px; border-width: 1px;
          background: rgba(18,24,36,.42); }

#arrange-bar {
  position: fixed; z-index: 200;
  left: 50%; transform: translateX(-50%);
  top: calc(var(--safe-t) + 10px);
  display: flex; gap: 12px; align-items: center;
  background: rgba(10,13,19,.92); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 12px; font-size: 13px;
}
#arrange-bar[hidden] { display: none; }

/* ------------------------------------------------------------- narrow -- */

@media (max-width: 560px) {
  .card { padding: 20px 16px 18px; border-radius: 14px; }
  h1 { font-size: 1.3rem; }
}

/* Landscape phone: the screens themselves must not become a scroll pit. */
@media (max-height: 460px) and (orientation: landscape) {
  .screen { align-items: flex-start; }
  .card { padding: 16px; }
  ol.terms li { margin-bottom: 9px; }
}

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