/* xpsi: a PS1 on a desk, hooked up to a big CRT monitor, with a controller plugged into port 1.
   On desktop the scene is laid out at a fixed 600x600 design size and scaled to fit, so it renders
   the same inside X's 600x600 player card and full screen; the disc rack stands beside it.
   On phones and tablets (.mobile) it becomes just the game picture with see-through buttons. */

:root {
  --bg: #121216;
  --ink: #6c6c77;
  --btn-hi: #5d5d66;
  --btn: #45454d;
  --btn-lo: #34343a;
  --tri: #2fbf95;
  --cir: #ee5a5f;
  --crs: #7d9cf0;
  --sqr: #ef8cc8;
  --led-off: #5a3434;
  --led-on: #4fe07a;
  --led-busy: #ffb32b;
  --led-err: #ff4d4d;
  --sheet: rgba(14, 14, 20, .94);
  --sheet-ink: #ecebf2;
  --sheet-dim: #a3a1b3;
  --accent: #8fb0ff;
  --lit-hi: #a9bcff;
  --lit: #6f88e0;
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 90% at 50% 0%, #1f1f27 0%, var(--bg) 60%);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.stage { position: fixed; inset: 0; }

/* ---------- the rig: the disc rack beside the framed scene, scaled together ---------- */
.rig {
  position: absolute; left: 50%; top: 50%;
  width: var(--rig-w, 600px); height: 600px;
  transform: translate(-50%, -50%) scale(var(--scale, 1));
}
.rig:not(.with-rack) .rack { display: none; }

/* ---------- the scene: wall, desk, and the light the screen throws on them ---------- */
@property --glow { syntax: "<number>"; inherits: true; initial-value: .08; }
.scene {
  --W: 600px; --H: 600px;
  /* monitor */
  --mon-top: 8px; --screen-w: 424px; --screen-h: 318px; --bezel: 18px; --chin: 30px; --desk-y: 397px;
  /* console */
  --ps-k: 1;
  /* controller */
  --pad-w: 316px; --pad-h: 158px; --dpad: 76px; --fb: 28px; --fo: 28px; --sys-w: 22px; --sys-h: 9px;
  --glow: .08;

  position: absolute; right: 0; top: 0;
  width: var(--W); height: var(--H);
  overflow: hidden;
  border-radius: 26px;
  background:
    radial-gradient(70% 34% at 50% var(--desk-y), rgba(120, 140, 255, var(--glow)), transparent 70%),
    linear-gradient(180deg, #1e1e27 0, #16161c var(--desk-y),
      #3d332b var(--desk-y), #2e261f calc(var(--desk-y) + 12px), #1b1613 100%);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .7), 0 0 0 1px rgba(255, 255, 255, .04);
  user-select: none; -webkit-user-select: none;
  transition: --glow .4s;
}
.scene[data-state="on"] { --glow: .2; }
.scene[data-state="loading"], .scene[data-state="paused"] { --glow: .13; }
/* Inside X the card is already framed; fill it edge to edge. */
.embedded .scene { border-radius: 0; box-shadow: none; }

.anchor { position: absolute; width: 0; height: 0; pointer-events: none; }

/* ---------- cables (paths are drawn by console.js from the anchors) ---------- */
.cables { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.cables.back { z-index: 1; }
.cables.front { z-index: 4; }
.cable { fill: none; stroke: #131317; stroke-width: 5; stroke-linecap: round; }
.cable-sheen { fill: none; stroke: rgba(255, 255, 255, .11); stroke-width: 1.3; stroke-linecap: round; transform: translate(-.8px, -1.3px); }
#cable-p1, #cable-p2 { stroke-width: 4; }
.plug { fill: #26262c; stroke: rgba(255, 255, 255, .1); stroke-width: .8; }
.p2-cable { opacity: 0; transition: opacity .4s; }
.p2-on .p2-cable { opacity: 1; }
#p2-tag rect { fill: #4f6fd8; }
#p2-tag text { fill: #fff; font: 800 9px system-ui, sans-serif; letter-spacing: .06em; }

/* ---------- monitor ---------- */
.monitor {
  position: absolute; left: 50%; top: var(--mon-top); z-index: 2;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
}
.monitor-body {
  /* Fixed to the screen size, so a long disc name in the chin can't stretch the monitor. */
  width: calc(var(--screen-w) + 14px + var(--bezel) * 2);
  padding: var(--bezel) var(--bezel) 0;
  border-radius: 26px 26px 18px 18px;
  background: linear-gradient(180deg, #383841, #28282e 55%, #202025);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .14), inset 0 -2px 0 rgba(0, 0, 0, .45),
    0 22px 30px -12px rgba(0, 0, 0, .75), 0 0 0 1px rgba(0, 0, 0, .65);
}
.bezel {
  padding: 7px; border-radius: 18px;
  background: linear-gradient(180deg, #111114, #1c1c21);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, .85), 0 1px 0 rgba(255, 255, 255, .07);
}
.chin { height: var(--chin); display: flex; align-items: center; gap: 10px; padding: 0 4px 0 6px; }
.mon-brand {
  font: italic 800 13px/1 system-ui, sans-serif; letter-spacing: .12em; color: #55555f;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, .7), 0 1px 0 rgba(255, 255, 255, .07);
}
.osd {
  flex: 1; min-width: 0; height: 16px; padding: 0 8px; border-radius: 4px;
  background: #0c0d10; box-shadow: inset 0 1px 2px rgba(0, 0, 0, .9), 0 1px 0 rgba(255, 255, 255, .05);
  color: #3f6650; font: 600 10px/16px ui-monospace, "Cascadia Mono", Menlo, monospace; letter-spacing: .14em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.scene:not([data-state="off"]) .osd { color: #93f2bb; text-shadow: 0 0 6px rgba(120, 255, 170, .45); }
.tools { display: flex; gap: 5px; }
.tool {
  display: grid; place-items: center; width: 26px; height: 18px; padding: 0; border: 0; border-radius: 5px;
  background: linear-gradient(180deg, #3d3d46, #2a2a31); color: #a2a2b0;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .7), inset 0 1px 0 rgba(255, 255, 255, .09);
}
.tool:hover { color: #fff; }
.tool:active { transform: translateY(1px); }
.tool svg { width: 11px; height: 11px; }
.foot {
  position: relative; width: 44%; height: 12px; margin-top: -1px;
  background: linear-gradient(180deg, #232329, #141418);
  clip-path: polygon(7% 0, 93% 0, 100% 100%, 0 100%);
}
#monitor-plug { left: 30%; top: 2px; }

/* ---------- screen ---------- */
.screen {
  position: relative; overflow: hidden;
  width: var(--screen-w); height: var(--screen-h);
  border-radius: 14px / 16px; background: #000;
}
.screen::after { /* soft CRT vignette and a little glass reflection */
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 5; border-radius: inherit;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, .07), transparent 38%),
    radial-gradient(130% 120% at 50% 50%, transparent 60%, rgba(0, 0, 0, .4) 100%);
}
.frame-host, .frame-host iframe, .frame-host video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.frame-host video { object-fit: contain; background: #000; pointer-events: none; }
/* The emulator never takes focus or pointer input; the shell forwards everything. */
.frame-host iframe { pointer-events: none; }

/* Overlays drawn on the screen. When the scene is scaled down (phones, small cards) they are
   scaled back up by --ui so their text stays readable; they lay out in a smaller box instead. */
.boot, .veil, .sheet {
  position: absolute; left: 0; top: 0;
  width: calc(100% / var(--ui, 1)); height: calc(100% / var(--ui, 1));
  transform: scale(var(--ui, 1)); transform-origin: 0 0;
}

/* boot / status screen */
.boot {
  z-index: 2;
  display: grid; grid-template-rows: 1fr auto auto auto; grid-template-columns: minmax(0, 1fr);
  justify-items: center; align-content: center; gap: 12px;
  padding: 18px 22px 12px;
  background:
    radial-gradient(80% 70% at 50% 30%, rgba(122, 140, 255, .16), transparent 70%),
    linear-gradient(180deg, #0b0b12, #050508);
  color: #f1f0f7; text-align: center;
  transition: opacity .35s ease;
}
.scene[data-state="on"] .boot, .scene[data-state="paused"] .boot { opacity: 0; pointer-events: none; }

.cd {
  align-self: end;
  width: 92px; height: 92px; border-radius: 50%;
  position: relative;
  background:
    radial-gradient(circle, #050508 0 9%, #c8ccd6 9.5% 15%, rgba(255, 255, 255, .12) 15.5% 17%, transparent 17.5%),
    conic-gradient(from 20deg, #9fb3ff, #f1a7d9, #ffe4a3, #a6f0d4, #9fb3ff, #e1b0ff, #ffd0a3, #9fe6ff, #9fb3ff);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .25), 0 10px 30px rgba(120, 140, 255, .25);
}
.cd i { /* label sheen */
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 200deg, transparent 0 20%, rgba(255, 255, 255, .55) 25%, transparent 30% 70%, rgba(255, 255, 255, .35) 75%, transparent 80%);
  mix-blend-mode: soft-light;
}
.scene[data-state="loading"] .cd { animation: spin 1.1s linear infinite; }
.cd.empty { filter: grayscale(1) brightness(.5); }
@keyframes spin { to { transform: rotate(360deg); } }

.boot-text { display: grid; grid-template-columns: minmax(0, 1fr); gap: 5px; justify-items: center; width: 100%; min-width: 0; }
.boot-title { display: block; font-size: 17px; letter-spacing: .02em; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.boot-status { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.boot-status { font-size: 12px; color: #a9a7bb; min-height: 1.2em; }
.scene[data-state="error"] .boot-status { color: #ff9c9c; }
.meter { width: 180px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .12); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #8fb0ff, #e7a6ff); transition: width .2s; }
.boot-actions { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.boot-keys { margin: 0; font-size: 10.5px; color: #6f6d82; align-self: end; }
.touch .boot-keys { display: none; }

.cta, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 16px; border-radius: 16px; border: 0;
  font-size: 13px; font-weight: 650; text-decoration: none; white-space: nowrap;
}
.cta { background: #f1f0f7; color: #121218; box-shadow: 0 2px 10px rgba(143, 176, 255, .35); }
.cta:hover { background: #fff; }
.btn { background: rgba(255, 255, 255, .1); color: var(--sheet-ink); }
.btn:hover { background: rgba(255, 255, 255, .16); }
.cta.wide, .btn.wide { width: 100%; }
.cta svg { width: 12px; height: 12px; }
.cta:disabled { opacity: .45; cursor: default; box-shadow: none; }
.link { border: 0; background: none; color: #b8c6ff; font-size: 12px; padding: 4px 6px; text-decoration: underline; text-underline-offset: 3px; }

.veil {
  z-index: 3; border: 0;
  display: grid; place-content: center; justify-items: center; gap: 4px;
  background: rgba(5, 5, 10, .55); color: #fff; backdrop-filter: blur(2px);
}
.veil-badge { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: rgba(255, 255, 255, .14); margin-bottom: 6px; }
.veil-badge svg { width: 20px; height: 20px; }
.veil b { font-size: 15px; }
.veil small { font-size: 11.5px; color: #c9c7d8; }

.toast {
  position: absolute; left: 50%; bottom: calc(10px * var(--ui, 1)); z-index: 6; transform: translate(-50%, 8px);
  max-width: calc(100% - 24px); padding: calc(7px * var(--ui, 1)) calc(12px * var(--ui, 1)); border-radius: 10px;
  background: rgba(20, 20, 28, .92); color: #fff; font-size: calc(12px * var(--ui, 1)); text-align: center;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- menu sheet (lives inside the screen) ---------- */
.sheet {
  z-index: 4;
  display: grid; grid-template-rows: auto 1fr;
  background: var(--sheet); color: var(--sheet-ink); font-size: 12.5px;
}
.tabs { display: flex; gap: 2px; padding: 6px 6px 0; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.tabs button {
  border: 0; background: none; padding: 7px 9px 8px; border-radius: 8px 8px 0 0;
  color: var(--sheet-dim); font-size: 12px; font-weight: 650; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: #fff; box-shadow: inset 0 -2px 0 var(--accent); }
.tabs .close { margin-left: auto; padding: 6px 10px; }
.panel { overflow-y: auto; padding: 10px 14px 14px; display: none; scrollbar-width: thin; }
.panel.active { display: block; }
.panel h3 { margin: 14px 0 6px; font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--sheet-dim); }
.fine { margin: 6px 0 8px; color: var(--sheet-dim); font-size: 11.5px; line-height: 1.45; }
.fine a { color: var(--accent); }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.now { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.now b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now:empty { display: none; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.list li { display: flex; align-items: center; gap: 6px; }
.list .pick {
  flex: 1; min-width: 0; display: grid; text-align: left; gap: 1px;
  padding: 7px 10px; border-radius: 8px; border: 0; background: rgba(255, 255, 255, .06);
}
.list .pick:hover { background: rgba(255, 255, 255, .11); }
.list .pick b { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .pick small { color: var(--sheet-dim); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .x { border: 0; background: none; color: var(--sheet-dim); padding: 6px 8px; border-radius: 6px; }
.list .x:hover { color: #fff; background: rgba(255, 255, 255, .08); }

.keys { list-style: none; margin: 4px 0 10px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.keys li { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.keys span { color: var(--sheet-dim); }
.keys button {
  min-width: 84px; padding: 4px 8px; border-radius: 6px; border: 1px solid rgba(255, 255, 255, .12);
  background: rgba(255, 255, 255, .05); font-size: 11.5px; font-family: ui-monospace, monospace;
}
.keys button.capturing { border-color: var(--accent); color: var(--accent); }

/* play together */
.sheet.as-guest [data-tab="discs"], .sheet.as-guest [data-tab="saves"] { display: none; }
.code {
  margin: 4px 0 10px; text-align: center;
  font: 800 30px/1.1 ui-monospace, "Cascadia Mono", Menlo, monospace; letter-spacing: .32em; text-indent: .32em;
}
.invite { display: flex; gap: 6px; margin: 6px 0; }
.invite input {
  flex: 1; min-width: 0; height: 32px; padding: 0 10px; border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .14); background: rgba(255, 255, 255, .06); color: var(--sheet-ink);
  font: 12px ui-monospace, monospace;
}
.invite input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
#join-code { text-transform: uppercase; letter-spacing: .2em; font-size: 14px; }

/* ---------- LEDs (monitor + console) ---------- */
.led {
  width: 6px; height: 6px; border-radius: 50%; flex: none;
  background: var(--led-off); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .3);
}
.scene[data-state="on"] .led { background: var(--led-on); box-shadow: 0 0 6px var(--led-on); }
.scene[data-state="loading"] .led { background: var(--led-busy); box-shadow: 0 0 6px var(--led-busy); animation: blink 1s steps(2) infinite; }
.scene[data-state="paused"] .led { background: var(--led-busy); }
.scene[data-state="error"] .led { background: var(--led-err); box-shadow: 0 0 6px var(--led-err); }
@keyframes blink { 50% { opacity: .35; } }

/* ---------- the console (176x116, scaled by --ps-k) ---------- */
.ps1-wrap {
  position: absolute; z-index: 3; left: 20px; top: 458px;
  width: calc(176px * var(--ps-k)); height: calc(116px * var(--ps-k));
}
.ps1 {
  position: absolute; left: 0; top: 0; width: 176px; height: 116px;
  transform: scale(var(--ps-k)); transform-origin: 0 0;
  filter: drop-shadow(0 10px 9px rgba(0, 0, 0, .55));
}
#ps1-back { left: 82%; top: 6px; }
.ps1-top {
  position: absolute; left: 0; top: 0; width: 176px; height: 86px;
  border-radius: 13px 13px 3px 3px;
  background: linear-gradient(180deg, #d8d8de, #c4c4cb);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .85), inset 0 -1px 0 rgba(0, 0, 0, .12);
}
.ps1-top::before { /* the raised rear section */
  content: ""; position: absolute; left: 6px; right: 6px; top: 5px; height: 1px; background: rgba(0, 0, 0, .09);
}
.ps1-front {
  position: absolute; left: 0; top: 86px; width: 176px; height: 30px;
  border-radius: 2px 2px 10px 10px;
  background: linear-gradient(180deg, #ababb3, #95959e);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35);
}
.slot { position: absolute; top: 5px; width: 24px; height: 3px; border-radius: 2px; background: #4c4c55; box-shadow: 0 1px 0 rgba(255, 255, 255, .25); }
.port { position: absolute; top: 13px; width: 26px; height: 11px; border-radius: 3px 3px 5px 5px; background: #2a2a30; box-shadow: inset 0 2px 2px rgba(0, 0, 0, .6), 0 1px 0 rgba(255, 255, 255, .3); }
.slot.one { left: 21px; } .port.one { left: 20px; }
.slot.two { left: 57px; } .port.two { left: 56px; }
.p2-on .port.two { box-shadow: inset 0 2px 2px rgba(0, 0, 0, .6), 0 0 6px rgba(120, 150, 255, .8); }

.lid {
  position: absolute; left: 10px; top: 8px; width: 72px; height: 72px; padding: 0; border: 0; border-radius: 50%;
  overflow: hidden;
  background: radial-gradient(circle, rgba(40, 40, 50, .62) 0 58%, rgba(28, 28, 36, .8) 100%);
  box-shadow: 0 0 0 3px #bdbdc4, 0 0 0 4px rgba(0, 0, 0, .14), inset 0 2px 6px rgba(0, 0, 0, .6);
}
.lid-disc {
  position: absolute; inset: 6px; border-radius: 50%; opacity: 0; transition: opacity .3s;
  background:
    radial-gradient(circle, #1a1a22 0 10%, #9aa0ad 10.5% 17%, transparent 17.5%),
    conic-gradient(from 20deg, #9fb3ff, #f1a7d9, #ffe4a3, #a6f0d4, #9fb3ff, #e1b0ff, #ffd0a3, #9fe6ff, #9fb3ff);
}
.has-disc .lid-disc { opacity: .78; }
.scene[data-state="on"] .lid-disc { animation: spin .5s linear infinite; }
.scene[data-state="loading"] .lid-disc { animation: spin 1.2s linear infinite; }
.lid::after { /* smoked glass glare */
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: linear-gradient(140deg, rgba(255, 255, 255, .32), transparent 42%, transparent 70%, rgba(255, 255, 255, .08));
}
.ps1-open {
  position: absolute; left: 112px; top: 10px; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #e2e2e7, #b8b8bf);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .28), 0 0 0 2px rgba(0, 0, 0, .05);
}
.ps1-btn {
  position: absolute; top: 55px; width: 16px; height: 16px; padding: 0; border: 0; border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #dcdce1, #b1b1b9);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .28);
}
.ps1-btn.power { left: 102px; }
.ps1-btn.reset { left: 144px; }
.ps1-open:active, .ps1-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(0, 0, 0, .28); }
.ps1-led { position: absolute; left: 123px; top: 60px; width: 5px; height: 5px; }
.ps1-label { position: absolute; font: 700 5.5px/1 system-ui, sans-serif; letter-spacing: .12em; color: #80808a; }
.ps1-label.open { left: 119px; top: 45px; }
.ps1-label.power { left: 98px; top: 75px; }
.ps1-label.reset { left: 141px; top: 75px; }

/* ---------- controller ---------- */
.pad {
  position: absolute; z-index: 5; right: 16px; top: 432px;
  width: var(--pad-w); height: var(--pad-h);
}
.pad-body {
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1;
  pointer-events: none; overflow: visible;
  filter: drop-shadow(0 8px 8px rgba(0, 0, 0, .5));
}
.pad-nub {
  position: absolute; z-index: 2; left: 50%; top: 15%; width: 6%; height: 6%;
  transform: translate(-50%, -50%); border-radius: 3px;
  background: linear-gradient(180deg, #3a3a42, #222227);
}
.pad-brand {
  position: absolute; z-index: 2; left: 50%; top: 29%; transform: translate(-50%, -50%);
  font: italic 800 calc(var(--pad-w) * .037)/1 system-ui, sans-serif; letter-spacing: .1em;
  color: transparent; text-shadow: 0 1px 0 rgba(255, 255, 255, .7), 0 -1px 0 rgba(0, 0, 0, .22);
}
.shoulder {
  position: absolute; z-index: 0; top: -6%; width: 13%; height: 19%;
  display: flex; justify-content: center; align-items: flex-start; padding: 1.4% 0 0; border: 0;
  border-radius: calc(var(--pad-w) * .03) calc(var(--pad-w) * .03) 3px 3px;
  background: linear-gradient(180deg, #c4c4cb, #9e9ea7);
  color: #6a6a74; font-size: calc(var(--pad-w) * .026); font-weight: 800; letter-spacing: .04em; line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), 0 0 0 1px rgba(0, 0, 0, .12);
}
.shoulder.l2 { left: 12.2%; }
.shoulder.l1 { left: 24.8%; }
.shoulder.r1 { right: 24.8%; }
.shoulder.r2 { right: 12.2%; }

.pad .dpad, .pad .face { position: absolute; z-index: 2; top: 44%; transform: translate(-50%, -50%); }
.pad .dpad { left: 25%; }
.pad .face { left: 75%; }

.dpad {
  width: var(--dpad); height: var(--dpad); border-radius: 50%;
  background: radial-gradient(circle, #a8a8b0 0 32%, #b6b6bd 70%);
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, .25), inset 0 -2px 0 rgba(255, 255, 255, .4);
  touch-action: none;
}
.dpad::before { /* hub joining the four arms */
  content: ""; position: absolute; left: 34%; top: 34%; width: 32%; height: 32%;
  background: radial-gradient(circle, var(--btn-lo) 0 38%, var(--btn) 42%);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .35);
}
.arm {
  position: absolute; border: 0; padding: 0;
  width: 32%; height: 36%;
  background: linear-gradient(180deg, var(--btn-hi), var(--btn) 55%, var(--btn-lo));
  box-shadow: 0 2px 0 rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .14);
  pointer-events: none; /* the pad handles touches as one zone */
}
.arm::after { /* arrow */
  content: ""; position: absolute; left: 50%; top: 22%; transform: translateX(-50%);
  border: calc(var(--dpad) * .045) solid transparent; border-bottom: calc(var(--dpad) * .06) solid #8d8d98; border-top: 0;
}
.arm.up    { left: 34%; top: 4%; border-radius: 6px 6px 3px 3px; }
.arm.down  { left: 34%; bottom: 4%; border-radius: 6px 6px 3px 3px; transform: rotate(180deg); }
.arm.left  { left: 6%; top: 32%; border-radius: 6px 6px 3px 3px; transform: rotate(-90deg); }
.arm.right { right: 6%; top: 32%; border-radius: 6px 6px 3px 3px; transform: rotate(90deg); }

.face { width: calc(var(--fo) * 2 + var(--fb)); height: calc(var(--fo) * 2 + var(--fb)); touch-action: none; }
.fb {
  position: absolute; width: var(--fb); height: var(--fb); border-radius: 50%; border: 0; padding: 0;
  display: grid; place-items: center; color: var(--c);
  background: radial-gradient(circle at 50% 35%, var(--btn-hi), var(--btn) 60%, var(--btn-lo));
  box-shadow: 0 0 0 calc(var(--fb) * .12) rgba(0, 0, 0, .07), 0 2px 0 rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .15);
}
.fb svg { width: 56%; height: 56%; }
.fb.tri { left: var(--fo); top: 0; --c: var(--tri); }
.fb.cir { left: calc(var(--fo) * 2); top: var(--fo); --c: var(--cir); }
.fb.crs { left: var(--fo); top: calc(var(--fo) * 2); --c: var(--crs); }
.fb.sqr { left: 0; top: var(--fo); --c: var(--sqr); }

.pill {
  position: absolute; z-index: 2; top: 47%;
  width: var(--sys-w); height: var(--sys-h); border: 0; border-radius: 99px; padding: 0;
  background: linear-gradient(180deg, var(--btn-hi), var(--btn));
  box-shadow: 0 2px 0 rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .14);
  transform: translate(-50%, -50%) rotate(-14deg);
}
.pill.select { left: 44.3%; }
.pill.start { left: 55.7%; }
.pill-label {
  position: absolute; z-index: 2; top: 55%; transform: translateX(-50%);
  font-size: calc(var(--pad-w) * .019); font-weight: 800; letter-spacing: .08em; color: #74747f;
}
.pill-label.select { left: 44.3%; }
.pill-label.start { left: 55.7%; }

/* ---------- pressed: every button lights up while held (touch, keys or gamepad) ----------
   Face buttons glow in their own colour; everything else in the accent blue. */
.fb, .arm, .pill, .shoulder { transition: background .12s, box-shadow .12s, color .12s, transform .05s; }
.arm::after { transition: border-bottom-color .12s; }
.fb.is-down {
  transform: translateY(2px);
  color: #fff;
  background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--c) 80%, #fff), color-mix(in srgb, var(--c) 75%, #000) 78%);
  box-shadow: 0 0 0 calc(var(--fb) * .12) color-mix(in srgb, var(--c) 35%, transparent), 0 0 calc(var(--fb) * .6) calc(var(--fb) * .12) color-mix(in srgb, var(--c) 60%, transparent), inset 0 2px 3px rgba(0, 0, 0, .25);
  transition: none;
}
.arm.is-down {
  background: linear-gradient(180deg, var(--lit-hi), var(--lit) 60%, #5670c9);
  box-shadow: 0 0 calc(var(--dpad) * .16) 2px rgba(143, 176, 255, .7), inset 0 1px 0 rgba(255, 255, 255, .35);
  transition: none;
}
.arm.is-down::after { border-bottom-color: #fff; transition: none; }
.pill.is-down {
  transform: translate(-50%, -50%) rotate(-14deg) translateY(1px);
  background: linear-gradient(180deg, var(--lit-hi), var(--lit));
  box-shadow: 0 0 10px 2px rgba(143, 176, 255, .7);
  transition: none;
}
.shoulder.is-down {
  transform: translateY(1px);
  color: #fff;
  background: linear-gradient(180deg, var(--lit-hi), var(--lit));
  box-shadow: 0 0 12px 2px rgba(143, 176, 255, .65), inset 0 1px 0 rgba(255, 255, 255, .4);
  transition: none;
}

.shoulder:focus-visible, .lid:focus-visible, .ps1-open:focus-visible, .ps1-btn:focus-visible, .tool:focus-visible,
.cta:focus-visible, .btn:focus-visible, .link:focus-visible, .tabs button:focus-visible, .pick:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.fb:focus, .pill:focus, .arm:focus, .shoulder:focus:not(:focus-visible) { outline: none; }
[data-btn] { touch-action: none; }
.poster .boot-keys, .poster .link { display: none; }

/* ---------- volume ---------- */
/* A range input styled as the monitor's volume control; --v is the filled share, set by console.js. */
.vol {
  --v: 80%;
  -webkit-appearance: none; appearance: none;
  width: 64px; height: 18px; margin: 0; padding: 0; background: transparent; cursor: pointer;
}
.vol::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, #6fd99d var(--v), #0e0f12 var(--v));
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .9), 0 1px 0 rgba(255, 255, 255, .06);
}
.vol::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 12px; height: 12px; margin-top: -3px; border: 0; border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #e4e4ea, #9b9ba5);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .7);
}
.vol::-moz-range-track {
  height: 6px; border-radius: 3px; background: #0e0f12;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .9), 0 1px 0 rgba(255, 255, 255, .06);
}
.vol::-moz-range-progress { height: 6px; border-radius: 3px; background: #6fd99d; }
.vol::-moz-range-thumb {
  width: 12px; height: 12px; border: 0; border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #e4e4ea, #9b9ba5); box-shadow: 0 1px 2px rgba(0, 0, 0, .7);
}
.vol.is-muted::-webkit-slider-runnable-track { background: linear-gradient(90deg, #3b5a48 var(--v), #0e0f12 var(--v)); }
.vol.is-muted::-moz-range-progress { background: #3b5a48; }
.vol:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.vol-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.vol-row .vol { flex: 1; min-width: 0; height: 24px; }
.vol-value { width: 3.2em; text-align: right; color: var(--sheet-dim); font: 12px ui-monospace, monospace; }
.panel > h3:first-child { margin-top: 2px; }

/* The old-TV volume readout that flashes on screen. */
.tv-osd {
  position: absolute; z-index: 6; left: calc(14px * var(--ui, 1)); top: calc(14px * var(--ui, 1));
  display: flex; align-items: center; gap: calc(8px * var(--ui, 1));
  color: #8ef0b5; font: 700 calc(12px * var(--ui, 1))/1 ui-monospace, "Cascadia Mono", Menlo, monospace; letter-spacing: .12em;
  text-shadow: 0 0 6px rgba(120, 255, 170, .6), 0 1px 0 #000;
  opacity: 0; transition: opacity .25s; pointer-events: none;
}
.tv-osd.show { opacity: 1; transition: none; }
.tv-osd i {
  position: relative; display: block; width: calc(150px * var(--ui, 1)); height: calc(11px * var(--ui, 1));
  background: repeating-linear-gradient(90deg, rgba(142, 240, 181, .18) 0 calc(6px * var(--ui, 1)), transparent 0 calc(9.375px * var(--ui, 1)));
}
.tv-osd span {
  position: absolute; inset: 0; width: var(--v, 80%);
  background: repeating-linear-gradient(90deg, #8ef0b5 0 calc(6px * var(--ui, 1)), transparent 0 calc(9.375px * var(--ui, 1)));
  filter: drop-shadow(0 0 4px rgba(120, 255, 170, .6));
}

/* ---------- disc rack ---------- */
.rack {
  --rack-w: 132px; --rack-h: 420px; --spine-h: 18px; --spine-font: 7.5px;
  position: absolute; z-index: 2; left: 0; bottom: 6px;
  width: var(--rack-w); height: var(--rack-h); cursor: pointer; outline: none;
}
.rack::after { /* shadow on the floor */
  content: ""; position: absolute; left: -12%; right: -12%; bottom: -16px; height: 22px; z-index: -1;
  background: radial-gradient(closest-side, rgba(0, 0, 0, .65), transparent);
}
.rack-frame {
  position: absolute; inset: 0; padding: 7px 6px 9px;
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(90deg, #1f1f24, #34343c 18%, #2b2b32 82%, #1f1f24);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12), inset 0 -2px 0 rgba(0, 0, 0, .5),
    0 16px 18px -10px rgba(0, 0, 0, .75), 0 0 0 1px rgba(0, 0, 0, .65);
  transition: box-shadow .15s;
}
.rack-frame::before, .rack-frame::after { /* little feet */
  content: ""; position: absolute; bottom: -3px; width: 12px; height: 4px; border-radius: 0 0 2px 2px; background: #151518;
}
.rack-frame::before { left: 6px; }
.rack-frame::after { right: 6px; }
.rack-slots { display: flex; flex-direction: column; gap: 2px; height: 100%; overflow: visible; }
.spine {
  --band: #8fb0ff;
  position: relative; flex: none; height: var(--spine-h);
  display: flex; align-items: center; padding: 0 3px 0 calc(var(--spine-h) * .55 + 3px);
  border-radius: 2px; overflow: hidden;
  background: linear-gradient(180deg, #303037, #18181c 55%, #101013);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2), inset 0 -1px 0 rgba(0, 0, 0, .7);
  color: #e6e6ee; font: 700 var(--spine-font)/1 system-ui, sans-serif; letter-spacing: .05em; text-transform: uppercase;
  white-space: nowrap; text-overflow: clip;
  transition: transform .12s, filter .12s;
}
.spine::before { /* coloured band on the case spine */
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: calc(var(--spine-h) * .55); background: var(--band);
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, .35);
}
.spine.empty { background: #0b0b0e; box-shadow: inset 0 1px 2px rgba(0, 0, 0, .9); }
.spine.empty::before { display: none; }
.spine.playing::after { /* the disc that's in the console */
  content: ""; position: absolute; right: 3px; top: 50%; width: 4px; height: 4px; margin-top: -2px; border-radius: 50%;
  background: var(--led-on); box-shadow: 0 0 4px var(--led-on);
}

.rack:hover .rack-frame, .rack:focus-visible .rack-frame, .rack.is-open .rack-frame {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12), inset 0 -2px 0 rgba(0, 0, 0, .5),
    0 16px 18px -10px rgba(0, 0, 0, .75), 0 0 0 2px var(--accent), 0 0 20px 4px rgba(143, 176, 255, .45);
}
.rack:hover .spine:not(.empty) { filter: brightness(1.12); }
.rack .spine:not(.empty):hover { transform: translateX(6px); filter: brightness(1.45); }

.rack-tip {
  position: absolute; left: 0; bottom: calc(100% + 10px); z-index: 1;
  width: max-content; max-width: 240px;
  display: grid; gap: 2px; padding: 7px 10px; border-radius: 9px;
  background: rgba(18, 18, 26, .96); color: #fff; box-shadow: 0 6px 18px rgba(0, 0, 0, .5), 0 0 0 1px rgba(143, 176, 255, .35);
  font: 700 12px/1.2 system-ui, sans-serif; white-space: nowrap;
  opacity: 0; transform: translateY(4px); transition: opacity .15s, transform .15s; pointer-events: none;
}
.rack-tip::after { content: ""; position: absolute; left: 18px; top: 100%; border: 6px solid transparent; border-top-color: rgba(18, 18, 26, .96); }
.rack-tip small { max-width: 220px; overflow: hidden; text-overflow: ellipsis; color: var(--sheet-dim); font-weight: 500; font-size: 11px; }
.rack-tip small:empty { display: none; }
.rack:hover .rack-tip, .rack:focus-visible .rack-tip { opacity: 1; transform: none; }
.touch .rack-tip { display: none; }

/* ================= phones and tablets: just the picture, with see-through buttons ================= */
.mobile body { background: #000; }
.mobile .rig { position: fixed; inset: 0; width: auto; height: auto; transform: none; }
.mobile .scene {
  position: fixed; inset: 0; width: auto; height: auto;
  border-radius: 0; box-shadow: none; background: #000;
}
.mobile .rack, .mobile .ps1-wrap, .mobile .cables, .mobile .foot, .mobile .mon-brand, .mobile .mon-led,
.mobile .pad-body, .mobile .pad-nub, .mobile .pad-brand, .mobile .pill-label, .mobile .tools .vol { display: none !important; }
.mobile .monitor, .mobile .monitor-body, .mobile .bezel, .mobile .chin {
  position: static; display: block; transform: none; width: auto; height: auto;
  padding: 0; border-radius: 0; background: none; box-shadow: none;
}
.mobile .screen {
  position: absolute; left: var(--screen-left); top: var(--screen-top);
  width: var(--screen-w); height: var(--screen-h); border-radius: 0;
}
.mobile .screen::after { display: none; }

/* Portrait: a slim top bar (game name + sound/pause/menu), the picture, then the buttons. */
.mobile .osd { display: none; }
.mobile.portrait .osd {
  display: block; position: absolute; top: 14px; left: 14px; right: 150px; height: auto; padding: 0;
  background: none; box-shadow: none; color: rgba(255, 255, 255, .55); font-size: 11px; line-height: 20px;
}
.mobile .tools { position: absolute; z-index: 7; gap: 8px; }
.mobile.portrait .tools { top: 8px; right: 10px; }
.mobile.landscape .tools { left: 4vmin; bottom: 4vmin; }
.mobile .tool {
  width: 40px; height: 32px; border-radius: 16px;
  background: rgba(255, 255, 255, .06); border: 1.5px solid rgba(255, 255, 255, .32); color: rgba(255, 255, 255, .85);
  box-shadow: none;
}
.mobile .tool svg { width: 14px; height: 14px; }

.mobile .pad {
  position: absolute; left: 0; right: 0; top: var(--ctl-top); bottom: 0; z-index: 6;
  width: auto; height: auto; transform: none; pointer-events: none;
  --dpad: min(36vmin, 170px); --fb: min(13vmin, 62px); --fo: min(13vmin, 62px);
}
.mobile .pad > * { pointer-events: auto; }

/* Silhouettes: outlined, mostly transparent shapes that let the game show through. */
.mobile .pad .dpad { left: calc(5vmin + var(--dpad) / 2); top: 47%; background: none; box-shadow: none; }
.mobile .pad .face { left: calc(100% - 5vmin - var(--fo) - var(--fb) / 2); top: 47%; }
.mobile.landscape .pad .dpad, .mobile.landscape .pad .face { top: 52%; }
.mobile .dpad::before { background: none; box-shadow: none; }
.mobile .arm {
  background: rgba(255, 255, 255, .06); border: 2px solid rgba(255, 255, 255, .45); box-shadow: none;
  border-radius: 9px 9px 4px 4px;
}
.mobile .arm::after { top: 18%; border-bottom-color: rgba(255, 255, 255, .7); }
.mobile .fb {
  background: rgba(255, 255, 255, .05); border: 2px solid rgba(255, 255, 255, .45); box-shadow: none;
  color: rgba(255, 255, 255, .8);
}
.mobile .shoulder {
  top: 3vmin; width: min(16vmin, 80px); height: min(9vmin, 44px); padding: 0; align-items: center;
  border-radius: min(3vmin, 14px); border: 2px solid rgba(255, 255, 255, .45);
  background: rgba(255, 255, 255, .06); box-shadow: none; color: rgba(255, 255, 255, .8);
  font-size: min(3.4vmin, 15px);
}
.mobile .shoulder.l2 { left: 4vmin; }
.mobile .shoulder.l1 { left: calc(6vmin + min(16vmin, 80px)); }
.mobile .shoulder.r1 { right: calc(6vmin + min(16vmin, 80px)); }
.mobile .shoulder.r2 { right: 4vmin; }
.mobile .pill {
  top: auto; bottom: calc(5vmin + env(safe-area-inset-bottom, 0px)); width: min(15vmin, 72px); height: min(6.5vmin, 30px);
  transform: translateX(-50%); border: 2px solid rgba(255, 255, 255, .4); background: rgba(255, 255, 255, .05); box-shadow: none;
  display: grid; place-items: center; color: rgba(255, 255, 255, .75); font-size: min(2.6vmin, 12px); font-weight: 800; letter-spacing: .08em;
}
.mobile .pill::after { content: attr(aria-label); text-transform: uppercase; }
.mobile .pill.select { left: calc(50% - min(9vmin, 44px)); }
.mobile .pill.start { left: calc(50% + min(9vmin, 44px)); }
/* Landscape: Select/Start in the bottom-right corner, clear of the picture's centre. */
.mobile.landscape .pill { bottom: 4vmin; }
.mobile.landscape .pill.select { left: auto; right: calc(4vmin + min(15vmin, 72px) + 2vmin); transform: none; }
.mobile.landscape .pill.start { left: auto; right: 4vmin; transform: none; }
.mobile.landscape .pill.is-down { transform: translateY(1px); }

/* Pressed silhouettes light up too. */
.mobile .fb.is-down {
  transform: none; color: #fff; border-color: var(--c);
  background: color-mix(in srgb, var(--c) 55%, transparent);
  box-shadow: 0 0 calc(var(--fb) * .5) color-mix(in srgb, var(--c) 65%, transparent);
}
.mobile .arm.is-down, .mobile .shoulder.is-down, .mobile .pill.is-down {
  border-color: var(--lit-hi); background: rgba(111, 136, 224, .55); color: #fff;
  box-shadow: 0 0 16px rgba(143, 176, 255, .7);
}
.mobile .pill.is-down { transform: translateX(-50%) translateY(1px); }
.mobile .arm.is-down::after { border-bottom-color: #fff; }
