:root {
  --bg-void: #050711;
  --bg-deep: #090e20;
  --bg-surface: rgba(10, 16, 36, 0.84);
  --bg-card: rgba(13, 21, 46, 0.92);
  --border-cyan: rgba(0, 245, 255, 0.28);
  --border-strong: rgba(0, 245, 255, 0.62);
  --border-magenta: rgba(244, 63, 155, 0.48);
  --text-main: #f3f7ff;
  --text-muted: #93a4c8;
  --cyan: #00f5ff;
  --sky: #38bdf8;
  --magenta: #f43f9b;
  --violet: #a855f7;
  --amber: #ffb800;
  --emerald: #10b981;
  --crimson: #ff3d71;
  --font-sans: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 42%, #0e1736 0%, #050711 76%);
  color: var(--text-main);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  touch-action: manipulation;
}

.mono {
  font-family: var(--font-mono);
}

.hidden {
  display: none !important;
}

#app-shell {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#stage-root {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

#canvas-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

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

.ui-screen {
  position: absolute;
  inset: 0;
  z-index: 10;
}

/* ================= HUD ================= */
#screen-hud {
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px 14px;
  gap: 8px;
}

.hud-top-bar {
  pointer-events: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.hud-group {
  pointer-events: auto;
  display: flex;
  align-items: stretch;
  gap: 7px;
}

.hud-card {
  pointer-events: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-cyan);
  border-radius: 10px;
  padding: 7px 11px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.48), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.hud-sector-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 224px;
}

.hud-meta-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--cyan);
  background: rgba(0, 245, 255, 0.12);
  border: 1px solid rgba(0, 245, 255, 0.32);
  text-transform: uppercase;
}

.badge-tag.is-daily {
  color: var(--amber);
  background: rgba(255, 184, 0, 0.14);
  border-color: rgba(255, 184, 0, 0.42);
}

.hud-sector-val {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-main);
}

.hud-status-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hull-block,
.pylon-block {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-lbl {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: var(--text-muted);
}

.pip-row {
  display: flex;
  align-items: center;
  gap: 3px;
}

.hull-pip {
  width: 12px;
  height: 7px;
  border-radius: 2px;
  background: rgba(148, 163, 184, 0.22);
  border: 1px solid rgba(148, 163, 184, 0.25);
  transition: background-color 140ms ease, box-shadow 140ms ease;
}

.hull-pip.is-on {
  background: var(--emerald);
  border-color: #6ee7b7;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.55);
}

.hull-pip.is-low {
  background: var(--crimson);
  border-color: #fda4af;
  box-shadow: 0 0 8px rgba(255, 61, 113, 0.65);
}

.pylon-pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.22);
  border: 1px solid rgba(56, 189, 248, 0.28);
}

.pylon-pip.is-on {
  background: var(--cyan);
  border-color: #ffffff;
  box-shadow: 0 0 7px rgba(0, 245, 255, 0.72);
}

.pylon-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--sky);
}

.hud-center-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 12px;
}

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

.metric-cell {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.metric-num {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text-main);
}

.mult-num {
  color: var(--amber);
}

.tri-num {
  color: var(--magenta);
}

.detonate-bar-btn {
  position: relative;
  overflow: hidden;
  min-width: 156px;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid rgba(244, 63, 155, 0.35);
  background: rgba(15, 22, 48, 0.9);
  color: var(--text-main);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 120ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.detonate-bar-btn:hover {
  border-color: var(--magenta);
}

.detonate-bar-btn.is-ready {
  border-color: #fbbf24;
  box-shadow: 0 0 16px rgba(244, 63, 155, 0.55), 0 0 6px rgba(255, 184, 0, 0.45);
  animation: pulseReady 1.05s ease-in-out infinite alternate;
}

.harmonic-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, rgba(0, 245, 255, 0.36), rgba(244, 63, 155, 0.65), rgba(255, 184, 0, 0.72));
  transition: width 100ms linear;
}

.harmonic-text {
  position: relative;
  z-index: 1;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
}

@keyframes pulseReady {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.03);
  }
}

.hud-dash-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  min-width: 72px;
}

.dash-track {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.2);
  overflow: hidden;
}

.dash-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--sky), var(--cyan));
  box-shadow: 0 0 8px rgba(0, 245, 255, 0.6);
  transition: width 70ms linear;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 38px;
  padding: 0 9px;
  border-radius: 9px;
  border: 1px solid var(--border-cyan);
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: border-color 140ms ease, background-color 140ms ease, transform 100ms ease;
}

.tool-btn:hover {
  border-color: var(--cyan);
  background: rgba(16, 30, 62, 0.94);
}

.tool-btn:active {
  transform: scale(0.96);
}

.hud-banner {
  position: absolute;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  pointer-events: none;
  padding: 5px 15px;
  border-radius: 999px;
  background: rgba(10, 17, 38, 0.9);
  border: 1px solid var(--border-strong);
  color: var(--cyan);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: 0 0 22px rgba(0, 245, 255, 0.25);
}

.hud-banner.is-boss {
  border-color: var(--crimson);
  color: #fda4af;
  box-shadow: 0 0 24px rgba(255, 61, 113, 0.35);
}

.hud-bottom-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.controls-strip {
  pointer-events: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(8, 13, 29, 0.72);
  border: 1px solid rgba(56, 189, 248, 0.18);
  font-size: 11px;
  color: var(--text-muted);
}

.controls-strip kbd {
  display: inline-block;
  padding: 1px 5px;
  margin-right: 4px;
  border-radius: 4px;
  background: rgba(0, 245, 255, 0.12);
  border: 1px solid rgba(0, 245, 255, 0.28);
  color: var(--cyan);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
}

/* ================= TOUCH CONTROLS ================= */
.touch-controls {
  display: none;
  width: 100%;
  align-items: flex-end;
  justify-content: space-between;
  padding: 2px 4px 4px;
  pointer-events: none;
}

body.touch-ui .touch-controls {
  display: flex;
}

body.touch-ui .controls-strip {
  display: none;
}

.touch-joystick {
  pointer-events: auto;
  position: relative;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: rgba(10, 18, 40, 0.65);
  border: 1.5px solid rgba(0, 245, 255, 0.38);
  box-shadow: inset 0 0 18px rgba(0, 245, 255, 0.12);
  touch-action: none;
}

.joystick-ring {
  position: absolute;
  inset: 18px;
  border-radius: 50%;
  border: 1px dashed rgba(56, 189, 248, 0.35);
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  margin-left: -22px;
  margin-top: -22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #a5f3fc, #00b8d4);
  border: 2px solid #ffffff;
  box-shadow: 0 0 16px rgba(0, 245, 255, 0.6);
  pointer-events: none;
}

.touch-actions {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.touch-action-pair {
  display: flex;
  gap: 8px;
}

.touch-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  border: 1.5px solid var(--border-cyan);
  background: rgba(11, 20, 44, 0.85);
  color: var(--text-main);
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.touch-btn:active {
  transform: scale(0.95);
}

.touch-pylon {
  width: 72px;
  height: 58px;
  border-color: rgba(0, 245, 255, 0.65);
}

.touch-dash {
  width: 68px;
  height: 58px;
  border-color: rgba(16, 185, 129, 0.6);
}

.touch-detonate {
  width: 148px;
  height: 44px;
  flex-direction: row;
  gap: 8px;
  border-color: rgba(244, 63, 155, 0.52);
}

.touch-detonate.is-ready {
  background: linear-gradient(135deg, rgba(244, 63, 155, 0.36), rgba(255, 184, 0, 0.3));
  border-color: #fbbf24;
  box-shadow: 0 0 16px rgba(244, 63, 155, 0.55);
}

.tb-main {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.tb-sub {
  font-size: 10px;
  color: var(--cyan);
  font-weight: 700;
}

/* ================= TITLE SCREEN ================= */
.screen-title {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: radial-gradient(circle at 50% 45%, rgba(7, 13, 30, 0.56) 0%, rgba(4, 6, 14, 0.86) 100%);
  overflow-y: auto;
}

.title-layout {
  width: 100%;
  max-width: 980px;
  display: grid;
  grid-template-columns: 1.25fr 0.95fr;
  gap: 18px;
  align-items: stretch;
}

.title-panel,
.tactics-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-cyan);
  border-radius: 16px;
  padding: 22px 24px;
  backdrop-filter: blur(14px);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--cyan);
  margin-bottom: 10px;
}

.kicker-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
}

.hero-title {
  margin: 0 0 10px;
  line-height: 0.95;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hero-main {
  font-size: clamp(28px, 4.4vw, 48px);
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(95deg, #ffffff 0%, #67e8f9 52%, #f472b6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-sub {
  font-size: clamp(16px, 2.2vw, 24px);
  font-weight: 800;
  letter-spacing: 0.24em;
  color: var(--magenta);
  text-shadow: 0 0 18px rgba(244, 63, 155, 0.45);
}

.hero-desc {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.52;
  color: var(--text-muted);
}

.hero-desc strong {
  color: var(--text-main);
}

.title-cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.btn-primary,
.btn-secondary,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 110ms ease, box-shadow 140ms ease, border-color 140ms ease, background-color 140ms ease;
}

.btn-primary {
  border: 1px solid #67e8f9;
  background: linear-gradient(135deg, #00b4d8, #0077b6);
  color: #ffffff;
  box-shadow: 0 8px 24px rgba(0, 180, 216, 0.36);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(0, 245, 255, 0.48);
}

.btn-secondary {
  border: 1px solid var(--border-magenta);
  background: rgba(244, 63, 155, 0.14);
  color: #fbcfe8;
}

.btn-secondary:hover {
  border-color: var(--magenta);
  background: rgba(244, 63, 155, 0.24);
}

.btn-ghost {
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.65);
  color: var(--text-main);
}

.btn-ghost:hover {
  border-color: var(--cyan);
}

.daily-chip {
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 184, 0, 0.2);
  border: 1px solid rgba(255, 184, 0, 0.45);
  color: #fde047;
  font-size: 10px;
}

.best-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.16);
  font-size: 11px;
  color: var(--text-muted);
}

.best-strip strong {
  color: var(--cyan);
}

.tactics-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

.tactics-head {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--sky);
  margin-bottom: 2px;
}

.tactic-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  border-radius: 9px;
  background: rgba(7, 12, 28, 0.72);
  border: 1px solid rgba(56, 189, 248, 0.15);
}

.t-badge {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.t-badge.cyan { color: var(--cyan); }
.t-badge.magenta { color: #f472b6; }
.t-badge.amber { color: var(--amber); }
.t-badge.emerald { color: var(--emerald); }
.t-badge.violet { color: #c084fc; }

.t-note {
  font-size: 11px;
  color: var(--text-muted);
}

/* ================= MODALS ================= */
.modal-backdrop {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 7, 16, 0.76);
  backdrop-filter: blur(8px);
}

.modal-card {
  width: 100%;
  max-width: 540px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.75);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.modal-title {
  margin: 6px 0 0;
  font-size: 24px;
  font-weight: 800;
}

.modal-sub {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.pause-controls-grid {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
}

.pause-controls-grid > div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(6, 11, 24, 0.78);
  border: 1px solid rgba(56, 189, 248, 0.16);
  font-size: 12px;
}

.pause-controls-grid > div > span:first-child {
  color: var(--cyan);
  font-weight: 700;
}

.end-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(6, 11, 24, 0.8);
  border: 1px solid rgba(56, 189, 248, 0.2);
}

.stat-k {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.08em;
}

.stat-v {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-main);
}

.record-pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 184, 0, 0.18);
  border: 1px solid rgba(255, 184, 0, 0.55);
  color: #fde047;
  font-size: 11px;
  font-weight: 800;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ================= PORTAL FOOTER ================= */
.portal-footer {
  height: 26px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 10px;
  background: rgba(4, 6, 14, 0.96);
  border-top: 1px solid rgba(56, 189, 248, 0.16);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
}

.portal-footer a {
  color: var(--sky);
  text-decoration: none;
}

.portal-footer a:hover {
  color: var(--cyan);
  text-decoration: underline;
}

.footer-sep {
  opacity: 0.45;
}

/* ================= COMPACT / MOBILE RESPONSIVENESS ================= */
@media (max-width: 920px) {
  .title-layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .hud-top-bar {
    flex-wrap: wrap;
    gap: 6px;
  }

  .hud-center-card {
    order: 3;
    width: 100%;
    justify-content: space-between;
  }

  .hud-banner {
    top: 108px;
  }
}

@media (max-width: 680px) {
  #screen-hud {
    padding: 8px;
    gap: 6px;
  }

  .hud-sector-card {
    min-width: 0;
    padding: 6px 8px;
  }

  .hud-status-row {
    gap: 8px;
  }

  .hull-pip {
    width: 9px;
    height: 6px;
  }

  .pylon-pip {
    width: 7px;
    height: 7px;
  }

  .hud-dash-card {
    display: none;
  }

  .tool-btn {
    min-width: 32px;
    height: 34px;
    padding: 0 7px;
  }

  .hud-center-card {
    padding: 6px 9px;
    gap: 8px;
  }

  .center-metrics {
    gap: 9px;
  }

  .metric-num {
    font-size: 13px;
  }

  .detonate-bar-btn {
    min-width: 122px;
    height: 29px;
    font-size: 10px;
    padding: 0 8px;
  }

  .screen-title {
    align-items: flex-start;
    padding: 10px;
  }

  .title-panel,
  .tactics-panel {
    padding: 14px;
    border-radius: 12px;
  }

  .hero-desc {
    font-size: 12.5px;
    margin-bottom: 12px;
  }

  .btn-primary,
  .btn-secondary,
  .btn-ghost {
    padding: 9px 12px;
    font-size: 12px;
  }

  .tactic-row {
    padding: 6px 8px;
  }

  .controls-strip {
    gap: 6px;
    padding: 4px 9px;
    font-size: 9.5px;
  }

  .portal-footer {
    font-size: 10px;
    gap: 6px;
  }
}

@media (max-width: 520px), (hover: none) and (pointer: coarse) {
  .touch-controls {
    display: flex;
  }

  .controls-strip {
    display: none;
  }
}
