:root {
  --bg-yard: #070c18;
  --bg-slate: #101b33;
  --bg-card: rgba(10, 17, 34, 0.96);
  --brass: #f5c451;
  --brass-bright: #ffe598;
  --brass-border: rgba(245, 196, 81, 0.45);
  --mint: #2dd4a8;
  --mint-border: rgba(45, 212, 168, 0.45);
  --cyan: #38bdf8;
  --cyan-border: rgba(56, 189, 248, 0.45);
  --ruby: #fb6f7e;
  --ivory: #fbf4e4;
  --muted: #aabbd6;
  --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% 10%, #172444 0%, #070c18 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(--cyan); }
.accent-mint { color: var(--mint); }
.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(7, 11, 22, 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.66rem;
  color: var(--mint);
  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(15, 24, 48, 0.94);
  border: 1px solid rgba(245, 196, 81, 0.25);
  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.44);
}

.tele-box.is-frozen {
  border-color: var(--cyan);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.45);
}

.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.58rem;
  color: var(--muted);
  letter-spacing: 0.07em;
  line-height: 1;
}

.tele-v {
  font-size: 0.78rem;
  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: #38bdf8;
}

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

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

.hdr-btn:hover,
.hdr-link:hover {
  border-color: var(--brass-bright);
  background: rgba(245, 196, 81, 0.16);
}

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

.hdr-btn.is-active {
  border-color: var(--cyan);
  color: var(--cyan);
}

/* ================= STAGE & CANVAS ================= */
#arena-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 6px;
}

#canvas-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

#game-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  border: 1px solid rgba(245, 196, 81, 0.34);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.72), inset 0 0 28px rgba(56, 189, 248, 0.08);
  background: #070d1b;
  cursor: pointer;
  touch-action: none;
}

/* ================= TOAST BANNER ================= */
.toast-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 22;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(8, 14, 28, 0.94);
  border: 1px solid var(--cyan-border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  font-size: 0.72rem;
  pointer-events: none;
  white-space: nowrap;
}

.toast-badge {
  color: #07101f;
  background: var(--brass);
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.64rem;
  letter-spacing: 0.06em;
}

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

/* ================= OVERLAY SCREENS ================= */
.overlay-screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(5, 9, 19, 0.78);
  backdrop-filter: blur(5px);
}

.overlay-card {
  width: 100%;
  max-width: 780px;
  max-height: calc(100% - 8px);
  overflow-y: auto;
  background: linear-gradient(165deg, rgba(13, 21, 42, 0.97), rgba(8, 13, 26, 0.98));
  border: 1px solid var(--brass-border);
  border-radius: 14px;
  padding: 18px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.75);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.compact-card {
  max-width: 460px;
  text-align: center;
  align-items: center;
}

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

.chip {
  font-size: 0.63rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
}

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

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

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

.hero-title,
.modal-title {
  margin: 0;
  font-size: 1.48rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  line-height: 1.15;
}

.hero-copy,
.modal-sub {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.45;
  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(17, 27, 52, 0.9);
  border: 1px solid rgba(245, 196, 81, 0.22);
  border-radius: 9px;
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

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

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

.mech-card {
  background: rgba(15, 24, 46, 0.88);
  border: 1px solid rgba(56, 189, 248, 0.24);
  border-radius: 10px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.35;
}

.mech-tag {
  font-size: 0.58rem;
  color: var(--brass);
  font-weight: 700;
  letter-spacing: 0.05em;
}

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

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

.upg-item {
  background: rgba(16, 26, 51, 0.92);
  border: 1px solid rgba(245, 196, 81, 0.28);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 7px;
}

.upg-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.upg-name {
  font-weight: 800;
  font-size: 0.84rem;
  color: var(--ivory);
}

.upg-lvl {
  font-size: 0.66rem;
  color: var(--mint);
  font-weight: 700;
}

.upg-desc {
  margin: 0;
  font-size: 0.73rem;
  color: var(--muted);
  line-height: 1.35;
}

.upg-buy-btn {
  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.72rem;
  font-weight: 800;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
}

.upg-buy-btn:hover:not(:disabled) {
  background: var(--brass);
  color: #070d1b;
}

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

.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  justify-content: center;
}

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

.btn-primary-lg {
  border: 1px solid var(--brass-bright);
  background: linear-gradient(135deg, #f5c451, #e59922);
  color: #091021;
  box-shadow: 0 8px 24px rgba(245, 196, 81, 0.28);
}

.btn-primary-lg:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(245, 196, 81, 0.42);
}

.btn-secondary-lg {
  border: 1px solid var(--cyan-border);
  background: rgba(56, 189, 248, 0.14);
  color: var(--cyan);
}

.btn-secondary-lg:hover {
  background: rgba(56, 189, 248, 0.25);
}

.tiny-hint {
  margin: 0;
  text-align: center;
  font-size: 0.67rem;
  color: var(--muted);
}

/* ================= FOOTERS ================= */
.desktop-controls-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 5px 12px;
  font-size: 0.67rem;
  color: var(--muted);
  background: rgba(7, 11, 22, 0.96);
  border-top: 1px solid rgba(245, 196, 81, 0.2);
}

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

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

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

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

.touch-btn {
  border: 1px solid var(--brass-border);
  background: rgba(15, 24, 48, 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: 28px;
  font-size: 0.85rem;
}

.touch-flip,
.touch-bell {
  min-width: 76px;
  height: 54px;
  padding: 0 9px;
  font-size: 0.72rem;
}

.touch-flip {
  border-color: var(--mint-border);
  color: var(--mint);
}

.touch-bell {
  border-color: var(--cyan-border);
  color: var(--cyan);
}

.touch-sub {
  font-size: 0.51rem;
  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.76rem;
  }

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

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

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

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

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

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

  .overlay-screen {
    padding: 6px;
  }

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

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

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

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

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

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

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

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

  .desktop-controls-bar {
    padding: 3px 8px;
    font-size: 0.61rem;
    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.74rem;
  }

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

  .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;
  }
}
