/* Self-hosted Inter (SIL OFL, see fonts/OFL.txt) - modern UI typeface, no CDN. */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/inter.woff2") format("woff2");
}

:root {
  color-scheme: dark;

  /* ---- Surfaces: near-black canvas ramp to raised controls ---- */
  --bg: #08090d;
  --bg-2: #050608;
  --surface-1: #12141c;   /* cards, panels */
  --surface-2: #181b26;   /* inputs, secondary buttons */
  --surface-3: #1f2330;   /* hover / active surface */
  --panel: var(--surface-1);    /* legacy aliases */
  --panel-2: var(--surface-2);

  /* ---- Text ramp ---- */
  --text: #e8eaf1;        /* primary */
  --text-2: #b6bccb;      /* secondary */
  --muted: #969db0;       /* tertiary / hints */

  /* ---- Accent: vivid electric green (arcade neon) ---- */
  --accent: #a6ff1a;
  --accent-bright: #ccff6b;
  --accent-dark: #2f5e2c;
  --accent-contrast: #07140a;   /* text on an accent fill */
  --accent-soft: rgba(166, 255, 26, 0.14);
  --accent-soft-border: rgba(166, 255, 26, 0.4);
  --accent-grad: linear-gradient(180deg, #b8ff3d, #86d40c);
  /* ---- Arcade neon: electric secondaries + glow tokens ---- */
  --accent-2: #2ee9ff;          /* electric cyan */
  --accent-3: #ff2fd6;          /* hot magenta */
  --glow: 0 0 16px rgba(166, 255, 26, 0.45);
  --glow-strong: 0 0 26px rgba(166, 255, 26, 0.6), 0 0 56px rgba(166, 255, 26, 0.28);
  --glow-cyan: 0 0 18px rgba(46, 233, 255, 0.45);
  --glow-magenta: 0 0 18px rgba(255, 47, 214, 0.42);
  /* ---- Monospace for arcade/terminal micro-labels ---- */
  --font-mono: ui-monospace, "Cascadia Code", "Segoe UI Mono", Menlo, Consolas, monospace;

  /* ---- Brand colours (console families) - vivid for the colour grid ---- */
  --brand-nintendo: #ff2740;
  --brand-sony: #3b82f6;
  --brand-sega: #1fb6ff;
  --brand-other: #a6ff1a;

  /* ---- Lines ---- */
  --border: #272c3a;
  --border-strong: #3a4255;

  /* ---- Semantic ---- */
  --danger: #c0504a;
  --danger-text: #ff9a9a;
  --error: #ff8e8e;

  /* ---- Radius scale ---- */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;
  --radius: 14px;         /* legacy alias */
  --radius-sm: 9px;       /* legacy alias */

  /* ---- Spacing scale (8px base) ---- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* ---- Type ---- */
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --text-xs: 0.75rem;
  --text-sm: 0.85rem;
  --text-md: 0.92rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.6rem;
  --text-2xl: 2rem;

  /* ---- Elevation ---- */
  --e1: 0 1px 2px rgba(0, 0, 0, 0.30), 0 2px 6px rgba(0, 0, 0, 0.22);
  --e2: 0 2px 4px rgba(0, 0, 0, 0.28), 0 10px 24px rgba(0, 0, 0, 0.36);
  --e3: 0 4px 10px rgba(0, 0, 0, 0.30), 0 20px 48px rgba(0, 0, 0, 0.46);
  --shadow: var(--e3);          /* legacy alias */
  --shadow-sm: var(--e1);       /* legacy alias */
}

* { box-sizing: border-box; }

::selection { background: rgba(166, 255, 26, 0.4); color: var(--accent-contrast); }

/* Themed scrollbars so the chrome matches the dark UI. */
html { scrollbar-color: var(--border) transparent; scrollbar-width: thin; scroll-behavior: smooth; scroll-padding-top: 72px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* Calm, premium dark canvas: one restrained green bloom up top, nothing busy. */
  background:
    radial-gradient(1100px 520px at 50% -260px, rgba(166, 255, 26, 0.1), transparent 68%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  background-attachment: fixed;
  line-height: 1.5;
  /* Crisper text + slight optical tightening, the way modern UIs (Linear/Vercel) render. */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern", "liga", "calt";
  letter-spacing: -0.01em;
}

/* CRT scanlines removed for a clean, premium dark surface (giga.ai-style calm). */

footer { text-align: center; padding: var(--space-6) var(--space-4); border-top: 1px solid var(--border); margin-top: var(--space-5); }

/* Slim sticky top nav. */
.nav {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) clamp(var(--space-4), 4vw, var(--space-6));
  background: rgba(8, 9, 13, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.nav-brand {
  font-weight: 800;
  letter-spacing: 0.04em;
  font-size: 0.95rem;
  color: var(--accent);
  text-decoration: none;
  filter: drop-shadow(0 0 12px rgba(166, 255, 26, 0.55));
}
.nav-link {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.18s ease;
}
.nav-link:hover { color: var(--accent); }

main { flex: 1; width: 100%; margin: 0 auto; padding: 0; }
#picker { width: 100%; }

/* --- Hero --- */
.hero {
  text-align: center;
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(3.5rem, 11vw, 7.5rem) var(--space-4) clamp(2rem, 5vw, 3.5rem);
}
.hero-eyebrow {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent);
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--accent-soft-border);
  border-radius: var(--r-pill);
  background: var(--accent-soft);
}
.hero-title {
  margin: var(--space-4) auto 0;
  max-width: 18ch;
  font-size: clamp(2.3rem, 7.5vw, 4rem);
  font-weight: 800;
  line-height: 1.04;
  letter-spacing: -0.035em;
  color: var(--text);
}
.hero-title .neon {
  background: linear-gradient(100deg, var(--accent) 10%, var(--accent-2) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 26px rgba(166, 255, 26, 0.5));
}
.hero-sub {
  margin: var(--space-4) auto 0;
  max-width: 32rem;
  color: var(--text-2);
  font-size: 1.05rem;
  line-height: 1.6;
}
.hero-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: var(--space-5);
  padding: 0.9rem 1.55rem;
  background: linear-gradient(180deg, #aacd1d, #8aa70c);
  color: var(--accent-contrast);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
  border-radius: var(--r-md);
  text-decoration: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 10px 26px -10px rgba(155, 188, 15, 0.55);
  transition: transform 0.14s ease, box-shadow 0.2s ease, background 0.18s ease;
}
.hero-cta::after {
  content: "\2192";
  font-weight: 600;
  transition: transform 0.18s ease;
}
.hero-cta:hover {
  transform: translateY(-2px);
  background: linear-gradient(180deg, #b6da26, #94b20e);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.34), 0 14px 34px -10px rgba(155, 188, 15, 0.65);
}
.hero-cta:hover::after { transform: translateX(3px); }
.hero-cta:active { transform: translateY(0); }

/* Hero product shot: a browser-window mockup showing a game (giga-style visual). */
.hero-visual {
  margin: clamp(2.75rem, 7vw, 4.5rem) auto 0;
  max-width: 760px;
  perspective: 1600px;
}
.hero-window {
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(160deg, #1a1d29, #0c0e15);
  border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--border-strong));
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 12%, transparent),
    0 40px 90px -36px rgba(0, 0, 0, 0.95),
    0 0 90px -24px color-mix(in srgb, var(--accent) 32%, transparent);
}
.hero-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 11px 16px;
  background: linear-gradient(180deg, #20242f, #161922);
  border-bottom: 1px solid var(--border);
}
.hero-bar span {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--border-strong);
}
.hero-bar span:nth-child(1) { background: #ff5f57; }
.hero-bar span:nth-child(2) { background: #febc2e; }
.hero-bar span:nth-child(3) { background: #28c840; }
.hero-bar em {
  margin-left: auto;
  font-family: var(--font-mono);
  font-style: normal;
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.hero-window img {
  display: block;
  width: 100%;
  /* Fixed box + crop-to-fill so swapping games (different native aspect ratios)
     never changes the hero's size. */
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #000;
  transition: opacity 0.32s ease;
}

/* --- Home sections (open, generous spacing) --- */
.home-section { max-width: 720px; margin: 0 auto; padding: var(--space-7) var(--space-4); }

/* Modular feature/value row (giga.ai-style), clean cards under the hero. */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--space-3);
}
.feature {
  padding: var(--space-5) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, var(--surface-1), var(--surface-2));
  text-align: left;
}
.feature-icon {
  width: 28px;
  height: 28px;
  margin-bottom: var(--space-3);
  color: var(--accent);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.feature h3 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-base);
  font-weight: 700;
  letter-spacing: -0.01em;
}
.feature p {
  margin: 0;
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--text-2);
}
.section-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin: 0 0 var(--space-4);
  text-align: center;
}

/* --- Load view: a single focused card --- */
#load-view {
  max-width: 480px;
  margin: var(--space-6) auto;
  padding: clamp(1.75rem, 5vw, 2.75rem);
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  box-shadow: var(--shadow);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
#picker.dragover #load-view {
  border-color: var(--accent);
  box-shadow: var(--glow-strong), var(--shadow);
}

.picker-icon {
  width: 56px;
  height: 56px;
  color: var(--accent);
  margin-bottom: var(--space-3);
}
.picker-title {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-2);
}

#console-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: var(--space-2);
  max-width: 780px;
  margin: var(--space-4) auto 0;
}
.console-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 4px;
  min-height: 78px;
  padding: var(--space-3);
  padding-left: calc(var(--space-3) + 3px);
  text-align: left;
  /* Premium calm: mostly the dark surface with a restrained brand tint; the
     console identity reads from the left spine, the label, and the hover glow. */
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--brand, var(--accent)) 20%, var(--surface-1)), var(--surface-2));
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--brand, var(--accent)) 22%, var(--border));
  border-radius: var(--r-md);
  overflow: hidden;
  /* Calm at rest: a neutral soft elevation. The brand glow is saved for hover. */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), var(--e1);
  transition: transform 0.14s ease, border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
/* Brand-coloured spine down the left edge of each tile (launcher style). */
.console-btn::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--brand, var(--accent));
}
/* Plain label: brand eyebrow + name, no panel - keeps the small tile clean. */
.console-label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  width: 100%;
}
.console-brand {
  font-family: var(--font-mono);
  font-size: 0.5rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brand, var(--accent));
}
.console-name {
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: -0.01em;
}
.console-glyph { display: none; }
/* Tile lifts and glows in its own brand colour on hover. */
.console-btn:hover:not(:disabled) {
  transform: translateY(-3px);
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--brand, var(--accent)) 54%, var(--surface-1)), color-mix(in srgb, var(--brand, var(--accent)) 14%, var(--surface-1)) 84%);
  border-color: var(--brand, var(--accent));
  box-shadow: 0 0 0 1px var(--brand, var(--accent)), 0 10px 30px -8px var(--brand, var(--accent)), var(--e2);
}
.console-btn:active:not(:disabled) { transform: translateY(-1px); }
.console-btn:focus-visible { outline-color: var(--brand, var(--accent)); }
/* Quiet ghost back control rather than a heavy dark button. */
.back-btn {
  margin: 0 0 var(--space-3);
  padding: var(--space-1) var(--space-2);
  background: none;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: var(--text-sm);
}
.back-btn:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
  transform: none;
}

.filebtn {
  display: inline-block;
  cursor: pointer;
  background: linear-gradient(180deg, #aacd1d, #8aa70c);
  color: var(--accent-contrast);
  padding: 0.9rem 1.55rem;
  border-radius: var(--r-md);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
  border: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 10px 26px -10px rgba(155, 188, 15, 0.55);
  transition: transform 0.14s ease, box-shadow 0.2s ease, background 0.18s ease;
}
.filebtn:hover {
  transform: translateY(-2px);
  background: linear-gradient(180deg, #b6da26, #94b20e);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.34), 0 14px 34px -10px rgba(155, 188, 15, 0.65);
}
.filebtn:active { transform: translateY(0); }

/* Small file buttons read as secondary controls, matching the dark buttons. */
.filebtn.small {
  padding: 0.45rem 0.85rem;
  font-weight: 500;
  font-size: 0.85rem;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}
.filebtn.small:hover { filter: none; border-color: var(--accent); transform: translateY(-1px); }

/* Visually hidden but still keyboard-focusable, so the label gets a focus ring. */
.filebtn input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.filebtn input:disabled + span { opacity: 0.4; }

button:focus-visible,
.filebtn:focus-within,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hint { color: var(--muted); font-size: var(--text-xs); margin-top: var(--space-4); line-height: 1.6; }

.controls-help {
  max-width: 440px;
  margin: var(--space-4) auto 0;
  text-align: left;
  font-size: var(--text-xs);
}
.controls-help summary {
  cursor: pointer;
  color: var(--accent);
  width: fit-content;
  margin: 0 auto;
}
.controls-help p { color: var(--muted); margin: 0.5rem 0 0; line-height: 1.6; }
.controls-help strong { color: var(--text-2); font-weight: 600; }
kbd {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text);
}

.error {
  color: var(--error);
  font-size: 0.85rem;
  margin-top: 1rem;
}

#recent { text-align: left; }
.recent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
}
.recent-head .section-eyebrow { margin: 0; text-align: left; }
#recent h2 {
  font-size: var(--text-sm);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0;
}
.recent-clear { font-size: var(--text-xs); padding: var(--space-1) var(--space-2); }
#recent-list { list-style: none; margin: 0; padding: 0; }
.recent-item {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-1);
}
.recent-resume {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-3);
  background: linear-gradient(160deg, var(--surface-2), var(--surface-1));
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--space-3);
  transition: transform 0.12s ease, border-color 0.18s ease, background 0.18s ease;
}
.recent-info { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; flex: 1; }
.recent-resume:hover {
  border-color: var(--accent);
  background: linear-gradient(160deg, var(--surface-3), var(--surface-2));
  transform: translateY(-1px);
}
.recent-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
}
.recent-top .recent-name { flex: 1; min-width: 0; }
.recent-top .badge { flex-shrink: 0; }
.recent-name {
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Portrait "game case" cover so fetched box art fills it; letter is the fallback. */
.recent-resume .b-cover {
  width: 44px;
  height: 58px;
  border-radius: var(--r-sm);
  font-size: 1.35rem;
  align-self: center;
}
.recent-meta {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--muted);
}
.recent-del {
  align-self: stretch;
  width: 38px;
  padding: 0;
  line-height: 1;
  font-size: 1.05rem;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  box-shadow: none;
}
#storage { margin-top: 0.8rem; text-align: left; }

/* Prominent "try one of these" example-games shelf on the home screen. */
#examples-list, #recent-list { max-width: 520px; margin-left: auto; margin-right: auto; }
.examples-head {
  font-size: var(--text-sm);
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 var(--space-1);
}
.examples-hint { margin-top: 0; }
/* The full author/license meta is only for the load-view list, not the cards. */
.b-system { display: none; }

/* Home example games render as a compact card grid (mini game library). */
#examples-list {
  list-style: none;
  margin: var(--space-3) auto 0;
  padding: 0;
  max-width: 560px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-2);
}
#examples-list li { margin: 0; }
#examples-list .builtin-game {
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-2);
  height: 100%;
  padding: var(--space-2);
  border-radius: var(--r-md);
}
#examples-list .b-cover {
  width: 100%;
  height: 88px;
  border-radius: var(--r-sm);
  font-size: 1.9rem;
}
#examples-list .b-text { width: 100%; gap: 2px; }
#examples-list .b-name { font-size: 0.82rem; line-height: 1.18; white-space: normal; }
#examples-list .b-system { display: block; font-size: 0.66rem; color: var(--muted); }
#examples-list .b-meta { display: none; }
#examples-list .builtin-game::after { display: none; }

#builtin { margin: var(--space-5) auto 0; max-width: 440px; text-align: left; }
#builtin h2 {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 0.6rem;
}
#builtin-list { list-style: none; margin: 0; padding: 0; }
#builtin-list li { margin-bottom: 0.4rem; }
.builtin-game {
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-3);
  background: linear-gradient(160deg, var(--surface-2), var(--surface-1));
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--space-3);
  transition: transform 0.12s ease, border-color 0.18s ease, background 0.18s ease;
}
.builtin-game:hover:not(:disabled) {
  border-color: var(--accent);
  background: linear-gradient(160deg, var(--surface-3), var(--surface-2));
  transform: translateY(-1px);
}
/* Generated placeholder cover: system-coloured square with the game's initial. */
.b-cover {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.15rem;
  color: #fff;
  position: relative;
  overflow: hidden;
  background: linear-gradient(150deg, var(--cover, var(--accent)), rgba(0, 0, 0, 0.35));
  border: 1px solid color-mix(in srgb, var(--cover, var(--accent)) 55%, transparent);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.25), 0 4px 12px -4px color-mix(in srgb, var(--cover, var(--accent)) 55%, transparent);
}
/* Real box art fills the cover; the letter underneath is the fallback. */
.b-cover.has-art { color: transparent; }
.b-cover-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}
.b-text { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; text-align: left; }
.b-name { font-weight: 600; }
/* Play affordance so game tiles clearly read as click-to-play. */
.builtin-game::after,
.recent-resume::after {
  content: "\25B6";
  margin-left: auto;
  flex: none;
  color: var(--muted);
  font-size: 0.7rem;
  transition: color 0.18s ease, transform 0.18s ease;
}
.builtin-game:hover:not(:disabled)::after,
.recent-resume:hover::after {
  color: var(--accent);
  transform: translateX(2px);
}
.b-meta { font-size: 0.72rem; color: var(--muted); }

.url-load { max-width: 440px; margin: var(--space-4) auto 0; text-align: left; }
.url-load > summary { cursor: pointer; color: var(--accent); width: fit-content; margin: 0 auto; }
.url-row { display: flex; gap: 0.5rem; margin-top: 0.6rem; }
#rom-url {
  flex: 1;
  min-width: 0;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
}
.url-load .hint { text-align: center; margin-top: 0.6rem; }

#game {
  position: relative;
  width: 100%;
  aspect-ratio: 10 / 9;
  background: #000;
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.85);
  /* The screen sits inside the bezel; a neutral inner edge + vignette gives it
     depth without any coloured glow. */
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    inset 0 0 60px rgba(0, 0, 0, 0.5);
}

/* In-game view: hide the landing nav, centre + frame the screen and control bar. */
body.playing .nav { display: none; }
body.playing:not(.skin-mode) main { padding: var(--space-6) var(--space-4); }
#game-wrap { max-width: 760px; margin: 0 auto; }
#console-body { max-width: min(680px, 94vw); margin: 0 auto; }

/* The screen sits in a clean neutral bezel (arcade-monitor surround), no glow. */
body.playing:not(.skin-mode) #console-body {
  position: relative;
  padding: 16px;
  background: linear-gradient(160deg, #191c28 0%, #0c0e15 70%);
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    inset 0 0 0 1px rgba(0, 0, 0, 0.5),
    0 26px 64px -32px rgba(0, 0, 0, 0.9),
    var(--e3);
}

.hint-inline { color: var(--muted); font-size: 0.75rem; }

/* Optional mouse/touch joystick (opt-in, off by default). */
#joystick:not([hidden]) {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}
.joystick-main {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 2rem;
  flex-wrap: wrap;
}
#joystick-actions { display: flex; gap: 1rem; align-items: center; }
#joystick-meta { display: flex; gap: 1rem; }
.meta-btn {
  padding: 0.45rem 1.1rem;
  border-radius: 999px;
  font-size: 0.8rem;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.meta-btn.pressed { filter: brightness(0.85); transform: scale(0.96); }

/* Active state for the control toggle buttons. */
#controls-row button.active,
#fast-forward-btn.active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

/* --- Game Boy Color faceplate skin --- */
.gb-brand { display: none; }

.gb-skin #console-body {
  max-width: 380px;
  margin: 0 auto;
  padding: 22px 22px 26px;
  border-radius: 18px 18px 52px 18px;
  background: linear-gradient(160deg, #8a5fc7, #5b3f9c 55%, #46307e);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.25), inset 0 -8px 18px rgba(0, 0, 0, 0.35), var(--shadow);
  position: relative;
}
/* Power LED */
.gb-skin #console-body::before {
  content: "";
  position: absolute;
  left: 30px;
  top: 34px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ff9a9a, #c0392b);
  box-shadow: 0 0 6px rgba(255, 90, 90, 0.85);
}
/* Screen sunk into a dark bezel */
.gb-skin #game {
  /* content-box so the inline 10:9 aspect sizes the screen itself, not the box
     including the thick asymmetric bezel - otherwise the game letterboxes. */
  box-sizing: content-box;
  width: calc(100% - 28px);
  border: 14px solid #2a2740;
  border-bottom-width: 28px;
  border-radius: 8px 8px 22px 8px;
  background: #11131c;
  box-shadow: inset 0 0 0 2px #14121f, 0 2px 6px rgba(0, 0, 0, 0.5);
}
.gb-skin .gb-brand {
  display: block;
  text-align: right;
  font-style: italic;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
  margin: 0.5rem 4px 0.3rem;
  color: #1d1630;
}
.gb-skin .gb-brand span {
  background: linear-gradient(90deg, #d33, #d80, #2a2, #28d, #92c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-size: 0.7em;
  letter-spacing: 0.04em;
}

.gb-skin #joystick:not([hidden]) { margin-top: 0.4rem; gap: 0.5rem; }
.gb-skin .joystick-main { gap: 2.5rem; }

/* D-pad cross built from the round base (input mapping is unchanged). */
.gb-skin #joystick-base {
  width: 108px;
  height: 108px;
  background: none;
  border: none;
  box-shadow: none;
}
.gb-skin #joystick-thumb { display: none; }
.gb-skin #joystick-base::before,
.gb-skin #joystick-base::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: #423e52;
  border-radius: 7px;
  box-shadow: inset 0 2px 2px rgba(255, 255, 255, 0.08), 0 2px 4px rgba(0, 0, 0, 0.5);
}
.gb-skin #joystick-base::before { width: 38px; height: 108px; }
.gb-skin #joystick-base::after { width: 108px; height: 38px; }

/* A / B as small round grey buttons (real GBC), gently angled and close. */
.gb-skin #joystick-actions { transform: rotate(-18deg); gap: 0.55rem; }
.gb-skin .action-btn {
  width: 44px;
  height: 44px;
  color: #ece9f2;
  background: radial-gradient(circle at 35% 30%, #6f6a7d, #423d52);
  border: 1px solid #2c2838;
  box-shadow: 0 3px 0 #241f30, inset 0 1px 2px rgba(255, 255, 255, 0.22);
}
.gb-skin .action-btn:hover:not(:disabled) { filter: brightness(1.08); transform: none; }
.gb-skin .action-btn.pressed { transform: translateY(2px); box-shadow: 0 1px 0 #241f30; filter: none; }

/* Start / Select as straight horizontal grey pills (real GBC). */
.gb-skin #joystick-meta { transform: none; margin-top: 0.5rem; }
.gb-skin .meta-btn {
  color: #cfcae0;
  background: #3a3550;
  border: 1px solid #2a2640;
  padding: 0.3rem 0.9rem;
  font-size: 0.62rem;
  text-transform: uppercase;
  box-shadow: 0 2px 0 #221f33;
}
.gb-skin .meta-btn.pressed { transform: translateY(2px); filter: none; }

/* --- Generic console controller skin (non-handheld systems) --- */
/* Screen as the "TV", a gamepad below it. Per-console refinements hook off
   [data-system="..."]. */
.console-skin #console-body { max-width: min(560px, 96vw); margin: 0 auto; }
.console-skin #joystick:not([hidden]) {
  position: relative;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  margin-top: 1.3rem;
  padding: 1.6rem 2.1rem 1.8rem;
  background: linear-gradient(168deg, var(--surface-3) 0%, var(--surface-2) 52%, var(--surface-1) 100%);
  border: 1px solid var(--border-strong);
  border-radius: 30px 30px 26px 26px / 34px 34px 26px 26px;
  box-shadow:
    inset 0 2px 1px rgba(255, 255, 255, 0.10),
    inset 0 -14px 26px rgba(0, 0, 0, 0.38),
    0 18px 40px rgba(0, 0, 0, 0.5);
}
/* Grip "wings" flaring from the bottom corners to suggest a real gamepad. */
.console-skin #joystick:not([hidden])::before,
.console-skin #joystick:not([hidden])::after {
  content: "";
  position: absolute;
  bottom: -2px;
  width: 76px;
  height: 66px;
  background: linear-gradient(168deg, var(--surface-2), var(--surface-1));
  border: 1px solid var(--border-strong);
  z-index: -1;
}
.console-skin #joystick:not([hidden])::before { left: -32px; border-radius: 40px 12px 36px 40px; }
.console-skin #joystick:not([hidden])::after { right: -32px; border-radius: 12px 40px 40px 36px; }
.console-skin .joystick-main { gap: 2.5rem; align-items: center; }
.console-skin #joystick-base { width: 104px; height: 104px; background: none; border: none; box-shadow: none; }
.console-skin #joystick-thumb { display: none; }
.console-skin #joystick-base::before,
.console-skin #joystick-base::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(155deg, var(--surface-2), var(--bg));
  border-radius: 9px;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.10), 0 3px 6px rgba(0, 0, 0, 0.5);
}
.console-skin #joystick-base::before { width: 36px; height: 104px; }
.console-skin #joystick-base::after { width: 104px; height: 36px; }
.console-skin #joystick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  max-width: 170px;
  justify-content: center;
}
.console-skin .action-btn {
  width: 48px;
  height: 48px;
  background: radial-gradient(circle at 38% 30%, var(--surface-3), var(--surface-1) 72%);
  color: var(--text);
  border: 1px solid var(--bg);
  font-weight: 700;
  box-shadow: 0 3px 0 var(--bg-2), inset 0 1px 1px rgba(255, 255, 255, 0.18);
}
.console-skin .action-btn.pressed {
  transform: translateY(3px);
  box-shadow: 0 0 0 var(--bg-2), inset 0 1px 2px rgba(0, 0, 0, 0.4);
  filter: none;
}
.console-skin #joystick-meta { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; }
.console-skin .meta-btn {
  background: linear-gradient(180deg, var(--surface-3), var(--surface-2));
  border: 1px solid var(--bg);
  color: var(--text-2);
  padding: 0.35rem 1rem;
  border-radius: var(--r-pill);
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 2px 0 var(--bg-2), inset 0 1px 1px rgba(255, 255, 255, 0.12);
}
.console-skin .shoulder-btn { border-radius: 8px 8px 4px 4px; }
.console-skin .meta-btn.pressed { transform: translateY(2px); filter: none; }

/* SNES: iconic Super Famicom coloured diamond (face order in DOM: Y X B A). */
.console-skin[data-system="snes"] #joystick-actions {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  place-items: center;
  max-width: none;
  gap: 0.2rem;
}
.console-skin[data-system="snes"] .action-btn { color: #fff; border: none; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.4); }
.console-skin[data-system="snes"] .action-btn:nth-child(1) { grid-area: 2 / 1; background: radial-gradient(circle at 35% 30%, #57cf78, #2ea84f); }
.console-skin[data-system="snes"] .action-btn:nth-child(2) { grid-area: 1 / 2; background: radial-gradient(circle at 35% 30%, #5b8ff0, #2e6ad1); }
.console-skin[data-system="snes"] .action-btn:nth-child(3) { grid-area: 3 / 2; background: radial-gradient(circle at 35% 30%, #f2cd56, #e0b020); color: #3a2e00; }
.console-skin[data-system="snes"] .action-btn:nth-child(4) { grid-area: 2 / 3; background: radial-gradient(circle at 35% 30%, #db5a4e, #c0392b); }
.console-skin[data-system="snes"] .action-btn.pressed { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.4); }

/* NES: two round dark-red face buttons (B, A). */
.console-skin[data-system="nes"] .action-btn {
  background: radial-gradient(circle at 38% 30%, #d2424a, #9e1f29 72%);
  border: 1px solid #6e121a;
  color: #ffe2e4;
}

/* PlayStation: Sony face diamond - dark buttons, coloured symbols
   (Square pink / Triangle green / Cross blue / Circle red). DOM order: square, triangle, cross, circle. */
.console-skin[data-system="psx"] #joystick-actions {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  place-items: center;
  max-width: none;
  gap: 0.2rem;
}
.console-skin[data-system="psx"] .action-btn {
  background: radial-gradient(circle at 38% 30%, #474c5b, #2a2e38 72%);
  border: 1px solid #15171c;
  font-size: 1.15rem;
  line-height: 1;
  box-shadow: 0 3px 0 #14171f, inset 0 1px 1px rgba(255, 255, 255, 0.14);
}
.console-skin[data-system="psx"] .action-btn:nth-child(1) { grid-area: 2 / 1; color: #ff86bd; }
.console-skin[data-system="psx"] .action-btn:nth-child(2) { grid-area: 1 / 2; color: #54d894; }
.console-skin[data-system="psx"] .action-btn:nth-child(3) { grid-area: 3 / 2; color: #6ea3ff; }
.console-skin[data-system="psx"] .action-btn:nth-child(4) { grid-area: 2 / 3; color: #ff6f6f; }
.console-skin[data-system="psx"] .action-btn.pressed { transform: translateY(2px); box-shadow: 0 1px 0 #14171f; }

/* Sega Genesis: the iconic A B C in a gentle upward arc (3-button pad), dark buttons. */
.console-skin[data-system="segaMD"] #joystick-actions {
  flex-wrap: nowrap;
  max-width: none;
  gap: 0.7rem;
  align-items: flex-end;
}
.console-skin[data-system="segaMD"] .action-btn {
  width: 50px;
  height: 50px;
  background: radial-gradient(circle at 38% 30%, #4a4f57, #25282f 72%);
  border: 1px solid #14161c;
  color: #e3e6ec;
  font-weight: 700;
}
.console-skin[data-system="segaMD"] .action-btn:nth-child(2) { transform: translateY(-9px); }
.console-skin[data-system="segaMD"] .action-btn:nth-child(3) { transform: translateY(-18px); }
.console-skin[data-system="segaMD"] .action-btn:nth-child(2).pressed { transform: translateY(-7px); }
.console-skin[data-system="segaMD"] .action-btn:nth-child(3).pressed { transform: translateY(-16px); }

/* Nintendo DS: A/B/X/Y diamond (same arrangement as SNES), neutral buttons. */
.console-skin[data-system="nds"] #joystick-actions {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  place-items: center;
  max-width: none;
  gap: 0.2rem;
}
.console-skin[data-system="nds"] .action-btn:nth-child(1) { grid-area: 2 / 1; }
.console-skin[data-system="nds"] .action-btn:nth-child(2) { grid-area: 1 / 2; }
.console-skin[data-system="nds"] .action-btn:nth-child(3) { grid-area: 3 / 2; }
.console-skin[data-system="nds"] .action-btn:nth-child(4) { grid-area: 2 / 3; }

/* ---- Nintendo 64: clean pad in the standard console body (analog stick + C-cluster) ---- */
.pad-shell { display: none; }
/* Centre control is a round analog stick (drives the left analog stick), not a cross. */
.console-skin[data-system="n64"] #joystick-base {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, var(--surface-3), var(--surface-1) 72%);
  border: 1px solid var(--bg);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.5);
}
.console-skin[data-system="n64"] #joystick-base::before,
.console-skin[data-system="n64"] #joystick-base::after { display: none; }
.console-skin[data-system="n64"] #joystick-thumb {
  display: block;
  width: 42px;
  height: 42px;
  margin: -21px 0 0 -21px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, #d7dade, #abafb5 72%, #9a9ea4);
  border: 1px solid #84878c;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
}
/* Right cluster: green B / blue A diagonal + yellow C-button diamond. */
.console-skin[data-system="n64"] #joystick-actions {
  display: grid;
  grid-template-columns: 44px 44px 16px 36px 36px;
  grid-template-rows: 40px 40px 40px;
  gap: 5px;
  max-width: none;
  place-items: center;
}
.console-skin[data-system="n64"] .action-btn { border: none; font-weight: 700; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.32); }
.console-skin[data-system="n64"] .action-btn:nth-child(1) { /* B - green */
  grid-area: 1 / 1 / 2 / 2;
  width: 42px; height: 42px;
  background: radial-gradient(circle at 38% 30%, #57d088, #1f9b53);
  color: #08361b;
}
.console-skin[data-system="n64"] .action-btn:nth-child(2) { /* A - blue */
  grid-area: 2 / 2 / 3 / 3;
  width: 46px; height: 46px;
  background: radial-gradient(circle at 38% 30%, #6098f2, #2456c8);
  color: #fff;
}
.console-skin[data-system="n64"] .action-btn:nth-child(n+3) { /* C buttons - yellow */
  width: 32px; height: 32px;
  font-size: 0.62rem;
  color: #5a3d00;
  background: radial-gradient(circle at 38% 30%, #ffd451, #e3a91d);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}
.console-skin[data-system="n64"] .action-btn:nth-child(3) { grid-area: 1 / 4 / 2 / 6; } /* C-up */
.console-skin[data-system="n64"] .action-btn:nth-child(4) { grid-area: 3 / 4 / 4 / 6; } /* C-down */
.console-skin[data-system="n64"] .action-btn:nth-child(5) { grid-area: 2 / 4 / 3 / 5; } /* C-left */
.console-skin[data-system="n64"] .action-btn:nth-child(6) { grid-area: 2 / 5 / 3 / 6; } /* C-right */
.console-skin[data-system="n64"] .action-btn.pressed { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.32); }
/* A bit more room between the stick, the cluster, and the trigger row. */
.console-skin[data-system="n64"] .joystick-main { gap: 3rem; }
.console-skin[data-system="n64"] #joystick-meta { gap: 0.55rem; margin-top: 0.6rem; }
/* Start in N64 red; L / R / Z keep the standard grey pill look. */
.console-skin[data-system="n64"] #joystick-meta .meta-btn:last-child {
  background: radial-gradient(circle at 40% 35%, #ea5a51, #c0291f);
  border: 1px solid #8e1e16;
  color: #fff;
  box-shadow: 0 2px 0 #7a160f;
}

/* Immersive mode: with a game running and the skin on, the Game Boy fills the
   view and the page chrome gets out of the way. */
.skin-mode header,
.skin-mode footer { display: none; }
.skin-mode main { max-width: none; padding: 0.5rem; }
.skin-mode #game-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
}
.skin-mode #console-body { max-width: min(540px, 96vw); margin: 0; }
/* In skin mode the menu stays the full, normal card (cover, label, badge, all
   controls) - just width-matched to the faceplate above it. */
.skin-mode #save-controls { max-width: min(540px, 96vw); }
.skin-mode #status { text-align: center; }
.action-btn {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-contrast);
  background: var(--accent-grad);
  border: 1px solid rgba(155, 188, 15, 0.55);
  box-shadow: var(--shadow-sm);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.action-btn:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--accent-bright), #8aac0d);
  border-color: rgba(155, 188, 15, 0.7);
  transform: none;
}
.action-btn.pressed { filter: brightness(0.82); transform: scale(0.94); }
#joystick-base {
  position: relative;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, var(--panel-2), var(--panel));
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
#joystick-base:active { cursor: grabbing; border-color: var(--accent); }
#joystick-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 60px;
  height: 60px;
  margin: -30px 0 0 -30px;
  border-radius: 50%;
  background: var(--accent-grad);
  border: 1px solid rgba(155, 188, 15, 0.6);
  box-shadow: var(--shadow-sm);
  transition: transform 0.08s ease-out;
  pointer-events: none;
}

#save-controls {
  max-width: min(680px, 94vw);
  margin: var(--space-4) auto 0;
  background: linear-gradient(180deg, var(--surface-1), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--e2);
  padding: var(--space-5);
}
/* Gentle entrance when the panel first appears on game ready. */
#save-controls:not([hidden]) { animation: panel-in 0.25s ease both; }
@keyframes panel-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-2) 0;
}
/* Divider + spacing only at the start of each logical group of controls. */
.row.group-start {
  border-top: 1px solid var(--border);
  margin-top: var(--space-1);
  padding-top: var(--space-3);
}

/* Save/backup options are tucked behind a disclosure to keep the panel calm. */
.save-backup > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 0.6rem 0;
  border-top: 1px solid var(--border);
  margin-top: 0.3rem;
}
.save-backup > summary:hover,
.save-backup[open] > summary { color: var(--text); }
/* The first group inside doesn't need its own divider right under the summary. */
.save-backup > .row.group-start:first-of-type {
  border-top: none;
  margin-top: 0;
  padding-top: 0.2rem;
}

.group-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 140px;
}

.now-playing {
  flex: 0 1 auto;
  min-width: 0;
  font-weight: 600;
  font-size: var(--text-base);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* "Now playing" header: tiny eyebrow over a prominent game title + chip, with
   the session actions grouped to the right. Makes the game the hero of the panel. */
.np-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
/* Album-art style cover thumbnail for the game that's currently playing. */
.np-cover {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: var(--r-sm);
  font-size: 1.4rem;
}
.now-playing-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  flex: 1;
  min-width: 0;
}
.now-playing-head .group-label { min-width: 0; }
.now-playing-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 100%;
  min-width: 0;
}
.np-header .now-playing {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.np-header #change-game { flex-shrink: 0; }
/* Icon + label controls read as a real player bar, not plain text buttons. */
.np-header #change-game,
.np-tools button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.btn-icon {
  width: 15px;
  height: 15px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.8;
}
.np-tools button:hover:not(:disabled) .btn-icon,
.np-tools button.active .btn-icon { opacity: 1; }
/* One clean tools row, divided from the header - no verbose labels. Buttons are
   grouped (state / playback / input) so related controls stay together. */
.np-tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}
.tool-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}
.state-info { font-size: 0.7rem; color: var(--muted); white-space: nowrap; }
.state-info:empty { display: none; }

.badge {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--badge, var(--accent));
  background: color-mix(in srgb, var(--badge, var(--accent)) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--badge, var(--accent)) 34%, transparent);
  border-radius: var(--r-pill);
  padding: 2px 9px;
  white-space: nowrap;
}
.badge:empty { display: none; }

button {
  background: linear-gradient(180deg, var(--surface-3), var(--surface-2));
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--r-md);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: -0.01em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: transform 0.12s ease, border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}
button:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 60%, var(--border-strong));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 6px 16px -10px rgba(0, 0, 0, 0.75);
  transform: translateY(-1px);
}
button:active:not(:disabled) { transform: translateY(0); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Destructive actions (clear all, remove a game) signal intent on hover. */
.recent-clear:hover:not(:disabled),
.recent-del:hover:not(:disabled) {
  border-color: var(--danger);
  background: rgba(192, 80, 74, 0.16);
  color: var(--danger-text);
  box-shadow: none;
  transform: none;
}

select {
  appearance: none;
  -webkit-appearance: none;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--space-2) 1.7rem var(--space-2) var(--space-2);
  font-size: var(--text-sm);
  cursor: pointer;
  /* Custom caret (inline SVG data URI - no external request). */
  background-color: var(--panel-2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%23969db0' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M2.5 4.5l3.5 3.5 3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
}
select:hover { border-color: var(--accent); }

.status {
  color: var(--text-2);
  font-size: var(--text-sm);
  min-height: 1.1rem;
  margin: var(--space-2) 0 0;
}
.status.inline { margin: 0; min-height: 0; }

/* Confirmation/feedback messages read as a distinct neutral chip when present. */
#status:not(:empty) {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: var(--space-2) var(--space-3);
}

/* Spinner on the loading line (pseudo-element survives JS textContent updates). */
#loading::before {
  content: "";
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-right: 0.5em;
  vertical-align: -0.12em;
  border: 2px solid var(--accent-dark);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading.failed { color: var(--error); }
#loading.failed::before { display: none; }

footer p { color: var(--muted); font-size: 0.78rem; max-width: 600px; margin: 0.3rem auto; }
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* On narrow phones, let each control group's label sit on its own line so the
   buttons aren't squeezed by the fixed label width. */
@media (max-width: 480px) {
  main { padding: 0.85rem; }
  h1 { font-size: 1.7rem; }
  /* Class beats the bare h1 rule, so scale the hero explicitly for phones and
     keep the eyebrow chip from overflowing the viewport. */
  html, body { overflow-x: hidden; }
  .hero { padding-left: var(--space-3); padding-right: var(--space-3); }
  /* Fixed rem (not vw) so an overflow can't feed back and enlarge the type. */
  .hero-title { font-size: 1.7rem; max-width: 100%; overflow-wrap: break-word; }
  .hero-eyebrow {
    white-space: normal;
    font-size: 0.6rem;
    letter-spacing: 0.1em;
    padding: 0.32rem 0.7rem;
    max-width: 100%;
  }
  .hero-sub { font-size: 0.95rem; }
  #picker { padding: 2.5rem 1rem; }
  .group-label { min-width: 100%; }
  /* Comfortable tap targets on touch screens. */
  button, select { min-height: 42px; }
  .filebtn.small { min-height: 42px; display: inline-flex; align-items: center; }
  .recent-del { min-width: 42px; }
  /* Scale the Game Boy faceplate controls down so they fit narrow phones. */
  .gb-skin .joystick-main { gap: 1.6rem; }
  .gb-skin #joystick-base { width: 92px; height: 92px; }
  .gb-skin #joystick-base::before { width: 32px; height: 92px; }
  .gb-skin #joystick-base::after { width: 92px; height: 32px; }
  .gb-skin .action-btn { width: 46px; height: 46px; }
  /* Drop the gamepad grip wings on narrow phones (they'd cause overflow). */
  .console-skin #joystick:not([hidden])::before,
  .console-skin #joystick:not([hidden])::after { display: none; }
  .console-skin #joystick:not([hidden]) { padding: 1.4rem 1.4rem 1.6rem; }
  /* Scale the console gamepad down so the d-pad + buttons don't overflow ~360px. */
  .console-skin .joystick-main { gap: 1.4rem; }
  .console-skin #joystick-base { width: 92px; height: 92px; }
  .console-skin #joystick-base::before { width: 32px; height: 92px; }
  .console-skin #joystick-base::after { width: 92px; height: 32px; }
  .console-skin .action-btn { width: 44px; height: 44px; }
  .console-skin[data-system="snes"] #joystick-actions,
  .console-skin[data-system="psx"] #joystick-actions,
  .console-skin[data-system="nds"] #joystick-actions {
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
  }
  /* N64: scale the stick + C-cluster so they fit ~360px. */
  .console-skin[data-system="n64"] #joystick-base { width: 84px; height: 84px; }
  .console-skin[data-system="n64"] #joystick-thumb { width: 36px; height: 36px; margin: -18px 0 0 -18px; }
  .console-skin[data-system="n64"] #joystick-actions { grid-template-columns: 38px 38px 10px 30px 30px; grid-template-rows: 34px 34px 34px; }
  .console-skin[data-system="n64"] .joystick-main { gap: 1.6rem; }
  .console-skin[data-system="n64"] .action-btn:nth-child(1) { width: 36px; height: 36px; }
  .console-skin[data-system="n64"] .action-btn:nth-child(2) { width: 40px; height: 40px; }
  .console-skin[data-system="n64"] .action-btn:nth-child(n+3) { width: 28px; height: 28px; }
}

/* Honour reduced-motion preferences: no spinner rotation or transitions. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  #loading::before { animation: none; }
  #save-controls:not([hidden]) { animation: none; }
  *, *::before, *::after { transition: none !important; }
}
