/* DEEP HORIZON '94 — 90s 16-Bit Arcade, CRT & Responsive Smartphone Gamepad Styling */

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

:root {
  --bg-deep: #050a14;
  --bezel-dark: #141c2b;
  --bezel-mid: #222f46;
  --bezel-light: #394d6e;
  --accent-cyan: #2cf5e8;
  --accent-amber: #ffb830;
  --accent-red: #ff3c5a;
  --text-main: #d9ecff;
}

html, body {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 30%, #0d1d35 0%, #050a14 75%);
  color: var(--text-main);
  font-family: 'Courier New', Courier, monospace;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
}

#cabinet {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: min(99vw, 1180px);
  height: min(99vh, 740px);
  height: min(99dvh, 740px);
  gap: 6px;
  padding: 6px;
}

#marquee {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  background: linear-gradient(180deg, #1d2b44 0%, #101829 100%);
  border: 2px solid var(--bezel-light);
  border-radius: 6px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 4px 16px rgba(0, 0, 0, 0.6);
  flex-shrink: 0;
  z-index: 20;
}

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

.badge {
  background: linear-gradient(180deg, #ff5f2e 0%, #c92045 100%);
  color: #fff;
  font-weight: 900;
  font-size: 11px;
  letter-spacing: 1px;
  padding: 3px 6px;
  border: 1px solid #ffae88;
  border-radius: 3px;
  text-shadow: 1px 1px 0 #4d0014;
  flex-shrink: 0;
}

#marquee h1 {
  font-size: clamp(12px, 2vw, 20px);
  letter-spacing: 2px;
  color: #e4f7ff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 0 8px rgba(44, 245, 232, 0.45), 2px 2px 0 #071222;
}

#marquee h1 .accent {
  color: var(--accent-amber);
  text-shadow: 0 0 8px rgba(255, 184, 48, 0.5), 2px 2px 0 #2b1400;
}

.marquee-controls {
  display: flex;
  gap: 5px;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.retro-btn {
  font-family: 'Courier New', Courier, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: #9ec0df;
  background: #0d1626;
  border: 2px solid #304566;
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, color 0.15s ease;
}

.retro-btn:hover {
  border-color: var(--accent-cyan);
  color: #ffffff;
}

.retro-btn:active {
  transform: translateY(1px);
}

.retro-btn.active {
  color: #06181f;
  background: linear-gradient(180deg, #4afff2 0%, #16b5bc 100%);
  border-color: #a8fff9;
  box-shadow: 0 0 8px rgba(44, 245, 232, 0.4);
}

#screen-bezel {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #24324a 0%, #101724 55%, #1c273b 100%);
  border: 3px solid #3c5275;
  border-radius: 12px;
  padding: 8px;
  box-shadow:
    inset 0 2px 8px rgba(0, 0, 0, 0.8),
    0 12px 32px rgba(0, 0, 0, 0.75);
}

#screen-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: calc((100vh - 130px) * 16 / 9);
  aspect-ratio: 16 / 9;
  background: #000814;
  border: 3px solid #070d17;
  border-radius: 8px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(100, 180, 255, 0.15),
    0 0 28px rgba(18, 160, 200, 0.22);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  outline: none;
}

#crt-overlay {
  pointer-events: none;
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.2s ease;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.26) 0px,
      rgba(0, 0, 0, 0.26) 1px,
      transparent 1px,
      transparent 3px
    ),
    radial-gradient(
      ellipse at center,
      rgba(255, 255, 255, 0.02) 55%,
      rgba(0, 0, 0, 0.42) 100%
    );
}

#screen-wrapper.crt-on #crt-overlay {
  opacity: 1;
}

/* ---------- Touch / Smartphone Compact 90s Handheld Deck ---------- */
#touch-controls {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, #162238 0%, #0b1220 100%);
  border: 2px solid #2e4366;
  border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
  touch-action: none;
  flex-shrink: 0;
  gap: 8px;
}

body.touch-mode #touch-controls {
  display: flex;
}

body.touch-mode #control-strip {
  display: none;
}

body.touch-mode #screen-wrapper {
  max-width: 100%;
  height: auto;
  max-height: 100%;
}

.touch-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.joystick-base {
  position: relative;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #101b30 0%, #070d18 75%);
  border: 2px solid #355078;
  box-shadow:
    inset 0 3px 10px rgba(0, 0, 0, 0.8),
    0 0 12px rgba(44, 245, 232, 0.12);
  touch-action: none;
}

.joystick-ring {
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  border: 1px dashed rgba(68, 224, 255, 0.28);
  pointer-events: none;
}

.joystick-cross {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.joystick-cross::before,
.joystick-cross::after {
  content: '';
  position: absolute;
  background: rgba(95, 165, 220, 0.2);
}

.joystick-cross::before {
  left: 50%;
  top: 16%;
  width: 2px;
  height: 68%;
  transform: translateX(-50%);
}

.joystick-cross::after {
  top: 50%;
  left: 16%;
  height: 2px;
  width: 68%;
  transform: translateY(-50%);
}

.joy-arrow {
  position: absolute;
  font-size: 8px;
  color: rgba(120, 225, 255, 0.55);
  pointer-events: none;
  line-height: 1;
}
.joy-up { top: 4px; left: 50%; transform: translateX(-50%); }
.joy-down { bottom: 4px; left: 50%; transform: translateX(-50%); }
.joy-left { left: 5px; top: 50%; transform: translateY(-50%); }
.joy-right { right: 5px; top: 50%; transform: translateY(-50%); }

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 34px;
  margin-left: -17px;
  margin-top: -17px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #7afff6 0%, #19a8bf 55%, #0c4d6b 100%);
  border: 2px solid #c2ffff;
  box-shadow:
    0 3px 8px rgba(0, 0, 0, 0.65),
    0 0 10px rgba(44, 245, 232, 0.45);
  pointer-events: none;
  transform: translate3d(0, 0, 0);
  transition: box-shadow 0.1s ease;
}

.joystick-base.active .joystick-knob {
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.7),
    0 0 16px rgba(74, 255, 242, 0.85);
}

.touch-caption {
  display: none;
}

.touch-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tbtn {
  font-family: 'Courier New', Courier, monospace;
  font-weight: 900;
  letter-spacing: 0.5px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  color: #ffffff;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.65);
  cursor: pointer;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 3px 0 rgba(0, 0, 0, 0.55),
    inset 0 2px 3px rgba(255, 255, 255, 0.25);
  transition: transform 0.06s ease, filter 0.08s ease;
}

.tbtn.pressed,
.tbtn:active {
  transform: translateY(2px) scale(0.94);
  filter: brightness(1.22);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
}

.tbtn-torp {
  width: 54px;
  height: 54px;
  font-size: 9px;
  background: radial-gradient(circle at 35% 28%, #ff7a59 0%, #e02847 62%, #8a0f26 100%);
  border-color: #ffb8a8;
}

.tbtn-bomb {
  width: 44px;
  height: 44px;
  font-size: 8px;
  background: radial-gradient(circle at 35% 28%, #ffd766 0%, #d98218 65%, #7d4108 100%);
  border-color: #ffea9e;
}

.tbtn-sonar {
  width: 48px;
  height: 24px;
  border-radius: 12px;
  font-size: 8px;
  background: linear-gradient(180deg, #3bf5d8 0%, #108a80 100%);
  color: #041d1c;
  text-shadow: none;
  border-color: #a8fff0;
}

.tbtn-light {
  width: 46px;
  height: 24px;
  border-radius: 12px;
  font-size: 8px;
  background: linear-gradient(180deg, #2d3e5c 0%, #172236 100%);
  color: #9ec0df;
  border-color: #4f6c99;
}

.tbtn-light.active {
  background: linear-gradient(180deg, #fff099 0%, #d4a62a 100%);
  color: #211603;
  text-shadow: none;
  border-color: #fff8cc;
}

/* Desktop keyboard strip */
#control-strip {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 6px 12px;
  background: rgba(11, 18, 32, 0.88);
  border: 1px solid #263854;
  border-radius: 6px;
  font-size: 11px;
  color: #8cb2d8;
  flex-shrink: 0;
}

.key-hint {
  display: flex;
  align-items: center;
  gap: 4px;
}

kbd {
  display: inline-block;
  padding: 2px 5px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 10px;
  font-weight: 700;
  color: #fff4d2;
  background: #1a2740;
  border: 1px solid #496694;
  border-bottom-width: 2px;
  border-radius: 3px;
}

/* ---------- Portrait Smartphone Layout ---------- */
@media (max-width: 720px) {
  #cabinet {
    width: 100vw;
    height: 100dvh;
    max-height: none;
    padding: 3px;
    gap: 4px;
    justify-content: flex-start;
  }

  #marquee {
    padding: 3px 6px;
  }

  .badge {
    display: none;
  }

  #marquee h1 {
    font-size: 12px;
    letter-spacing: 1px;
  }

  .retro-btn {
    font-size: 8px;
    padding: 3px 5px;
  }

  #screen-bezel {
    flex: 1 1 auto;
    padding: 4px;
    border-radius: 8px;
  }

  #screen-wrapper {
    width: 100%;
    height: auto;
    max-width: 100%;
    aspect-ratio: 16 / 9;
  }

  body.touch-mode #touch-controls {
    flex: 0 0 auto;
    align-items: center;
    padding: 6px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  }
}

/* ---------- Landscape Smartphone Overlay Layout ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  body.touch-mode #cabinet {
    width: 100vw;
    height: 100dvh;
    max-height: none;
    padding: 2px;
    gap: 2px;
  }

  body.touch-mode #marquee {
    padding: 2px 8px;
  }

  body.touch-mode #marquee h1 {
    font-size: 11px;
  }

  body.touch-mode .retro-btn {
    font-size: 8px;
    padding: 2px 5px;
  }

  body.touch-mode #screen-bezel {
    flex: 1;
    padding: 2px;
    border-width: 2px;
  }

  body.touch-mode #screen-wrapper {
    height: 100%;
    width: auto;
    max-width: 100%;
    aspect-ratio: 16 / 9;
  }

  /* Float compact semi-transparent controls over the lower corners in landscape */
  body.touch-mode #touch-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 2px;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0 10px 4px;
    pointer-events: none;
    z-index: 30;
  }

  body.touch-mode .touch-left,
  body.touch-mode .touch-right {
    pointer-events: auto;
    opacity: 0.72;
  }

  body.touch-mode .joystick-base {
    width: 72px;
    height: 72px;
  }

  body.touch-mode .joystick-knob {
    width: 28px;
    height: 28px;
    margin-left: -14px;
    margin-top: -14px;
  }

  body.touch-mode .tbtn-torp {
    width: 46px;
    height: 46px;
    font-size: 8px;
  }

  body.touch-mode .tbtn-bomb {
    width: 38px;
    height: 38px;
    font-size: 7px;
  }

  body.touch-mode .tbtn-sonar,
  body.touch-mode .tbtn-light {
    width: 42px;
    height: 21px;
    font-size: 7px;
  }
}
