:root {
  --bg-deep: #090b10;
  --cabinet-top: #282c36;
  --cabinet-body: #1b1e26;
  --cabinet-dark: #101218;
  --bezel-border: #383e4c;
  --accent-red: #e52521;
  --accent-gold: #fac800;
  --ps2-blue: #4ea1ff;
  --text-main: #f4f4f6;
  --text-muted: #98a0b3;
  --font-pixel: "Press Start 2P", "Courier New", Courier, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  background: radial-gradient(circle at 50% 28%, #181f33 0%, var(--bg-deep) 68%, #040508 100%);
  color: var(--text-main);
  font-family: var(--font-pixel);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

.room-ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 45% at 50% 42%, rgba(78, 161, 255, 0.13), transparent 70%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02) 0%, transparent 40%, rgba(0, 0, 0, 0.48) 100%);
  z-index: 0;
}

.console-shell {
  position: relative;
  z-index: 1;
  width: min(94vw, 760px, calc((100dvh - 110px) * (512 / 480)));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* CRT Monitor Cabinet */
.crt-cabinet {
  width: 100%;
  background: linear-gradient(180deg, var(--cabinet-top) 0%, var(--cabinet-body) 18%, var(--cabinet-dark) 100%);
  border: 2px solid var(--bezel-border);
  border-radius: 18px;
  padding: 14px 14px 10px;
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.78),
    0 0 0 1px rgba(0, 0, 0, 0.7),
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 -3px 6px rgba(0, 0, 0, 0.65);
}

.crt-bezel {
  width: 100%;
  padding: 10px;
  background: #0c0e13;
  border-radius: 12px;
  border: 2px solid #08090d;
  box-shadow:
    inset 0 4px 14px rgba(0, 0, 0, 0.9),
    0 1px 0 rgba(255, 255, 255, 0.08);
}

.crt-screen {
  position: relative;
  width: 100%;
  aspect-ratio: 512 / 480;
  background: #000000;
  border-radius: 8px;
  overflow: hidden;
  box-shadow:
    0 0 28px rgba(78, 161, 255, 0.18),
    inset 0 0 18px rgba(0, 0, 0, 0.75);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
  touch-action: none;
}

/* Optional CRT Glass & Scanline Overlay */
.crt-glass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 8px;
  background:
    radial-gradient(ellipse at center, transparent 62%, rgba(0, 0, 0, 0.38) 100%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, transparent 36%);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.crt-screen.crt-scanlines .crt-glass {
  opacity: 1;
}

.crt-screen.crt-scanlines::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.17) 0px,
    rgba(0, 0, 0, 0.17) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: multiply;
}

/* Bezel Control Bar */
.bezel-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 6px 2px;
  flex-wrap: wrap;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.power-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff2b2b;
  box-shadow:
    0 0 8px rgba(255, 43, 43, 0.9),
    0 0 2px #ff8a8a inset;
  flex-shrink: 0;
}

.power-led.paused {
  background: var(--accent-gold);
  box-shadow: 0 0 8px rgba(250, 200, 0, 0.85);
}

.brand-name {
  font-size: 9px;
  letter-spacing: 0.08em;
  color: #e4e7f0;
  white-space: nowrap;
}

.brand-model {
  font-size: 7px;
  color: #79849e;
  padding: 2px 5px;
  border: 1px solid #353b4a;
  border-radius: 3px;
  letter-spacing: 0.06em;
}

.bezel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bezel-btn {
  appearance: none;
  background: linear-gradient(180deg, #2d3240 0%, #1c202a 100%);
  color: #b7bfd4;
  border: 1px solid #41485b;
  border-bottom-color: #11131a;
  border-radius: 5px;
  font-family: var(--font-pixel);
  font-size: 8px;
  letter-spacing: 0.04em;
  padding: 6px 9px;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow:
    0 2px 0 #0d0f14,
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: transform 0.08s ease, color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.bezel-btn:hover {
  color: #ffffff;
  border-color: #636d87;
  background: linear-gradient(180deg, #363c4d 0%, #232834 100%);
}

.bezel-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #0d0f14;
}

.bezel-btn.is-on {
  color: #ffffff;
  border-color: #5b79b8;
  box-shadow:
    0 2px 0 #0d0f14,
    0 0 10px rgba(78, 161, 255, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.bezel-btn:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: 2px;
}

.bezel-btn.is-hidden {
  display: none;
}

/* Desktop Controls Legend */
.controls-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px 16px;
  padding: 7px 14px;
  background: rgba(17, 20, 29, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  backdrop-filter: blur(6px);
}

.control-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 8px;
  color: var(--text-muted);
}

.control-item kbd {
  font-family: var(--font-pixel);
  font-size: 7px;
  color: #eef1f8;
  background: #232836;
  border: 1px solid #41495e;
  border-bottom: 2px solid #0e1118;
  border-radius: 4px;
  padding: 3px 5px;
  line-height: 1;
}

/* PS2 DualShock 2 Style Touch Controller (Centered Big Directional Pad) */
.ps2-controller {
  display: none;
  width: 100%;
  touch-action: none;
}

.ps2-body {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 16px 12px;
  background: radial-gradient(ellipse at 50% 0%, #2a2e38 0%, #171920 55%, #0f1116 100%);
  border: 2px solid #303543;
  border-radius: 26px;
  box-shadow:
    0 16px 36px rgba(0, 0, 0, 0.72),
    inset 0 2px 1px rgba(255, 255, 255, 0.11),
    inset 0 -4px 10px rgba(0, 0, 0, 0.65);
}

.ps2-dpad-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  padding: 4px;
}

.ps2-dpad-well {
  --key-size: 72px;
  --pivot-size: 46px;
  position: relative;
  display: grid;
  grid-template-columns: var(--key-size) var(--pivot-size) var(--key-size);
  grid-template-rows: var(--key-size) var(--pivot-size) var(--key-size);
  align-items: center;
  justify-items: center;
  padding: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, #0c0e12 0%, #151820 62%, #20242f 100%);
  border: 2px solid #2d3240;
  box-shadow:
    inset 0 8px 20px rgba(0, 0, 0, 0.92),
    inset 0 -2px 6px rgba(255, 255, 255, 0.06),
    0 2px 0 rgba(255, 255, 255, 0.06);
}

.ps2-pivot {
  grid-column: 2;
  grid-row: 2;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #232732 0%, #0d0f14 78%);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

/* Sculpted DualShock 2 Separate Directional Keys */
.ps2-dir {
  position: relative;
  appearance: none;
  border: none;
  background: linear-gradient(160deg, #3b404e 0%, #232731 46%, #14171e 100%);
  cursor: pointer;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 5px 4px rgba(0, 0, 0, 0.78));
  transition: transform 0.06s ease, filter 0.08s ease, background 0.08s ease;
}

.ps2-dir::before {
  content: "";
  position: absolute;
  inset: 2px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0.02) 45%, rgba(0, 0, 0, 0.35) 100%);
  clip-path: inherit;
  pointer-events: none;
}

/* Iconic PS2 pointed directional button shapes */
.ps2-up {
  grid-column: 2;
  grid-row: 1;
  width: calc(var(--key-size) - 6px);
  height: calc(var(--key-size) + 8px);
  align-self: end;
  border-radius: 12px 12px 0 0;
  clip-path: polygon(10% 0%, 90% 0%, 100% 10%, 100% 66%, 50% 100%, 0% 66%, 0% 10%);
  padding-bottom: 14px;
}

.ps2-down {
  grid-column: 2;
  grid-row: 3;
  width: calc(var(--key-size) - 6px);
  height: calc(var(--key-size) + 8px);
  align-self: start;
  border-radius: 0 0 12px 12px;
  clip-path: polygon(50% 0%, 100% 34%, 100% 90%, 90% 100%, 10% 100%, 0% 90%, 0% 34%);
  padding-top: 14px;
}

.ps2-left {
  grid-column: 1;
  grid-row: 2;
  width: calc(var(--key-size) + 8px);
  height: calc(var(--key-size) - 6px);
  justify-self: end;
  border-radius: 12px 0 0 12px;
  clip-path: polygon(10% 0%, 66% 0%, 100% 50%, 66% 100%, 10% 100%, 0% 90%, 0% 10%);
  padding-right: 14px;
}

.ps2-right {
  grid-column: 3;
  grid-row: 2;
  width: calc(var(--key-size) + 8px);
  height: calc(var(--key-size) - 6px);
  justify-self: start;
  border-radius: 0 12px 12px 0;
  clip-path: polygon(34% 0%, 90% 0%, 100% 10%, 100% 90%, 90% 100%, 34% 100%, 0% 50%);
  padding-left: 14px;
}

/* Engraved PS2 Silver Directional Chevrons */
.ps2-arrow {
  width: 0;
  height: 0;
  position: relative;
  z-index: 1;
  opacity: 0.78;
  transition: opacity 0.08s ease, filter 0.08s ease;
}

.ps2-up .ps2-arrow {
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-bottom: 14px solid #9aa3b8;
}

.ps2-down .ps2-arrow {
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 14px solid #9aa3b8;
}

.ps2-left .ps2-arrow {
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-right: 14px solid #9aa3b8;
}

.ps2-right .ps2-arrow {
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 14px solid #9aa3b8;
}

/* Tactile Pressed State */
.ps2-dir.active,
.ps2-dir:active {
  background: linear-gradient(160deg, #273754 0%, #172033 55%, #0f1522 100%);
  transform: scale(0.95) translateY(2px);
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.9)) drop-shadow(0 0 10px rgba(78, 161, 255, 0.45));
}

.ps2-dir.active .ps2-arrow,
.ps2-dir:active .ps2-arrow {
  opacity: 1;
  filter: drop-shadow(0 0 6px rgba(78, 161, 255, 0.95));
}

.ps2-up.active .ps2-arrow,
.ps2-up:active .ps2-arrow {
  border-bottom-color: var(--ps2-blue);
}

.ps2-down.active .ps2-arrow,
.ps2-down:active .ps2-arrow {
  border-top-color: var(--ps2-blue);
}

.ps2-left.active .ps2-arrow,
.ps2-left:active .ps2-arrow {
  border-right-color: var(--ps2-blue);
}

.ps2-right.active .ps2-arrow,
.ps2-right:active .ps2-arrow {
  border-left-color: var(--ps2-blue);
}

/* PS2 Select / Analog LED / Start Strip */
.ps2-meta-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.ps2-select-btn,
.ps2-start-btn {
  appearance: none;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  touch-action: none;
  padding: 2px 4px;
}

.ps2-select-cap {
  width: 34px;
  height: 14px;
  border-radius: 3px;
  background: linear-gradient(180deg, #3c4252 0%, #20242e 100%);
  border: 1px solid #4c5366;
  box-shadow: 0 2px 0 #0a0b0f, inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.ps2-start-cap {
  width: 34px;
  height: 14px;
  background: linear-gradient(180deg, #3c4252 0%, #20242e 100%);
  clip-path: polygon(0% 0%, 100% 50%, 0% 100%);
  filter: drop-shadow(0 2px 1px #0a0b0f);
}

.ps2-meta-label {
  font-size: 6px;
  color: #7d869c;
  letter-spacing: 0.06em;
}

.ps2-analog-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e52521;
  box-shadow: 0 0 8px rgba(229, 37, 33, 0.85), inset 0 1px 2px rgba(255, 190, 190, 0.6);
}

.ps2-select-btn.active .ps2-select-cap,
.ps2-select-btn:active .ps2-select-cap,
.ps2-start-btn.active .ps2-start-cap,
.ps2-start-btn:active .ps2-start-cap {
  transform: scale(0.92);
  filter: brightness(1.3);
}

/* Fullscreen Mode */
.crt-cabinet:fullscreen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #050609;
  border: none;
  border-radius: 0;
  padding: 12px;
}

.crt-cabinet:fullscreen .crt-bezel,
.crt-cabinet:fullscreen .bezel-bar {
  width: min(96vw, calc((100vh - 76px) * (512 / 480)));
}

/* Mobile & Touch Portrait Mode */
@media (max-width: 820px), (hover: none) and (pointer: coarse) {
  body {
    padding:
      max(6px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
    align-items: stretch;
  }

  .console-shell {
    width: min(100%, 540px);
    height: 100%;
    margin: 0 auto;
    justify-content: space-between;
    gap: 8px;
  }

  .crt-cabinet {
    padding: 8px 8px 6px;
    border-radius: 14px;
    flex-shrink: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .crt-bezel {
    padding: 5px;
    border-radius: 10px;
    width: min(100%, calc((100dvh - 305px) * (512 / 480)));
  }

  .bezel-bar {
    width: 100%;
    padding: 7px 2px 1px;
    gap: 6px;
  }

  .brand-name {
    font-size: 8px;
  }

  .brand-model {
    display: none;
  }

  .bezel-btn {
    font-size: 7px;
    padding: 6px 8px;
    min-height: 28px;
  }

  .controls-strip {
    display: none;
  }

  .ps2-controller {
    display: block;
    flex-shrink: 0;
  }
}

/* Compact Portrait Phones */
@media (max-width: 430px) and (orientation: portrait) {
  .brand-name {
    display: none;
  }

  .crt-bezel {
    width: min(100%, calc((100dvh - 285px) * (512 / 480)));
  }

  .ps2-body {
    padding: 10px 12px 10px;
    gap: 10px;
    border-radius: 22px;
  }

  .ps2-dpad-well {
    --key-size: 66px;
    --pivot-size: 40px;
    padding: 12px;
  }
}

/* Short Portrait Phones */
@media (max-height: 680px) and (orientation: portrait) {
  .crt-bezel {
    width: min(100%, calc((100dvh - 255px) * (512 / 480)));
  }

  .ps2-dpad-well {
    --key-size: 58px;
    --pivot-size: 36px;
    padding: 10px;
  }
}

/* Landscape Mobile Layout (Screen + Big PS2 D-Pad Side-by-Side) */
@media (max-height: 540px) and (orientation: landscape) {
  body {
    padding:
      max(4px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(4px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
    align-items: center;
  }

  .console-shell {
    width: 100%;
    max-width: none;
    height: 100%;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 14px;
  }

  .crt-cabinet {
    width: auto;
    height: 100%;
    padding: 6px 8px 4px;
    border-radius: 12px;
    justify-content: center;
  }

  .crt-bezel {
    width: min(56vw, calc((100dvh - 54px) * (512 / 480)));
    padding: 4px;
  }

  .bezel-bar {
    width: min(56vw, calc((100dvh - 54px) * (512 / 480)));
    padding: 5px 2px 0;
  }

  .brand-name,
  .brand-model {
    display: none;
  }

  .bezel-btn {
    font-size: 7px;
    padding: 4px 7px;
    min-height: 24px;
  }

  .controls-strip {
    display: none;
  }

  .ps2-controller {
    display: block;
    width: auto;
    flex-shrink: 0;
  }

  .ps2-body {
    padding: 12px 14px 10px;
    gap: 10px;
    border-radius: 22px;
  }

  .ps2-dpad-well {
    --key-size: 62px;
    --pivot-size: 38px;
    padding: 12px;
  }
}
