/* Unified emulator shell — shared between the picker view and every
 * per-console boot card. Identity colors (Genesis red, Famicom red,
 * Game Boy violet) come from the registry via inline custom-property
 * overrides set by launch.js, so this file stays brand-agnostic. */

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

:root {
  --bg: var(--surface-0);
  --surface: var(--surface-1);
  --surface2: var(--surface-2);
  --accent: var(--accent-primary);
  /* These three get overridden by launch.js per-console. Sega red is
   * the fallback so the page still has identity when the registry
   * fails to load (e.g. blocked CDN, dropped CSP). */
  --accent-bright: #e94560;
  --accent-bright-soft: rgba(233, 69, 96, 0.08);
  --accent-bright-ring: rgba(233, 69, 96, 0.25);
  --accent-gold: #c2410c;
  --text: var(--text-1);
  --text-dim: var(--text-2);
  --border: var(--hairline-strong);
  --card-bg: var(--surface-1);
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
}

#boot {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  /* Top pad clears the fixed .app-header breadcrumb bar. */
  padding: 72px 24px 24px;
  overflow-y: auto;
}

#boot.hidden {
  display: none;
}

/* Sit above the boot overlay; below /nav.js (999999). */
#emu-header.app-header {
  z-index: 150;
}

#emu-header.is-playing {
  display: none;
}

.brand {
  text-align: center;
  margin-bottom: 32px;
}

.brand-logo {
  font-size: 72px;
  line-height: 1;
  margin-bottom: 12px;
  display: block;
}

.brand h1 {
  font-size: clamp(28px, 5vw, 42px);
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
  /* Hero wordmark uses the identity accent on both ends of the
   * gradient so a console swap re-tints the title without
   * touching this file. Identity-text gradients are an explicit
   * BRAND.md carve-out for hero wordmarks. */
  background: linear-gradient(
    135deg,
    var(--accent-bright) 0%,
    var(--accent-gold) 50%,
    var(--accent-bright) 100%
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand .sub {
  display: block;
  font-size: 12px;
  letter-spacing: 4px;
  color: var(--text-dim);
  font-weight: 400;
  margin-top: 6px;
  -webkit-text-fill-color: var(--text-dim);
  background: none;
}

.boot-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 520px;
  width: 100%;
  box-shadow: var(--shadow-card);
}

/* The console picker needs more room than a single-console lander. */
.boot-card-picker {
  max-width: 640px;
}

.boot-card h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 20px;
  border-radius: 8px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-bright);
  color: var(--text-on-accent);
  border: 1px solid var(--accent-bright);
  transition: filter 0.2s, transform 0.2s;
}

.btn-primary:hover {
  transform: translateY(-1px);
  filter: brightness(0.88);
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--accent);
  border-color: var(--accent-bright);
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-stack rom-browser {
  display: block;
  width: 100%;
}

.bios-panel {
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--accent-bright-soft);
}

.bios-status {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
}

.bios-status[data-ready='1'] {
  /* Lifted --accent-gold in dark mode via launch.js; still prefer the
   * brighter identity token so status stays readable on surface-1. */
  color: var(--accent-bright);
  font-weight: 600;
}

.bios-progress {
  margin: 0 0 12px;
}

.bios-progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.bios-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--accent-bright);
  transition: width 0.15s ease-out;
}

.bios-progress[data-indeterminate='1'] .bios-progress-bar {
  width: 35% !important;
  animation: bios-progress-indeterminate 1.1s ease-in-out infinite;
}

@keyframes bios-progress-indeterminate {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(320%);
  }
}

.bios-progress-label {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.bios-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.bios-actions .btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.bios-actions .btn {
  flex: 1 1 auto;
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  padding: 4px 2px;
}

.btn-text:hover {
  color: var(--text);
}

.bios-help {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.45;
}

.rom-help {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.45;
  text-align: left;
}

.audio-note {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--accent-bright-soft);
  font-size: 13px;
  color: var(--text);
  line-height: 1.45;
  text-align: left;
}

#emu-play-chrome {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  max-width: min(560px, calc(100vw - 24px));
}

#emu-play-chrome[hidden] {
  display: none;
}

.emu-chrome-btn {
  background: rgba(20, 20, 24, 0.72);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}

.emu-chrome-btn:hover {
  filter: brightness(1.1);
}

.emu-chrome-note {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.35;
}

.howto {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.howto summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
  user-select: none;
  list-style: none;
}

.howto summary::-webkit-details-marker {
  display: none;
}

.howto ol {
  margin: 10px 0 0;
  padding-left: 1.25rem;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}

.howto li + li {
  margin-top: 4px;
}

.divider {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  letter-spacing: 2px;
  margin: 4px 0;
  position: relative;
}

.divider::before,
.divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 42%;
  height: 1px;
  background: var(--border);
}

.divider::before {
  left: 0;
}
.divider::after {
  right: 0;
}

.controls-info {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.controls-info summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.controls-info summary::-webkit-details-marker {
  display: none;
}

.controls-info summary::before {
  content: '▶';
  font-size: 9px;
  transition: transform 0.2s;
}

.controls-info[open] summary::before {
  transform: rotate(90deg);
}

.controls-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 13px;
}

.controls-grid .key-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  background: var(--surface);
  border-radius: 6px;
}

.controls-grid .key-row span {
  color: var(--text-dim);
}

kbd {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-family: monospace;
  color: var(--text-1);
}

.hidden-input {
  display: none;
}

#game-container {
  position: fixed;
  inset: 0;
  background: #000;
  display: none;
}

#game-container.visible {
  display: block;
}

#game {
  width: 100%;
  height: 100%;
}

.share-overlay {
  position: fixed;
  /* Top-right cluster with the related-projects 🎯 FAB — keeps both
   * clear of the boot card / game canvas (they used to sit bottom-left
   * and bottom-right and collided with controls). */
  top: 10px;
  right: 84px;
  bottom: auto;
  left: auto;
  z-index: 200;
}

/* Pull the sitewide 🎯 related-projects FAB up into the same cluster.
 * Panel opens downward; share-fab (if present) stacks below the toggle. */
.related-projects-container {
  top: 6px !important;
  right: 16px !important;
  bottom: auto !important;
}

.related-projects-panel {
  top: 70px !important;
  bottom: auto !important;
  transform: translateY(-8px) scale(0.95) !important;
}

.related-projects-panel.open {
  transform: translateY(0) scale(1) !important;
}

.related-projects-container .share-fab {
  top: 68px !important;
  bottom: auto !important;
}

/* Leave room for the top-right share + 🎯 cluster over the breadcrumb bar. */
#emu-header.app-header .app-breadcrumbs {
  padding-right: 170px;
}

@media (max-width: 768px) {
  .share-overlay {
    top: 8px;
    right: 72px;
  }

  .related-projects-container {
    top: 6px !important;
    right: 12px !important;
  }

  #emu-header.app-header .app-breadcrumbs {
    padding-right: 140px;
  }
}

.seo-intro {
  display: none;
}

/* Picker (when no ?console= is set) — tiles that mirror the
 * boot-card identity language. Hover behavior matches .btn-primary
 * so the affordance reads the same. Column count follows the card
 * width, not the viewport: the card is capped well below most
 * viewports, so viewport breakpoints packed columns too tightly. */
.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
}

.picker-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.15s, border-color 0.15s, background-color 0.15s;
}

.picker-tile:hover {
  transform: translateY(-2px);
  border-color: var(--accent-bright);
  background: var(--accent-bright-soft);
}

.picker-emoji {
  font-size: 36px;
  line-height: 1;
}

.picker-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.picker-sub {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  letter-spacing: 0.5px;
}

.picker-extra {
  margin-top: 18px;
}

.picker-extra-heading {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.picker-tile-flash {
  width: 100%;
  flex-direction: row;
  justify-content: flex-start;
  gap: 14px;
  padding: 16px 18px;
  text-align: left;
  /* Flash-era red — distinct from console accent tiles. */
  border-color: color-mix(in srgb, #e31c25 45%, var(--border));
  background: color-mix(in srgb, #e31c25 8%, var(--surface));
}

.picker-tile-flash:hover {
  border-color: #e31c25;
  background: color-mix(in srgb, #e31c25 14%, var(--surface));
}

.picker-tile-flash .picker-emoji {
  font-size: 28px;
  flex-shrink: 0;
}

.picker-tile-flash .picker-title,
.picker-tile-flash .picker-sub {
  text-align: left;
}

.picker-tile-flash .picker-title {
  line-height: 1.2;
}

.picker-help {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
}

@media (max-width: 480px) {
  .brand-logo {
    font-size: 52px;
  }
  .boot-card {
    padding: 20px;
  }
  .controls-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Lean-back / TV mode (data-mode stamped by leanback.js) ───────── */

.leanback-banner {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--accent-bright-soft);
  border: 1px solid var(--accent-bright-ring);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}

.leanback-banner[data-connected='1'] {
  border-color: var(--accent-bright);
}

.coi-fail-copy {
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 12px;
}

.deeplink-error {
  color: var(--danger, #dc2626);
  font-size: 14px;
  margin: 0 0 12px;
  line-height: 1.4;
}

/* `?rom=` deep link: download handoff above the boot card. */
.deeplink-handoff {
  margin: 0 0 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--accent-bright-soft);
  text-align: left;
}

.deeplink-handoff h3 {
  margin: 0 0 6px;
  font-size: 15px;
  color: var(--text);
  line-height: 1.3;
}

.deeplink-handoff p {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.45;
}

.deeplink-handoff-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.deeplink-handoff-actions .btn {
  flex: 1 1 220px;
  text-decoration: none;
}

.controls-gamepad-hint {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
}

:root[data-modality='pointer'] *:focus:not(:focus-visible) {
  outline: none;
}

:root[data-mode='tv'] {
  --tv-focus-ring: 4px solid var(--accent-bright);
}

:root[data-mode='tv'] #emu-header {
  display: none !important;
}

:root[data-mode='tv'] #boot {
  padding: 40px 48px;
  overflow-y: auto;
}

:root[data-mode='tv'] .brand-logo {
  font-size: 88px;
}

:root[data-mode='tv'] .brand h1 {
  font-size: clamp(32px, 4vw, 48px);
}

:root[data-mode='tv'] .brand .sub {
  font-size: 14px;
  letter-spacing: 3px;
}

:root[data-mode='tv'] .boot-card {
  max-width: 720px;
  padding: 36px;
}

:root[data-mode='tv'] .boot-card h2 {
  font-size: 18px;
  margin-bottom: 24px;
}

:root[data-mode='tv'] .boot-card-picker {
  max-width: 900px;
}

:root[data-mode='tv'] .picker-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

:root[data-mode='tv'] .picker-tile {
  padding: 28px 16px;
  gap: 10px;
}

:root[data-mode='tv'] .picker-emoji {
  font-size: 48px;
}

:root[data-mode='tv'] .picker-title {
  font-size: 20px;
}

:root[data-mode='tv'] .picker-sub {
  font-size: 14px;
}

:root[data-mode='tv'] .picker-tile:focus-visible,
:root[data-mode='tv'] .btn:focus-visible,
:root[data-mode='tv'] .leanback-banner:focus-visible {
  outline: var(--tv-focus-ring);
  outline-offset: 4px;
  transform: scale(1.03);
}

:root[data-mode='tv'] .btn {
  padding: 18px 24px;
  font-size: 17px;
}

:root[data-mode='tv'] .leanback-banner {
  font-size: 16px;
  padding: 14px 18px;
}

:root[data-mode='tv'] .picker-help,
:root[data-mode='tv'] .coi-fail-copy {
  font-size: 15px;
}

/* Hide mouse-oriented site chrome on lean-back surfaces */
:root[data-mode='tv'] feedback-button,
:root[data-mode='tv'] share-button,
:root[data-mode='tv'] .share-overlay,
:root[data-mode='tv'] .related-projects-container {
  display: none !important;
}

@media (max-width: 768px) {
  #boot {
    padding: 64px 16px 24px;
  }
}
