:root {
  color-scheme: dark;
  --bg: #07080c;
  --bg-raised: #0d0f17;
  --surface: #121521;
  --surface-2: #181c2b;
  --surface-3: #22273c;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #eceef6;
  --text-2: #a7adc2;
  --text-3: #6f758c;
  --accent: #8b5cf6;
  --accent-2: #a78bfa;
  --accent-glow: rgba(139, 92, 246, 0.35);
  --snes: #a594ff;
  --red: #ef4444;
  --yellow: #facc15;
  --green: #22c55e;
  --blue: #3b82f6;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --radius-lg: 22px;
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent-2);
}

:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

body[data-view='home'] #player,
body[data-view='player'] #home {
  display: none;
}

body[data-view='player'] {
  overflow: hidden;
}

/* ---------- Shared controls ---------- */

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn:hover {
  background: var(--surface-3);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn:active {
  transform: translateY(1px);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: transparent;
  color: var(--text);
}

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.btn-primary:hover {
  background: #7c4def;
  border-color: transparent;
}

.btn-xs {
  height: 26px;
  padding: 0 10px;
  border-radius: 7px;
  font-size: 12px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text-2);
  font: 700 10px/1 var(--font);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-snes {
  background: rgba(165, 148, 255, 0.16);
  color: #cdc4ff;
  box-shadow: inset 0 0 0 1px rgba(165, 148, 255, 0.32);
}

.badge-n64 {
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.24), rgba(34, 197, 94, 0.22), rgba(59, 130, 246, 0.24), rgba(250, 204, 21, 0.22));
  color: #f4f5ff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.badge-gb {
  background: rgba(163, 36, 92, 0.2);
  color: #f5bdd6;
  box-shadow: inset 0 0 0 1px rgba(214, 72, 135, 0.38);
}

.badge-psx {
  background: rgba(91, 143, 224, 0.16);
  color: #c9d9f6;
  box-shadow: inset 0 0 0 1px rgba(91, 143, 224, 0.35);
}

.badge-md {
  background: rgba(30, 136, 229, 0.18);
  color: #cfe3fb;
  box-shadow: inset 0 0 0 1px rgba(232, 72, 72, 0.4);
}

.badge-psp {
  background: rgba(200, 205, 220, 0.12);
  color: #e3e6ef;
  box-shadow: inset 0 0 0 1px rgba(200, 205, 220, 0.3);
}

.badge-ps2 {
  background: rgba(37, 99, 235, 0.2);
  color: #cbdcff;
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.45);
}

.badge-dc {
  background: rgba(249, 115, 22, 0.16);
  color: #ffd6b8;
  box-shadow: inset 0 0 0 1px rgba(249, 115, 22, 0.4);
}

.badge-gc {
  background: rgba(124, 58, 237, 0.2);
  color: #ddd0ff;
  box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.45);
}

.badge-zip {
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text);
  font: 600 11px/1 var(--font);
  white-space: nowrap;
}

.muted {
  color: var(--text-3);
  font-size: 14px;
}

/* ---------- Home ---------- */

.page {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  isolation: isolate;
}

.page::before,
.page::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.page::before {
  background:
    radial-gradient(60rem 40rem at 12% -12%, rgba(139, 92, 246, 0.24), transparent 60%),
    radial-gradient(50rem 36rem at 100% 6%, rgba(59, 130, 246, 0.14), transparent 60%),
    radial-gradient(44rem 30rem at 50% 112%, rgba(244, 63, 94, 0.1), transparent 60%);
}

.page::after {
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 28%, #000 25%, transparent 80%);
  mask-image: radial-gradient(ellipse 70% 60% at 50% 28%, #000 25%, transparent 80%);
}

.site-header,
main,
.site-footer {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding-left: clamp(16px, 4vw, 40px);
  padding-right: clamp(16px, 4vw, 40px);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 20px;
  padding-bottom: 20px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
}

.logo-mark {
  display: grid;
  grid-template-columns: repeat(2, 9px);
  gap: 3px;
}

.logo-mark i {
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.logo-mark i:nth-child(1) { background: var(--red); }
.logo-mark i:nth-child(2) { background: var(--yellow); }
.logo-mark i:nth-child(3) { background: var(--green); }
.logo-mark i:nth-child(4) { background: var(--blue); }

.logo-text {
  font: 15px/1 var(--pixel);
  letter-spacing: 1px;
}

.logo-text span {
  color: var(--accent-2);
}

/* "EmuRomRom" is nine pixel-font characters: shrink it on the smallest phones
   so the header buttons keep their room. */
@media (max-width: 370px) {
  .logo {
    gap: 8px;
  }

  .logo-text {
    font-size: 12px;
  }
}

main {
  flex: 1;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(20px, 6vh, 64px) 0 44px;
  text-align: center;
}

.eyebrow {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 8px;
  max-width: 100%;
  margin: 0 0 20px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot-snes {
  background: var(--snes);
  box-shadow: 0 0 10px var(--snes);
}

.dot-n64 {
  background: conic-gradient(var(--red) 0 25%, var(--green) 0 50%, var(--blue) 0 75%, var(--yellow) 0);
}

.dot-gb {
  background: #d64887;
  box-shadow: 0 0 10px rgba(214, 72, 135, 0.8);
}

.dot-psx {
  background: conic-gradient(#2fae95 0 25%, #e0565b 0 50%, #5b8fe0 0 75%, #c86fd0 0);
}

.dot-md {
  background: linear-gradient(135deg, #1e88e5 50%, #e84848 50%);
}

.dot-psp {
  background: #d7dbe6;
  box-shadow: 0 0 8px rgba(215, 219, 230, 0.7);
}

.dot-ps2 {
  background: #2563eb;
  box-shadow: 0 0 10px rgba(37, 99, 235, 0.8);
}

.dot-dc {
  background: radial-gradient(circle at 50% 50%, #05060a 0 22%, #f97316 24%);
  box-shadow: 0 0 10px rgba(249, 115, 22, 0.7);
}

.dot-gc {
  background: #7c3aed;
  box-shadow: 0 0 10px rgba(124, 58, 237, 0.8);
}

.plus {
  margin: 0 4px;
  color: var(--text-3);
}

.hero h1 {
  margin: 0;
  font-size: clamp(34px, 6vw, 64px);
  font-weight: 800;
  line-height: 1.04;
  letter-spacing: -0.035em;
}

.grad {
  background: linear-gradient(90deg, #c4b5fd, #8b5cf6 35%, #60a5fa 66%, #fb7185);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lede {
  max-width: 600px;
  margin: 18px auto 34px;
  color: var(--text-2);
  font-size: clamp(15px, 1.6vw, 18px);
}

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(720px, 100%);
  padding: 40px 24px 30px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(24, 28, 43, 0.92), rgba(15, 17, 27, 0.92));
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.dropzone::before {
  content: '';
  position: absolute;
  inset: 10px;
  border: 2px dashed rgba(167, 139, 250, 0.28);
  border-radius: 16px;
  pointer-events: none;
  transition: border-color 0.2s;
}

.dropzone:hover,
.dropzone:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(167, 139, 250, 0.5);
  box-shadow: 0 30px 90px -30px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  outline: none;
}

.dropzone:hover::before,
.dropzone:focus-visible::before {
  border-color: rgba(167, 139, 250, 0.65);
}

.cart-art {
  width: 120px;
  height: 100px;
  margin-bottom: 10px;
  filter: drop-shadow(0 14px 24px rgba(0, 0, 0, 0.5));
  transition: transform 0.3s;
}

.dropzone:hover .cart-art {
  transform: translateY(-4px) rotate(-2deg);
}

.dz-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.dz-sub {
  color: var(--text-2);
}

.link {
  color: var(--accent-2);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.dz-formats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin-top: 18px;
  color: var(--text-3);
  font: 13px var(--mono);
}

.fmt {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.features {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  width: min(980px, 100%);
  margin: 36px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
}

.features li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.025);
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.4;
}

.features b {
  display: block;
  margin-bottom: 2px;
  color: var(--text);
  font-size: 14px;
}

.feat-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(139, 92, 246, 0.14);
  color: var(--accent-2);
}

.library {
  padding: 16px 0 56px;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}

.section-head h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
}

.game-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}

.game-card:hover {
  transform: translateY(-3px);
  border-color: var(--line-strong);
  box-shadow: 0 18px 40px -20px rgba(0, 0, 0, 0.85);
}

.game-play {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

.game-play:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: -2px;
  border-radius: var(--radius);
}

.game-art {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #0b0d14;
}

.game-art-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.game-art-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px;
}

.game-art.has-art .game-art-fallback {
  display: none;
}

.game-card[data-system='gb'] .game-art-fallback {
  background:
    radial-gradient(circle at 78% 80%, rgba(255, 255, 255, 0.14) 0 12%, transparent 13%),
    radial-gradient(circle at 92% 66%, rgba(255, 255, 255, 0.14) 0 12%, transparent 13%),
    linear-gradient(150deg, #4a1838, #a3245c 60%, #e2649a);
}

.game-card[data-system='md'] .game-art-fallback {
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.05) 0 2px, transparent 2px 6px),
    linear-gradient(165deg, #0d47a1, #1565c0 45%, #101826 46%, #0a0f18);
}

.game-card[data-system='psp'] .game-art-fallback {
  background:
    radial-gradient(ellipse 60% 40% at 50% 46%, rgba(255, 255, 255, 0.1), transparent 70%),
    linear-gradient(160deg, #3a3f4c, #15171e);
}

.game-card[data-system='ps2'] .game-art-fallback {
  background:
    radial-gradient(ellipse 70% 50% at 50% 40%, rgba(59, 130, 246, 0.28), transparent 70%),
    linear-gradient(160deg, #0b1d4a, #070a14);
}

.game-card[data-system='dc'] .game-art-fallback {
  background:
    radial-gradient(circle at 78% 26%, rgba(249, 115, 22, 0.45), transparent 30%),
    linear-gradient(160deg, #2a2d36, #0d0f14);
}

.game-card[data-system='gc'] .game-art-fallback {
  background:
    radial-gradient(circle at 76% 74%, rgba(167, 139, 250, 0.4), transparent 32%),
    linear-gradient(160deg, #3b1d7a, #120a26);
}

.game-card[data-system='psx'] .game-art-fallback {
  background:
    radial-gradient(circle at 80% 22%, rgba(47, 174, 149, 0.55), transparent 26%),
    radial-gradient(circle at 92% 50%, rgba(224, 86, 91, 0.5), transparent 24%),
    radial-gradient(circle at 68% 50%, rgba(200, 111, 208, 0.5), transparent 24%),
    radial-gradient(circle at 80% 78%, rgba(91, 143, 224, 0.55), transparent 26%),
    linear-gradient(160deg, #2a2f3b, #12141c);
}

.game-card[data-system='snes'] .game-art-fallback {
  background:
    radial-gradient(circle at 82% 78%, rgba(255, 255, 255, 0.16) 0 14%, transparent 15%),
    radial-gradient(circle at 64% 86%, rgba(255, 255, 255, 0.1) 0 10%, transparent 11%),
    linear-gradient(140deg, #3b3176, #6c5ce7 55%, #a594ff);
}

.game-card[data-system='n64'] .game-art-fallback {
  background:
    radial-gradient(circle at 18% 85%, rgba(239, 68, 68, 0.5), transparent 32%),
    radial-gradient(circle at 45% 100%, rgba(34, 197, 94, 0.45), transparent 32%),
    radial-gradient(circle at 75% 85%, rgba(59, 130, 246, 0.55), transparent 32%),
    radial-gradient(circle at 100% 60%, rgba(250, 204, 21, 0.4), transparent 30%),
    linear-gradient(160deg, #1c2140, #0a0c18);
}

.game-art-system {
  font: 10px/1 var(--pixel);
  opacity: 0.8;
}

.game-art-title {
  display: -webkit-box;
  overflow: hidden;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.game-play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 56px;
  height: 56px;
  margin: -28px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  background: rgba(8, 10, 16, 0.6);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.18s, transform 0.18s;
}

.game-play-icon::after {
  content: '';
  position: absolute;
  top: 17px;
  left: 22px;
  border-top: 11px solid transparent;
  border-bottom: 11px solid transparent;
  border-left: 16px solid #fff;
}

.game-card:hover .game-play-icon,
.game-play:focus-visible .game-play-icon {
  opacity: 1;
  transform: scale(1);
}

.game-meta {
  display: block;
  padding: 12px 14px 14px;
}

.game-title {
  display: block;
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  color: var(--text-3);
  font-size: 12px;
}

.game-when {
  margin-left: auto;
  white-space: nowrap;
}

.game-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(8, 10, 16, 0.65);
  color: var(--text-2);
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.game-remove svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

.game-card:hover .game-remove,
.game-remove:focus-visible {
  opacity: 1;
}

.game-remove:hover {
  background: rgba(239, 68, 68, 0.85);
  color: #fff;
}

@media (hover: none) {
  .game-remove {
    opacity: 1;
  }
}

.site-footer {
  padding-top: 24px;
  padding-bottom: 32px;
  border-top: 1px solid var(--line);
  color: var(--text-3);
  font-size: 13px;
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: var(--text-2);
}

/* ---------- Player ---------- */

.player {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #000;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
}

.btn-back {
  padding: 0 12px 0 8px;
}

.now-playing {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.np-title {
  margin: 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.np-region {
  color: var(--text-3);
  font-size: 13px;
  white-space: nowrap;
}

.player-tools {
  display: flex;
  align-items: center;
  gap: 2px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  margin-right: 8px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.status-pill::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
}

.status-pill[data-state='on']::before {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

.status-pill[data-state='mouse'] {
  border-color: rgba(167, 139, 250, 0.45);
  color: #ddd6fe;
}

.status-pill[data-state='mouse']::before {
  background: var(--accent-2);
  box-shadow: 0 0 8px var(--accent-2);
}

.status-pill[data-state='off'] {
  border-color: rgba(251, 191, 36, 0.35);
  color: var(--warn);
}

.status-pill[data-state='off']::before {
  background: var(--warn);
}

.stage {
  position: relative;
  min-height: 0;
  background: #05060a;
}

.game-frame {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #05060a;
}

.stage-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: radial-gradient(40rem 26rem at 50% 40%, rgba(139, 92, 246, 0.14), transparent 70%), #05060a;
  text-align: center;
}

.stage-loading[data-system='n64'] {
  background: radial-gradient(40rem 26rem at 50% 40%, rgba(59, 130, 246, 0.14), transparent 70%), #05060a;
}

.loader {
  display: grid;
  grid-template-columns: repeat(2, 14px);
  gap: 5px;
  margin-bottom: 6px;
}

.loader i {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  animation: loader-blink 1.2s infinite;
}

/* lights chase clockwise: top-left, top-right, bottom-right, bottom-left */
.loader i:nth-child(1) { background: var(--red); }
.loader i:nth-child(2) { background: var(--yellow); animation-delay: 0.15s; }
.loader i:nth-child(4) { background: var(--blue); animation-delay: 0.3s; }
.loader i:nth-child(3) { background: var(--green); animation-delay: 0.45s; }

@keyframes loader-blink {
  0%, 100% { opacity: 0.25; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

.loader-title {
  max-width: 640px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.loader-text {
  min-height: 1.5em;
  color: var(--text-2);
  font: 13px var(--mono);
}

.stage-loading.is-error .loader,
.stage-loading.is-native .loader {
  display: none;
}

.stage-loading.is-native .loader-text {
  max-width: 520px;
  font: 14px var(--font);
}

/* Games in a native emulator (PSP in PPSSPP): the in-browser game tools don't
   apply, but an open online session (guests are told the game can't be shared) stays reachable. */
.player.is-native .player-tools > :not([data-action='open-controls']):not(.online-btn[data-state='on']):not(.mic-btn) {
  display: none;
}

.stage-loading.is-error .loader-text {
  max-width: 520px;
  color: var(--danger);
  font: 14px var(--font);
}

.stage-loading-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.cheatsheet {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 24px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text-3);
  font-size: 12px;
}

.cs-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
}

.cs-hotkeys {
  margin-left: auto;
}

.cs-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.cs-label {
  margin-right: 2px;
  color: var(--text-2);
  font-weight: 600;
}

.kbd-mouse {
  border-color: rgba(167, 139, 250, 0.4);
  background: rgba(139, 92, 246, 0.16);
  color: #ddd6fe;
}

@media (max-width: 720px) {
  .btn-back span,
  .np-region,
  .status-pill,
  .cheatsheet {
    display: none;
  }
}

/* ---------- Drop overlay ---------- */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(5, 6, 10, 0.74);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  animation: fade-in 0.15s ease-out;
}

.drop-overlay::before {
  content: '';
  position: absolute;
  inset: 16px;
  border: 2px dashed rgba(167, 139, 250, 0.65);
  border-radius: 24px;
  pointer-events: none;
}

.drop-overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  text-align: center;
}

.drop-overlay .cart-art {
  width: 150px;
  height: 125px;
  animation: bob 1.4s ease-in-out infinite;
}

.drop-overlay-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.drop-overlay-sub {
  color: var(--text-2);
}

@keyframes bob {
  50% { transform: translateY(-10px); }
}

@keyframes fade-in {
  from { opacity: 0; }
}

/* ---------- Dialogs ---------- */

.modal {
  width: min(840px, calc(100vw - 32px));
  max-height: min(88dvh, 920px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 40px 120px -20px rgba(0, 0, 0, 0.9);
}

.modal[open] {
  display: flex;
  flex-direction: column;
  animation: pop 0.18s ease-out;
}

.modal::backdrop {
  background: rgba(3, 4, 8, 0.66);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

@keyframes pop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
}

.modal-sm {
  width: min(460px, calc(100vw - 32px));
}

.modal-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding: 14px 14px 14px 22px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.modal-head .icon-btn {
  margin-left: auto;
}

.modal-body {
  padding: 20px 22px;
  overflow: auto;
}

.modal-body > p:first-child {
  margin-top: 0;
}

.modal-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 12px 22px;
  border-top: 1px solid var(--line);
  background: var(--bg-raised);
}

.controls-notice {
  flex: 1;
  min-width: 200px;
  margin: 0;
  color: var(--warn);
  font-size: 13px;
}

.tabs {
  display: inline-flex;
  max-width: 100%;
  overflow-x: auto;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

.tabs [role='tab'] {
  flex: none;
  height: 30px;
  padding: 0 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* Eleven tabs: a little tighter so they share the header row with the title. */
.modal-controls .tabs [role='tab'] {
  padding: 0 11px;
}

.tabs [role='tab']:hover {
  color: var(--text);
}

.tabs [aria-selected='true'] {
  background: var(--surface-3);
  color: var(--text);
}

.controls-intro {
  margin: 0 0 16px;
  color: var(--text-2);
  font-size: 13px;
}

.bind-group {
  margin-bottom: 18px;
}

.bind-group h3,
.segmented legend,
.mouse-buttons h4 {
  margin: 0 0 8px;
  padding: 0;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.bind-grid,
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.field-grid + .field-grid {
  margin-top: 8px;
}

.bind-row,
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 6px 6px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 14px;
}

.field-row {
  padding-left: 12px;
  font-size: 13px;
}

.field-row > span {
  white-space: nowrap;
}

.field-row .select {
  flex: 0 1 150px;
  min-width: 0;
}

.bind-name {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 500;
}

.btn-chip {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 12px;
  background: var(--chip, var(--surface-3));
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
}

.key-btn {
  min-width: 88px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 8px;
  background: var(--bg-raised);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.key-btn:hover {
  border-color: rgba(167, 139, 250, 0.6);
}

.key-btn.is-fixed {
  display: inline-grid;
  place-items: center;
  cursor: default;
}

.key-btn.is-fixed:hover {
  border-color: var(--line-strong);
}

.key-btn.unbound {
  color: var(--text-3);
  font-weight: 500;
}

.key-btn.capturing {
  border-color: var(--accent-2);
  background: rgba(139, 92, 246, 0.2);
  color: #ede9fe;
  animation: capture-pulse 1s infinite;
}

@keyframes capture-pulse {
  50% { box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.25); }
}

.mouse-panel {
  margin-bottom: 22px;
  padding: 18px;
  border: 1px solid rgba(167, 139, 250, 0.24);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(139, 92, 246, 0.11), rgba(139, 92, 246, 0.03));
}

.mouse-panel.is-off .mouse-grid,
.mouse-panel.is-off .mouse-buttons {
  opacity: 0.4;
  pointer-events: none;
}

.mouse-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.mouse-panel h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.mouse-panel-head p {
  margin: 0;
  color: var(--text-2);
  font-size: 13px;
}

.mouse-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 16px;
}

.segmented {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
}

.segmented label:has(input:checked) {
  border-color: var(--accent-2);
  background: rgba(139, 92, 246, 0.15);
}

.segmented input,
.check input,
input[type='range'] {
  accent-color: var(--accent);
}

.segmented input {
  margin-top: 3px;
}

.segmented b {
  display: block;
  font-size: 14px;
}

.segmented small {
  display: block;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.4;
}

.sliders {
  display: grid;
  align-content: start;
  gap: 12px;
  padding-top: 22px;
}

.slider {
  display: grid;
  grid-template-columns: 100px 1fr 52px;
  align-items: center;
  gap: 10px;
  color: var(--text-2);
  font-size: 13px;
}

.slider input {
  width: 100%;
}

.slider output {
  color: var(--text);
  font-family: var(--mono);
  text-align: right;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.mouse-buttons {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid rgba(167, 139, 250, 0.16);
}

.select {
  height: 32px;
  padding: 0 30px 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--bg-raised) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a7adc2' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 9px center / 12px;
  font-size: 13px;
  font-weight: 600;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.switch {
  position: relative;
  display: inline-flex;
  flex: none;
  cursor: pointer;
}

.switch input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-track {
  position: relative;
  width: 44px;
  height: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: var(--surface-3);
  transition: background 0.2s;
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s;
}

.switch input:checked + .switch-track {
  border-color: transparent;
  background: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(18px);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.info-card {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
}

.info-card h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.info-card p {
  margin: 0;
  color: var(--text-2);
  font-size: 13px;
}

.psx-card,
.native-card,
.warn-card {
  margin-bottom: 22px;
}

.warn-card {
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.07);
}

.warn-card h3 {
  color: var(--warn);
}

.psx-bios {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.psx-bios-actions {
  display: flex;
  flex: none;
  gap: 6px;
}

.psx-note {
  margin-top: 12px !important;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--text-3) !important;
}

.system-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.system-choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface-2);
  text-align: left;
  cursor: pointer;
}

.system-choice:hover {
  border-color: var(--accent-2);
  background: rgba(139, 92, 246, 0.12);
}

@media (max-width: 760px) {
  .features,
  .mouse-grid {
    grid-template-columns: 1fr;
  }

  .sliders {
    padding-top: 0;
  }
}

@media (max-width: 520px) {
  .game-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .game-art-title {
    font-size: 15px;
  }

  .game-when {
    display: none;
  }
}

/* ---------- Toasts ---------- */

.toasts {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 60;
  display: grid;
  justify-items: center;
  gap: 8px;
  width: min(560px, calc(100vw - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface-3);
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.8);
  font-size: 14px;
  animation: toast-in 0.2s ease-out;
  transition: opacity 0.25s, transform 0.25s;
}

.toast-error {
  border-color: rgba(248, 113, 113, 0.45);
  background: #2a1418;
  color: #fecaca;
}

.toast.leaving {
  opacity: 0;
  transform: translateY(6px);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

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

/* ---------- Phone controllers ---------- */

.header-tools {
  display: flex;
  align-items: center;
  gap: 4px;
}

.phone-count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--ok);
  color: #04130d;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.icon-btn-count {
  position: relative;
}

.icon-btn-count .phone-count {
  position: absolute;
  top: 1px;
  right: 1px;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  font-size: 10px;
  box-shadow: 0 0 0 2px var(--bg-raised);
}

/* Player colors, shared with the phone controller (css/pad.css). */
.player-chip {
  --pc: var(--surface-3);
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 26px;
  border-radius: 8px;
  background: var(--pc);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
}

.player-chip[data-player='0'] { --pc: var(--blue); }
.player-chip[data-player='1'] { --pc: var(--red); }
.player-chip[data-player='2'] { --pc: var(--green); }
.player-chip[data-player='3'] { --pc: #d4a90c; }

.modal-phone {
  width: min(620px, calc(100vw - 32px));
}

.phone-pair {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 22px;
  align-items: center;
}

.phone-qr {
  width: 196px;
  padding: 0;
  overflow: hidden;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 0 0 1px var(--line-strong), 0 18px 40px -18px rgba(139, 92, 246, 0.6);
}

.phone-qr svg {
  display: block;
  width: 100%;
  height: auto;
}

.phone-how h3,
.phone-players h3,
.phone-message h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

.phone-how p {
  margin: 0 0 8px;
  color: var(--text-2);
  font-size: 14px;
}

.phone-how .muted {
  font-size: 13px;
}

.phone-url {
  display: block;
  margin-top: 10px;
  padding: 7px 10px;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-raised);
  color: var(--text-2);
  font: 12px/1.4 var(--mono);
  -webkit-user-select: all;
  user-select: all;
}

.phone-network {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
}

.phone-network .select {
  flex: 1;
  min-width: 0;
}

.phone-players {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.phone-players h3 {
  color: var(--text-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.phone-list,
.pad-list {
  display: grid;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.phone-row,
.pad-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 7px 7px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  animation: fade-in 0.2s ease-out;
}

.phone-row.is-waiting .player-chip {
  opacity: 0.5;
}

.phone-name,
.pad-name {
  display: grid;
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
}

.phone-name small {
  color: var(--warn);
  font-size: 12px;
  font-weight: 500;
}

.phone-row .select,
.pad-row .select,
.pad-row .btn {
  flex: none;
}

.phone-kind {
  color: var(--text-3);
}

.phone-none {
  margin: 10px 0 0;
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  color: var(--text-3);
  font-size: 13px;
  text-align: center;
}

.phone-note {
  margin: 10px 0 0;
  color: var(--text-3);
  font-size: 12px;
}

.phone-empty {
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 40px 0;
  color: var(--text-2);
}

.phone-empty p {
  margin: 0;
}

.phone-message p {
  margin: 0;
  color: var(--text-2);
  font-size: 14px;
}

.phone-message code {
  font: 12px var(--mono);
  color: var(--text);
}

.phone-foot {
  flex: 1;
  min-width: 180px;
  margin: 0;
  color: var(--text-3);
  font-size: 12px;
}

@media (max-width: 560px) {
  .phone-pair {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    text-align: center;
  }

  .header-tools .btn {
    padding: 0 10px;
  }
}

/* ---------- Gamepads (Controls → Gamepads) ---------- */

.pad-list {
  margin: 0 0 22px;
}

.pad-row {
  flex-wrap: wrap;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.pad-row.is-pressed {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
}

.pad-name {
  min-width: 160px;
}

.pad-name small {
  color: var(--text-3);
  font-size: 12px;
  font-weight: 500;
}

.pad-name small.is-warn {
  color: var(--warn);
}

.pad-empty {
  margin-bottom: 22px;
}

.pad-empty ul {
  display: grid;
  gap: 6px;
  margin: 12px 0 0;
  padding: 12px 0 0 18px;
  border-top: 1px solid var(--line);
  color: var(--text-2);
  font-size: 13px;
}

.pad-map h3 span {
  margin-left: 8px;
  color: var(--text-3);
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

.pad-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.pad-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

.pad-table th,
.pad-table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.pad-table thead th {
  background: var(--bg-raised);
  color: var(--text-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pad-table tbody tr:last-child > * {
  border-bottom: 0;
}

.pad-table tbody th {
  font-weight: 600;
}

.pad-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  vertical-align: middle;
}

.pad-table td {
  color: var(--text-2);
}

.pad-table tbody tr {
  transition: background 0.08s;
}

.pad-table tbody tr.is-pressed {
  background: rgba(139, 92, 246, 0.22);
}

.pad-table tbody tr.is-pressed td {
  color: var(--text);
}

.pad-alt {
  color: var(--text-3);
  font-size: 12px;
}

.pad-note {
  margin: 10px 0 0;
  color: var(--text-3);
  font-size: 12px;
}

.pad-setup {
  padding: 20px;
  border: 1px solid rgba(167, 139, 250, 0.3);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(139, 92, 246, 0.13), rgba(139, 92, 246, 0.03));
}

.pad-setup-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.pad-setup-head h3 {
  margin: 0;
  font-size: 15px;
}

.pad-setup-head span {
  flex: none;
  color: var(--text-3);
  font: 12px var(--mono);
}

.pad-setup-bar {
  height: 4px;
  margin: 12px 0 22px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--surface-3);
}

.pad-setup-bar i {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
}

.pad-setup-prompt {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.pad-setup-hint {
  min-height: 20px;
  margin: 6px 0 20px;
  color: var(--text-2);
  font-size: 14px;
}

.pad-setup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---------- Online play ---------- */

.btn-danger {
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.1);
  color: #fecaca;
}

.btn-danger:hover {
  border-color: rgba(248, 113, 113, 0.55);
  background: rgba(248, 113, 113, 0.18);
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.badge-online {
  background: rgba(52, 211, 153, 0.14);
  color: var(--ok);
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 16px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
}

.input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--bg-raised);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
}

.input:focus {
  border-color: var(--accent-2);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input::placeholder {
  color: var(--text-3);
}

.input-code {
  height: 52px;
  font: 700 24px/1 var(--mono);
  letter-spacing: 0.18em;
  text-align: center;
  text-transform: uppercase;
}

.input-code::placeholder {
  letter-spacing: 0.18em;
}

.join-mic {
  margin-top: 16px;
  font-size: 14px;
}

.join-error {
  margin: 14px 0 0;
  padding: 10px 12px;
  border: 1px solid rgba(248, 113, 113, 0.4);
  border-radius: 10px;
  background: #2a1418;
  color: #fecaca;
  font-size: 13px;
}

.join-form {
  display: contents;
}

/* Home header: icon-only buttons on narrow screens. */
@media (max-width: 680px) {
  .header-tools .btn-label {
    display: none;
  }
}

.online-home {
  color: var(--ok);
}

.online-home-code {
  font: 700 12px var(--mono);
  letter-spacing: 0.08em;
}

.online-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

/* Player bar: "Play online" and, during a session, everyone's voice chip. */
.online-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  margin: 0 4px;
  padding: 0 12px 0 10px;
  border: 1px solid rgba(139, 92, 246, 0.45);
  border-radius: 999px;
  background: rgba(139, 92, 246, 0.14);
  color: #ddd6fe;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.online-btn:hover {
  background: rgba(139, 92, 246, 0.24);
}

.online-btn[data-state='on'],
.online-btn[data-state='guest'] {
  border-color: rgba(52, 211, 153, 0.4);
  background: rgba(52, 211, 153, 0.1);
  color: #bbf7d0;
}

.online-btn[data-state='on'] > .icon,
.online-btn[data-state='guest'] > .icon {
  color: var(--ok);
}

.voice-chips {
  display: inline-flex;
  margin-left: 2px;
}

.voice-chips:empty {
  display: none;
}

.voice-chips .avatar {
  width: 22px;
  height: 22px;
  margin-left: -4px;
  font-size: 11px;
  box-shadow: 0 0 0 2px var(--bg-raised);
}

/* A person's initial; glows while they talk, dims with the microphone off. */
.avatar {
  --level: 0;
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  transition: box-shadow 0.12s;
}

.avatar.is-speaking {
  box-shadow: 0 0 0 2px var(--bg-raised), 0 0 0 calc(3px + var(--level) * 3px) var(--ok), 0 0 14px rgba(52, 211, 153, 0.6);
}

.voice-chips .avatar.is-speaking {
  z-index: 1;
}

.avatar.is-muted::after {
  content: '';
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--danger) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round'%3E%3Cpath d='M6 6l12 12'/%3E%3C/svg%3E") center / 7px no-repeat;
  box-shadow: 0 0 0 2px var(--surface-2);
}

.voice-chips .avatar.is-muted::after {
  width: 9px;
  height: 9px;
  background-size: 6px;
  box-shadow: 0 0 0 2px var(--bg-raised);
}

.mic-btn {
  position: relative;
}

.mic-btn .mic-on,
.mic-btn[aria-pressed='true'] .mic-off {
  display: none;
}

.mic-btn[aria-pressed='true'] .mic-on {
  display: block;
  color: var(--ok);
}

.mic-btn .mic-off {
  color: var(--danger);
}

/* the microphone's level, as a ring */
.mic-level {
  --level: 0;
  position: absolute;
  inset: 3px;
  border-radius: 10px;
  pointer-events: none;
  box-shadow: inset 0 0 0 calc(var(--level) * 3px) rgba(52, 211, 153, 0.75);
}

.mic-btn[aria-pressed='false'] .mic-level {
  display: none;
}

@media (max-width: 900px) {
  .online-btn-label {
    display: none;
  }
}

/* Guests watch the host's game in a video. */
.guest-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #05060a;
  object-fit: contain;
}

.guest-badge {
  position: absolute;
  top: 14px;
  left: 50%;
  z-index: 1;
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(8, 10, 16, 0.8);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
  animation: fade-in 0.2s ease-out;
}

/* The guest plays someone else's game: the save tools are the host's. */
.player.is-guest .player-tools > [data-action='save-state'],
.player.is-guest .player-tools > [data-action='load-state'],
.player.is-guest .player-tools > [data-action='reset'] {
  display: none;
}

.player.is-guest .status-pill {
  cursor: default;
}

/* The Play online dialog */
.modal-online {
  width: min(620px, calc(100vw - 32px));
}

.online-intro {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.online-hero {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.3), rgba(59, 130, 246, 0.25));
  box-shadow: inset 0 0 0 1px rgba(167, 139, 250, 0.35);
  color: #ddd6fe;
}

.online-hero .icon {
  width: 28px;
  height: 28px;
}

.online-intro h3 {
  margin: 2px 0 6px;
  font-size: 16px;
}

.online-intro p {
  margin: 0;
  color: var(--text-2);
  font-size: 14px;
}

.online-points {
  display: grid;
  gap: 4px;
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--text-3);
  font-size: 13px;
}

.online-local {
  margin: 18px 0 0;
  color: var(--text-2);
  font-size: 13px;
}

.online-local b {
  color: var(--text);
}

.online-error {
  margin-bottom: 18px;
}

.online-start {
  margin: 0;
}

.online-share {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px 18px;
  align-items: center;
  padding: 18px;
  border: 1px solid rgba(167, 139, 250, 0.3);
  border-radius: 16px;
  background: radial-gradient(30rem 12rem at 0% 0%, rgba(139, 92, 246, 0.16), transparent 70%), var(--surface-2);
}

.online-share-code {
  display: grid;
  gap: 4px;
}

.online-code-label {
  color: var(--text-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.online-code {
  font: 700 34px/1.1 var(--mono);
  letter-spacing: 0.16em;
  white-space: nowrap;
  -webkit-user-select: all;
  user-select: all;
}

.online-share-actions {
  display: grid;
  gap: 8px;
}

.online-share-how,
.online-reconnecting {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--text-2);
  font-size: 13px;
}

.online-reconnecting {
  color: var(--warn);
}

.online-mic {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin-top: 18px;
}

.online-mic .btn[aria-pressed='true'] .icon {
  color: var(--ok);
}

.online-mic-level {
  --level: 0;
  width: 64px;
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--surface-3);
}

.online-mic:not(.is-on) .online-mic-level {
  display: none;
}

.online-mic-level i {
  display: block;
  width: calc(var(--level) * 100%);
  height: 100%;
  border-radius: 3px;
  background: var(--ok);
  transition: width 0.1s;
}

.online-mic-note {
  flex: 1;
  min-width: 200px;
  color: var(--text-3);
  font-size: 12px;
}

.online-row .phone-name small.is-quiet {
  color: var(--text-3);
}

.online-row.is-pending .avatar {
  opacity: 0.5;
}

.online-row .icon-btn {
  flex: none;
  width: 32px;
  height: 32px;
}

.online-you {
  margin: 0;
  color: var(--text-2);
  font-size: 14px;
}

.online-you b {
  color: var(--text);
}

.online-volumes {
  display: grid;
  gap: 10px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.online-volumes h3 {
  margin: 0 0 2px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.online-volumes .slider {
  grid-template-columns: 100px 1fr;
}

@media (max-width: 560px) {
  .online-share {
    grid-template-columns: minmax(0, 1fr);
  }

  .online-code {
    font-size: 28px;
  }

  .online-share-actions {
    grid-template-columns: 1fr 1fr;
  }

  .online-intro {
    grid-template-columns: minmax(0, 1fr);
  }

  .online-row .select {
    max-width: 104px;
  }
}

/* Four feature cards: two by two on medium screens. */
@media (min-width: 761px) and (max-width: 1000px) {
  .features {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
