:root {
  color-scheme: dark;
  --bg: #14171c;
  --fg: #f3efe8;
  --muted: #c8c2b8;
  --line: #343a44;
  --panel: #1c2128;
  --pass: #9ddeb4;
  --fail: #f0a090;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1.05rem;
  line-height: 1.55;
}

main {
  max-width: 40rem;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 3.5rem;
}

h1 {
  margin: 0 0 0.75rem;
  font-size: 1.7rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 650;
}

.lead,
.disclaimer {
  margin: 0 0 0.75rem;
  color: var(--muted);
}

section {
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

button {
  font: inherit;
  min-height: 2.75rem;
  padding: 0.45rem 1.15rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--panel);
  color: var(--fg);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#play-reason,
#frame-status {
  margin: 0.85rem 0 0;
  max-width: 38rem;
}

#frame {
  display: block;
  width: 100%;
  max-width: 800px;
  height: auto;
  background: transparent;
  border: 1px solid var(--line);
}

ul {
  margin: 0;
  padding-left: 1.2rem;
}

li {
  margin: 0.35rem 0;
}

.check[data-result="pass"] {
  color: var(--pass);
}

.check[data-result="fail"] {
  color: var(--fail);
}

#game-status {
  margin: 0;
  white-space: pre-wrap;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.45;
  background: var(--panel);
  border-radius: 0.4rem;
  padding: 0.9rem 1rem;
}

#log {
  max-height: 320px;
  overflow: auto;
  font-size: 12px;
  background: #111;
  color: #ddd;
  padding: 8px;
  white-space: pre-wrap;
  word-break: break-all;
}

#login {
  width: min(22rem, calc(100vw - 2rem));
  box-sizing: border-box;
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: var(--panel);
  color: var(--fg);
}

#login::backdrop {
  background: var(--bg);
}

#login label {
  display: block;
  margin: 1rem 0 0.35rem;
  color: var(--muted);
}

#login input {
  box-sizing: border-box;
  width: 100%;
  min-height: 2.75rem;
  padding: 0.45rem 0.7rem;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--bg);
  color: var(--fg);
}

#login p {
  margin: 0;
}

#login-error {
  min-height: 1.5rem;
  margin: 0.5rem 0 !important;
  color: var(--fail);
}

#login button {
  width: 100%;
}

#logout {
  margin-left: 0.5rem;
}

#load {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.85rem;
}

#load[hidden] {
  display: none;
}

#load-progress {
  flex: 1;
  height: 0.9rem;
  accent-color: var(--pass);
}

#load-text {
  min-width: 9rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* ---- On-screen gamepad (touchpad.js), touch screens only -------------- */
/* Console layout over the game: shoulders on top, d-pad and left stick on
 * the left, face buttons and right stick on the right. Sizes follow the
 * short side of the screen (vmin) so the pad fits any phone. Translucent
 * glass with white outlines; a control lights up while it is held. */
.pad {
  --glass: rgba(255, 255, 255, 0.13);
  --glass-on: rgba(255, 255, 255, 0.42);
  --line: rgba(255, 255, 255, 0.7);
  --edge: max(2vw, env(safe-area-inset-left), env(safe-area-inset-right));
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  color: #fff;
  font: 700 4.4vmin/1 system-ui, "Segoe UI", sans-serif;
}

.pad > *,
.pad-face > *,
.pad-center > * {
  pointer-events: auto;
}

.pad-look {
  position: absolute;
  inset: 0;
}

.pad-btn {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 2px solid var(--line);
  background: var(--glass);
  color: inherit;
  font: inherit;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  touch-action: none;
  cursor: pointer;
  transition: background 0.08s ease, transform 0.08s ease;
}

.pad-btn.on,
.pad-dpad i.on,
.pad-stick.on {
  background: var(--glass-on);
}

.pad-btn.on {
  transform: scale(0.92);
}

.pad-btn svg {
  width: 62%;
  height: 62%;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

/* Shoulders: rounded tabs, L2/R2 in the corners, L1/R1 a step inwards. */
.pad-shoulder {
  position: absolute;
  width: 17vmin;
  height: 12vmin;
  border-radius: 6vmin 6vmin 3vmin 3vmin;
}

.pad-l2 { left: var(--edge); top: 3vmin; }
.pad-l1 { left: calc(var(--edge) + 11vmin); top: 17vmin; }
.pad-r2 { right: var(--edge); top: 3vmin; }
.pad-r1 { right: calc(var(--edge) + 11vmin); top: 17vmin; }

/* D-pad: four arms around an empty middle; touchpad.js reads the finger's
 * position over the whole square. */
.pad-dpad {
  position: absolute;
  left: var(--edge);
  top: 33vmin;
  width: 36vmin;
  height: 36vmin;
  touch-action: none;
}

.pad-dpad i {
  position: absolute;
  width: 12vmin;
  height: 12vmin;
  border: 2px solid var(--line);
  background: var(--glass);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  transition: background 0.08s ease;
}

.pad-dpad i::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 0;
  height: 0;
  border: 1.6vmin solid transparent;
  border-bottom: 2.2vmin solid rgba(255, 255, 255, 0.85);
  border-top-width: 0;
  transform: translateY(-0.6vmin);
}

.pad-dpad [data-dir="up"] { left: 12vmin; top: 0; border-radius: 3vmin 3vmin 1vmin 1vmin; }
.pad-dpad [data-dir="down"] { left: 12vmin; bottom: 0; border-radius: 1vmin 1vmin 3vmin 3vmin; }
.pad-dpad [data-dir="left"] { left: 0; top: 12vmin; border-radius: 3vmin 1vmin 1vmin 3vmin; }
.pad-dpad [data-dir="right"] { right: 0; top: 12vmin; border-radius: 1vmin 3vmin 3vmin 1vmin; }
.pad-dpad [data-dir="down"]::after { transform: rotate(180deg) translateY(-0.6vmin); }
.pad-dpad [data-dir="left"]::after { transform: rotate(-90deg) translateY(-0.6vmin); }
.pad-dpad [data-dir="right"]::after { transform: rotate(90deg) translateY(-0.6vmin); }

/* Face buttons: the diamond on the right. */
.pad-face {
  position: absolute;
  right: var(--edge);
  top: 31vmin;
  width: 39vmin;
  height: 39vmin;
  pointer-events: none;
}

.pad-round {
  position: absolute;
  width: 13vmin;
  height: 13vmin;
  border-radius: 50%;
}

.pad-triangle { left: 13vmin; top: 0; }
.pad-square { left: 0; top: 13vmin; }
.pad-circle { right: 0; top: 13vmin; }
.pad-cross { left: 13vmin; bottom: 0; }

/* Sticks: a ring with a knob that follows the finger. */
.pad-stick {
  position: absolute;
  bottom: max(3vmin, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: 31vmin;
  height: 31vmin;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.16));
  touch-action: none;
  transition: background 0.08s ease;
}

.pad-stick-l { left: calc(var(--edge) + 31vmin); }
.pad-stick-r { right: calc(var(--edge) + 31vmin); }

.pad-knob {
  display: grid;
  place-items: center;
  width: 14vmin;
  height: 14vmin;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.35);
  font-size: 3.4vmin;
  color: rgba(255, 255, 255, 0.85);
  pointer-events: none;
}

.pad-stick.on .pad-knob {
  background: rgba(255, 255, 255, 0.5);
}

/* Menu (Esc) and OK (Enter), small, top centre. */
.pad-center {
  position: absolute;
  top: max(2.5vmin, env(safe-area-inset-top));
  left: 50%;
  display: flex;
  gap: 2.5vmin;
  transform: translateX(-50%);
  pointer-events: none;
}

.pad-pill {
  width: 13vmin;
  height: 8vmin;
  border-radius: 4vmin;
  font-size: 3.6vmin;
}

.pad-pill svg {
  width: 48%;
}

/* Portrait: a note to turn the phone (the pad still works). */
.pad-rotate {
  position: absolute;
  top: 38%;
  left: 50%;
  display: none;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  font: 600 0.95rem/1.2 system-ui, "Segoe UI", sans-serif;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
}

.pad-rotate svg {
  width: 1.6rem;
  height: 1.6rem;
}

@media (orientation: portrait) {
  .pad-rotate {
    display: flex;
  }
}

/* With the pad, the quit button moves out of R2's corner to the bottom
 * centre, and the keyboard hint is not shown. */
body.touch-pad .game-bar {
  top: auto;
  right: auto;
  bottom: max(2vmin, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  opacity: 0.6;
}

body.touch-pad #input-status {
  display: none;
}

body.touch-pad #frame {
  touch-action: none;
}

body.touch-pad .game-bar {
  z-index: 4;
}
