:root {
  --bg: #050811;
  --panel: rgba(12, 18, 34, 0.88);
  --panel-border: rgba(56, 189, 248, 0.18);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --cyan: #22d3ee;
  --violet: #a855f7;
  --amber: #fbbf24;
  --rose: #fb7185;
  --emerald: #34d399;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at 20% 10%, #101b36 0%, #050811 55%, #03050b 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

.lab-shell {
  max-width: 1040px;
  margin: 0 auto;
  padding: 18px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.lab-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: linear-gradient(90deg, #38bdf8, #c084fc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.header-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.mode-switch {
  display: inline-flex;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  padding: 3px;
}

.btn {
  appearance: none;
  border: 1px solid rgba(148, 163, 184, 0.24);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.08s ease;
}

.btn:hover {
  border-color: rgba(56, 189, 248, 0.55);
  background: rgba(30, 41, 59, 0.9);
}

.btn:active {
  transform: scale(0.97);
}

.btn-tab {
  border: none;
  background: transparent;
  padding: 6px 12px;
  color: var(--muted);
}

.btn-tab.active {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.22), rgba(168, 85, 247, 0.22));
  color: #f8fafc;
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.45);
}

.btn-primary {
  background: linear-gradient(135deg, #0ea5e9, #8b5cf6);
  border-color: transparent;
  color: #ffffff;
  padding: 10px 20px;
  font-size: 0.92rem;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #38bdf8, #a855f7);
  border-color: transparent;
}

.hud-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.hud-card {
  background: var(--panel);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hud-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.hud-value {
  font-size: 1rem;
  font-weight: 700;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-value.accent {
  color: var(--cyan);
}

.hud-value.gold {
  color: var(--amber);
}

.stage-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 3;
  background: #040711;
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.55), inset 0 0 40px rgba(14, 165, 233, 0.06);
  touch-action: manipulation;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
  touch-action: manipulation;
}

.stage-badge-row {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  gap: 8px;
}

.pill {
  background: rgba(5, 8, 17, 0.78);
  border: 1px solid rgba(148, 163, 184, 0.24);
  backdrop-filter: blur(6px);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
}

.pill.ready {
  border-color: rgba(52, 211, 153, 0.5);
  color: var(--emerald);
}

.pill.used {
  border-color: rgba(148, 163, 184, 0.2);
  color: var(--muted);
}

.stage-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(5, 8, 17, 0.76);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 0.76rem;
  color: #cbd5e1;
  pointer-events: none;
  max-width: calc(100% - 24px);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-overlay {
  position: absolute;
  inset: 0;
  background: rgba(3, 6, 14, 0.78);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 1;
  transition: opacity 0.18s ease;
}

.stage-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  max-width: 430px;
  width: 100%;
  background: rgba(11, 17, 32, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 16px;
  padding: 22px 24px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.overlay-card h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
  color: #f8fafc;
}

.overlay-card p {
  margin: 0 0 16px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--muted);
}

.overlay-stars {
  font-size: 1.5rem;
  letter-spacing: 0.22em;
  margin-bottom: 12px;
  color: var(--amber);
}

.overlay-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sector-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sector-btn {
  min-width: 58px;
  padding: 6px 10px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(12, 18, 34, 0.85);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: all 0.14s ease;
}

.sector-btn:hover {
  border-color: rgba(56, 189, 248, 0.5);
  color: var(--text);
}

.sector-btn.active {
  border-color: var(--cyan);
  background: rgba(14, 165, 233, 0.16);
  color: #f8fafc;
}

.sector-btn .stars-mini {
  font-size: 0.68rem;
  color: var(--amber);
  letter-spacing: 1px;
}

.controls-guide {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.guide-card {
  background: rgba(12, 18, 34, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 12px;
  padding: 11px 14px;
}

.guide-card strong {
  display: block;
  font-size: 0.82rem;
  color: var(--cyan);
  margin-bottom: 4px;
}

.guide-card span {
  display: block;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
}

.lab-footer {
  text-align: center;
  font-size: 0.76rem;
  color: #64748b;
  padding-top: 4px;
}

@media (max-width: 720px) {
  .hud-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .controls-guide {
    grid-template-columns: 1fr;
  }
  .stage-hint {
    font-size: 0.69rem;
    bottom: 6px;
  }
}
