/* RetroOnline — palette from the SNES itself: grey console plastic, the US pad's purple and
   lavender buttons, charcoal print, and the red power light for anything live. */
:root {
  --plastic: #d9d6de;
  --plastic-hi: #e8e6ec;
  --plastic-lo: #c4c0cb;
  --groove: #b3aebb;
  --ink: #26232e;
  --ink-soft: #5d5868;
  --purple: #4b3f9e;
  --purple-ink: #ffffff;
  --lavender: #a9a3d9;
  --lavender-soft: #d6d2f0;
  --power: #e2402f;
  --ok: #2f8a5b;
  --screen: #141218;
  --label: #f6f5f8;
  --focus: #4b3f9e;
  --radius-s: 6px;
  --radius-m: 12px;
  --radius-l: 20px;
  --shadow: 0 1px 0 var(--plastic-hi) inset, 0 -1px 0 var(--groove) inset;
  --display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --body: 'Atkinson Hyperlegible', 'Segoe UI', system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --plastic: #1c1a21;
    --plastic-hi: #2a2731;
    --plastic-lo: #24212a;
    --groove: #393541;
    --ink: #eceaf1;
    --ink-soft: #a7a2b2;
    --purple: #8a7fe6;
    --purple-ink: #15131a;
    --lavender: #5d5699;
    --lavender-soft: #312d4a;
    --label: #2e2b35;
    --focus: #b3acf5;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --plastic: #1c1a21;
  --plastic-hi: #2a2731;
  --plastic-lo: #24212a;
  --groove: #393541;
  --ink: #eceaf1;
  --ink-soft: #a7a2b2;
  --purple: #8a7fe6;
  --purple-ink: #15131a;
  --lavender: #5d5699;
  --lavender-soft: #312d4a;
  --label: #2e2b35;
  --focus: #b3acf5;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--plastic);
  color: var(--ink);
  font: 400 1rem/1.5 var(--body);
}
h1, h2, h3 { font-family: var(--display); line-height: 1.1; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(2rem, 4.5vw, 3.25rem); font-weight: 800; }
h2 { font-size: 1.375rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-s); }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-soft); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--groove);
}
.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-word { font-family: var(--display); font-weight: 800; font-size: 1.375rem; letter-spacing: -0.02em; }
.brand-pad { position: relative; width: 30px; height: 30px; transform: rotate(-12deg); }
.brand-pad i { position: absolute; width: 12px; height: 12px; border-radius: 50%; }
.brand-pad i:nth-child(1) { left: 9px; top: 0; background: var(--lavender); }
.brand-pad i:nth-child(2) { left: 0; top: 9px; background: var(--lavender); }
.brand-pad i:nth-child(3) { left: 18px; top: 9px; background: var(--purple); }
.brand-pad i:nth-child(4) { left: 9px; top: 18px; background: var(--purple); }
.topnav { display: flex; align-items: center; gap: 12px; }
.pad-status { font-size: 0.875rem; color: var(--ink-soft); display: inline-flex; align-items: center; gap: 8px; }
.pad-status .led { width: 8px; height: 8px; border-radius: 50%; background: var(--groove); }
.pad-status .led.on { background: var(--power); box-shadow: 0 0 0 3px color-mix(in srgb, var(--power) 25%, transparent); }
@media (max-width: 560px) {
  .pad-status span:not(.led) { display: none; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .topnav { flex-wrap: wrap; gap: 4px; }
  .topnav .btn { min-height: 34px; padding: 4px 10px; font-size: 0.875rem; }
}

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px;
  border: 0; border-radius: 999px;
  background: var(--plastic-hi); color: var(--ink);
  font-weight: 700; cursor: pointer; text-decoration: none; white-space: nowrap;
  box-shadow: var(--shadow), 0 1px 2px rgb(0 0 0 / 0.12);
  transition: transform 80ms ease, background-color 120ms ease;
}
.btn:hover { background: color-mix(in srgb, var(--plastic-hi) 80%, var(--lavender)); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--purple); color: var(--purple-ink); box-shadow: 0 2px 0 color-mix(in srgb, var(--purple) 60%, black); }
.btn.primary:hover { background: color-mix(in srgb, var(--purple) 88%, white); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--plastic-lo); }
.btn.small { min-height: 32px; padding: 4px 12px; font-size: 0.875rem; }
.btn.danger { color: var(--power); }

.field { display: grid; gap: 6px; }
.field label { font-weight: 700; font-size: 0.9375rem; }
.input, .select {
  min-height: 44px; width: 100%; padding: 8px 14px;
  border: 2px solid var(--groove); border-radius: var(--radius-m);
  background: var(--label); color: var(--ink);
}
.input:focus, .select:focus { border-color: var(--purple); outline: none; }
.code-input { font-family: var(--display); font-weight: 700; letter-spacing: 0.04em; text-transform: lowercase; }

main { outline: none; }
.page { width: min(1160px, 100%); margin: 0 auto; padding: clamp(24px, 5vw, 56px) clamp(16px, 4vw, 40px) 64px; }

/* ---------- home ---------- */
.home-intro { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: clamp(24px, 5vw, 64px); align-items: end; }
.home-intro h1 { max-width: 13ch; }
.home-intro .lede { margin-top: 16px; max-width: 46ch; font-size: 1.125rem; color: var(--ink-soft); }
.joinbox {
  display: grid; gap: 16px; padding: 24px;
  background: var(--plastic-hi); border-radius: var(--radius-l);
  box-shadow: var(--shadow), 0 10px 30px -18px rgb(0 0 0 / 0.35);
}
.joinbox .row { display: flex; gap: 8px; }
.joinbox .row .input { flex: 1; }
.joinbox .or { display: flex; align-items: center; gap: 12px; color: var(--ink-soft); font-size: 0.875rem; }
.joinbox .or::before, .joinbox .or::after { content: ''; flex: 1; height: 1px; background: var(--groove); }
.recent { display: flex; flex-wrap: wrap; gap: 8px; }
.recent a { font-size: 0.875rem; padding: 4px 12px; border-radius: 999px; background: var(--plastic-lo); text-decoration: none; font-weight: 700; }
.recent a:hover { background: var(--lavender-soft); }
@media (max-width: 820px) { .home-intro { grid-template-columns: 1fr; } }

.shelf-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin: clamp(40px, 7vw, 72px) 0 20px; }
.shelf-head .search { flex: 0 1 320px; margin-left: auto; min-height: 40px; }
.shelf-count { margin: -8px 0 16px; }
@media (max-width: 640px) { .shelf-head { flex-wrap: wrap; } .shelf-head .search { flex: 1 1 100%; order: 3; } }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: clamp(16px, 2.5vw, 28px); }
.empty-shelf { padding: 32px; border: 2px dashed var(--groove); border-radius: var(--radius-l); color: var(--ink-soft); }

/* The cartridge: grey shell, gripped top, bevelled shoulders, a printed label with the title screen. */
.cart {
  position: relative; display: grid; gap: 10px; padding: 26px 16px 18px;
  border: 0; text-align: left; cursor: pointer;
  background: linear-gradient(180deg, var(--plastic-hi), var(--plastic-lo));
  color: var(--ink);
  clip-path: polygon(9% 0, 91% 0, 100% 7%, 100% 100%, 0 100%, 0 7%);
  border-radius: 0 0 var(--radius-m) var(--radius-m);
  box-shadow: inset 0 -3px 0 var(--groove);
  transition: transform 160ms cubic-bezier(.2,.9,.3,1.3);
}
.cart::before { /* grip ridges along the top */
  content: ''; position: absolute; left: 22%; right: 22%; top: 9px; height: 9px;
  background: repeating-linear-gradient(90deg, var(--groove) 0 3px, transparent 3px 8px);
  border-radius: 2px; opacity: 0.9;
}
.cart:hover, .cart:focus-visible { transform: translateY(-6px); }
.cart:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
.cart-label {
  /* SNES pictures are 8:7 */
  position: relative; aspect-ratio: 8 / 7; overflow: hidden;
  border-radius: var(--radius-s);
  background: var(--screen);
  box-shadow: 0 0 0 4px var(--label), 0 0 0 5px var(--groove);
}
.cart-label img { width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; display: block; }
.cart-title { font-family: var(--display); font-weight: 700; font-size: 1.0625rem; line-height: 1.2; margin-top: 6px; }
.cart-meta { font-size: 0.8125rem; color: var(--ink-soft); }

/* ---------- room ---------- */
.room { display: grid; grid-template-columns: minmax(0, 1fr) 340px; align-items: start; gap: 20px; padding: 20px clamp(16px, 3vw, 32px) 40px; }
.main-col { display: grid; gap: 20px; min-width: 0; }
@media (max-width: 1000px) { .room { grid-template-columns: 1fr; } }
.roombar { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; }
.roombar h1 { font-size: 1.5rem; }
.roombar .code { font-family: var(--display); font-weight: 800; padding: 2px 12px; border-radius: var(--radius-s); background: var(--plastic-hi); box-shadow: var(--shadow); }
.roombar .spacer { flex: 1; }

.stage {
  position: relative; display: flex; flex-direction: column;
  background: var(--screen); border-radius: var(--radius-l); overflow: hidden;
  min-height: 320px;
  box-shadow: 0 0 0 6px var(--plastic-lo), 0 0 0 7px var(--groove);
  color: #eceaf1;
}
.screen { position: relative; flex: 1; display: flex; align-items: center; justify-content: center; padding: 12px; min-height: 0; }
/* Picture shape comes from --ar (16:9 wide or 4:3 like a TV); the width is capped so the whole
   screen fits the window. The canvas is drawn at device pixels by js/screen.js. */
.stage { --ar: 16 / 9; }
.screen canvas {
  display: block; width: min(100%, calc((100vh - 230px) * var(--ar))); height: auto;
  aspect-ratio: var(--ar); background: #000;
}
.stage:fullscreen { border-radius: 0; box-shadow: none; }
.stage:fullscreen .screen canvas { width: min(100%, calc((100vh - 72px) * var(--ar))); }
.stage-overlay {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  padding: 24px; background: rgb(20 18 24 / 0.72); backdrop-filter: blur(3px);
}
.stage-overlay .inner { position: relative; display: grid; gap: 14px; justify-items: center; max-width: 42ch; }
.stage-overlay h2 { font-size: clamp(1.25rem, 3vw, 1.75rem); }
.stage-overlay p { color: #c9c4d4; }
.stage-art { position: absolute; inset: 0; pointer-events: none; width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; opacity: 0.35; filter: saturate(0.8); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid rgb(255 255 255 / 0.2); border-top-color: #fff; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.stage-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 14px; background: #1d1b22; border-top: 1px solid #2e2b35; }
.stage-bar .btn { background: #2e2b35; color: #eceaf1; box-shadow: none; }
.stage-bar .btn:hover { background: #3b3744; }
.stage-bar .btn.primary { background: #8a7fe6; color: #15131a; }
.stage-bar .spacer { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.8125rem; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: #2e2b35; color: #c9c4d4; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: #6b6677; }
.chip .dot.live { background: var(--power); }
.chip .dot.good { background: #4cc38a; }
.chip .dot.warn { background: #f0b429; }
.stage-bar .select.small { min-height: 32px; width: auto; padding: 2px 10px; border: 0; border-radius: 999px; background: #2e2b35; color: #eceaf1; font-size: 0.8125rem; font-weight: 700; }
.volume { display: inline-flex; align-items: center; gap: 8px; font-size: 0.8125rem; color: #c9c4d4; }
.volume input { width: 90px; accent-color: #8a7fe6; }

.panel { display: grid; gap: 20px; align-content: start; }
.card { display: grid; gap: 12px; padding: 18px; background: var(--plastic-hi); border-radius: var(--radius-l); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.seats { display: grid; gap: 8px; list-style: none; margin: 0; padding: 0; }
.seat { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 8px 10px; border-radius: var(--radius-m); background: var(--plastic); }
.seat .port {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  font-family: var(--display); font-weight: 800; font-size: 0.875rem;
  background: var(--lavender-soft); color: var(--ink);
}
.seat.filled .port { background: var(--purple); color: var(--purple-ink); }
.seat .who { min-width: 0; }
.seat .who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .who span { font-size: 0.8125rem; color: var(--ink-soft); }
.seat.me { box-shadow: inset 0 0 0 2px var(--purple); }

.queue { margin: 0; padding: 0 0 0 1.4em; display: grid; gap: 4px; }
.queue li::marker { font-family: var(--display); font-weight: 700; color: var(--ink-soft); }
.queue .me { font-weight: 700; }
.watchers { font-size: 0.875rem; color: var(--ink-soft); }

.saves { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.save { display: grid; gap: 6px; padding: 8px; border-radius: var(--radius-m); background: var(--plastic); }
.save-thumb { aspect-ratio: 4 / 3; border-radius: var(--radius-s); background: var(--screen); overflow: hidden; display: grid; place-items: center; color: #6b6677; font-family: var(--display); font-weight: 800; font-size: 1.25rem; }
.save-thumb img { width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; }
.save-info { font-size: 0.75rem; color: var(--ink-soft); line-height: 1.3; min-height: 2.6em; }
.save-info strong { color: var(--ink); font-size: 0.8125rem; }
.save-actions { display: flex; gap: 6px; }
.save-actions .btn { flex: 1; min-height: 30px; padding: 2px 8px; font-size: 0.8125rem; }
.note { font-size: 0.8125rem; color: var(--ink-soft); }

/* ---------- controls sheet ---------- */
.sheet {
  width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 0; border-radius: var(--radius-l);
  background: var(--plastic-hi); color: var(--ink);
  box-shadow: 0 30px 80px -20px rgb(0 0 0 / 0.5);
}
.sheet::backdrop { background: rgb(20 18 24 / 0.55); backdrop-filter: blur(2px); }
.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; background: var(--plastic-hi); border-bottom: 1px solid var(--groove); }
#controlsBody { padding: 18px 22px 24px; display: grid; gap: 18px; }
.devices { display: flex; flex-wrap: wrap; gap: 8px; }
.device { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--plastic); font-size: 0.875rem; }
.device .led { width: 8px; height: 8px; border-radius: 50%; background: var(--power); }
.device.idle .led { background: var(--groove); }
.binds { width: 100%; border-collapse: collapse; }
.binds th { text-align: left; font-size: 0.8125rem; color: var(--ink-soft); font-weight: 700; padding: 0 8px 8px; }
.binds td { padding: 4px 8px; border-top: 1px solid var(--groove); }
.binds .snes { display: flex; align-items: center; gap: 10px; }
.snes-btn {
  display: inline-grid; place-items: center; min-width: 34px; height: 34px; padding: 0 8px; border-radius: 999px;
  font-family: var(--display); font-weight: 800; font-size: 0.8125rem;
  background: var(--plastic); box-shadow: var(--shadow);
  transition: background-color 60ms, color 60ms;
}
.snes-btn.face-a, .snes-btn.face-b { background: var(--purple); color: var(--purple-ink); }
.snes-btn.face-x, .snes-btn.face-y { background: var(--lavender); color: #1d1a29; }
.snes-btn.lit { background: var(--power) !important; color: #fff !important; }
.bind-btn { min-width: 120px; justify-content: flex-start; font-weight: 400; }
.bind-btn.listening { background: var(--purple); color: var(--purple-ink); }
.sheet-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; }

/* ---------- gate / admin ---------- */
.gate { min-height: calc(100vh - 80px); display: grid; place-items: center; padding: 24px 16px; }
.gate form { width: min(380px, 100%); display: grid; gap: 16px; }
.error { color: var(--power); font-weight: 700; font-size: 0.9375rem; }

.drop {
  display: grid; place-items: center; gap: 10px; text-align: center; padding: 40px 20px;
  border: 2px dashed var(--groove); border-radius: var(--radius-l); background: var(--plastic-hi); cursor: pointer;
}
.drop.over { border-color: var(--purple); background: var(--lavender-soft); }
.imports { display: grid; gap: 16px; margin-top: 20px; }
.import { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 20px; padding: 18px; background: var(--plastic-hi); border-radius: var(--radius-l); box-shadow: var(--shadow); }
.import .cart-label {
  /* SNES pictures are 8:7 */ align-self: start; }
.import-fields { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.import-fields .wide { grid-column: 1 / -1; }
.import details { grid-column: 1 / -1; }
.import summary { cursor: pointer; font-weight: 700; }
.labels-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.import-actions { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; }
@media (max-width: 680px) { .import { grid-template-columns: 1fr; } .labels-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.lib-list { display: grid; gap: 8px; list-style: none; padding: 0; margin: 0; }
.lib-list li { display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; padding: 8px; border-radius: var(--radius-m); background: var(--plastic-hi); }
.lib-list img { width: 64px; aspect-ratio: 4/3; object-fit: cover; image-rendering: pixelated; border-radius: 4px; background: var(--screen); }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { padding: 10px 18px; border-radius: 999px; background: var(--ink); color: var(--plastic); font-weight: 700; box-shadow: 0 10px 30px -10px rgb(0 0 0 / 0.5); animation: toast-in 180ms ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

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