/* Starbase Defense — responsive shell (mobile → desktop) */
:root {
  --lcars-orange: #ff9900;
  --lcars-mint: #99ffcc;
  --lcars-sky: #99ccff;
  --panel: #121018;
  --ink: #f2efe8;
  --muted: #b89a6a;
  --danger: #ff8866;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --hud-fs: clamp(0.58rem, 2.4vw, 0.72rem);
  --hud-num: clamp(0.85rem, 3.2vw, 1.05rem);
  --ui-pad: clamp(0.35rem, 1.5vw, 0.65rem);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: #050508;
  color: var(--ink);
  font-family: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

.bridge-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: calc(var(--ui-pad) + var(--safe-top)) var(--ui-pad) calc(0.75rem + var(--safe-bottom));
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.lcars-top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.lcars-bar {
  flex: 1 1 12rem;
  background: linear-gradient(90deg, #ff9900, #ffcc66, #cc99ff);
  border-radius: 0 999px 999px 0;
  padding: 0.45rem 0.85rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #000;
  font-size: clamp(0.7rem, 2.5vw, 0.85rem);
}
.lcars-bar a {
  color: #111;
  margin-left: 0.55rem;
  font-size: 0.85em;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.lcars-pill {
  border: 2px solid var(--lcars-orange);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: clamp(0.6rem, 2.2vw, 0.72rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--lcars-mint);
  font-weight: 700;
}
.lcars-pill.warn { color: var(--danger); border-color: #ff6644; }

.tactical-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #0a0a10;
  border: 2px solid #333;
  border-radius: 0.55rem;
  overflow: hidden;
  min-height: 0;
}

/* HUD: readable denser grid */
.mp-hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem 0.4rem;
  padding: var(--ui-pad);
  background: #121018;
  border-bottom: 3px solid var(--lcars-orange);
  font-size: var(--hud-fs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
@media (min-width: 520px) {
  .mp-hud { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
@media (min-width: 900px) {
  .mp-hud { grid-template-columns: repeat(8, minmax(0, 1fr)); font-size: 0.68rem; }
}
.mp-hud strong {
  display: block;
  color: var(--lcars-mint);
  font-size: var(--hud-num);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.mp-hud .label {
  color: var(--muted);
  font-size: 0.9em;
  font-weight: 600;
}
.meter-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}
.track {
  height: 0.5rem;
  background: #222;
  border-radius: 99px;
  overflow: hidden;
}
.track > i { display: block; height: 100%; width: 100%; transition: width 0.12s; }
.track.hull > i { background: linear-gradient(90deg, #ff4466, #ff9900); }
.track.shield > i { background: linear-gradient(90deg, #4488ff, #99ccff, #99ffcc); }

/* Stage: fill remaining viewport responsively */
.mp-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: min(48vh, 420px);
  max-height: none;
  height: clamp(280px, 58dvh, 720px);
  background: #05060c;
  isolation: isolate;
}
@media (orientation: landscape) and (max-height: 500px) {
  .mp-stage { height: clamp(200px, 70dvh, 480px); min-height: 200px; }
  .mp-hud { padding: 0.3rem 0.4rem; gap: 0.25rem; }
  .bridge-shell { padding-bottom: 0.35rem; }
}
#c {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  background: #05060c;
}

.combo-pop {
  position: absolute;
  left: 50%;
  top: 10%;
  transform: translateX(-50%);
  font-weight: 800;
  font-size: clamp(1rem, 4vw, 1.35rem);
  color: #ffcc66;
  text-shadow: 0 0 12px rgba(255, 204, 102, 0.9);
  pointer-events: none;
  opacity: 0;
  z-index: 5;
  letter-spacing: 0.06em;
  transition: opacity 0.15s;
}
.combo-pop.show { opacity: 1; }

.turn-banner {
  position: absolute;
  left: 50%;
  bottom: 0.6rem;
  transform: translateX(-50%);
  z-index: 6;
  background: rgba(10, 12, 20, 0.88);
  border: 2px solid var(--lcars-sky);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: clamp(0.7rem, 2.5vw, 0.85rem);
  font-weight: 700;
  color: var(--lcars-mint);
  pointer-events: none;
  max-width: 92%;
  text-align: center;
}
.turn-banner.yours { border-color: var(--lcars-orange); color: #ffcc66; }

.overlay-msg, .intermission, .board-panel, .mission-panel, .mp-lobby {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.82);
  z-index: 8;
  padding: max(0.5rem, var(--ui-pad));
  text-align: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.overlay-msg[hidden], .intermission[hidden], .board-panel[hidden],
.mission-panel[hidden], .mp-lobby[hidden] {
  display: none !important;
}

.panel-card {
  background: var(--panel);
  border: 2px solid var(--lcars-orange);
  border-radius: 0.65rem;
  padding: clamp(0.75rem, 3vw, 1.15rem);
  width: min(28rem, 100%);
  max-height: min(90dvh, 640px);
  overflow-y: auto;
  text-align: left;
}
.panel-card h2 {
  margin: 0 0 0.45rem;
  font-size: clamp(1.05rem, 4vw, 1.35rem);
  color: #ffcc66;
  letter-spacing: 0.04em;
}
.panel-card p {
  margin: 0 0 0.75rem;
  font-size: clamp(0.85rem, 2.8vw, 0.95rem);
  line-height: 1.45;
  color: #ddd6c8;
}
.panel-card b { color: #ffcc66; }

.name-row input, .field input, .field select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 0.4rem;
  border: 2px solid #444;
  background: #0a0a10;
  color: var(--ink);
  font-size: 1rem; /* iOS zoom avoid */
  margin-bottom: 0.55rem;
}
.field label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.2rem;
  font-weight: 700;
}

.btn-row, .shop-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.35rem;
}
.btn {
  appearance: none;
  border: 2px solid var(--lcars-orange);
  background: linear-gradient(180deg, #ffb84d, #ff9900);
  color: #111;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.55rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: clamp(0.72rem, 2.5vw, 0.82rem);
  min-height: 2.5rem;
  flex: 1 1 auto;
}
.btn:active { transform: scale(0.98); }
.btn.ghost {
  background: transparent;
  color: #ffcc66;
}
.btn.mint {
  border-color: var(--lcars-mint);
  background: linear-gradient(180deg, #c8ffe8, #99ffcc);
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.cost {
  display: block;
  font-size: 0.72em;
  font-weight: 600;
  opacity: 0.85;
  text-transform: none;
  letter-spacing: 0;
}

.mp-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: var(--ui-pad);
  background: #0e0e14;
  border-top: 1px solid #333;
}
.mp-controls .btn { min-width: 5.5rem; flex: 1 1 30%; }

.how-foot {
  text-align: center;
  color: var(--muted);
  font-size: clamp(0.68rem, 2.2vw, 0.78rem);
  line-height: 1.4;
  margin: 0.2rem 0.15rem 0;
}
.how-foot b { color: var(--lcars-mint); }

.mission-list { list-style: none; padding: 0; margin: 0 0 0.75rem; }
.mission-list li {
  border: 1px solid #333;
  border-radius: 0.45rem;
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.4rem;
  cursor: pointer;
  background: #0a0a12;
}
.mission-list li.selected {
  border-color: var(--lcars-orange);
  background: #1a1410;
}
.mission-list li strong {
  display: block;
  color: #ffcc66;
  font-size: 0.95rem;
}
.mission-list li span {
  font-size: 0.82rem;
  color: #c9c2b4;
  line-height: 1.35;
}

.lb-list { list-style: none; padding: 0; margin: 0 0 0.75rem; }
.lb-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid #2a2a32;
  font-size: 0.88rem;
}
.lb-list .rank { color: var(--lcars-sky); font-weight: 700; }

.player-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem;
}
.player-list li {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid #2a2a32;
  font-size: 0.9rem;
}
.player-list .ready { color: var(--lcars-mint); }
.player-list .wait { color: var(--muted); }

.room-code {
  font-size: clamp(1.4rem, 6vw, 1.9rem);
  letter-spacing: 0.2em;
  font-weight: 800;
  color: #ffcc66;
  text-align: center;
  margin: 0.35rem 0 0.75rem;
}

.log-line {
  font-size: 0.78rem;
  color: #a8b0c0;
  max-height: 5rem;
  overflow-y: auto;
  margin-bottom: 0.5rem;
  font-family: ui-monospace, Consolas, monospace;
}

/* Ambient splash behind UI only */
.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: #000 url("../assets/intro-frame.jpg") center/cover no-repeat;
  opacity: 0;
  transition: opacity 1.2s ease;
}
.ambient-bg.on { opacity: 0.28; }
.bridge-shell { position: relative; z-index: 1; }

.intro-load {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 1s ease, visibility 1s;
  padding: var(--ui-pad);
}
.intro-load.done { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-load video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.9;
}
@media (max-width: 700px), (prefers-reduced-motion: reduce) {
  .intro-load video { display: none; }
  .intro-load { background: #000 url("../assets/intro-frame.jpg") center/cover no-repeat; }
}
.intro-ui { position: relative; z-index: 2; text-align: center; }
.intro-ui h1 {
  margin: 0 0 0.35rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ffcc66;
  font-size: clamp(1.35rem, 6vw, 2.1rem);
}
.intro-bar {
  width: min(260px, 70vw);
  height: 0.4rem;
  background: #222;
  border-radius: 99px;
  overflow: hidden;
  margin: 0.6rem auto;
}
.intro-bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #ff9900, #99ffcc);
}
.intro-status {
  color: #99ffcc;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.intro-skip {
  margin-top: 0.9rem;
  background: transparent;
  border: 2px solid #ff9900;
  color: #ffcc66;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.8rem;
}

.toast {
  position: fixed;
  bottom: calc(1rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: #1a1520;
  border: 2px solid var(--lcars-orange);
  color: #ffcc66;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}
.toast[hidden] { display: none !important; }

/* High contrast / large type preference */
@media (prefers-contrast: more) {
  .mp-hud strong { color: #fff; }
  .panel-card { border-width: 3px; }
  .btn { border-width: 3px; }
}
