/* DERELICT SHIP co-op — grim low-fi sci-fi lobby + game chrome
   Evidence: quasi-corridors--hud-region.png (thin green-outlined dark panels),
   quasi-materials.png (rust + gunmetal, warm light pools on near-black) */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --amber: #e8b44d;
  --o2green: #9adc50;
  --green: #52c46a;
  --red: #d84848;
  --rust: #8a5a3c;
  --bg-deep: #050508;
  --bg-panel: rgba(12, 12, 18, 0.94);
  --line: #26262e;
  --line-hi: #44444e;
  --dim: #8a8a96;
  --p1: #4aa3ff;
  --p2: #ff9f43;
  --p3: #5cd65c;
  --p4: #e056fd;
}

html, body {
  width: 100%; height: 100%;
  background: radial-gradient(ellipse at center, #0c0c14 0%, var(--bg-deep) 75%);
  color: #d2d2da;
  font-family: "Courier New", monospace;
  overflow: hidden;
}

#app { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }

/* ── Lobby ─────────────────────────────────────────────────────────────── */
#lobby-screen {
  width: min(560px, 94vw);
  max-height: 96vh;
  overflow-y: auto;
  padding: 0 30px 26px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  box-shadow: 0 0 40px rgba(232, 180, 77, 0.08), inset 0 0 60px rgba(0,0,0,0.6);
}

/* hero strip: derelict hull silhouette against deep space, warm porthole lights */
#lobby-hero {
  height: 64px;
  margin: 0 -30px 14px;
  background:
    radial-gradient(circle at 20% 30%, rgba(255,233,176,0.25) 0 2px, transparent 3px),
    radial-gradient(circle at 34% 55%, rgba(255,233,176,0.2) 0 2px, transparent 3px),
    radial-gradient(circle at 62% 40%, rgba(216,72,72,0.35) 0 2px, transparent 3px),
    radial-gradient(circle at 78% 62%, rgba(255,233,176,0.18) 0 2px, transparent 3px),
    linear-gradient(180deg, rgba(0,0,0,0) 40%, #050508 100%),
    linear-gradient(160deg, #10101c 0%, #1c1826 45%, #241c1c 75%, #14100e 100%);
  border-bottom: 2px solid #000;
  position: relative;
}
#lobby-hero::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0; height: 22px;
  background: repeating-linear-gradient(90deg,
    #030305 0 34px, transparent 34px 40px, #030305 40px 74px, transparent 74px 82px);
}

#lobby-title {
  font-size: 44px;
  font-weight: bold;
  letter-spacing: 6px;
  color: var(--amber);
  text-shadow: 3px 3px 0 #000, 0 0 22px rgba(232, 180, 77, 0.35);
}
#lobby-title span { color: #f0d88a; }

#lobby-subtitle { margin: 6px 0 16px; font-size: 12px; color: var(--dim); letter-spacing: 1px; }

#connection-status { font-size: 12px; margin-bottom: 12px; }
#connection-status.connected { color: var(--green); }
#connection-status.disconnected { color: var(--red); }

.lobby-section { margin-bottom: 16px; }
.lobby-section-title {
  font-size: 11px; letter-spacing: 3px; color: var(--o2green);
  text-transform: uppercase; margin-bottom: 7px;
}

.btn-row { display: flex; gap: 8px; }

input#room-code-input {
  flex: 0 0 110px;
  background: #0c0c14; border: 1px solid var(--line-hi); color: var(--amber);
  font-family: inherit; font-size: 18px; font-weight: bold; letter-spacing: 3px;
  padding: 8px 10px; text-transform: uppercase; text-align: center;
}

button {
  background: #16161e; border: 1px solid var(--line-hi); color: #d2d2da;
  font-family: inherit; font-size: 13px; padding: 9px 14px; cursor: pointer;
  letter-spacing: 1px;
}
button:hover:not(:disabled) { background: #22222e; border-color: var(--amber); }
button:disabled { opacity: 0.45; cursor: default; }

.player-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.player-slot {
  padding: 9px 12px; background: #0c0c14; border: 1px solid var(--line);
  min-height: 52px;
}
.player-slot.occupied { border-color: var(--line-hi); }
.player-slot.ready { border-color: var(--green); box-shadow: 0 0 10px rgba(82,196,106,.3); }
.slot-label { font-size: 12px; font-weight: bold; letter-spacing: 1px; }
.slot-label.p1 { color: var(--p1); }
.slot-label.p2 { color: var(--p2); }
.slot-label.p3 { color: var(--p3); }
.slot-label.p4 { color: var(--p4); }
.slot-status { font-size: 11px; color: var(--dim); margin-top: 4px; }

.btn-ready {
  width: 100%; font-size: 20px; font-weight: bold;
  letter-spacing: 5px; padding: 13px;
  background: linear-gradient(180deg, #3a2c14, #201808);
  border: 1px solid var(--amber);
  text-shadow: 0 0 8px var(--amber);
}
.btn-ready.is-ready { background: linear-gradient(180deg, #24401e, #122411); border-color: var(--green); text-shadow: 0 0 8px var(--green); }

#lobby-status-text { font-size: 12px; color: var(--dim); min-height: 16px; }
#lobby-help { font-size: 11px; color: #74747e; line-height: 1.7; border-top: 1px solid var(--line); padding-top: 10px; }
#lobby-help b { color: var(--red); }

/* ── Game ──────────────────────────────────────────────────────────────── */
#game-wrapper { display: none; position: relative; width: 100%; height: 100%; align-items: center; justify-content: center; }
#game-wrapper.active { display: flex; }
#lobby-screen.hidden { display: none; }

canvas#game-canvas {
  max-width: 100vw; max-height: 100vh;
  aspect-ratio: 16 / 9;
  width: 100%;
  object-fit: contain;
  background: #000;
  cursor: crosshair;
  image-rendering: pixelated;
}

#countdown-overlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center; pointer-events: none;
}
#countdown-overlay.active { display: flex; }
#countdown-number {
  font-size: 120px; font-weight: bold; color: var(--amber);
  text-shadow: 5px 5px 0 #000, 0 0 40px var(--amber);
}

#disconnected-overlay {
  position: absolute; inset: 0; display: none; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  background: rgba(4, 4, 8, 0.9); z-index: 30;
}
#disconnected-overlay.active { display: flex; }
#dc-title { color: var(--red); letter-spacing: 4px; }
#dc-message { color: var(--dim); font-size: 13px; }

#mute-btn, #fullscreen-btn {
  position: absolute; bottom: 10px; z-index: 20;
  width: 40px; height: 40px; padding: 0; font-size: 18px;
  background: rgba(12, 12, 18, 0.6); border: 1px solid var(--line-hi);
}
#mute-btn { right: 10px; }
#fullscreen-btn { right: 58px; }

/* ── Rotate hint (portrait phones) ─────────────────────────────────────── */
#rotate-hint {
  display: none; position: absolute; inset: 0; z-index: 40;
  align-items: center; justify-content: center;
  background: rgba(4, 4, 8, 0.92); color: var(--amber);
  font-size: 20px; letter-spacing: 2px; text-align: center; padding: 20px;
}
@media (orientation: portrait) {
  body.touch #rotate-hint { display: flex; }
}

/* ── Touch UI ──────────────────────────────────────────────────────────── */
#touch-ui { display: none; }
body.touch #touch-ui { display: block; }
#joy-left, #joy-right {
  position: absolute; bottom: 0; width: 42%; height: 55%; z-index: 15;
}
#joy-left { left: 0; }
#joy-right { right: 0; }
#touch-buttons {
  position: absolute; right: 12px; top: 12%;
  display: flex; flex-direction: column; gap: 10px; z-index: 16;
}
.tbtn {
  width: 64px; height: 44px; font-size: 11px; font-weight: bold;
  background: rgba(12, 12, 18, 0.45); border: 1px solid rgba(232, 180, 77, 0.75);
  color: var(--amber); border-radius: 6px;
}
.tbtn:active { background: rgba(232, 180, 77, 0.35); }

/* on-canvas thumb hint zones for first-time mobile players (fade after ~9s) */
.joy-hint {
  display: none; position: absolute; bottom: 16%; width: 86px; height: 86px;
  border: 2px dashed rgba(255, 255, 255, 0.35); border-radius: 50%;
  color: rgba(255, 255, 255, 0.55); font-size: 10px; letter-spacing: 2px;
  align-items: center; justify-content: center; text-align: center;
  pointer-events: none; z-index: 14;
}
body.touch .joy-hint { display: flex; animation: hintFade 1.2s ease 9s forwards; }
#joy-hint-left { left: 10%; }
#joy-hint-right { right: 10%; }
@keyframes hintFade { to { opacity: 0; } }

body.touch #mute-btn { right: 112px; }
body.touch #fullscreen-btn { right: 160px; }
