:root {
  --ink: #f7f4e8;
  --muted: #a8b3ad;
  --panel: #18232b;
  --panel-2: #202e35;
  --line: #3c4a4f;
  --red: #e84855;
  --gold: #f9c74f;
  --green: #43aa8b;
  --blue: #4d96ff;
  --black: #0b0f14;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.36);
}

/* TV launcher */
body {
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 255, 255, 0.28), transparent 22%),
    linear-gradient(180deg, #8f9693 0%, #6f7774 48%, #4f5856 100%);
}

.gamebox-shell {
  min-height: 100vh;
  padding: 24px 38px 34px;
}

.tv-topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  max-width: 1680px;
  margin: 0 auto 20px;
}

.tv-stage {
  position: relative;
  max-width: 1680px;
  min-height: calc(100vh - 122px);
  margin: 0 auto;
  padding: 18px 8px 74px;
}

.tv-view[hidden] {
  display: none;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  grid-auto-rows: minmax(145px, 18vh);
  gap: 22px;
}

.category-tile {
  position: relative;
  display: grid;
  align-content: end;
  min-height: 145px;
  padding: 18px;
  overflow: hidden;
  border: 0;
  border-radius: 10px;
  background: #2f5e9e;
  color: #fff;
  text-align: left;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.24);
}

.category-tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.22), transparent 42%, rgba(0, 0, 0, 0.24));
}

.category-tile strong,
.category-tile small,
.category-tile .tile-icon,
.category-tile .tile-copy,
.category-tile .tile-art {
  position: relative;
  z-index: 1;
}

.category-tile strong {
  display: block;
  font-size: clamp(22px, 2vw, 34px);
  line-height: 1;
}

.category-tile small,
.category-tile em {
  display: block;
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.86);
  font-size: 14px;
  font-style: normal;
  font-weight: 800;
}

.tile-icon {
  position: absolute;
  top: 16px;
  right: 18px;
  font-size: clamp(36px, 4vw, 68px);
  font-weight: 1000;
  opacity: 0.28;
}

.continue-tile {
  grid-column: span 2;
  background: linear-gradient(135deg, #222, #535b62);
}

.continue-tile[hidden] {
  display: none;
}

.continue-tile .tile-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  opacity: 0.46;
  background-size: cover;
  background-position: center;
}

.continue-tile .tile-copy {
  align-self: end;
}

.hot-tile { background: #e85c3a; }
.fc-tile { background: #2497c6; }
.arcade-tile { background: #8a5ecf; }
.fight-tile { background: #d64563; }
.shoot-tile { background: #3a8e55; }
.adventure-tile { background: #ca9330; }
.puzzle-tile { background: #4d7cc9; }
.racing-tile { background: #2f6d70; }
.rpg-tile { background: #6650a6; }

.category-tile.is-launcher-focus,
.game-card.is-launcher-focus,
.start-game-button.is-launcher-focus,
.secondary-action.is-launcher-focus,
.device-row select.is-launcher-focus,
.device-row button.is-launcher-focus,
.toggle-row.is-launcher-focus {
  outline: 5px solid #fff;
  outline-offset: 5px;
  transform: translateY(-8px) scale(1.045);
  box-shadow: 0 24px 45px rgba(0, 0, 0, 0.35), 0 0 0 8px rgba(255, 255, 255, 0.18);
}

.view-head {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 64px;
  margin-bottom: 18px;
}

.view-head h1 {
  margin: 0;
  font-size: clamp(30px, 3vw, 54px);
  line-height: 1;
}

.back-chip {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  color: #fff;
  font-weight: 900;
}

.poster-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 20px;
  max-height: calc(100vh - 240px);
  padding: 10px 8px 24px;
  overflow-y: auto;
}

.poster-grid .game-card {
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  gap: 10px;
  min-height: 236px;
  margin: 0;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: rgba(32, 39, 42, 0.82);
  color: #fff;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.26);
}

.poster-grid .game-thumb {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  background-color: #111;
}

.poster-grid .game-card strong {
  min-height: 42px;
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
}

.poster-grid .game-card small {
  color: rgba(255, 255, 255, 0.72);
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(360px, 42%) 1fr;
  gap: 44px;
  align-items: start;
}

.detail-layout .detail-thumb {
  min-height: 320px;
  border: 0;
  border-radius: 12px;
  background-color: #111;
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.3);
}

.detail-copy {
  display: grid;
  gap: 16px;
  color: #fff;
}

.detail-copy h1 {
  margin: 0;
  font-size: clamp(38px, 5vw, 72px);
  line-height: 1;
}

.detail-meta,
.detail-description {
  margin: 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 18px;
  line-height: 1.65;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 8px;
}

.start-game-button,
.secondary-action {
  min-height: 58px;
  padding: 0 28px;
  border: 0;
  border-radius: 999px;
  background: #f5c144;
  color: #151515;
  font-size: 20px;
  font-weight: 1000;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.26);
}

.secondary-action {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.tv-settings {
  display: grid;
  gap: 10px;
  max-width: 650px;
  margin-top: 8px;
  padding: 16px;
  border-radius: 12px;
  background: rgba(22, 29, 32, 0.42);
}

.tv-settings h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.tv-tabs,
.tv-prompts {
  position: fixed;
  left: 38px;
  right: 38px;
  bottom: 22px;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 26px;
  color: rgba(255, 255, 255, 0.78);
  font-weight: 900;
}

.tv-tabs {
  justify-content: center;
  pointer-events: none;
}

.tv-tabs span {
  padding: 8px 18px;
  border-radius: 999px;
}

.tv-tabs .is-active {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.tv-prompts {
  justify-content: flex-end;
  pointer-events: none;
}

.play-shell[hidden] {
  display: none;
}

@media (max-width: 1180px) {
  .category-grid,
  .poster-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .detail-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .gamebox-shell {
    padding: 14px;
  }

  .tv-topbar {
    grid-template-columns: 1fr auto;
  }

  .category-grid,
  .poster-grid {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
    gap: 12px;
  }

  .tv-tabs,
  .tv-prompts {
    left: 14px;
    right: 14px;
    gap: 10px;
    font-size: 12px;
  }

  .mapping-grid,
  .mapping-grid-compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 14%, rgba(232, 72, 85, 0.14), transparent 28%),
    linear-gradient(135deg, #101820 0%, #172226 52%, #121619 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
a {
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
}

.gamebox-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 900;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--red);
  color: #fff;
  font-size: 13px;
  box-shadow: 4px 4px 0 var(--black);
}

.status-strip {
  display: flex;
  justify-content: center;
  gap: 10px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-strip span {
  min-height: 34px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(11, 15, 20, 0.38);
  white-space: nowrap;
}

.icon-button,
.toolbar button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 3px 3px 0 var(--black);
  font-weight: 900;
}

.icon-button {
  width: 42px;
}

.stage,
.tv-stage {
  display: grid;
  grid-template-columns: minmax(210px, 260px) minmax(380px, 1fr) minmax(300px, 380px);
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
  align-items: stretch;
}

.library,
.controls {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 35, 43, 0.88);
  box-shadow: var(--shadow);
}

.game-browser {
  min-height: calc(100vh - 108px);
}

.detail-panel {
  max-height: calc(100vh - 108px);
  overflow-y: auto;
}

.continue-card {
  display: grid;
  grid-template-columns: 118px 1fr;
  gap: 14px;
  width: 100%;
  min-height: 112px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid rgba(249, 199, 79, 0.42);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(249, 199, 79, 0.16), rgba(77, 150, 255, 0.12)), #10181f;
  box-shadow: 3px 3px 0 var(--black);
  text-align: left;
}

.continue-card[hidden] {
  display: none;
}

.continue-card.is-launcher-focus,
.system-card.is-launcher-focus,
.game-card.is-launcher-focus,
.start-game-button.is-launcher-focus,
.device-row select.is-launcher-focus,
.device-row button.is-launcher-focus,
.toggle-row.is-launcher-focus {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(249, 199, 79, 0.12), 3px 3px 0 var(--black);
}

.continue-thumb {
  display: block;
  width: 118px;
  aspect-ratio: 4 / 3;
  border-radius: 6px;
  background: #070a0f;
  image-rendering: pixelated;
}

.continue-copy {
  min-width: 0;
  align-self: center;
}

.continue-copy small,
.continue-copy strong,
.continue-copy em {
  display: block;
}

.continue-copy small,
.detail-kicker {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
}

.continue-copy strong {
  margin-bottom: 6px;
  font-size: 20px;
  line-height: 1.18;
}

.continue-copy em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.game-detail {
  display: grid;
  gap: 12px;
}

.detail-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #070a0f;
  image-rendering: pixelated;
}

.detail-thumb.is-animated,
.continue-thumb.is-animated {
  background-size: calc(100% * var(--thumb-frames)) 100%;
  background-position: 0 50%;
  animation: thumb-preview var(--thumb-duration, 2.1s) steps(var(--thumb-steps, 1), end) infinite;
}

.game-detail h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 42px);
  line-height: 1.05;
}

.detail-meta,
.detail-description,
.tv-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.detail-description {
  min-height: 58px;
}

.start-game-button {
  min-height: 58px;
  border: 1px solid #05070c;
  border-radius: 8px;
  background: var(--gold);
  color: #111;
  box-shadow: 4px 4px 0 #05070c;
  font-size: 20px;
  font-weight: 1000;
}

.start-game-button:disabled {
  opacity: 0.56;
  cursor: default;
}

.library-head h1,
.game-list h2,
.translation-panel h2,
.keymap h2 {
  margin: 0 0 8px;
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

.game-list h2 {
  margin-top: 18px;
  font-size: 15px;
  color: var(--gold);
}

.library-search {
  margin: 10px 0 8px;
}

.library-search input {
  width: 100%;
  min-height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10181f;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
}

.library-search input::placeholder {
  color: #71807f;
}

.library-count {
  min-height: 20px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.game-card-list {
  max-height: calc(100vh - 250px);
  margin-top: 8px;
  padding-right: 4px;
  overflow-y: auto;
}

.library-head p,
.keymap p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.translation-panel {
  margin-top: 18px;
}

.device-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 12px;
}

.device-row-wide {
  grid-template-columns: 1fr;
}

.device-row select,
.device-row input,
.device-row button {
  min-height: 38px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10181f;
  color: var(--ink);
  font-weight: 800;
}

.device-row select {
  padding: 0 10px;
}

.device-row input {
  padding: 0 10px;
}

.device-row button {
  padding: 0 12px;
}

.gamepad-map-panel {
  margin-top: 10px;
}

.mapping-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.mapping-grid-compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mapping-grid label {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.mapping-grid input {
  width: 100%;
  min-height: 34px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10181f;
  color: var(--ink);
  font-weight: 900;
  text-align: center;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.system-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.system-card {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 62px;
  padding: 10px 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111b22;
}

.system-card.is-active {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px rgba(77, 150, 255, 0.2);
}

.system-card.is-disabled {
  opacity: 0.68;
}

.system-card strong,
.system-card small {
  display: block;
}

.system-card small {
  color: var(--muted);
  font-size: 12px;
}

.game-card {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 12px;
  width: 100%;
  min-height: 82px;
  margin-top: 12px;
  padding: 10px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.game-card.is-active {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 2px rgba(249, 199, 79, 0.2);
}

.game-card strong,
.game-card small {
  display: block;
}

.game-card strong {
  margin: 2px 0 6px;
  font-size: 15px;
}

.game-card small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.game-thumb {
  width: 58px;
  height: 58px;
  border-radius: 6px;
  image-rendering: pixelated;
}

.game-thumb.is-animated {
  background-size: calc(100% * var(--thumb-frames)) 100%;
  background-position: 0 50%;
  animation: thumb-preview var(--thumb-duration, 2.1s) steps(var(--thumb-steps, 1), end) infinite;
}

@keyframes thumb-preview {
  to {
    background-position: 100% 50%;
  }
}

.lj65-thumb {
  background:
    linear-gradient(#e84855 0 0) 12px 10px / 12px 12px no-repeat,
    linear-gradient(#f9c74f 0 0) 24px 10px / 12px 12px no-repeat,
    linear-gradient(#43aa8b 0 0) 24px 22px / 12px 12px no-repeat,
    linear-gradient(#4d96ff 0 0) 36px 22px / 12px 12px no-repeat,
    #11172b;
}

.croom-thumb {
  background:
    repeating-linear-gradient(90deg, #4d96ff 0 10px, #f7f4e8 10px 12px, #43aa8b 12px 22px),
    #18232b;
}

.arcade-thumb {
  background:
    linear-gradient(#f9c74f 0 0) 10px 12px / 38px 8px no-repeat,
    linear-gradient(#e84855 0 0) 14px 24px / 30px 8px no-repeat,
    linear-gradient(#43aa8b 0 0) 18px 36px / 22px 8px no-repeat,
    #101820;
}

.arcade-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.game-exit-fullscreen {
  pointer-events: none;
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  z-index: 8;
  min-width: 78px;
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 8px;
  background: rgba(11, 15, 20, 0.78);
  color: #fff;
  font-weight: 900;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.is-game-fullscreen-control-visible .game-exit-fullscreen {
  pointer-events: auto;
  opacity: 1;
  transform: translateY(0);
}

.console {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 12px;
  min-width: 0;
}

.play-shell[hidden] {
  display: none;
}

.play-shell {
  max-width: 1440px;
  min-height: calc(100vh - 96px);
  margin: 0 auto;
}

.play-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
}

.screen-bezel {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  padding: clamp(10px, 2vw, 20px);
  border: 12px solid #2a3034;
  border-radius: 8px;
  background: #070a0f;
  box-shadow: var(--shadow), inset 0 0 0 2px #555d62;
  overflow: hidden;
}

#emulator-screen {
  position: relative;
  display: grid;
  width: min(100%, calc((100vh - 170px) * 1.3333));
  max-width: 100%;
  height: auto;
  min-height: 260px;
  place-items: center;
  aspect-ratio: var(--screen-aspect, 4 / 3);
}

#emulator-screen:fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  min-height: 0;
  background: #000;
}

.screen-bezel:fullscreen {
  width: 100vw;
  height: 100vh;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #000;
}

.screen-bezel:fullscreen #emulator-screen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  min-height: 0;
}

#emulator-screen canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: fill;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.system-empty {
  display: grid;
  width: 100%;
  min-height: 240px;
  place-items: center;
  align-content: center;
  gap: 10px;
  padding: 24px;
  border: 1px dashed rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.system-empty strong {
  color: var(--ink);
  font-size: 22px;
}

.system-empty span {
  max-width: 420px;
  line-height: 1.6;
}

.scanlines {
  pointer-events: none;
  position: absolute;
  inset: 12px;
  z-index: 2;
  opacity: 0.12;
  background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.2) 0 1px, transparent 1px 4px);
  mix-blend-mode: screen;
}

.translation-layer {
  pointer-events: none;
  position: absolute;
  inset: 20px;
  z-index: 5;
  display: none;
  overflow: visible;
}

.translation-layer.is-active {
  display: block;
}

.translation-label {
  position: absolute;
  transform: translate(-50%, -100%);
  min-width: 74px;
  max-width: min(240px, 72%);
  padding: 4px 8px;
  border: 1px solid rgba(249, 199, 79, 0.78);
  border-radius: 6px;
  background: rgba(5, 7, 12, 0.9);
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.25;
  text-align: center;
  text-shadow: 1px 1px 0 #000;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.34);
  white-space: normal;
}

.translation-label::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 8px;
  height: 8px;
  border-right: 1px solid rgba(249, 199, 79, 0.78);
  border-bottom: 1px solid rgba(249, 199, 79, 0.78);
  background: rgba(5, 7, 12, 0.9);
  transform: translateX(-50%) rotate(45deg);
}

.translation-label[data-placement="below"] {
  transform: translate(-50%, 0);
}

.translation-label[data-placement="below"]::after {
  top: -5px;
  bottom: auto;
  transform: translateX(-50%) rotate(225deg);
}

.pause-layer {
  pointer-events: none;
  position: absolute;
  inset: 12px;
  z-index: 8;
  display: none;
  place-items: center;
  align-content: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.56);
  text-align: center;
}

.pause-layer.is-visible {
  display: none;
}

.pause-layer strong {
  font-size: clamp(36px, 8vw, 84px);
  letter-spacing: 0;
}

.pause-layer span {
  color: var(--gold);
  font-weight: 800;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.nes-pad {
  display: grid;
  gap: 18px;
  margin-top: 22px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 54px);
  justify-content: center;
}

.dpad button,
.round-buttons button,
.system-buttons button {
  border: 1px solid #05070c;
  background: #303941;
  box-shadow: 3px 3px 0 #05070c;
  font-weight: 900;
  user-select: none;
  touch-action: none;
}

.dpad button {
  border-radius: 8px;
}

.dpad [data-touch="up"] {
  grid-column: 2;
}

.dpad [data-touch="left"] {
  grid-column: 1;
  grid-row: 2;
}

.dpad [data-touch="right"] {
  grid-column: 3;
  grid-row: 2;
}

.dpad [data-touch="down"] {
  grid-column: 2;
  grid-row: 3;
}

.round-buttons,
.system-buttons {
  display: flex;
  justify-content: center;
  gap: 18px;
}

.round-buttons button {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--red);
}

.round-buttons button span,
.round-buttons button strong {
  display: block;
  line-height: 1;
}

.round-buttons button span {
  font-size: 13px;
}

.round-buttons button strong {
  font-size: 18px;
}

.round-buttons [data-touch="a"] {
  background: var(--gold);
  color: #141414;
}

.system-buttons button {
  min-width: 92px;
  min-height: 38px;
  border-radius: 999px;
  background: var(--green);
  font-size: 12px;
}

[data-pressed="true"] {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #05070c;
}

@media (max-width: 1080px) {
  .stage,
  .tv-stage {
    grid-template-columns: 1fr;
  }

  .library,
  .game-browser {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
  }

  .game-browser {
    min-height: 0;
  }

  .detail-panel {
    max-height: none;
  }

  .game-card {
    margin: 0;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 18px;
    align-items: center;
  }

  .nes-pad {
    margin: 0;
  }

  .play-controls {
    grid-template-columns: 1fr;
  }

  #emulator-screen {
    width: min(100%, calc((100vh - 210px) * 1.3333));
    height: auto;
    min-height: 0;
  }
}

@media (max-width: 720px) {
  .gamebox-shell {
    padding: 10px;
  }

  .topbar {
    grid-template-columns: 1fr auto;
  }

  .status-strip {
    grid-column: 1 / -1;
    justify-content: flex-start;
    overflow-x: auto;
  }

  .library,
  .controls {
    padding: 12px;
  }

  .library,
  .game-browser {
    grid-template-columns: 1fr;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .screen-bezel {
    border-width: 8px;
  }

  #emulator-screen {
    width: 100%;
  }

  .toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .continue-card {
    grid-template-columns: 92px 1fr;
  }

  .continue-thumb {
    width: 92px;
  }
}

/* Final TV overrides: keep these after legacy rules. */
body {
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 255, 255, 0.28), transparent 22%),
    linear-gradient(180deg, #8f9693 0%, #6f7774 48%, #4f5856 100%);
}

.gamebox-shell {
  min-height: 100vh;
  padding: 24px 38px 34px;
}

.tv-topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  max-width: 1680px;
  margin: 0 auto 20px;
}

.tv-stage {
  display: block;
  position: relative;
  max-width: 1680px;
  min-height: calc(100vh - 122px);
  margin: 0 auto;
  padding: 18px 8px 74px;
}

.tv-view[hidden],
.play-shell[hidden],
.continue-tile[hidden] {
  display: none !important;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  grid-auto-rows: minmax(145px, 18vh);
  gap: 22px;
}

.category-tile {
  min-height: 145px;
  border: 0;
  border-radius: 10px;
}

.poster-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 20px;
  max-height: calc(100vh - 240px);
  overflow-y: auto;
}

.poster-grid .game-card {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 236px;
  margin: 0;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: rgba(32, 39, 42, 0.82);
}

.poster-grid .game-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  height: auto;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(360px, 42%) 1fr;
  gap: 44px;
}

.tv-tabs,
.tv-prompts {
  position: fixed;
  left: 38px;
  right: 38px;
  bottom: 22px;
  z-index: 12;
}

/* In-game view uses page-internal fullscreen. The browser fullscreen API is
   intentionally not required here so gamepads/remotes keep working normally. */
body.is-playing {
  overflow: hidden;
  background: #000;
}

body.is-playing .gamebox-shell {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  background: #000;
}

body.is-playing .tv-topbar,
body.is-playing .tv-stage,
body.is-playing .play-controls {
  display: none !important;
}

body.is-playing .play-shell {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  min-height: 0;
  max-width: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #000;
}

body.is-playing .screen-bezel {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #000;
  box-shadow: none;
}

body.is-playing #emulator-screen {
  width: min(100vw, calc(100vh * var(--screen-ratio, 1.333333)));
  height: min(100vh, calc(100vw * var(--screen-inverse-ratio, 0.75)));
  min-height: 0;
  max-width: 100vw;
  max-height: 100vh;
  aspect-ratio: var(--screen-aspect, 4 / 3);
  background: #000;
}

body.is-playing #emulator-screen canvas,
body.is-playing #emulator-screen iframe {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
}

body.is-playing .scanlines,
body.is-playing .translation-layer,
body.is-playing .pause-layer {
  inset: auto;
  top: 50%;
  left: 50%;
  width: min(100vw, calc(100vh * var(--screen-ratio, 1.333333)));
  height: min(100vh, calc(100vw * var(--screen-inverse-ratio, 0.75)));
  transform: translate(-50%, -50%);
}
