:root {
  --bg: #050811;
  --panel: #0C1324;
  --panel-alt: #121C34;
  --amber: #FF9900;
  --peach: #FFCC66;
  --coral: #FF6666;
  --lilac: #CC99CC;
  --blue: #99CCFF;
  --teal: #66CCCC;
  --green: #55EE88;
  --text: #F2E8D5;
  --muted: #8FA3BF;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, sans-serif;
  overflow: hidden;
  user-select: none;
}

button, input { font-family: inherit; }

/* Top LCARS Header Bar */
.lcars-header {
  height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: #070C18;
  border-bottom: 3px solid var(--amber);
}
.lcars-elbow {
  background: var(--amber);
  color: #050811;
  font-weight: 900;
  letter-spacing: 1.5px;
  padding: 6px 18px 6px 14px;
  border-radius: 18px 4px 4px 18px;
  font-size: 0.85rem;
  white-space: nowrap;
}
.lcars-header.red-alert { border-bottom-color: var(--coral); animation: redPulse 1s infinite alternate; }
.lcars-header.red-alert .lcars-elbow { background: var(--coral); }
@keyframes redPulse { from { box-shadow: inset 0 0 0 rgba(255,60,60,0); } to { box-shadow: inset 0 -12px 24px rgba(255,60,60,0.3); } }

.header-pills { display: flex; align-items: center; gap: 8px; flex: 1; overflow-x: auto; }
.pill {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  background: var(--panel-alt);
  color: var(--peach);
  border: 1px solid rgba(255, 153, 0, 0.4);
  white-space: nowrap;
}
.pill.ok { border-color: var(--green); color: var(--green); }
.pill.bad { border-color: var(--coral); color: var(--coral); }

.btn {
  background: var(--amber);
  color: #070B14;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 800;
  font-size: 0.76rem;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.06s, filter 0.12s;
}
.btn:hover:not(:disabled) { filter: brightness(1.14); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.blue { background: var(--blue); }
.btn.lilac { background: var(--lilac); }
.btn.coral { background: var(--coral); }
.btn.teal { background: var(--teal); }
.btn.ghost { background: #182542; color: var(--peach); border: 1px solid var(--amber); }

/* Views */
.view { display: none; height: calc(100vh - 46px); width: 100vw; }
.view.active { display: flex; }

/* LOBBY */
#lobbyView {
  flex-direction: column;
  gap: 14px;
  padding: 16px 20px;
  overflow-y: auto;
}
.lobby-top {
  display: flex; gap: 14px; flex-wrap: wrap; align-items: center; justify-content: space-between;
  background: var(--panel); border-left: 10px solid var(--amber); border-radius: 12px; padding: 12px 16px;
}
.lobby-top input {
  background: #060B16; color: var(--peach); border: 1px solid var(--amber);
  border-radius: 999px; padding: 6px 14px; font-size: 0.85rem; width: 190px;
}
.lobby-cols { display: grid; grid-template-columns: 2fr 1.1fr; gap: 16px; }
@media (max-width: 980px) { .lobby-cols { grid-template-columns: 1fr; } }

.section-card {
  background: var(--panel);
  border-top: 3px solid var(--amber);
  border-radius: 10px;
  padding: 12px 14px;
}
.section-title {
  font-size: 0.82rem; letter-spacing: 1.4px; color: var(--peach);
  text-transform: uppercase; margin-bottom: 10px; font-weight: 800;
}

.roster-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(235px, 1fr)); gap: 10px; }
.crew-card {
  background: var(--panel-alt);
  border: 2px solid #223458;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.12s;
}
.crew-card:hover { border-color: var(--amber); }
.crew-card.mine { border-color: var(--green); background: #102420; }
.crew-card.taken { border-color: var(--coral); opacity: 0.72; }
.crew-card canvas { width: 56px; height: 56px; image-rendering: pixelated; border-radius: 6px; flex-shrink: 0; border: 1px solid #2E4670; }
.crew-meta h4 { font-size: 0.86rem; color: #FFF; }
.crew-meta .st { font-size: 0.7rem; color: var(--blue); text-transform: uppercase; font-weight: 700; }
.crew-meta .passive { font-size: 0.7rem; color: var(--muted); margin-top: 3px; line-height: 1.25; }
.crew-meta .holder { font-size: 0.68rem; margin-top: 4px; color: var(--peach); font-weight: 700; }

.mission-list { display: flex; flex-direction: column; gap: 9px; }
.mission-card {
  background: var(--panel-alt);
  border-left: 6px solid var(--blue);
  border-radius: 8px;
  padding: 10px 12px;
}
.mission-card.done { border-left-color: var(--green); }
.mission-card h4 { font-size: 0.9rem; color: var(--peach); display: flex; justify-content: space-between; align-items: center; }
.mission-card p { font-size: 0.75rem; color: var(--muted); margin: 4px 0 8px; line-height: 1.3; }
.mission-card ul { padding-left: 16px; font-size: 0.72rem; color: var(--text); margin-bottom: 8px; }

/* GAMEPLAY SHELL (BRIDGE + AWAY) */
#gameView {
  display: none;
  grid-template-columns: 270px 1fr 330px;
  gap: 8px;
  padding: 8px;
}
#gameView.active { display: grid; }
@media (max-width: 1120px) {
  #gameView.active { grid-template-columns: 230px 1fr 290px; }
}

.col-panel {
  background: var(--panel);
  border-radius: 10px;
  border-top: 3px solid var(--amber);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.viewport-wrap {
  position: relative;
  background: #04070F;
  border: 2px solid var(--amber);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.canvas-stage { position: relative; flex: 1; min-height: 0; }
.canvas-stage canvas { width: 100%; height: 100%; display: block; }

/* Status Bars */
.bar-row { display: flex; align-items: center; gap: 6px; font-size: 0.72rem; margin-bottom: 4px; }
.bar-row .lbl { width: 66px; color: var(--muted); text-transform: uppercase; font-weight: 700; }
.bar-track { flex: 1; height: 9px; background: #070C18; border-radius: 99px; overflow: hidden; border: 1px solid #233454; }
.bar-fill { height: 100%; background: var(--blue); transition: width 0.1s; }
.bar-val { width: 42px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 0.7rem; }

/* Shield Diamond */
.shield-box {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  text-align: center;
  font-size: 0.7rem;
  background: #081020;
  padding: 6px;
  border-radius: 8px;
}
.sh-cell { background: #111D35; padding: 4px 6px; border-radius: 6px; border: 1px solid #28446E; }
.sh-cell strong { color: var(--blue); display: block; font-size: 0.78rem; }

/* Objectives & Log */
.obj-item { font-size: 0.74rem; padding: 4px 6px; border-left: 3px solid var(--amber); background: #091122; margin-bottom: 4px; border-radius: 4px; }
.obj-item.done { border-left-color: var(--green); color: var(--green); text-decoration: line-through; opacity: 0.8; }

.log-feed {
  flex: 1;
  min-height: 90px;
  background: #060B16;
  border-radius: 6px;
  padding: 6px 8px;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.log-line.alert { color: var(--coral); font-weight: 700; }
.log-line.good { color: var(--green); }
.log-line.hail { color: var(--lilac); font-weight: 700; }
.log-line.ability { color: var(--peach); }
.log-line.warn { color: #FFBB44; }

/* Officer Ability Cards */
.my-officer {
  display: flex; gap: 8px; align-items: center;
  background: var(--panel-alt); border: 1px solid #2E4670; border-radius: 8px; padding: 6px;
  margin-bottom: 6px;
}
.my-officer canvas { width: 40px; height: 40px; image-rendering: pixelated; border-radius: 5px; }
.my-officer .info { flex: 1; min-width: 0; }
.my-officer .info b { font-size: 0.76rem; color: var(--peach); display: block; }
.my-officer .btns { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.my-officer .btns .btn { padding: 4px 8px; font-size: 0.66rem; }

/* Station Tabs on Right Console */
.station-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab-btn {
  flex: 1 1 30%;
  background: #14203B;
  color: var(--muted);
  border: 1px solid #283E6B;
  border-radius: 6px;
  padding: 5px 6px;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
}
.tab-btn.active { background: var(--amber); color: #050811; border-color: var(--amber); }
.tab-btn.mine { box-shadow: inset 0 -2px 0 var(--green); }

.station-pane { display: none; flex-direction: column; gap: 9px; }
.station-pane.active { display: flex; }

.ctrl-group { background: #081020; border: 1px solid #1E3156; border-radius: 8px; padding: 8px; }
.ctrl-group h5 { font-size: 0.7rem; color: var(--peach); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }
.ctrl-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
input[type="range"] { width: 100%; accent-color: var(--amber); cursor: pointer; }

/* Power Triangle */
#powerTriangle {
  width: 100%; height: 175px; background: #060B16; border-radius: 8px;
  border: 1px solid #263B63; cursor: crosshair; display: block;
}

/* 4x4 Damage Control Conduit Grid */
.dc-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px;
  max-width: 220px; margin: 4px auto;
}
.dc-cell {
  aspect-ratio: 1;
  background: #0D1830;
  border: 1px solid #2B4570;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
}
.dc-cell.source { border-color: var(--green); }
.dc-cell.target { border-color: var(--amber); }

/* Overlays inside Viewport (Hail, Tricorder Hack, Debrief) */
.overlay-banner {
  position: absolute;
  left: 14px; right: 14px; top: 12px;
  background: rgba(10, 16, 32, 0.94);
  border: 2px solid var(--lilac);
  border-radius: 12px;
  padding: 12px 14px;
  z-index: 20;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.75);
}
.hail-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.hail-head strong { color: var(--lilac); font-size: 0.9rem; letter-spacing: 1px; }
.hail-quote { font-size: 0.83rem; color: #FFF; margin-bottom: 10px; font-style: italic; }
.hail-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 6px; }
.hail-opt {
  background: #162340; border: 1px solid var(--lilac); color: var(--text);
  padding: 7px 9px; border-radius: 8px; cursor: pointer; text-align: left; font-size: 0.75rem;
}
.hail-opt.voted { background: #2D1E4A; border-color: var(--green); }
.hail-opt small { display: block; color: var(--blue); font-size: 0.67rem; margin-top: 3px; }

/* Tricorder Hack Modal */
.hack-modal {
  position: absolute; inset: 0; background: rgba(4, 8, 16, 0.85);
  display: none; align-items: center; justify-content: center; z-index: 25;
}
.hack-modal.active { display: flex; }
.hack-card {
  background: var(--panel); border: 2px solid var(--teal); border-radius: 14px;
  padding: 18px; width: min(400px, 92%); text-align: center;
}
.sym-row { display: flex; justify-content: center; gap: 8px; margin: 12px 0; min-height: 46px; }
.sym-chip {
  width: 44px; height: 44px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; font-weight: 900; background: #14223C; border: 2px solid #35568A; color: #FFF;
}
.sym-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.sym-pad button {
  padding: 10px; font-size: 1.2rem; font-weight: 900; border-radius: 8px;
  border: 2px solid #2E4D7B; background: #101C33; color: #FFF; cursor: pointer;
}

/* Debrief Modal */
.debrief-modal {
  position: absolute; inset: 0; background: rgba(4, 7, 15, 0.88);
  display: none; align-items: center; justify-content: center; z-index: 30;
}
.debrief-modal.active { display: flex; }
.debrief-card {
  background: var(--panel); border: 3px solid var(--amber); border-radius: 14px;
  padding: 24px; max-width: 460px; text-align: center;
}

/* Toast Stack */
#toastBox {
  position: fixed; bottom: 14px; right: 14px; z-index: 60;
  display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
.toast {
  background: rgba(14, 22, 42, 0.96); border-left: 5px solid var(--amber);
  padding: 8px 14px; border-radius: 6px; font-size: 0.78rem; color: #FFF;
  box-shadow: 0 6px 18px rgba(0,0,0,0.6);
}
.toast.warn { border-left-color: var(--coral); }


/* ---------- Away-team terminal minigames ---------- */
.hack-meta { font-size: 0.72rem; color: var(--muted); margin-top: 8px; min-height: 1em; }

.lights-grid { display: grid; grid-template-columns: repeat(3, 62px); gap: 8px; justify-content: center; margin: 12px 0 4px; }
.light-cell {
  height: 62px; border-radius: 10px; cursor: pointer;
  background: #0E1A30; border: 2px solid #2E4D7B; transition: background 0.08s, box-shadow 0.08s;
}
.light-cell:hover { border-color: var(--amber); }
.light-cell.on { background: #FFB020; border-color: #FFE08A; box-shadow: 0 0 16px rgba(255, 176, 32, 0.75); }

.tune-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.tune-lbl { font-size: 0.72rem; color: var(--peach); font-weight: 800; width: 38px; text-align: left; }
.tune-row input[type="range"] { flex: 1; }
.tune-meter { width: 74px; height: 12px; background: #070C18; border: 1px solid #233454; border-radius: 99px; overflow: hidden; }
.tune-fill { height: 100%; width: 0; background: linear-gradient(90deg, #FF6666, #FFCC66, #55EE88); }
.tune-lock { width: 52px; font-size: 0.68rem; font-weight: 800; color: var(--muted); text-align: right; }
.tune-lock.ok { color: var(--green); }

.code-hist { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; min-height: 26px; max-height: 128px; overflow-y: auto; }
.code-row { display: flex; align-items: center; justify-content: center; gap: 4px; }
.code-row .sym-chip { width: 26px; height: 26px; font-size: 0.9rem; border-radius: 6px; }
.code-score { font-size: 0.78rem; font-weight: 800; margin-left: 8px; color: var(--peach); min-width: 56px; text-align: left; }
.sym-pad button.used { opacity: 0.3; }
.code-btns { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }

.timing-track { position: relative; height: 34px; margin: 14px 4px 10px; background: #070C18; border: 2px solid #2E4D7B; border-radius: 8px; overflow: hidden; }
.timing-zone { position: absolute; top: 0; bottom: 0; background: rgba(85, 238, 136, 0.38); border-left: 2px solid #55EE88; border-right: 2px solid #55EE88; }
.timing-marker { position: absolute; top: 0; bottom: 0; width: 4px; margin-left: -2px; background: #FFCC66; box-shadow: 0 0 10px #FFCC66; }

/* ---------- Briefing room: fit the viewport, scroll inside panels ---------- */
#lobbyView { overflow: hidden; }
#lobbyView .lobby-top { flex: 0 0 auto; }
#lobbyView .lobby-cols {
  flex: 1 1 0;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr);
}
#lobbyView .section-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
#lobbyView .section-card .section-title { flex: 0 0 auto; }
#lobbyView .roster-grid,
#lobbyView .mission-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  align-content: start;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: #FF9900 #0C1324;
}
#lobbyView .roster-grid::-webkit-scrollbar,
#lobbyView .mission-list::-webkit-scrollbar { width: 8px; }
#lobbyView .roster-grid::-webkit-scrollbar-thumb,
#lobbyView .mission-list::-webkit-scrollbar-thumb { background: #FF9900; border-radius: 99px; }
#lobbyView .roster-grid::-webkit-scrollbar-track,
#lobbyView .mission-list::-webkit-scrollbar-track { background: #0C1324; border-radius: 99px; }

@media (max-width: 980px) {
  #lobbyView .lobby-cols { grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
}
