/* ── Game Canvas ─────────────────────────────────────── */
.canvas-container {
  position: relative;
  width: 100%;
  /* max-width: calc((100vh - 100px) * 4 / 3); */
  height: auto;
  max-height: calc(100vh - 100px);
  aspect-ratio: 4 / 3;
  background: #000;
  border: 2px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#nes-canvas {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* CRT scanline overlay */
.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.12) 2px,
    rgba(0,0,0,0.12) 4px
  );
  mix-blend-mode: multiply;
}

/* Fullscreen adjustments */
.canvas-container:fullscreen,
.canvas-container:-webkit-full-screen {
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  border: none;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.canvas-container:fullscreen #nes-canvas,
.canvas-container:-webkit-full-screen #nes-canvas {
  width: min(100vw, calc(100vh * 4 / 3));
  height: min(100vh, calc(100vw * 3 / 4));
  max-width: 100%;
  max-height: 100%;
}

.canvas-container:fullscreen #guest-video,
.canvas-container:-webkit-full-screen #guest-video {
  width: min(100vw, calc(100vh * 4 / 3));
  height: min(100vh, calc(100vw * 3 / 4));
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

#screen-game { flex-direction: column; }
#screen-game.chat-open {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: 1fr;
  padding: 0;
}

/* ── Game Main (right column when sidebar open) ────── */
.game-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  /* justify-content: center; */
  position: relative;
  min-height: 100vh;
  /* width: 100%; */
  width: calc(100vw - 320px);
}

/* When sidebar is open, canvas fills the shorter dimension */
.chat-open .canvas-container {
  max-width: calc((100vh - 100px) * 4 / 3);
  max-height: calc((100vw - 320px) * 3 / 4);
}

/* When sidebar is open, center fixed overlays to the game area */
#screen-game.chat-open ~ .game-controls {
  left: calc(320px + (100vw - 320px) / 2);
}

#screen-game.chat-open .swap-prompt,
#screen-game.chat-open .rematch-prompt {
  left: calc(320px + (100vw - 320px) / 2);
}

#screen-game.chat-open .sys-status {
  left: calc(320px + 8px);
}

#screen-game.chat-open .chat {
  left: calc(320px + 12px);
}

#screen-game.chat-open ~ #flash {
  left: calc(320px + (100vw - 320px) / 2);
}

#screen-game.chat-open ~ .disk-picker {
  left: calc(320px + (100vw - 320px) / 2);
}

#screen-game.chat-open ~ .cheatsheet {
  left: calc(320px + (100vw - 320px) / 2);
}

#screen-game.chat-open ~ .game-change-overlay {
  left: 320px;
}

/* Hide overlay when sidebar is open */
.chat-open .chat { display: none !important; }

/* ── Chat Sidebar ──────────────────────────────────── */
.chat-sidebar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  left: 0;
}

.chat-sidebar.hidden { display: none; }

.chat-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-sidebar-title {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 2px;
}

.chat-sidebar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-sidebar-mic {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px;
  opacity: 0.35;
  filter: grayscale(1);
  transition: opacity 0.2s, filter 0.2s;
}

.btn-sidebar-mic.mic-active {
  opacity: 1;
  filter: grayscale(0) brightness(1.2);
}

.sidebar-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-messages::-webkit-scrollbar { width: 4px; }
.sidebar-messages::-webkit-scrollbar-track { background: transparent; }
.sidebar-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.sidebar-messages .chat-msg {
  animation: none;
  opacity: 1;
  background: transparent;
  backdrop-filter: none;
  padding: 4px 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  word-break: break-word;
}

.chat-sidebar-input {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
  flex-shrink: 0;
}

.sidebar-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  outline: none;
}

.sidebar-input:focus { border-color: var(--accent); }

.btn-sidebar-send {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}
.btn-sidebar-send:hover { opacity: 0.85; }

/* ── Game Controls Hint (desktop keyboard) ──────────── */
.game-controls-hint {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 20px;
  max-width: 960px;
  margin: 10px auto 0;
  padding: 6px 12px;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--text-dim);
  opacity: 0.6;
  letter-spacing: 1px;
}
.game-controls-hint span { white-space: nowrap; }
.game-controls-hint .hint-label { color: var(--accent); margin-right: 4px; }

.canvas-container:fullscreen ~ .game-controls-hint,
.canvas-container:-webkit-full-screen ~ .game-controls-hint { display: none; }

/* ── Guest Video (Hosted Netplay) ────────────────────── */
#guest-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
#guest-video.hidden { display: none; }

/* ── System Status Indicator ─────────────────────────── */
.sys-status {
  position: fixed;
  top: 8px;
  left: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(10, 10, 15, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 10px;
  z-index: 100;
  backdrop-filter: blur(8px);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.sys-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.sys-dot.ok    { background: #00e5a0; box-shadow: 0 0 4px #00e5a0; }
.sys-dot.warn  { background: #ffaa00; box-shadow: 0 0 4px #ffaa00; }
.sys-dot.error { background: #ff4060; box-shadow: 0 0 4px #ff4060; }

.sys-text {
  white-space: nowrap;
}

/* ── HUD ─────────────────────────────────────────────── */
.hud {
  position: fixed;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 12px;
  background: rgba(10, 10, 15, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.hud-label {
  font-family: var(--font-pixel);
  font-size: 7px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.hud-value {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

/* Delay tuning control */
.delay-control {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-tiny {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.12s;
  line-height: 1;
}

.btn-tiny:hover {
  background: var(--border);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-tiny:active {
  transform: scale(0.9);
}

/* Sync status */
.hud-value.sync-ok {
  color: var(--accent);
}

.hud-value.desync {
  color: var(--danger);
}

/* ── Chat ───────────────────────────────────────────── */
.chat {
  position: fixed;
  bottom: 60px;
  left: 12px;
  width: 280px;
  z-index: 300;
  pointer-events: none;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 0;
}

.chat-msg {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 8px;
  background: rgba(10, 10, 15, 0.7);
  border-radius: 4px;
  color: var(--text);
  backdrop-filter: blur(4px);
  animation: chat-fade 5s ease forwards;
  max-width: 100%;
  word-break: break-word;
}

.chat-name-p1 { color: var(--accent); font-weight: 600; }
.chat-name-p2 { color: var(--accent2); font-weight: 600; }
.chat-name-spec { color: var(--text-dim); font-weight: 600; }

@keyframes chat-fade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

.chat-input {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 10px;
  background: rgba(10, 10, 15, 0.85);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  outline: none;
  pointer-events: auto;
  backdrop-filter: blur(8px);
}

.chat-input:focus {
  border-color: var(--accent);
}

.btn-tiny-lg {
  width: 32px;
  height: 32px;
  font-size: 16px;
}

/* ── Game Prompts ───────────────────────────────────── */
.rematch-prompt,
.swap-prompt {
  position: fixed;
  top: 48px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(10, 10, 15, 0.9);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 8px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  z-index: 300;
  backdrop-filter: blur(8px);
}

/* ── Game Controls Bar ───────────────────────────────── */
.game-controls {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 100;
  transition: transform 0.25s ease, opacity 0.2s ease;
}

.game-controls.dock-hidden {
  transform: translate(-50%, calc(100% + 20px));
  opacity: 0;
  pointer-events: none;
}

/* ── Disk Picker Overlay ────────────────────────────── */
.disk-picker {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 0;
  z-index: 150;
  min-width: 240px;
  max-height: 300px;
  overflow-y: auto;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

.disk-picker-title {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--text-dim);
  padding: 4px 12px 8px;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.disk-picker-item {
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

.disk-picker-item:hover,
.disk-picker-item.focused {
  background: rgba(255,255,255,0.05);
}

.disk-picker-item.active {
  color: var(--accent);
}

.disk-picker-item.active::before {
  content: '\25B6';
  font-size: 8px;
}

.disk-picker-item:not(.active)::before {
  content: '';
  display: inline-block;
  width: 8px;
}

/* ── Game Change Overlay ───────────────────────────── */
.game-change-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 2rem 0;
}
.game-change-content {
  max-width: 480px;
  width: 90%;
  padding: 1.5rem;
}
.game-change-content .system-selector {
  margin-bottom: 1rem;
}
.game-change-content .rom-library {
  max-height: 50vh;
  overflow-y: auto;
}

/* ── Cheat Sheet Overlay ────────────────────────────── */
.cheatsheet {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 200;
  max-width: 720px;
  width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

.cheatsheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.cheatsheet-title {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.cheatsheet-body {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding: 12px 14px 16px;
}

.cheatsheet-col h4 {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 10px 0 4px;
}

.cheatsheet-col h4:first-child {
  margin-top: 0;
}

.cs-row {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text);
  line-height: 1.8;
}

.cs-row kbd {
  display: inline-block;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--accent);
  line-height: 1.6;
}

.cs-row code {
  color: var(--accent2);
  font-family: var(--font-mono);
  font-size: 10px;
}

.cs-note {
  font-size: 10px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-top: 4px;
}

@media (max-width: 600px) {
  .cheatsheet-body {
    grid-template-columns: 1fr;
  }
}

/* ── Touch Gamepad ───────────────────────────────────── */
.touch-gamepad {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 150;
  pointer-events: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-gamepad > * {
  pointer-events: auto;
}

/* D-Pad */
.touch-dpad {
  display: grid;
  grid-template-columns: 44px 44px 44px;
  grid-template-rows: 44px 44px 44px;
  gap: 0;
  touch-action: none;
}

.touch-btn {
  border: none;
  outline: none;
  font-family: var(--font-pixel);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.dpad-up,
.dpad-down,
.dpad-left,
.dpad-right {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  position: relative;
}

.dpad-up    { grid-column: 2; grid-row: 1; border-radius: 8px 8px 0 0; }
.dpad-left  { grid-column: 1; grid-row: 2; border-radius: 8px 0 0 8px; }
.dpad-center { grid-column: 2; grid-row: 2; background: rgba(255, 255, 255, 0.15); border-radius: 0; }
.dpad-right { grid-column: 3; grid-row: 2; border-radius: 0 8px 8px 0; }
.dpad-down  { grid-column: 2; grid-row: 3; border-radius: 0 0 8px 8px; }

/* D-Pad arrows */
.dpad-up::after,
.dpad-down::after,
.dpad-left::after,
.dpad-right::after {
  content: '';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dpad-up::after {
  content: '';
  width: 0; height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 10px solid rgba(255,255,255,0.4);
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}
.dpad-down::after {
  content: '';
  width: 0; height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 10px solid rgba(255,255,255,0.4);
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}
.dpad-left::after {
  content: '';
  width: 0; height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-right: 10px solid rgba(255,255,255,0.4);
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}
.dpad-right::after {
  content: '';
  width: 0; height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 10px solid rgba(255,255,255,0.4);
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}

.dpad-up.active, .dpad-down.active,
.dpad-left.active, .dpad-right.active {
  background: rgba(0, 229, 160, 0.35);
}

/* Right-side column: meta buttons above face buttons */
.touch-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  touch-action: none;
}

/* A / B buttons — row for 2 buttons, 2x2 grid for 4 */
.touch-ab {
  display: flex;
  gap: 10px;
  align-items: center;
  touch-action: none;
}

.touch-ab.touch-ab-4 {
  display: grid;
  grid-template-columns: 52px 52px;
  grid-template-rows: 52px 52px;
  gap: 8px;
}

.ab-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.5);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-a {
  background: rgba(220, 40, 60, 0.3);
}

.btn-b {
  background: rgba(220, 40, 60, 0.2);
}

.ab-btn.active {
  background: rgba(220, 40, 60, 0.6);
  color: rgba(255, 255, 255, 0.9);
}

/* Start / Select */
.touch-meta {
  display: flex;
  gap: 8px;
  touch-action: none;
}

.meta-btn {
  padding: 6px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.35);
  font-size: 7px;
  letter-spacing: 1px;
}

.meta-btn.active {
  background: rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 0.8);
}

/* ── Touch Shoulders (SNES/GBA L/R) ─────────────────── */
.touch-shoulders {
  display: flex;
  justify-content: space-between;
  position: absolute;
  top: -36px;
  left: 0;
  right: 0;
  padding: 0 16px;
  touch-action: none;
}

.shoulder-btn {
  padding: 6px 18px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.35);
  font-size: 9px;
  font-family: var(--font-pixel);
  letter-spacing: 1px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.shoulder-btn.active {
  background: rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 0.8);
}

/* X/Y button styling (SNES) */
.btn-x, .btn-y {
  font-size: 12px;
}

/* Only show on touch / small screens. Touch devices keep the gamepad
   at any width; desktops hide it above the 800px mobile breakpoint. */
@media (min-width: 801px) {
  body:not(.is-touch) .touch-gamepad { display: none !important; }
}

@media (max-width: 800px) {
  /* Gamepad height: ~140px dpad + padding. Controls sit just above it. */
  #screen-game .canvas-container {
    max-height: calc(100dvh - 220px);
  }

  .game-controls {
    position: fixed;
    bottom: auto;
    top: 0;
    left: 0;
    right: 0;
    transform: none;
    justify-content: flex-start;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(8px);
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
    z-index: 200;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  .game-controls::-webkit-scrollbar {
    display: none;
  }

  /* Auto-hide is desktop-only — neutralize on mobile top bar */
  .game-controls.dock-hidden {
    transform: none;
    opacity: 1;
    pointer-events: auto;
  }

  .game-controls .btn-icon-only {
    font-size: 14px;
    padding: 6px 10px;
  }

  /* Override canvas constraint when in mobile fullscreen */
  body.mobile-fullscreen #screen-game {
    padding-top: 0;
  }
  body.mobile-fullscreen #screen-game .canvas-container {
    max-height: 100vh;
  }
}

/* Mirror of the above for touch devices at any viewport width. */
body.is-touch #screen-game .canvas-container {
  max-height: calc(100dvh - 220px);
}

body.is-touch .game-controls {
  position: fixed;
  bottom: auto;
  top: 0;
  left: 0;
  right: 0;
  transform: none;
  justify-content: flex-start;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(8px);
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  z-index: 200;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-wrap: nowrap;
  scrollbar-width: none;
}

body.is-touch .game-controls::-webkit-scrollbar {
  display: none;
}

body.is-touch .game-controls.dock-hidden {
  transform: none;
  opacity: 1;
  pointer-events: auto;
}

body.is-touch .game-controls .btn-icon-only {
  font-size: 14px;
  padding: 6px 10px;
}

body.is-touch.mobile-fullscreen #screen-game {
  padding-top: 0;
}
body.is-touch.mobile-fullscreen #screen-game .canvas-container {
  max-height: 100vh;
}

/* ── Mobile Fullscreen (iOS fallback + auto landscape) ───
   Manual: user taps ⛶ → body.mobile-fullscreen.
   Auto:   touch device in short-landscape → body.landscape-fs (via matchMedia in main.js).
   MUST be the last block in the file so these selectors win by source order over
   body.is-touch rules (they tie on specificity for #screen-game / .canvas-container).
   The #screen-game ancestor raises specificity to (1,2,1) to match
   body.is-touch #screen-game .canvas-container (same specificity, earlier in source). */
body.mobile-fullscreen,
body.landscape-fs {
  overflow: hidden;
}

body.mobile-fullscreen .game-controls-hint,
body.landscape-fs .game-controls-hint { display: none; }

body.mobile-fullscreen #screen-game,
body.landscape-fs #screen-game {
  position: fixed;
  inset: 0;
  z-index: 9000;
  padding: 0;
  min-height: 0;
}

body.mobile-fullscreen #screen-game .canvas-container,
body.landscape-fs #screen-game .canvas-container {
  width: auto;
  height: 100vh;
  max-height: 100vh;
  max-width: 100vw;
  border: none;
  border-radius: 0;
  aspect-ratio: unset;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

body.mobile-fullscreen #nes-canvas,
body.landscape-fs #nes-canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: 100vh;
  aspect-ratio: inherit;
}

body.mobile-fullscreen #guest-video,
body.landscape-fs #guest-video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

body.mobile-fullscreen .game-controls,
body.landscape-fs .game-controls {
  z-index: 9001;
}

/* Tap-to-toggle toolbar in auto-landscape fullscreen.
   Click handler lives on #canvas-container in main.js. */
body.landscape-fs .game-controls {
  transition: transform 0.2s ease, opacity 0.2s ease;
}
body.landscape-fs .game-controls.tap-hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

body.mobile-fullscreen .touch-gamepad,
body.landscape-fs .touch-gamepad {
  z-index: 9002;
}

/* Outline-only gamepad in fullscreen */
body.mobile-fullscreen .dpad-up,
body.mobile-fullscreen .dpad-down,
body.mobile-fullscreen .dpad-left,
body.mobile-fullscreen .dpad-right,
body.landscape-fs .dpad-up,
body.landscape-fs .dpad-down,
body.landscape-fs .dpad-left,
body.landscape-fs .dpad-right {
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.25);
}

body.mobile-fullscreen .dpad-center,
body.landscape-fs .dpad-center {
  background: transparent;
}

body.mobile-fullscreen .dpad-up.active,
body.mobile-fullscreen .dpad-down.active,
body.mobile-fullscreen .dpad-left.active,
body.mobile-fullscreen .dpad-right.active,
body.landscape-fs .dpad-up.active,
body.landscape-fs .dpad-down.active,
body.landscape-fs .dpad-left.active,
body.landscape-fs .dpad-right.active {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.5);
}

body.mobile-fullscreen .ab-btn,
body.landscape-fs .ab-btn {
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.3);
}

body.mobile-fullscreen .btn-a,
body.mobile-fullscreen .btn-b,
body.landscape-fs .btn-a,
body.landscape-fs .btn-b {
  background: transparent;
}

body.mobile-fullscreen .ab-btn.active,
body.landscape-fs .ab-btn.active {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.5);
  color: rgba(255,255,255,0.7);
}

body.mobile-fullscreen .meta-btn,
body.landscape-fs .meta-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
}

body.mobile-fullscreen .meta-btn.active,
body.landscape-fs .meta-btn.active {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.4);
}

/* D-pad arrow indicators — lighter in fullscreen */
body.mobile-fullscreen .dpad-up::after,
body.landscape-fs .dpad-up::after { border-bottom-color: rgba(255,255,255,0.25); }
body.mobile-fullscreen .dpad-down::after,
body.landscape-fs .dpad-down::after { border-top-color: rgba(255,255,255,0.25); }
body.mobile-fullscreen .dpad-left::after,
body.landscape-fs .dpad-left::after { border-right-color: rgba(255,255,255,0.25); }
body.mobile-fullscreen .dpad-right::after,
body.landscape-fs .dpad-right::after { border-left-color: rgba(255,255,255,0.25); }
