/* ============================================================================
 * RetroGame Hub - Design System
 * --------------------------------------------------------------------------
 * Mood: dark, cinematic, retro-futuristic.
 * Inspiration: EmulationStation + PlayStation Store (2013) + arcade cabinet.
 *
 * Architecture:
 *   1. @import & font face
 *   2. Design tokens (:root custom properties)
 *   3. Reset + base (html, body, typography defaults)
 *   4. CRT overlay (body::after) + parallax background (body::before)
 *   5. Layout primitives (.app-shell, .sidebar, .content)
 *   6. Components (.console-item, .game-card, .btn, .skeleton, .badge)
 *   7. Utilities & state (.is-active, .is-loading, .visually-hidden)
 *   8. Animations (@keyframes)
 *   9. Responsive breakpoints
 *  10. Accessibility (prefers-reduced-motion, focus-visible)
 * ========================================================================= */

/* ---------- 1. Fonts ----------------------------------------------------- */
/* L'@import di Google Fonts e' stato spostato in /assets/css/fonts.css
   (incluso solo da index.html). Vedi fonts.css per i dettagli sul perche'
   la player page non puo' caricare risorse cross-origin (SharedArrayBuffer
   richiede COEP=require-corp, che blocca i font Google senza CORP). */

/* ---------- 2. Design tokens -------------------------------------------- */

:root {
  /* ----- Color: backgrounds ----- */
  --color-bg:           #0a0b0f;            /* deep blue-black */
  --color-bg-elev:      #11131a;            /* one step up */
  --color-surface:      rgba(22, 25, 34, 0.72);   /* glass card */
  --color-surface-2:    rgba(30, 34, 46, 0.85);   /* hover/elevated */
  --color-overlay:      rgba(10, 11, 15, 0.78);   /* modal/scrim */

  /* ----- Color: brand accents ----- */
  --color-accent:       #00d4ff;            /* electric cyan */
  --color-accent-soft:  #38e3ff;
  --color-accent-2:     #7c3aed;            /* violet */
  --color-accent-2-soft:#a78bfa;
  --color-accent-warm:  #ff5d8f;            /* used for badges, alerts */
  --color-success:      #22c55e;
  --color-warning:      #f59e0b;
  --color-danger:       #ef4444;

  /* ----- Color: text ----- */
  --color-text:         #ffffff;
  --color-text-muted:   #a0aec0;
  --color-text-dim:     #6b7280;
  --color-text-inverse: #0a0b0f;

  /* ----- Color: borders & dividers ----- */
  --color-border:       rgba(255, 255, 255, 0.08);
  --color-border-strong:rgba(255, 255, 255, 0.16);
  --color-divider:      rgba(255, 255, 255, 0.06);

  /* ----- Glow / alpha tints (use color-mix for legibility) ----- */
  --glow-accent-12:     rgba(0, 212, 255, 0.12);
  --glow-accent-25:     rgba(0, 212, 255, 0.25);
  --glow-accent-45:     rgba(0, 212, 255, 0.45);
  --glow-accent-2-25:   rgba(124, 58, 237, 0.25);

  /* Per-game / per-console color is set via JS:
     element.style.setProperty('--color-console', game.color)
     Default fallback = primary accent. */
  --color-console:      var(--color-accent);

  /* ----- Typography ----- */
  --font-display: 'Orbitron', 'Bank Gothic', 'Eurostile', sans-serif;
  --font-body:    'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Fluid type scale (clamp(min, preferred, max)) */
  --fs-xs:   clamp(0.72rem, 0.68rem + 0.18vw, 0.80rem);
  --fs-sm:   clamp(0.82rem, 0.78rem + 0.20vw, 0.92rem);
  --fs-base: clamp(0.95rem, 0.90rem + 0.25vw, 1.06rem);
  --fs-md:   clamp(1.08rem, 1.02rem + 0.30vw, 1.22rem);
  --fs-lg:   clamp(1.30rem, 1.18rem + 0.55vw, 1.56rem);
  --fs-xl:   clamp(1.65rem, 1.45rem + 0.95vw, 2.10rem);
  --fs-2xl:  clamp(2.10rem, 1.75rem + 1.60vw, 2.95rem);
  --fs-3xl:  clamp(2.85rem, 2.30rem + 2.50vw, 4.10rem);

  --lh-tight:  1.15;
  --lh-snug:   1.35;
  --lh-normal: 1.55;

  --tracking-tight:  -0.01em;
  --tracking-normal: 0;
  --tracking-wide:   0.06em;
  --tracking-wider:  0.14em;

  /* ----- Spacing (4px base scale) ----- */
  --space-0:  0;
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;

  /* ----- Radius ----- */
  --radius-xs:   4px;
  --radius-sm:   6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  20px;
  --radius-2xl: 28px;
  --radius-pill: 999px;

  /* ----- Elevation / shadow ----- */
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-md:  0 6px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg:  0 18px 42px rgba(0, 0, 0, 0.55);
  --shadow-xl:  0 28px 60px rgba(0, 0, 0, 0.65);
  --shadow-glow:0 0 18px var(--glow-accent-45);
  --shadow-inner: inset 0 1px 0 rgba(255, 255, 255, 0.06);

  /* ----- Motion ----- */
  --easing-standard:  cubic-bezier(0.2, 0.8, 0.2, 1);
  --easing-emphasis:  cubic-bezier(0.16, 1, 0.3, 1);
  --easing-decel:     cubic-bezier(0, 0, 0.2, 1);
  --easing-accel:     cubic-bezier(0.4, 0, 1, 1);
  --duration-instant:  120ms;
  --duration-fast:     200ms;
  --duration-base:     280ms;
  --duration-slow:     420ms;
  --duration-slower:   620ms;

  /* ----- Z-index scale ----- */
  --z-base:        1;
  --z-sticky:    100;
  --z-overlay:   500;
  --z-modal:    1000;
  --z-toast:    1500;
  --z-tooltip:  2000;
  --z-crt:      9000;   /* CRT scanline overlay */

  /* ----- Layout ----- */
  --sidebar-width:        280px;
  --sidebar-width-md:     240px;
  --sidebar-width-sm:     200px;
  --header-height:        72px;
  --content-max-width:    1600px;
  --grid-card-min:        180px;
  --grid-card-min-lg:     220px;
  --grid-gap:             var(--space-5);
}

/* ---------- 3. Reset + base --------------------------------------------- */

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

* {
  margin: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-size: 100%;
}

body {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  letter-spacing: var(--tracking-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow: hidden;            /* Home is full-viewport, no body scroll */
  isolation: isolate;          /* New stacking context for ::before/::after */
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

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

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--duration-fast) var(--easing-standard);
}
a:hover {
  color: var(--color-accent-soft);
}

ul, ol {
  list-style: none;
  padding: 0;
}

/* Custom scrollbar (WebKit + Firefox) */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-strong) transparent;
}
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--color-border-strong);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--color-accent);
  background-clip: padding-box;
  border: 2px solid transparent;
}

/* Selection */
::selection {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-wide);
  color: var(--color-text);
}
h1 { font-size: var(--fs-3xl); letter-spacing: var(--tracking-wider); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }
h5 { font-size: var(--fs-md); letter-spacing: var(--tracking-wide); }
h6 { font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: var(--tracking-wider); color: var(--color-text-muted); }

p, li {
  color: var(--color-text-muted);
  line-height: var(--lh-normal);
}

/* ---------- 4. CRT scanlines + parallax background ---------------------- */

/*
 * body::before -> ambient parallax background (slow translate via JS-set var)
 * body::after  -> CRT scanline overlay (fixed, ignores pointer)
 */

body::before {
  content: '';
  position: fixed;
  inset: -8% -8%;                  /* extra so parallax does not show edges */
  z-index: -1;
  background:
    radial-gradient(circle at 18% 22%, rgba(0, 212, 255, 0.10), transparent 38%),
    radial-gradient(circle at 82% 78%, rgba(124, 58, 237, 0.13), transparent 42%),
    radial-gradient(circle at 50% 110%, rgba(255, 93, 143, 0.06), transparent 48%),
    linear-gradient(180deg, #06070b 0%, #0a0b0f 60%, #0e1018 100%);
  /* parallax: JS sets --parallax-x / --parallax-y in pixels on body */
  transform: translate3d(var(--parallax-x, 0px), var(--parallax-y, 0px), 0);
  transition: transform 600ms var(--easing-standard);
  will-change: transform;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: var(--z-crt);
  pointer-events: none;
  background-image:
    repeating-linear-gradient(
      to bottom,
      rgba(255, 255, 255, 0.035) 0px,
      rgba(255, 255, 255, 0.035) 1px,
      transparent 1px,
      transparent 3px
    );
  mix-blend-mode: overlay;
  opacity: 0.85;                   /* the lines themselves are very faint */
}

/* Optional vignette helper — apply .vignette to the .app-shell */
.vignette::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center,
              transparent 55%, rgba(0, 0, 0, 0.55) 100%);
  z-index: var(--z-base);
}

/* ---------- 5. Layout primitives ---------------------------------------- */

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: 100vh;
  grid-template-rows: 100dvh;
  width: 100vw;
  max-width: 100%;
  overflow: hidden;
}

.sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;                    /* allow inner scroll */
  padding: var(--space-6) var(--space-4);
  background: linear-gradient(180deg,
              rgba(14, 16, 24, 0.85) 0%,
              rgba(8, 9, 14, 0.92) 100%);
  border-right: 1px solid var(--color-border);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-2) var(--space-6);
  border-bottom: 1px solid var(--color-divider);
  margin-bottom: var(--space-5);
}
.sidebar__brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent-2));
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-glow);
  color: var(--color-text-inverse);
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 1rem;
}
.sidebar__brand-name {
  font-family: var(--font-display);
  font-size: var(--fs-md);
  font-weight: 700;
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
}
.sidebar__brand-sub {
  display: block;
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: var(--tracking-wide);
  color: var(--color-text-muted);
  text-transform: uppercase;
}

.sidebar__section-title {
  padding: 0 var(--space-3) var(--space-2);
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--color-text-dim);
}

.console-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  overflow-y: auto;
  padding-right: var(--space-1);
}

.content {
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.content__header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4) var(--space-6);
  padding: var(--space-8) var(--space-10) var(--space-5);
  border-bottom: 1px solid var(--color-divider);
}
.content__title {
  font-size: var(--fs-2xl);
  text-transform: uppercase;
  background: linear-gradient(180deg,
              var(--color-text) 0%,
              color-mix(in oklab, var(--color-console) 60%, var(--color-text)) 100%);
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
  text-shadow: 0 0 28px var(--glow-accent-25);
}
.content__subtitle {
  display: block;
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  margin-top: var(--space-2);
}

.content__body {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-6) var(--space-10) var(--space-10);
}

/* ---------- 6. Components ----------------------------------------------- */

/* ----- 6.a Console list item ----- */

.console-item {
  --console-color: var(--color-console);
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-align: left;
  cursor: pointer;
  transition:
    background-color var(--duration-fast) var(--easing-standard),
    color            var(--duration-fast) var(--easing-standard),
    transform        var(--duration-fast) var(--easing-standard);
}
.console-item__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--console-color);
  box-shadow: 0 0 10px color-mix(in oklab, var(--console-color) 60%, transparent);
  flex-shrink: 0;
  transition: transform var(--duration-fast) var(--easing-standard);
}
.console-item__label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
}
.console-item__count {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--color-text-dim);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--color-border);
}
.console-item:hover {
  background: var(--color-surface);
  color: var(--color-text);
  transform: translateX(2px);
}
.console-item.is-active {
  background: linear-gradient(90deg,
              color-mix(in oklab, var(--console-color) 18%, transparent),
              transparent 90%);
  color: var(--color-text);
}
.console-item.is-active::before {
  content: '';
  position: absolute;
  left: -4px;
  top: 12%;
  bottom: 12%;
  width: 3px;
  border-radius: var(--radius-pill);
  background: var(--console-color);
  box-shadow: 0 0 12px var(--console-color);
  animation: glow-pulse 2.4s ease-in-out infinite;
}
.console-item.is-active .console-item__dot {
  transform: scale(1.25);
}

/* ----- 6.b Game grid ----- */

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--grid-card-min), 1fr));
  gap: var(--grid-gap);
  animation: fade-in var(--duration-slow) var(--easing-emphasis) both;
}

/* ----- 6.c Game card ----- */

.game-card {
  --console-color: var(--color-console);
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md), var(--shadow-inner);
  overflow: hidden;
  cursor: pointer;
  isolation: isolate;
  transition:
    transform   var(--duration-base) var(--easing-emphasis),
    box-shadow  var(--duration-base) var(--easing-standard),
    border-color var(--duration-base) var(--easing-standard);
}
.game-card__cover {
  position: relative;
  aspect-ratio: 3 / 4;
  background: linear-gradient(135deg, #1a1c24, #0e0f15);
  overflow: hidden;
}
.game-card__cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--duration-slow) var(--easing-emphasis),
              filter    var(--duration-slow) var(--easing-emphasis);
}
.game-card__cover::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg,
              transparent 0%,
              transparent 55%,
              rgba(0, 0, 0, 0.55) 85%,
              rgba(0, 0, 0, 0.85) 100%);
  pointer-events: none;
  transition: opacity var(--duration-base) var(--easing-standard);
}
.game-card__body {
  padding: var(--space-3) var(--space-4) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.game-card__title {
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  font-weight: 700;
  letter-spacing: var(--tracking-wide);
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
}
.game-card__meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  font-family: var(--font-mono);
}
.game-card__meta-sep {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--color-text-dim);
}

.game-card__badges {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  right: var(--space-3);
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  z-index: 2;
  pointer-events: none;
}

/* Hover / focus */
.game-card:hover,
.game-card:focus-visible,
.game-card.is-active {
  transform: translateY(-4px);
  border-color: var(--console-color);
  box-shadow:
    0 18px 38px rgba(0, 0, 0, 0.55),
    0 0 0 1px color-mix(in oklab, var(--console-color) 70%, transparent),
    0 0 22px color-mix(in oklab, var(--console-color) 55%, transparent);
}
.game-card:hover .game-card__cover img,
.game-card:focus-visible .game-card__cover img {
  transform: scale(1.06);
  filter: brightness(1.08) saturate(1.1);
}

/* ----- 6.d Buttons ----- */

.btn {
  --btn-bg:     var(--color-surface-2);
  --btn-fg:     var(--color-text);
  --btn-border: var(--color-border-strong);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--fs-sm);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  transition:
    background-color var(--duration-fast) var(--easing-standard),
    border-color     var(--duration-fast) var(--easing-standard),
    box-shadow       var(--duration-fast) var(--easing-standard),
    transform        var(--duration-fast) var(--easing-standard);
}
.btn:hover {
  background: color-mix(in oklab, var(--btn-bg) 80%, var(--color-accent));
  border-color: var(--color-accent);
  box-shadow: 0 0 14px var(--glow-accent-25);
}
.btn:active {
  transform: translateY(1px);
}

.btn--primary {
  --btn-bg: linear-gradient(135deg, var(--color-accent), var(--color-accent-2));
  --btn-fg: var(--color-text-inverse);
  --btn-border: transparent;
  box-shadow: 0 6px 18px var(--glow-accent-25);
}
.btn--primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 10px 28px var(--glow-accent-45);
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-border: var(--color-border-strong);
}

.btn--icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
}

/* ----- 6.e Badges ----- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.55);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  backdrop-filter: blur(6px);
}
.badge--console {
  background: color-mix(in oklab, var(--console-color, var(--color-accent)) 22%, rgba(0,0,0,0.65));
  border-color: color-mix(in oklab, var(--console-color, var(--color-accent)) 55%, transparent);
}
.badge--bios {
  background: rgba(245, 158, 11, 0.18);
  color: var(--color-warning);
  border-color: rgba(245, 158, 11, 0.45);
}
.badge--players {
  background: rgba(124, 58, 237, 0.20);
  color: var(--color-accent-2-soft);
  border-color: rgba(124, 58, 237, 0.45);
}
/* Arcade badge (#ff6b35 brand color, used in player.html info-meta for consoleId === 'arcade') */
.badge--arcade {
  background: rgba(255, 107, 53, 0.18);
  color: #ff6b35;
  border-color: rgba(255, 107, 53, 0.55);
  font-weight: 700;
  letter-spacing: 0.06em;
}

/* ----- 6.f Skeleton (loading shimmer) ----- */

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--color-surface);
  border-radius: var(--radius-md);
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.06) 40%,
    rgba(255, 255, 255, 0.10) 50%,
    rgba(255, 255, 255, 0.06) 60%,
    transparent 100%
  );
  transform: translateX(-100%);
  animation: shimmer 1.4s linear infinite;
}
.skeleton--card {
  aspect-ratio: 3 / 4;
  height: auto;
}
.skeleton--line {
  height: 12px;
  border-radius: var(--radius-sm);
}

/* ---------- 7. Utilities & state ---------------------------------------- */

.is-hidden        { display: none !important; }
.is-invisible     { visibility: hidden; }
.is-disabled      { opacity: 0.5; pointer-events: none; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.text-muted     { color: var(--color-text-muted); }
.text-display   { font-family: var(--font-display); letter-spacing: var(--tracking-wide); }
.text-mono      { font-family: var(--font-mono); }
.uppercase      { text-transform: uppercase; }

/* Slide transitions for the content area when console changes */
.content__body.is-entering-right { animation: slide-in-right var(--duration-base) var(--easing-emphasis); }
.content__body.is-entering-left  { animation: slide-in-left  var(--duration-base) var(--easing-emphasis); }

/* ---------- 8. Animations ----------------------------------------------- */

@keyframes shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

@keyframes glow-pulse {
  0%, 100% {
    box-shadow: 0 0  8px var(--color-console),
                0 0 14px color-mix(in oklab, var(--color-console) 50%, transparent);
    opacity: 0.85;
  }
  50% {
    box-shadow: 0 0 14px var(--color-console),
                0 0 26px color-mix(in oklab, var(--color-console) 75%, transparent);
    opacity: 1;
  }
}

@keyframes slide-in-left {
  from { opacity: 0; transform: translateX(-24px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes slide-in-right {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}

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

@keyframes scanline-flicker {
  0%, 100% { opacity: 0.85; }
  50%      { opacity: 0.78; }
}
body::after {
  animation: scanline-flicker 6s ease-in-out infinite;
}

/* ---------- 9. Responsive breakpoints ----------------------------------- */

@media (max-width: 1280px) {
  :root {
    --sidebar-width: var(--sidebar-width-md);
    --grid-card-min: 170px;
  }
  .content__header,
  .content__body {
    padding-inline: var(--space-6);
  }
}

@media (max-width: 960px) {
  :root {
    --sidebar-width: var(--sidebar-width-sm);
    --grid-card-min: 150px;
  }
}

@media (max-width: 720px) {
  body { overflow: auto; }
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--color-border);
  }
  .console-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: var(--space-2);
  }
  .console-item {
    flex-shrink: 0;
  }
  .content__body {
    overflow: visible;
  }
}

/* ---------- 10. Accessibility ------------------------------------------- */

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

/* Disable parallax + heavy animations for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  body::before { transform: none !important; }
  body::after  { animation: none !important; }
}

/* High-contrast preference: make borders/outlines stronger */
@media (prefers-contrast: more) {
  :root {
    --color-border:        rgba(255, 255, 255, 0.30);
    --color-border-strong: rgba(255, 255, 255, 0.55);
  }
}

/* ============================================================================
 * 11. Theme system
 * --------------------------------------------------------------------------
 * Each theme overrides ONLY the necessary --color-* / --glow-* tokens.
 * The default values in :root above are equivalent to data-theme="dark-neon".
 *
 * Apply via the html element:    <html data-theme="dark-purple">
 * The theme.js module sets / clears this attribute and syncs ?theme=NAME.
 *
 * Smooth transitions are applied via the .theme-transition selector group
 * below; use the .no-theme-transition class on <html> to suppress them
 * during the very first paint (theme.js does this automatically).
 * ========================================================================= */

/* ----- 11.a Dark Purple ------------------------------------------------- */

[data-theme='dark-purple'] {
  --color-bg:           #0d0b14;
  --color-bg-elev:      #16122a;
  --color-surface:      rgba(28, 22, 50, 0.72);
  --color-surface-2:    rgba(40, 30, 70, 0.85);
  --color-overlay:      rgba(13, 11, 20, 0.78);

  --color-accent:       #a855f7;
  --color-accent-soft:  #c084fc;
  --color-accent-2:     #ec4899;
  --color-accent-2-soft:#f472b6;
  --color-accent-warm:  #f472b6;

  --glow-accent-12:     rgba(168, 85, 247, 0.14);
  --glow-accent-25:     rgba(168, 85, 247, 0.28);
  --glow-accent-45:     rgba(168, 85, 247, 0.50);
  --glow-accent-2-25:   rgba(236, 72, 153, 0.28);

  --shadow-glow:        0 0 20px var(--glow-accent-45);
}

/* Theme-specific parallax background tint */
[data-theme='dark-purple'] body::before {
  background:
    radial-gradient(circle at 18% 22%, rgba(168, 85, 247, 0.16), transparent 38%),
    radial-gradient(circle at 82% 78%, rgba(236, 72, 153, 0.13), transparent 42%),
    radial-gradient(circle at 50% 110%, rgba(124, 58, 237, 0.10), transparent 48%),
    linear-gradient(180deg, #08060f 0%, #0d0b14 60%, #15101e 100%);
}

/* ----- 11.b Retro Amber (arcade) ---------------------------------------- */

[data-theme='dark-amber'] {
  --color-bg:           #0f0b00;
  --color-bg-elev:      #1a1404;
  --color-surface:      rgba(46, 34, 8, 0.74);
  --color-surface-2:    rgba(66, 48, 12, 0.86);
  --color-overlay:      rgba(15, 11, 0, 0.82);

  --color-accent:       #f59e0b;
  --color-accent-soft:  #fbbf24;
  --color-accent-2:     #ef4444;
  --color-accent-2-soft:#f87171;
  --color-accent-warm:  #fb923c;

  --color-text:         #fff5d6;
  --color-text-muted:   #d6b97a;
  --color-text-dim:     #a08956;

  --glow-accent-12:     rgba(245, 158, 11, 0.16);
  --glow-accent-25:     rgba(245, 158, 11, 0.34);
  --glow-accent-45:     rgba(245, 158, 11, 0.55);
  --glow-accent-2-25:   rgba(239, 68, 68, 0.28);

  --shadow-glow:        0 0 22px var(--glow-accent-45);
}

[data-theme='dark-amber'] body::before {
  background:
    radial-gradient(circle at 18% 22%, rgba(245, 158, 11, 0.18), transparent 38%),
    radial-gradient(circle at 82% 78%, rgba(239, 68, 68, 0.10), transparent 42%),
    radial-gradient(circle at 50% 110%, rgba(180, 83, 9, 0.10), transparent 48%),
    linear-gradient(180deg, #0a0700 0%, #0f0b00 60%, #160f02 100%);
}

/* Stronger CRT scanlines for full arcade feel */
[data-theme='dark-amber'] body::after {
  background-image:
    repeating-linear-gradient(
      to bottom,
      rgba(245, 158, 11, 0.060) 0px,
      rgba(245, 158, 11, 0.060) 1px,
      transparent 1px,
      transparent 3px
    );
  opacity: 0.95;
}

/* ----- 11.c Light Minimal ----------------------------------------------- */

[data-theme='light-minimal'] {
  --color-bg:           #f7f7f9;
  --color-bg-elev:      #ffffff;
  --color-surface:      rgba(255, 255, 255, 0.85);
  --color-surface-2:    rgba(244, 246, 252, 0.95);
  --color-overlay:      rgba(20, 25, 40, 0.45);

  --color-accent:       #2563eb;
  --color-accent-soft:  #3b82f6;
  --color-accent-2:     #7c3aed;
  --color-accent-2-soft:#a78bfa;
  --color-accent-warm:  #ec4899;

  --color-text:         #0f172a;
  --color-text-muted:   #475569;
  --color-text-dim:     #94a3b8;
  --color-text-inverse: #ffffff;

  --color-border:       rgba(15, 23, 42, 0.10);
  --color-border-strong:rgba(15, 23, 42, 0.22);
  --color-divider:      rgba(15, 23, 42, 0.06);

  --glow-accent-12:     rgba(37, 99, 235, 0.10);
  --glow-accent-25:     rgba(37, 99, 235, 0.20);
  --glow-accent-45:     rgba(37, 99, 235, 0.35);
  --glow-accent-2-25:   rgba(124, 58, 237, 0.20);

  --shadow-sm:   0 1px 2px rgba(15, 23, 42, 0.08);
  --shadow-md:   0 6px 18px rgba(15, 23, 42, 0.10);
  --shadow-lg:   0 18px 42px rgba(15, 23, 42, 0.12);
  --shadow-xl:   0 28px 60px rgba(15, 23, 42, 0.14);
  --shadow-glow: 0 0 14px var(--glow-accent-25);
  --shadow-inner:inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

/* Light theme: soft tinted background, NO CRT scanlines */
[data-theme='light-minimal'] body::before {
  background:
    radial-gradient(circle at 18% 18%, rgba(37, 99, 235, 0.06), transparent 38%),
    radial-gradient(circle at 82% 82%, rgba(124, 58, 237, 0.06), transparent 42%),
    linear-gradient(180deg, #f7f7f9 0%, #eef0f5 100%);
}
[data-theme='light-minimal'] body::after {
  display: none;
}
[data-theme='light-minimal'] .sidebar {
  background: linear-gradient(180deg,
              rgba(255, 255, 255, 0.86) 0%,
              rgba(244, 246, 252, 0.95) 100%);
  border-right-color: var(--color-border);
}
[data-theme='light-minimal'] .game-card {
  background: rgba(255, 255, 255, 0.94);
}
[data-theme='light-minimal'] .game-card__cover {
  background: linear-gradient(135deg, #e6e8ef, #f7f7f9);
}
[data-theme='light-minimal'] .game-card__cover::after {
  background: linear-gradient(180deg,
              transparent 0%, transparent 60%,
              rgba(15, 23, 42, 0.18) 100%);
}
[data-theme='light-minimal'] .badge {
  background: rgba(255, 255, 255, 0.85);
  color: var(--color-text);
}
[data-theme='light-minimal'] ::selection {
  background: var(--color-accent);
  color: #ffffff;
}

/* ----- 11.d Smooth theme transitions ------------------------------------ */

body,
.sidebar,
.content,
.content__header,
.content__title,
.content__subtitle,
.console-item,
.console-item__count,
.game-card,
.game-card__cover,
.game-card__title,
.game-card__meta,
.btn,
.badge,
.skeleton,
.detail-panel,
.theme-switcher__panel,
.theme-switcher__trigger,
.theme-option {
  transition:
    background-color 0.5s var(--easing-standard),
    color            0.3s var(--easing-standard),
    border-color     0.3s var(--easing-standard),
    box-shadow       0.3s var(--easing-standard);
}

/* Suppress all transitions during the very first paint (avoids flash when
 * theme.js applies the initial data-theme attribute). */
.no-theme-transition,
.no-theme-transition *,
.no-theme-transition *::before,
.no-theme-transition *::after {
  transition: none !important;
  animation-duration: 0.001ms !important;
}

/* Reduced-motion users: collapse the theme transition to instant */
@media (prefers-reduced-motion: reduce) {
  body,
  .sidebar,
  .content,
  .content__header,
  .console-item,
  .game-card,
  .btn,
  .badge,
  .theme-switcher__panel {
    transition-duration: 0.001ms !important;
  }
}

/* ============================================================================
 * 12. Theme switcher UI (button + dropdown panel)
 * ========================================================================= */

.theme-switcher {
  position: relative;
  display: inline-flex;
  z-index: var(--z-overlay);
  align-self: center;
}

.theme-switcher--floating {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
}

.theme-switcher__trigger {
  /* Composes .btn .btn--icon */
  position: relative;
}
.theme-switcher__trigger svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  display: block;
}
.theme-switcher.is-open .theme-switcher__trigger {
  background: color-mix(in oklab, var(--color-accent) 18%, var(--color-surface-2));
  border-color: var(--color-accent);
  color: var(--color-text);
  box-shadow: 0 0 16px var(--glow-accent-25);
}

.theme-switcher__panel {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  min-width: 240px;
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  background: color-mix(in oklab, var(--color-bg-elev) 92%, transparent);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);

  transform-origin: top right;
  transform: translateY(-6px) scale(0.96);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity    var(--duration-fast) var(--easing-emphasis),
    transform  var(--duration-fast) var(--easing-emphasis),
    visibility 0s linear var(--duration-fast);
}
.theme-switcher.is-open .theme-switcher__panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  transition-delay: 0s;
}

.theme-switcher__title {
  padding: var(--space-1) var(--space-2) var(--space-2);
  margin-bottom: var(--space-1);
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--color-text-dim);
  border-bottom: 1px solid var(--color-divider);
}

.theme-option {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-muted);
  text-align: left;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}
.theme-option:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}
.theme-option:focus-visible {
  background: var(--color-surface-2);
  color: var(--color-text);
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}
.theme-option.is-active {
  background: color-mix(in oklab, var(--color-accent) 16%, transparent);
  color: var(--color-text);
}
.theme-option__preview {
  position: relative;
  width: 34px;
  height: 26px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--color-border);
  display: grid;
  grid-template-columns: 1fr 1fr;
  box-shadow: var(--shadow-inner);
}
.theme-option__preview span {
  display: block;
  height: 100%;
}
.theme-option__name {
  min-width: 0;
}
.theme-option__check {
  font-family: var(--font-mono);
  font-size: var(--fs-base);
  font-weight: 700;
  color: var(--color-accent);
  opacity: 0;
  transition: opacity var(--duration-fast) var(--easing-standard);
}
.theme-option.is-active .theme-option__check {
  opacity: 1;
}

@media (max-width: 720px) {
  .theme-switcher--floating {
    top: var(--space-3);
    right: var(--space-3);
  }
  .theme-switcher__panel {
    min-width: 220px;
    right: 0;
  }
}

/* ============================================================================
 * 13. Page-shell components used by index.html
 *     (header toolbar, search, clock, sidebar footer, status, empty state,
 *      detail panel modal)
 * ========================================================================= */

/* ----- 13.a Sidebar footer + clock ----- */

.sidebar__footer {
  margin-top: auto;
  padding: var(--space-4) var(--space-2) 0;
  border-top: 1px solid var(--color-divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.clock {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  color: var(--color-text-muted);
}
.clock::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success);
  box-shadow: 0 0 8px color-mix(in oklab, var(--color-success) 60%, transparent);
  animation: glow-pulse 2.4s ease-in-out infinite;
}

/* ----- 13.b Content header toolbar (search + theme button) ----- */

.content__heading {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1 1 320px;
}
.content__toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 0 1 auto;
  margin-left: auto;
}

/* ----- 13.c Search field ----- */

.search {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: clamp(220px, 28vw, 360px);
}
.search__icon {
  position: absolute;
  left: var(--space-3);
  width: 16px;
  height: 16px;
  color: var(--color-text-dim);
  pointer-events: none;
}
.search__input {
  width: 100%;
  padding: var(--space-3) var(--space-3) var(--space-3) calc(var(--space-3) * 2 + 16px);
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 500;
  letter-spacing: var(--tracking-wide);
  outline: none;
  transition:
    border-color var(--duration-fast) var(--easing-standard),
    box-shadow   var(--duration-fast) var(--easing-standard),
    background   var(--duration-fast) var(--easing-standard);
}
.search__input::placeholder {
  color: var(--color-text-dim);
}
.search__input:focus,
.search__input:hover {
  border-color: var(--color-accent);
  background: var(--color-surface-2);
  box-shadow: 0 0 0 3px var(--glow-accent-12), 0 0 16px var(--glow-accent-25);
}
.search__input::-webkit-search-cancel-button {
  filter: invert(1) opacity(0.4);
}

/* ----- 13.d Status message + empty state ----- */

.status-message {
  margin-top: var(--space-3);
  font-size: var(--fs-xs);
  color: var(--color-text-dim);
  letter-spacing: var(--tracking-wide);
  text-align: center;
}
.status-message:empty {
  display: none;
}

.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-16) var(--space-6);
  text-align: center;
  color: var(--color-text-muted);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}
.empty-state h3 {
  font-size: var(--fs-lg);
  color: var(--color-text);
  margin: 0;
}
.empty-state p {
  margin: 0;
  max-width: 38ch;
}
.empty-state code {
  font-family: var(--font-mono);
  font-size: 0.95em;
  padding: 2px 6px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: var(--radius-xs);
  border: 1px solid var(--color-border);
}

/* ============================================================================
 * 14. Detail panel (modal overlay opened when a game card is clicked)
 * ========================================================================= */

.detail-panel {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--space-6);
  background: var(--color-overlay);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity    var(--duration-base) var(--easing-emphasis),
    visibility 0s linear var(--duration-base);
}
.detail-panel.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.detail-panel__inner {
  --console-color: var(--color-console);
  position: relative;
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  gap: var(--space-8);
  width: min(900px, 100%);
  max-height: min(720px, 90vh);
  padding: var(--space-8);
  background: var(--color-bg-elev);
  border: 1px solid color-mix(in oklab, var(--console-color) 50%, var(--color-border-strong));
  border-radius: var(--radius-xl);
  box-shadow:
    var(--shadow-xl),
    0 0 0 1px color-mix(in oklab, var(--console-color) 35%, transparent),
    0 0 60px color-mix(in oklab, var(--console-color) 30%, transparent);
  transform: translateY(12px) scale(0.98);
  transition:
    transform var(--duration-base) var(--easing-emphasis);
  overflow: hidden;
}
.detail-panel.is-open .detail-panel__inner {
  transform: translateY(0) scale(1);
}

.detail-panel__close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 2;
  width: 36px;
  height: 36px;
  font-size: 1.4rem;
  line-height: 1;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--color-border-strong);
}
.detail-panel__close:hover {
  background: var(--console-color);
  border-color: var(--console-color);
  color: var(--color-text-inverse);
}

.detail-panel__cover {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: linear-gradient(135deg, #1a1c24, #0e0f15);
  box-shadow: var(--shadow-lg),
              0 0 0 1px color-mix(in oklab, var(--console-color) 60%, transparent),
              0 0 28px color-mix(in oklab, var(--console-color) 40%, transparent);
}
.detail-panel__cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-panel__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
  overflow-y: auto;
  padding-right: var(--space-2);
}
.detail-panel__title {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  background: linear-gradient(180deg,
              var(--color-text) 0%,
              color-mix(in oklab, var(--console-color) 60%, var(--color-text)) 100%);
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
}
.detail-panel__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.detail-panel__description {
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--color-text-muted);
}
.detail-panel__genres {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.detail-panel__actions {
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-divider);
  display: flex;
  gap: var(--space-3);
}
.detail-panel__actions .btn--primary {
  --btn-bg: linear-gradient(135deg, var(--console-color), var(--color-accent-2));
  flex: 1;
  padding: var(--space-4) var(--space-6);
  font-size: var(--fs-md);
}

/* Light theme: tone down the blur darkness */
[data-theme='light-minimal'] .detail-panel {
  background: rgba(15, 23, 42, 0.35);
}
[data-theme='light-minimal'] .detail-panel__close {
  background: rgba(255, 255, 255, 0.85);
  color: var(--color-text);
}

/* Detail panel responsive */
@media (max-width: 720px) {
  .detail-panel {
    padding: var(--space-3);
  }
  .detail-panel__inner {
    grid-template-columns: 1fr;
    gap: var(--space-5);
    padding: var(--space-5);
    max-height: 92vh;
    overflow-y: auto;
  }
  .detail-panel__cover {
    max-width: 220px;
    margin: 0 auto;
  }
}

/* ----- 14.a Header responsive: stack toolbar below title ----- */

@media (max-width: 960px) {
  .content__header {
    flex-direction: column;
    align-items: stretch;
  }
  .content__toolbar {
    justify-content: flex-end;
  }
  .search {
    flex: 1;
    width: auto;
  }
}

/* ============================================================================
 * 15. Auth & Upload UI (login button, user menu, modals, forms, dropzone,
 *     progress bar)  --  consumed by /assets/js/auth.js
 * ========================================================================= */

/* ----- 15.a Header auth button ----- */
.auth-btn {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.auth-btn__avatar {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--color-text-inverse);
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent-2));
  width: 28px; height: 28px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 0 12px var(--glow-accent-25);
}
.auth-btn__icon { font-size: 1.1rem; line-height: 1; opacity: 0.9; }

/* ----- 15.b User menu (dropdown) ----- */
.user-menu {
  position: absolute;
  z-index: var(--z-dropdown);
  min-width: 220px;
  padding: var(--space-2);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg), 0 0 24px var(--glow-accent-12);
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: fade-in var(--duration-fast) var(--easing-emphasis);
}
.user-menu__header {
  padding: var(--space-3) var(--space-3) var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid var(--color-divider);
  margin-bottom: var(--space-2);
}
.user-menu__header strong {
  font-family: var(--font-display);
  letter-spacing: var(--tracking-wide);
}
.user-menu__header small { color: var(--color-text-dim); font-size: var(--fs-xs); }
.user-menu__item {
  appearance: none;
  background: transparent;
  border: 0;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  text-align: left;
  font: inherit;
  color: var(--color-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  transition: background var(--duration-fast) var(--easing-standard);
}
.user-menu__item:hover { background: var(--color-surface-3); }
.user-menu__item--danger { color: var(--color-danger); }
.user-menu__item--danger:hover { background: color-mix(in oklab, var(--color-danger) 18%, transparent); }

/* ----- 15.c Modal (login, change password, add ROM) ----- */
body.rgh-modal-open { overflow: hidden; }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--space-6);
  background: var(--color-overlay);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  opacity: 0;
  transition: opacity var(--duration-base) var(--easing-emphasis);
}
.modal-overlay.is-open { opacity: 1; }

.modal {
  width: min(560px, 100%);
  max-height: 90vh;
  background: var(--color-bg-elev);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl), 0 0 60px var(--glow-accent-12);
  display: flex;
  flex-direction: column;
  transform: translateY(12px) scale(0.97);
  opacity: 0;
  transition:
    transform var(--duration-base) var(--easing-emphasis),
    opacity   var(--duration-base) var(--easing-emphasis);
  overflow: hidden;
}
.modal-overlay.is-open .modal {
  transform: translateY(0) scale(1);
  opacity: 1;
}
.auth-form--wide { /* used inside Add ROM, makes the modal wider */ }
.modal:has(.auth-form--wide) { width: min(720px, 100%); }

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-divider);
}
.modal__title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  background: linear-gradient(180deg, var(--color-text), var(--color-accent));
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
}
.modal__close {
  background: transparent;
  border: 0;
  font-size: 1.6rem;
  line-height: 1;
  width: 36px; height: 36px;
  border-radius: 50%;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background var(--duration-fast) var(--easing-standard),
              color      var(--duration-fast) var(--easing-standard);
}
.modal__close:hover { background: var(--color-surface-2); color: var(--color-text); }

.modal__body {
  padding: var(--space-6);
  overflow-y: auto;
}

.modal__footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-divider);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* ----- 15.d Form fields ----- */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.auth-form__hint {
  margin: 0;
  padding: var(--space-3);
  background: color-mix(in oklab, var(--color-warning) 14%, transparent);
  border: 1px solid color-mix(in oklab, var(--color-warning) 40%, transparent);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: var(--fs-sm);
}
.auth-form__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.field > span {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  letter-spacing: var(--tracking-wide);
  outline: none;
  transition:
    border-color var(--duration-fast) var(--easing-standard),
    box-shadow   var(--duration-fast) var(--easing-standard),
    background   var(--duration-fast) var(--easing-standard);
}
.input:focus {
  border-color: var(--color-accent);
  background: var(--color-surface-2);
  box-shadow: 0 0 0 3px var(--glow-accent-12);
}
textarea.input { resize: vertical; min-height: 4em; }
select.input {
  cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--color-text-muted) 50%),
    linear-gradient(135deg, var(--color-text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 13px) calc(50% - 2px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: var(--space-8);
  appearance: none;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
@media (max-width: 520px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.form-error,
.form-ok {
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  letter-spacing: var(--tracking-wide);
}
.form-error {
  background: color-mix(in oklab, var(--color-danger) 16%, transparent);
  border: 1px solid color-mix(in oklab, var(--color-danger) 40%, transparent);
  color: var(--color-text);
}
.form-ok {
  background: color-mix(in oklab, var(--color-success) 16%, transparent);
  border: 1px solid color-mix(in oklab, var(--color-success) 40%, transparent);
  color: var(--color-text);
}

/* ----- 15.e Drop zone (Add ROM) ----- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
  background: var(--color-surface);
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: center;
  transition:
    border-color var(--duration-fast) var(--easing-standard),
    background   var(--duration-fast) var(--easing-standard),
    transform    var(--duration-fast) var(--easing-standard);
}
.dropzone:hover,
.dropzone:focus {
  border-color: var(--color-accent);
  background: var(--color-surface-2);
  outline: none;
}
.dropzone.is-dragging {
  border-color: var(--color-accent);
  background: color-mix(in oklab, var(--color-accent) 14%, var(--color-surface));
  transform: scale(1.01);
}
.dropzone.has-file {
  border-style: solid;
  border-color: var(--color-success);
  background: color-mix(in oklab, var(--color-success) 8%, var(--color-surface));
}
.dropzone__icon { font-size: 2rem; opacity: 0.7; }
.dropzone__text {
  font-family: var(--font-display);
  font-size: var(--fs-md);
  letter-spacing: var(--tracking-wide);
}
.dropzone__hint {
  font-size: var(--fs-xs);
  color: var(--color-text-dim);
  font-family: var(--font-mono);
}

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

/* ----- 15.f Progress bar ----- */
.progress {
  width: 100%;
  height: 8px;
  background: var(--color-surface-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
  border: 1px solid var(--color-border);
}
.progress__bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--color-accent), var(--color-accent-2));
  box-shadow: 0 0 12px var(--glow-accent-25);
  transition: width var(--duration-fast) linear;
}
.progress__label {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  text-align: center;
}

/* ----- 15.g Arcade-only fieldset (Add ROM modal) ----- */
.arcade-fields {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border: 1px solid color-mix(in oklab, #ff6b35 45%, transparent);
  border-radius: var(--radius-md);
  background: color-mix(in oklab, #ff6b35 10%, var(--color-surface));
}
.arcade-fields[hidden] { display: none; }
.arcade-fields legend {
  padding: 0 var(--space-2);
  color: #ff6b35;
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  letter-spacing: var(--tracking-wide);
  font-weight: 700;
}
.arcade-fields__hint {
  margin: 0 0 var(--space-3) 0;
  color: var(--color-text-dim);
  font-size: var(--fs-xs);
  line-height: 1.5;
}
.arcade-fields__hint code {
  font-family: var(--font-mono);
  background: color-mix(in oklab, var(--color-text) 8%, transparent);
  padding: 1px 4px;
  border-radius: 3px;
  color: var(--color-text);
}

/* ============================================================================
 * 16. Mobile polish (phones / small tablets)
 * --------------------------------------------------------------------------
 * Layered on top of the existing @media blocks (1280 / 960 / 720 / 520).
 * Goal: usable layout down to 320px wide, touch targets >= 44px,
 * iOS notch / home-indicator safe areas, no zoom-on-input.
 * ========================================================================= */

/* Prevent iOS auto-zoom on input focus: font-size must be >= 16px */
@media (max-width: 720px) {
  .search__input,
  .form-input,
  input[type='text'],
  input[type='search'],
  input[type='email'],
  input[type='password'],
  input[type='number'],
  textarea,
  select {
    font-size: 16px;
  }
}

/* ----- Topbar (sidebar collapsed) tightening on phones ----- */
@media (max-width: 720px) {
  .sidebar {
    padding: var(--space-3) var(--space-3) var(--space-2);
    padding-top: max(var(--space-3), env(safe-area-inset-top));
    padding-left: max(var(--space-3), env(safe-area-inset-left));
    padding-right: max(var(--space-3), env(safe-area-inset-right));
  }
  .sidebar__brand {
    padding: 0 0 var(--space-3);
    margin-bottom: var(--space-3);
    gap: var(--space-2);
  }
  .sidebar__brand-mark { width: 30px; height: 30px; font-size: 0.85rem; }
  .sidebar__brand-name { font-size: var(--fs-sm); }
  .sidebar__brand-sub  { display: none; }

  .sidebar__section-title { display: none; }

  .console-list {
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }
  .console-item {
    scroll-snap-align: start;
    min-height: 44px;
    padding: var(--space-2) var(--space-3);
  }
  .console-item:hover { transform: none; }

  .sidebar__footer { display: none; }

  .content__header {
    padding: var(--space-5) var(--space-4) var(--space-4);
    padding-left: max(var(--space-4), env(safe-area-inset-left));
    padding-right: max(var(--space-4), env(safe-area-inset-right));
    gap: var(--space-3);
  }
  .content__title { font-size: var(--fs-xl); }
  .content__body {
    padding: var(--space-4) var(--space-4) var(--space-8);
    padding-left: max(var(--space-4), env(safe-area-inset-left));
    padding-right: max(var(--space-4), env(safe-area-inset-right));
    padding-bottom: max(var(--space-8), env(safe-area-inset-bottom));
  }
}

/* ----- Game grid: keep at least 2 columns on small phones ----- */
@media (max-width: 720px) {
  :root {
    --grid-card-min: 140px;
    --grid-gap: var(--space-3);
  }
  .game-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .game-card__body { padding: var(--space-2) var(--space-3) var(--space-3); }
  .game-card__title { font-size: 0.82rem; }
  .game-card:hover { transform: none; }
}

@media (max-width: 360px) {
  .game-grid { gap: var(--space-2); }
  .game-card__title { font-size: 0.78rem; }
}

/* ----- Header toolbar: stack search + theme button on small phones ----- */
@media (max-width: 520px) {
  .content__header { flex-direction: column; align-items: stretch; }
  .content__heading { width: 100%; }
  .content__toolbar {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-2);
  }
  .search { flex: 1; min-width: 0; }
}

/* ----- Touch targets: bump icon buttons to 44px on coarse pointers ----- */
@media (hover: none) and (pointer: coarse) {
  .btn--icon,
  .auth-btn,
  .theme-switcher__btn {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }
  .btn { min-height: 44px; }
  .console-item { min-height: 44px; }
  .user-menu__item { min-height: 44px; }

  /* Hover effects don't make sense on touch -> kill transforms that
     trigger sticky-hover artifacts on phones */
  .game-card:hover { transform: none; }
  .console-item:hover { transform: none; }
  a:hover { color: var(--color-accent); }
}

/* ----- Detail panel: full-screen sheet on small phones ----- */
@media (max-width: 520px) {
  .detail-panel { padding: 0; }
  .detail-panel__inner {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    padding: var(--space-4);
    padding-top: max(var(--space-4), env(safe-area-inset-top));
    padding-bottom: max(var(--space-6), env(safe-area-inset-bottom));
    overflow-y: auto;
  }
  .detail-panel__cover { max-width: 180px; }
  .detail-panel__title { font-size: var(--fs-xl); }
  .detail-panel__close {
    width: 44px;
    height: 44px;
    top: var(--space-3);
    right: var(--space-3);
    font-size: 1.6rem;
  }
  .detail-panel__actions { position: sticky; bottom: 0; padding-top: var(--space-3); background: linear-gradient(180deg, transparent 0%, var(--color-surface-2) 30%); }
  .detail-panel__actions .btn { width: 100%; justify-content: center; }
}

/* ----- Modals (login / add-rom): full-screen sheet on phones ----- */
@media (max-width: 520px) {
  .modal-overlay { padding: 0; }
  .modal,
  .modal:has(.auth-form--wide) {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  .modal__header { padding: var(--space-4) var(--space-4); padding-top: max(var(--space-4), env(safe-area-inset-top)); }
  .modal__body   { padding: var(--space-4); }
  .modal__footer {
    padding: var(--space-3) var(--space-4);
    padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
    flex-wrap: wrap;
  }
  .modal__footer .btn { flex: 1; min-width: 0; justify-content: center; }
  .modal__close { width: 44px; height: 44px; }
}

/* ----- Theme switcher dropdown: clamp to viewport on tiny phones ----- */
@media (max-width: 380px) {
  .theme-switcher__panel {
    position: fixed;
    top: 60px;
    left: var(--space-3);
    right: var(--space-3);
    min-width: 0;
    width: auto;
  }
}

/* Note: body has overflow:hidden on the home page; safe-area-inset-bottom
   is applied directly to .content__body and modals so the global padding
   trick is not needed here. */

