:root {
  --bg: #04070c;
  --panel: #11151b;
  --panel-2: #1b2125;
  --line: #394246;
  --line-2: #525a5e;
  --fg: #e7edf0;
  --dim: #8ea0a6;
  --muted: #9fb0b8;
  --cyan: #57f2db;
  --amber: #ffb648;
  --danger: #ff8a8a;
  --tap: 44px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(720px 520px at 18% 0%, rgba(87, 242, 219, .10), transparent 66%),
    radial-gradient(900px 500px at 100% 0%, rgba(255, 182, 72, .05), transparent 58%),
    var(--bg);
  color: var(--fg);
  font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

button, a { font: inherit; }
button { cursor: pointer; }

.player {
  width: min(1240px, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.title {
  flex: 1 1 240px;
  margin: 0;
  color: var(--cyan);
  font-size: clamp(1.1rem, 3vw, 1.55rem);
  letter-spacing: .12em;
  text-transform: uppercase;
  text-shadow: 0 0 20px rgba(87, 242, 219, .22);
  overflow-wrap: anywhere;
}

/* Mobile menu: the sidebar becomes a burger-toggled drawer. */
.button.menu-toggle {
  display: none;
  flex: 0 0 auto;
  width: var(--tap);
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0;
}
.menu-bars {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
}
.menu-bars span {
  width: 18px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
}
.button.menu-close {
  display: none;
  flex: 0 0 auto;
  min-width: 36px;
  min-height: 36px;
  padding: 0 10px;
  font-size: 1.1rem;
  line-height: 1;
}
.menu-scrim {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(2, 4, 6, .62);
}

.button {
  min-height: 36px;
  padding: 7px 12px;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.button:hover { border-color: #6f7b80; }
.button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}
.button:disabled { opacity: .45; cursor: default; }

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 18px;
  align-items: start;
}

.screenwrap {
  position: relative;
  width: 100%;
  min-width: 0;
  align-self: stretch;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.screen {
  position: relative;
  width: 100%;
  max-width: calc(76dvh * 1.3333);
  aspect-ratio: 4 / 3;
  background: #000;
  border: 1px solid rgba(87, 242, 219, .26);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .55), 0 0 60px rgba(87, 242, 219, .06);
}

.screen.web {
  aspect-ratio: auto;
  align-self: stretch;
  height: 100%;
  min-height: min(76dvh, 620px);
  max-width: 900px;
}

.screen > iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

/* JSSpeccy has no soft keyboard, so phones get an on-screen Spectrum pad. */
.screenwrap.has-touch { flex-wrap: wrap; gap: 10px; }
.screenwrap.has-touch .screen { flex: 0 0 auto; }
.screenwrap.has-touch .speccy-touch { flex: 1 1 100%; }
.speccy-touch {
  display: flex; align-items: center; justify-content: center; gap: 20px;
  padding: 10px 12px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px;
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.speccy-touch .touch-dpad {
  display: grid; gap: 4px;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  grid-template-areas: ". up ." "left . right" ". down .";
}
.speccy-touch .touch-actions {
  display: grid; grid-template-columns: repeat(2, minmax(58px, auto)); gap: 8px;
}
.speccy-touch .touch-actions button[data-key="music"] { grid-column: 1 / -1; }
.speccy-touch button {
  min-width: 44px; min-height: 44px; padding: 0 8px;
  color: var(--fg); background: #1b2130;
  border: 1px solid var(--line); border-radius: 10px;
  font: inherit; font-size: 12px; font-weight: 600;
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; cursor: pointer;
}
.speccy-touch button.pressed {
  color: #06121f; background: var(--accent); border-color: var(--accent);
}
.speccy-touch button[data-key="up"] { grid-area: up; }
.speccy-touch button[data-key="left"] { grid-area: left; }
.speccy-touch button[data-key="down"] { grid-area: down; }
.speccy-touch button[data-key="right"] { grid-area: right; }

@media (max-width: 420px) {
  .speccy-touch { gap: 12px; padding: 8px; }
  .speccy-touch .touch-actions {
    grid-template-columns: repeat(2, minmax(50px, auto));
  }
}

.boot {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px;
  text-align: center;
  background: radial-gradient(circle at 50% 45%, #0b1b24 0%, #020406 72%);
  color: var(--fg);
}
.boot strong {
  color: var(--cyan);
  letter-spacing: .18em;
  text-transform: uppercase;
}
.boot span { color: var(--dim); font-size: .92rem; }

/* --------------------------------------------------------------- sidebar */
.panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  overflow: hidden;
  border: 1px solid var(--line-2);
  border-radius: 14px;
  background:
    radial-gradient(circle at 12px 12px, #d4dde0 0 1.1px, #4a5154 1.5px 2.2px, transparent 2.7px),
    radial-gradient(circle at calc(100% - 12px) 12px, #d4dde0 0 1.1px, #4a5154 1.5px 2.2px, transparent 2.7px),
    radial-gradient(circle at 12px calc(100% - 12px), #d4dde0 0 1.1px, #4a5154 1.5px 2.2px, transparent 2.7px),
    radial-gradient(circle at calc(100% - 12px) calc(100% - 12px), #d4dde0 0 1.1px, #4a5154 1.5px 2.2px, transparent 2.7px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .018) 0 1px, transparent 1px 4px),
    linear-gradient(160deg, #2a3034, #0e1113 58%, #1b2124);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .11),
    inset 0 -24px 50px rgba(0, 0, 0, .55),
    0 18px 40px rgba(0, 0, 0, .35);
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.sidebar-head .variants { flex: 1 1 auto; min-width: 0; }

/* Media bay: the same tape / disk / cartridge / web icons as the game page. */
.deck {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  overflow: hidden;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .08), transparent 22%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .02) 0 1px, transparent 1px 5px),
    linear-gradient(155deg, #2a3034, #0f1315 64%, #1b2124);
  box-shadow:
    inset 0 2px 1px rgba(255, 255, 255, .07),
    inset 0 -10px 20px rgba(0, 0, 0, .72),
    0 8px 18px rgba(0, 0, 0, .34);
}

.deck-media {
  position: relative;
  flex: 0 0 86px;
  display: grid;
  place-items: center;
  width: 86px;
  height: 56px;
  overflow: hidden;
  border: 1px solid #050708;
  border-radius: 8px;
  background: linear-gradient(180deg, #020304, #080a0b);
  box-shadow:
    inset 0 0 0 2px #3a4246,
    inset 0 8px 18px rgba(0, 0, 0, .95),
    0 1px 0 rgba(255, 255, 255, .08);
}

.deck-media::before {
  content: "";
  position: absolute;
  inset: 2px 2px auto;
  height: 38%;
  border-radius: 6px 6px 34% 34%;
  background: linear-gradient(180deg, rgba(255, 255, 255, .14), transparent);
  pointer-events: none;
}

.media-art {
  display: none;
  width: 76px;
  height: 48px;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .55));
}

.deck[data-media="tape"] .media-tape,
.deck[data-media="disk"] .media-disk,
.deck[data-media="cartridge"] .media-cartridge,
.deck[data-media="web"] .media-web { display: block; }

.media-shell {
  fill: #23282b;
  stroke: #7b8a90;
  stroke-width: 1.2;
}
.media-face {
  fill: #e7ddc2;
  stroke: #b6aa88;
  stroke-width: 1;
}
.media-reel {
  fill: none;
  stroke: #413a2c;
  stroke-width: 2;
  opacity: .9;
  transform-box: fill-box;
  transform-origin: center;
}
.media-hub { fill: #1a1812; opacity: .85; }
.media-detail { fill: rgba(40, 35, 25, .45); }
.media-shutter { fill: rgba(60, 53, 38, .55); }
.media-rule { stroke: #a99d7f; stroke-width: 1.2; }

.deck.is-loading .media-reel { animation: spin 2.4s linear infinite; }

.deck-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.deck-label {
  color: var(--dim);
  font-size: .58rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, .8);
}
.deck-meta strong {
  color: #e7f1f2;
  font-size: .96rem;
  font-weight: 400;
  letter-spacing: .14em;
  text-transform: uppercase;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .12), 0 -1px 0 rgba(0, 0, 0, .9);
}
.deck-meta::after {
  content: "000";
  align-self: flex-start;
  margin-top: 3px;
  padding: 1px 5px 0;
  border: 1px solid #3b4347;
  border-radius: 3px;
  color: var(--amber);
  background: #050504;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, .95);
  font-size: .62rem;
  letter-spacing: .22em;
  line-height: 1.2;
  text-shadow: 0 0 7px rgba(255, 182, 72, .72);
}
.deck-led {
  width: 7px;
  height: 7px;
  margin-left: auto;
  border-radius: 50%;
  background: #353d40;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18);
}
.deck.is-loading .deck-led {
  background: var(--amber);
  box-shadow: 0 0 12px rgba(255, 182, 72, .9);
  animation: pulse 1.1s ease-in-out infinite;
}

/* System selector as a rack of rocker keys. */
.systemgroup {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.systemhead {
  color: var(--dim);
  font-size: .58rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, .8);
}
.systems {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}
.system {
  position: relative;
  width: 100%;
  min-height: 30px;
  padding: 4px 20px 4px 8px;
  justify-content: flex-start;
  overflow: hidden;
  border: 1px solid #4e575b;
  border-radius: 6px;
  color: #c9d6d9;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .022) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, #353c40, #171b1e);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .12),
    inset 0 -2px 0 rgba(0, 0, 0, .5),
    0 2px 0 #050708;
  font-size: .66rem;
  letter-spacing: .05em;
  text-align: left;
  text-transform: uppercase;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, .8);
  white-space: nowrap;
  text-overflow: ellipsis;
}
.system:hover,
.system:focus-visible {
  border-color: #6f7b80;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .03) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, #3f474b, #1d2225);
}
.system.active {
  color: #f2f8fa;
  border-color: #75838a;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .03) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, #434c51, #20262a);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .18),
    inset 0 -2px 0 rgba(0, 0, 0, .5),
    0 1px 0 #050708;
}
.system::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 8px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #353d40;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12);
  transform: translateY(-50%);
}
.system.active::after {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
}

.panelhead { display: flex; flex-direction: column; gap: 2px; }
.systemlabel {
  color: var(--cyan);
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.status { min-height: 1em; color: var(--dim); font-size: .82rem; }
.status.bad { color: var(--danger); }
.hint { margin: 0; color: var(--fg); font-size: .9rem; }
.keys { margin: 0; color: var(--muted); font-size: .8rem; }
kbd {
  padding: 1px 5px;
  color: var(--fg);
  background: #1b2130;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .button {
  flex: 1 1 auto;
  border-color: #596266;
  border-top-color: #7d888d;
  border-radius: 6px;
  color: #e7edf0;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .025) 0 1px, transparent 1px 3px),
    linear-gradient(180deg, #3d4448 0%, #252b2e 45%, #14181a 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .24),
    inset 0 -4px 0 rgba(0, 0, 0, .65),
    0 4px 0 #050607;
  font-size: .64rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.actions .button:hover {
  border-color: #758187;
  border-top-color: #97a3a8;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .03) 0 1px, transparent 1px 3px),
    linear-gradient(180deg, #4a5257 0%, #2d3438 45%, #191e21 100%);
}
.actions .button:active {
  transform: translateY(3px);
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, .7), inset 0 1px 0 rgba(255, 255, 255, .12);
}

.fatal {
  max-width: 640px;
  margin: 15vh auto;
  padding: 24px;
  color: var(--danger);
  overflow-wrap: anywhere;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}

@media (max-width: 900px) {
  .player { padding: 0; gap: 0; }
  .topbar {
    padding: max(8px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right)) 8px
      max(10px, env(safe-area-inset-left));
  }
  .stage { grid-template-columns: 1fr; gap: 0; }
  .screenwrap { align-items: center; }
  .screenwrap.has-touch { align-content: space-between; }
  .screen {
    max-width: 100%;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  .screen.web { min-height: 64dvh; }
  .button.menu-toggle,
  .button.menu-close { display: inline-flex; }
  .panel {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 40;
    width: min(340px, 88vw);
    max-height: none;
    padding: 12px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    padding-right: max(12px, env(safe-area-inset-right));
    border-radius: 18px 0 0 18px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    transform: translateX(100%);
    visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
  }
  .panel.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform .22s ease, visibility 0s;
  }
  body.menu-open { overflow: hidden; }
}

@media (max-width: 520px) {
  .systems { grid-template-columns: 1fr; }
  .system { font-size: .62rem; }
}

/* Short landscape phones: fit the whole player to the viewport and compact the pad. */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 560px) {
  .player {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding: 0;
    gap: 0;
    overflow: hidden;
  }
  .topbar { flex-wrap: nowrap; gap: 8px; }
  .title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .stage {
    grid-template-rows: minmax(0, 1fr);
    gap: 10px;
    align-items: stretch;
    min-height: 0;
  }
  .screenwrap { min-height: 0; align-items: center; }
  .screen {
    width: 100%;
    height: 100%;
    max-width: 100%;
    aspect-ratio: auto;
    border: 0;
  }
  .screen.web { min-height: 0; }
  .panel { padding: 10px; gap: 8px; }
  .deck { display: none; }
  .keys { display: none; }
  .hint { font-size: .8rem; }
  .speccy-touch { gap: 12px; padding: 6px 8px; }
  .speccy-touch .touch-dpad {
    grid-template-columns: repeat(3, 36px);
    grid-template-rows: repeat(2, 36px);
    grid-template-areas: ". up ." "left down right";
    gap: 3px;
  }
  .speccy-touch .touch-actions { gap: 6px; grid-template-columns: repeat(2, minmax(46px, auto)); }
  .speccy-touch button { min-width: 36px; min-height: 36px; padding: 0 6px; font-size: 11px; }
}

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

/* Variant selector (shown only when a game exports more than one story). */
.variants[hidden] { display: none; }
.variants {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  min-width: 0;
  color: var(--dim);
  font-size: .62rem;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.variants label {
  color: var(--dim);
}
.variants select {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  min-height: 34px;
  padding: 5px 10px;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  letter-spacing: .08em;
  text-transform: none;
}
.variants select:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}
