/* ==========================================================================
   THEME PALETTES & ROOT VARIABLES
   ========================================================================== */
:root {
  /* Default: LCD Olive Handheld (Option A) */
  --bg-body: #1c2219;
  --console-body: #8f9b83;
  --console-border: #5c6851;
  --screen-bezel: #3d4734;
  --screen-bg: #8ba274;
  --pixel-main: #1d2b12;
  --pixel-accent: #374e25;
  --pixel-dim: #799063;
  --led-glow: #38ff42;
  --text-main: #1d2b12;
  --btn-face: #606d55;
  --btn-shadow: #3b4632;
  --font-family: 'Courier New', Courier, Monaco, monospace;
}

[data-theme="crt-amber"] {
  /* CRT Phosphor Amber (Option C) */
  --bg-body: #0a0805;
  --console-body: #1c1813;
  --console-border: #332b21;
  --screen-bezel: #120e0a;
  --screen-bg: #160c02;
  --pixel-main: #ffb000;
  --pixel-accent: #ff8000;
  --pixel-dim: #382400;
  --led-glow: #ffb000;
  --text-main: #ffb000;
  --btn-face: #2c251d;
  --btn-shadow: #0f0c09;
}

[data-theme="swiss-brutalist"] {
  /* Swiss Graphic Brutalist (Option B) */
  --bg-body: #e2dfd8;
  --console-body: #f4f1ea;
  --console-border: #111111;
  --screen-bezel: #111111;
  --screen-bg: #fdfbf7;
  --pixel-main: #111111;
  --pixel-accent: #ff3b00;
  --pixel-dim: #e2ded4;
  --led-glow: #ff3b00;
  --text-main: #111111;
  --btn-face: #111111;
  --btn-shadow: #444444;
}

/* ==========================================================================
   GLOBAL RESET & LAYOUT
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

body {
  background-color: var(--bg-body);
  font-family: var(--font-family);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  color: var(--text-main);
  transition: background-color 0.3s ease;
  overflow-x: hidden;
  overflow-y: auto;
}

/* ==========================================================================
   TACTILE HARDWARE CONSOLE HOUSING
   ========================================================================== */
.console-housing {
  background: var(--console-body);
  border: 4px solid var(--console-border);
  border-radius: 20px;
  padding: 14px;
  width: 100%;
  max-width: 400px;
  max-height: 98vh;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  transition: background 0.3s ease, border-color 0.3s ease;
}

/* Header & Power LED */
.console-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--console-border);
}

.brand-badge {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--text-main);
}

.brand-badge span {
  font-size: 10px;
  opacity: 0.7;
}

.device-engraving {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 3px;
  color: var(--console-border);
  padding: 3px 8px;
  border: 1px solid var(--console-border);
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.06);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.25),
    inset 0 -1px 1px rgba(0, 0, 0, 0.18);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
}

.power-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
}

.led-light {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--led-glow);
  box-shadow: 0 0 8px var(--led-glow);
}

.led-label {
  font-size: 9px;
  font-weight: bold;
  letter-spacing: 1px;
}

/* ==========================================================================
   SCREEN BEZEL & CANVAS
   ========================================================================== */
.screen-housing {
  background: var(--screen-bezel);
  border-radius: 12px;
  padding: 16px;
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.6);
}

.screen-bezel {
  background: var(--screen-bg);
  border: 3px solid var(--pixel-main);
  border-radius: 6px;
  padding: 12px;
  position: relative;
  overflow: hidden;
  transition: background 0.3s ease;
}

.screen-hud {
  display: flex;
  justify-content: space-between;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 2px dashed var(--pixel-main);
  font-size: 12px;
  font-weight: bold;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.hud-label {
  font-size: 9px;
  opacity: 0.8;
}

.hud-value {
  font-size: 14px;
  letter-spacing: 1px;
}

/* Canvas Wrapper & Screens */
.canvas-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--screen-bg);
}

#game-canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  display: block;
}

/* Texture Overlays */
.screen-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.scanlines {
  background: linear-gradient(
    rgba(18, 16, 16, 0) 50%, 
    rgba(0, 0, 0, 0.15) 50%
  );
  background-size: 100% 4px;
  z-index: 2;
}

.grid-texture {
  background-image: 
    linear-gradient(to right, rgba(0, 0, 0, 0.04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.04) 1px, transparent 1px);
  background-size: 20px 20px;
  z-index: 1;
}

/* Modals / Screen Overlays */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: var(--screen-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.glitch-title {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 3px;
  margin-bottom: 4px;
}

.modal-subtitle {
  font-size: 10px;
  letter-spacing: 2px;
  margin-bottom: 20px;
  opacity: 0.8;
}

.modal-prompt {
  font-size: 12px;
  font-weight: bold;
  padding: 8px 12px;
  border: 2px solid var(--pixel-main);
  margin-top: 12px;
}

.modal-hint {
  font-size: 10px;
  margin-top: 16px;
  opacity: 0.75;
}

.blink {
  animation: pulse-blink 1s infinite alternate;
}

@keyframes pulse-blink {
  from { opacity: 1; }
  to { opacity: 0.2; }
}

/* Shake Effect */
.shake {
  animation: rumble 0.25s ease-in-out;
}

@keyframes rumble {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-4px, 3px); }
  40% { transform: translate(4px, -3px); }
  60% { transform: translate(-3px, -2px); }
  80% { transform: translate(3px, 2px); }
  100% { transform: translate(0, 0); }
}

/* ==========================================================================
   CONTROLS PANEL & HARDWARE BUTTONS
   ========================================================================== */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.system-buttons {
  display: flex;
  justify-content: space-around;
  background: rgba(0, 0, 0, 0.1);
  padding: 8px;
  border-radius: 8px;
}

.sys-btn {
  background: var(--btn-face);
  border: 2px solid var(--console-border);
  color: var(--screen-bg);
  padding: 6px 12px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 10px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--btn-shadow);
}

.sys-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--btn-shadow);
}

.sys-btn:focus-visible,
.d-btn:focus-visible,
.act-btn:focus-visible {
  outline: 2px solid var(--led-glow);
  outline-offset: 2px;
}

.gamepad-deck {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 8px;
}

/* Physical D-Pad */
.d-pad {
  position: relative;
  width: 120px;
  height: 120px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}

.d-btn {
  background: var(--btn-face);
  border: 2px solid var(--console-border);
  color: var(--screen-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: pointer;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.2);
}

.d-btn:active {
  background: var(--pixel-main);
}

.d-up { grid-column: 2; grid-row: 1; border-radius: 6px 6px 0 0; }
.d-left { grid-column: 1; grid-row: 2; border-radius: 6px 0 0 6px; }
.d-center { grid-column: 2; grid-row: 2; background: var(--btn-face); border: 2px solid var(--console-border); }
.d-right { grid-column: 3; grid-row: 2; border-radius: 0 6px 6px 0; }
.d-down { grid-column: 2; grid-row: 3; border-radius: 0 0 6px 6px; }

/* Action Round Buttons */
.action-buttons {
  display: flex;
  gap: 16px;
  transform: rotate(-10deg);
}

.act-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--btn-face);
  border: 3px solid var(--console-border);
  color: var(--screen-bg);
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--btn-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}

.act-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--btn-shadow);
}

.act-label {
  font-size: 10px;
}

@media (max-width: 420px), (max-height: 720px) {
  .console-housing {
    padding: 10px;
    gap: 8px;
    border-radius: 16px;
  }

  .screen-housing {
    padding: 10px;
  }

  .screen-bezel {
    padding: 8px;
  }

  .controls-panel {
    gap: 12px;
  }

  .d-pad {
    width: 100px;
    height: 100px;
  }

  .act-btn {
    width: 48px;
    height: 48px;
  }

  .device-engraving {
    font-size: 8px;
    letter-spacing: 2px;
    padding: 2px 6px;
  }
}
