:root {
  --bg-atrium: #090e1c;
  --bg-mahogany: #131c33;
  --bg-card: rgba(13, 21, 41, 0.96);
  --brass: #f5c451;
  --brass-bright: #ffe28a;
  --brass-border: rgba(245, 196, 81, 0.45);
  --emerald: #2dd4a8;
  --emerald-border: rgba(45, 212, 168, 0.45);
  --sky-cyan: #38bdf8;
  --cyan-border: rgba(56, 189, 248, 0.42);
  --ruby: #fb6f7e;
  --ivory: #f9f5eb;
  --muted: #b0c0dc;
  --font-sans: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, 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% 8%, #1d2a4d 0%, #090e1c 85%);
  color: var(--ivory);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  touch-action: manipulation;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

.accent-gold { color: var(--brass-bright); }
.accent-amber { color: var(--brass); }
.accent-cyan { color: var(--sky-cyan); }
.accent-mint { color: var(--emerald); }
.accent-coral { color: var(--ruby); }

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

/* ================= TOP TELEMETRY BAR ================= */
.top-bar {
  flex-shrink: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(8, 12, 26, 0.96);
  border-bottom: 1px solid var(--brass-border);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
  min-width: 0;
  flex-wrap: wrap;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-icon {
  flex-shrink: 0;
  border-radius: 7px;
  border: 1px solid var(--brass-border);
}

.brand-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  line-height: 1.1;
  white-space: nowrap;
}

.title-accent {
  color: var(--brass);
}

.brand-sub {
  font-size: 0.68rem;
  color: var(--emerald);
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-telemetry {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  min-width: 0;
}

.tele-box,
.tele-cell,
.meter-box {
  background: rgba(17, 26, 51, 0.94);
  border: 1px solid rgba(245, 196, 81, 0.24);
  border-radius: 7px;
  padding: 3px 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.tele-box.is-urgent {
  border-color: var(--ruby);
  box-shadow: 0 0 12px rgba(251, 111, 126, 0.4);
}

.tele-box.is-stopped {
  border-color: var(--brass-bright);
  box-shadow: 0 0 12px rgba(255, 226, 138, 0.42);
}

.meter-box {
  min-width: 88px;
  gap: 2px;
}

.meter-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.tele-k {
  font-size: 0.6rem;
  color: var(--muted);
  letter-spacing: 0.07em;
  line-height: 1;
}

.tele-v {
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1.15;
}

.meter-prog {
  width: 100%;
  height: 5px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.1);
  appearance: none;
}

.meter-prog::-webkit-progress-bar {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
}

.meter-mint::-webkit-progress-value {
  background: linear-gradient(90deg, #10b981, #2dd4a8);
  border-radius: 999px;
}

.meter-cyan::-webkit-progress-value {
  background: linear-gradient(90deg, #38bdf8, #f5c451);
  border-radius: 999px;
}

.meter-mint::-moz-progress-bar {
  background: #2dd4a8;
}

.meter-cyan::-moz-progress-bar {
  background: #f5c451;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hdr-btn,
.hdr-link {
  border: 1px solid var(--brass-border);
  background: rgba(17, 26, 51, 0.94);
  color: var(--ivory);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 7px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.hdr-btn:hover,
.hdr-link:hover {
  border-color: var(--emerald);
  background: rgba(29, 42, 77, 0.95);
}

.hdr-btn.is-muted {
  border-color: rgba(251, 111, 126, 0.55);
  color: var(--ruby);
}

/* ================= ATRIUM STAGE ================= */
#arena-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#canvas-wrap {
  width: 100%;
  height: 100%;
  position: relative;
}

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

.toast-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(9, 14, 28, 0.94);
  border: 1px solid var(--brass-border);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  font-size: 0.74rem;
  pointer-events: none;
  white-space: nowrap;
}

.toast-badge {
  background: rgba(245, 196, 81, 0.18);
  color: var(--brass-bright);
  border: 1px solid rgba(245, 196, 81, 0.42);
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 800;
}

.toast-msg {
  color: var(--ivory);
  font-weight: 600;
}

/* ================= OVERLAYS ================= */
.overlay-screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(6, 10, 22, 0.8);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow-y: auto;
}

.overlay-card {
  width: min(760px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--brass-border);
  border-radius: 14px;
  padding: 16px 20px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.75);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.compact-card {
  width: min(460px, 100%);
  text-align: center;
  align-items: center;
}

.eyebrow-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(176, 192, 220, 0.35);
  background: rgba(19, 28, 51, 0.92);
}

.chip-amber {
  color: var(--brass-bright);
  border-color: var(--brass-border);
  background: rgba(245, 196, 81, 0.14);
}

.chip-cyan {
  color: var(--sky-cyan);
  border-color: var(--cyan-border);
  background: rgba(56, 189, 248, 0.12);
}

.chip-mint {
  color: var(--emerald);
  border-color: var(--emerald-border);
  background: rgba(45, 212, 168, 0.12);
}

.hero-title,
.modal-title {
  margin: 0;
  font-size: clamp(1.22rem, 2.7vw, 1.82rem);
  font-weight: 900;
  letter-spacing: 0.03em;
  line-height: 1.1;
}

.hero-copy,
.modal-sub {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.44;
  color: var(--muted);
}

.hero-copy strong {
  color: var(--ivory);
}

.title-stats,
.debrief-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.debrief-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat-pill {
  background: rgba(9, 14, 28, 0.92);
  border: 1px solid rgba(245, 196, 81, 0.25);
  border-radius: 9px;
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-k {
  font-size: 0.62rem;
  color: var(--muted);
  letter-spacing: 0.07em;
}

.stat-v {
  font-size: 1rem;
  font-weight: 800;
}

.mechanics-trio {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.mech-card {
  background: rgba(9, 14, 28, 0.92);
  border: 1px solid rgba(245, 196, 81, 0.28);
  border-radius: 10px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

.mech-card strong {
  color: var(--ivory);
  font-size: 0.82rem;
}

.mech-tag {
  font-size: 0.63rem;
  font-weight: 700;
  color: var(--brass);
}

.upgrade-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.upgrade-item {
  background: rgba(9, 14, 28, 0.94);
  border: 1px solid rgba(245, 196, 81, 0.34);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  color: var(--ivory);
}

.upgrade-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.upgrade-name {
  font-size: 0.88rem;
  font-weight: 800;
}

.upgrade-lvl {
  font-size: 0.7rem;
  color: var(--emerald);
  font-weight: 700;
}

.upgrade-desc {
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.35;
}

.upgrade-buy-btn {
  align-self: flex-start;
  margin-top: 2px;
  padding: 6px 11px;
  border-radius: 7px;
  border: 1px solid var(--brass-border);
  background: rgba(245, 196, 81, 0.16);
  color: var(--brass-bright);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 800;
  cursor: pointer;
}

.upgrade-buy-btn:hover:not(:disabled) {
  background: rgba(245, 196, 81, 0.3);
}

.upgrade-buy-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.btn-primary-lg,
.btn-secondary-lg {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 10px 16px;
  border-radius: 9px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease;
}

.btn-primary-lg {
  border: 1px solid var(--brass-bright);
  background: linear-gradient(135deg, #d99b26 0%, #f5c451 100%);
  color: #101628;
}

.btn-secondary-lg {
  border: 1px solid var(--emerald-border);
  background: rgba(16, 33, 46, 0.94);
  color: var(--emerald);
}

.btn-primary-lg:hover,
.btn-secondary-lg:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.tiny-hint {
  margin: 0;
  font-size: 0.68rem;
  color: var(--muted);
}

/* ================= FOOTER CONTROLS ================= */
.desktop-controls-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 5px 12px;
  background: rgba(8, 12, 26, 0.96);
  border-top: 1px solid rgba(245, 196, 81, 0.25);
  font-size: 0.7rem;
  color: var(--muted);
}

.desktop-controls-bar strong {
  color: var(--brass-bright);
}

.touch-dock {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px calc(7px + env(safe-area-inset-bottom, 0px));
  background: rgba(8, 12, 26, 0.97);
  border-top: 1px solid var(--brass-border);
}

.touch-pad {
  display: flex;
  align-items: center;
  gap: 5px;
}

.touch-ud {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.touch-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.touch-btn {
  border: 1px solid var(--brass-border);
  background: rgba(17, 26, 51, 0.95);
  color: var(--ivory);
  font-family: var(--font-mono);
  font-weight: 800;
  border-radius: 9px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.05;
  touch-action: none;
}

.touch-btn.is-active {
  background: rgba(245, 196, 81, 0.28);
  border-color: var(--brass-bright);
}

.touch-dir {
  width: 44px;
  height: 48px;
  font-size: 1rem;
}

.touch-dir-sm {
  width: 42px;
  height: 30px;
  font-size: 0.85rem;
}

.touch-latch,
.touch-timestop {
  min-width: 74px;
  height: 54px;
  padding: 0 9px;
  font-size: 0.74rem;
}

.touch-latch {
  border-color: var(--emerald-border);
  color: var(--emerald);
}

.touch-timestop {
  border-color: var(--brass-border);
  color: var(--brass-bright);
}

.touch-sub {
  font-size: 0.54rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ================= RESPONSIVE EMBED (630x500 & 960x540) ================= */
@media (max-height: 560px) {
  .top-bar {
    padding: 4px 9px;
    gap: 6px;
  }

  .brand-icon {
    width: 22px;
    height: 22px;
  }

  .brand-title {
    font-size: 0.78rem;
  }

  .brand-sub {
    font-size: 0.58rem;
  }

  .tele-box,
  .tele-cell,
  .meter-box {
    padding: 2px 6px;
  }

  .meter-box {
    min-width: 72px;
  }

  .tele-k {
    font-size: 0.54rem;
  }

  .tele-v {
    font-size: 0.7rem;
  }

  .hdr-btn,
  .hdr-link {
    padding: 3px 7px;
    font-size: 0.64rem;
  }

  .overlay-screen {
    padding: 6px;
  }

  .overlay-card {
    padding: 10px 14px;
    gap: 6px;
  }

  .hero-title,
  .modal-title {
    font-size: 1.12rem;
  }

  .hero-copy,
  .modal-sub {
    font-size: 0.74rem;
    line-height: 1.3;
  }

  .stat-pill {
    padding: 4px 8px;
  }

  .stat-v {
    font-size: 0.85rem;
  }

  .mech-card {
    padding: 6px 8px;
    font-size: 0.67rem;
  }

  .mech-card strong {
    font-size: 0.73rem;
  }

  .btn-primary-lg,
  .btn-secondary-lg {
    padding: 7px 12px;
    font-size: 0.72rem;
  }

  .desktop-controls-bar {
    padding: 3px 8px;
    font-size: 0.62rem;
    gap: 10px;
  }
}

@media (max-width: 680px) {
  .hide-sm {
    display: none;
  }
}

@media (max-width: 540px), (pointer: coarse) and (max-width: 900px) {
  .hide-xs {
    display: none;
  }

  .top-bar {
    padding: 5px 8px;
    gap: 5px;
  }

  .brand-title {
    font-size: 0.78rem;
  }

  .brand-sub {
    font-size: 0.58rem;
  }

  .hdr-link {
    display: none;
  }

  .desktop-controls-bar {
    display: none;
  }

  .touch-dock {
    display: flex;
  }

  .mechanics-trio {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .debrief-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .upgrade-grid {
    grid-template-columns: 1fr;
  }

  .overlay-card {
    padding: 12px;
    gap: 8px;
  }

  .btn-primary-lg,
  .btn-secondary-lg {
    width: 100%;
    text-align: center;
  }
}
