/* Nova Dominion - Core Styles - Mobile-first game UI */
:root {
  --bg-deep: #06060f;
  --panel-bg: rgba(16, 16, 40, 0.92);
  --panel-border: rgba(68, 136, 255, 0.3);
  --glow-blue: #4488ff;
  --glow-cyan: #88ccff;
  --text-primary: #d0d8f0;
  --text-secondary: #8888aa;
  --energy-color: #ffcc00;
  --mineral-color: #33cc88;
  --research-color: #8844ff;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text-primary);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}

#bg-canvas { z-index: 0; }
#game-canvas { z-index: 1; }

#ui-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 2;
  pointer-events: none;
}

#ui-overlay > * {
  pointer-events: auto;
}

/* ============ RESOURCE BAR (Top) ============ */
#resource-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 42px;
  display: flex;
  justify-content: center;
  gap: clamp(10px, 2.5vw, 22px);
  align-items: center;
  background: linear-gradient(to bottom, rgba(6,6,15,0.94), rgba(6,6,15,0.5), transparent);
  padding: 0 10px;
  z-index: 3;
}

#resource-bar.hidden { display: none; }

.resource {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: clamp(14px, 3.5vw, 17px);
  font-weight: 700;
  letter-spacing: 0.3px;
}

.res-icon-svg {
  display: inline-block;
  vertical-align: middle;
  filter: drop-shadow(0 0 4px currentColor);
  flex-shrink: 0;
}

#energy-val { color: var(--energy-color); }
#mineral-val { color: var(--mineral-color); }
#research-val { color: var(--research-color); }

.res-divider {
  width: 1px;
  height: 14px;
  background: rgba(68, 136, 255, 0.2);
  flex-shrink: 0;
}

/* ============ BOTTOM NAV BAR ============ */
#bottom-nav {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: calc(52px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  /* `safe center`: centred when the buttons fit, but when they don't (narrow
     windows between the phone breakpoint and ~700px) the row scrolls from its
     start instead of pushing the first/last buttons off both screen edges. */
  justify-content: safe center;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(to top, rgba(6,6,15,0.95), rgba(6,6,15,0.6), transparent);
  z-index: 3;
}
#bottom-nav::-webkit-scrollbar { display: none; }

#bottom-nav.hidden { display: none; }

#bug-hint:hover { opacity: 0.95 !important; border-color: rgba(68,136,255,0.5) !important; color: #aaccff; }

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(68, 136, 255, 0.15);
  color: #7788aa;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 9px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  min-width: 52px;
  min-height: 44px;
}

.nav-btn:active, .nav-btn.active {
  background: rgba(68, 136, 255, 0.2);
  border-color: rgba(68, 136, 255, 0.4);
  color: var(--glow-cyan);
}

.nav-btn svg { flex-shrink: 0; }

/* Speed controls in bottom nav */
#speed-controls {
  display: flex;
  gap: 2px;
  margin: 0 4px;
}

#zoom-controls {
  display: flex;
  gap: 2px;
  margin: 0 4px;
}

.speed-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(68, 136, 255, 0.2);
  color: #556;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  min-height: 44px;
  min-width: 40px;
}

.speed-btn.active {
  background: rgba(68, 136, 255, 0.3);
  border-color: rgba(68, 136, 255, 0.5);
  color: var(--glow-cyan);
}

.speed-btn:active { background: rgba(68, 136, 255, 0.15); color: var(--text-primary); }

/* ============ PANELS ============ */
.panel {
  position: absolute;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 4;
}

.panel.hidden {
  opacity: 0;
  pointer-events: none !important;
  transform: translateY(20px);
  visibility: hidden;
}

/* Star Panel */
#star-panel {
  width: 300px;
  max-height: 55vh;
  padding: 16px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(68,136,255,0.2) transparent;
}

/* Phone: bottom sheet */
@media (max-width: 767px) {
  #star-panel {
    bottom: calc(52px + var(--safe-bottom));
    left: 0; right: 0;
    width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 42vh;
  }
  #star-panel.hidden { transform: translateY(100%); }

  /* Bottom sheet handle */
  #star-panel::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    margin: 0 auto 10px;
  }
}

/* PC: right side panel */
@media (min-width: 768px) {
  #star-panel {
    top: 50px; right: 12px;
  }
  #star-panel.hidden { transform: translateX(20px); }
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: clamp(14px, 3.5vw, 16px);
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--glow-cyan);
  text-shadow: 0 0 10px rgba(136, 204, 255, 0.5);
}

.panel-body {
  font-size: clamp(12px, 3vw, 13px);
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ============ BUTTONS ============ */
.glow-btn {
  background: rgba(68, 136, 255, 0.15);
  border: 1px solid rgba(68, 136, 255, 0.4);
  color: var(--glow-cyan);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.15s;
  font-family: inherit;
  min-height: 40px;
}

.glow-btn:active {
  background: rgba(68, 136, 255, 0.35);
  box-shadow: 0 0 15px rgba(68, 136, 255, 0.3);
  transform: scale(0.97);
}

@media (min-width: 768px) {
  .glow-btn:hover {
    background: rgba(68, 136, 255, 0.3);
    box-shadow: 0 0 15px rgba(68, 136, 255, 0.3);
  }
}

.glow-btn.large {
  padding: 14px 40px;
  font-size: 18px;
  letter-spacing: 3px;
  border-radius: 8px;
  min-height: 48px;
}

/* Close button */
.panel-header .glow-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

/* ============ ACTION BUTTONS (in star panel) ============ */
.action-btn {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  text-align: left;
  min-height: 48px;
}

.action-btn .cost {
  float: right;
  font-size: 11px;
  opacity: 0.7;
}

.action-btn:disabled, .action-btn[disabled] {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

/* ============ STRUCTURE LIST ============ */
.structure-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(68, 136, 255, 0.08);
  min-height: 32px;
}

.structure-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.scrap-btn {
  background: rgba(255, 80, 80, 0.1);
  border: 1px solid rgba(255, 80, 80, 0.3);
  color: #ff8888;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  min-height: 36px;
}

.scrap-btn:active {
  background: rgba(255, 80, 80, 0.3);
}

/* ============ BUILD PROGRESS ============ */
.build-progress {
  margin-top: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
  height: 20px;
  overflow: hidden;
  position: relative;
}

.build-progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
  background-image: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.15) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: shimmer 2s linear infinite;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.build-progress-label {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* ============ TITLE SCREEN ============ */
#title-screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(20,20,60,0.6) 0%, rgba(6,6,15,0.95) 70%);
  transition: opacity 0.8s ease;
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Prevent title screen from being too tall on small screens */
@media (max-height: 700px) {
  #title-screen { justify-content: flex-start; padding-top: 20px; }
  #title-screen h1 { font-size: clamp(24px, 5vw, 40px); margin-bottom: 6px; }
  .subtitle { margin-bottom: 12px; }
  #title-menu { max-height: 55vh; }
}
@media (max-height: 500px) {
  #title-screen { padding-top: 10px; }
  #title-screen h1 { font-size: 22px; margin-bottom: 4px; }
  .subtitle { margin-bottom: 8px; font-size: 11px; }
  #title-menu { max-height: 50vh; }
}

#title-screen.hidden {
  opacity: 0;
  pointer-events: none !important;
}

#title-screen h1 {
  font-size: clamp(32px, 7vw, 64px);
  font-weight: 300;
  color: var(--glow-cyan);
  text-shadow: 0 0 30px rgba(68, 136, 255, 0.6), 0 0 60px rgba(68, 136, 255, 0.2);
  margin-bottom: 12px;
}

.subtitle {
  font-size: clamp(13px, 2.5vw, 18px);
  color: var(--text-secondary);
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 36px;
  font-weight: 400;
}

#title-menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 380px;
  padding: 0 16px;
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: rgba(68,136,255,0.3) transparent;
}
#title-menu::-webkit-scrollbar { width: 4px; }
#title-menu::-webkit-scrollbar-thumb { background: rgba(68,136,255,0.3); border-radius: 4px; }

.menu-page {
  width: 100%;
  animation: menuFadeIn 0.25s ease;
}

@keyframes menuFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Scroll indicator arrows for scrollable containers */
.scroll-indicator {
  position: sticky;
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  z-index: 5;
  color: rgba(68,136,255,0.6);
  font-size: 14px;
  text-shadow: 0 0 10px rgba(68,136,255,0.4);
  padding: 2px 0;
  margin: 0;
  flex-shrink: 0;
}
.scroll-indicator.top {
  top: 0;
  animation: scrollPulseUp 1.5s ease-in-out infinite;
  background: linear-gradient(180deg, rgba(6,6,15,0.95) 20%, transparent);
}
.scroll-indicator.bottom {
  bottom: 0;
  animation: scrollPulseDown 1.5s ease-in-out infinite;
  background: linear-gradient(0deg, rgba(6,6,15,0.95) 20%, transparent);
}
.scroll-indicator.hidden { display: none; }
@keyframes scrollPulseDown {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.9; }
}
@keyframes scrollPulseUp {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.9; }
}

/* Campaign mission list */
.campaign-mission-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 4px;
  border: 1px solid rgba(68, 136, 255, 0.1);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  min-height: 44px;
}
.campaign-mission-item:active { background: rgba(68, 136, 255, 0.1); }
@media (min-width: 768px) {
  .campaign-mission-item:hover { background: rgba(68, 136, 255, 0.08); border-color: rgba(68, 136, 255, 0.25); }
}
.campaign-mission-item.selected { border-color: rgba(68, 136, 255, 0.5); background: rgba(68, 136, 255, 0.1); }
.campaign-mission-item.completed { border-color: rgba(68, 200, 120, 0.3); }
.campaign-mission-item.completed .mission-num { color: #66ddaa; }
.campaign-mission-item.locked { opacity: 0.35; pointer-events: none; cursor: default; }
.mission-num { font-size: 12px; color: #4488ff; font-weight: 700; min-width: 24px; }
.mission-title { font-size: 13px; color: #ccccdd; flex: 1; }
.mission-check { font-size: 14px; color: #66ddaa; }

/* Campaign briefing */
#campaign-briefing { display: none; }
#campaign-briefing[style*="flex"] { display: flex; }

/* Campaign dialogue animation */
#campaign-dialogue {
  animation: dialogueSlideIn 0.3s ease;
}
/* Desktop: bigger dialogue box */
@media (min-width: 768px) {
  #campaign-dialogue {
    max-width: 700px !important;
    bottom: 100px !important;
  }
  #campaign-dialogue #dialogue-speaker {
    font-size: 15px !important;
  }
  #campaign-dialogue #dialogue-line {
    font-size: 17px !important;
  }
}
@keyframes dialogueSlideIn {
  from { opacity: 0; transform: translateX(-50%) translateY(15px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Tutorial highlight glow — pulses on buttons/elements to guide the player */
.tutorial-glow {
  animation: tutorialPulse 1.2s ease-in-out infinite !important;
  box-shadow: 0 0 15px rgba(255,200,50,0.6), 0 0 30px rgba(255,200,50,0.3), inset 0 0 8px rgba(255,200,50,0.1) !important;
  border-color: rgba(255,200,50,0.7) !important;
  position: relative;
  z-index: 2;
}
@keyframes tutorialPulse {
  0%, 100% { box-shadow: 0 0 10px rgba(255,200,50,0.4), 0 0 20px rgba(255,200,50,0.15); }
  50% { box-shadow: 0 0 20px rgba(255,200,50,0.8), 0 0 40px rgba(255,200,50,0.3), inset 0 0 10px rgba(255,200,50,0.15); }
}

/* Supernova fullscreen warning flash */
@keyframes supernovaFlash {
  0% { opacity: 0; }
  10% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes supernovaTextPulse {
  0% { opacity: 0; transform: scale(0.9); }
  10% { opacity: 1; transform: scale(1.05); }
  20% { transform: scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.02); }
}

/* Save manager items */
.save-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 4px;
  border: 1px solid rgba(68, 200, 120, 0.15);
  border-radius: 8px;
  background: rgba(68, 200, 120, 0.03);
  min-height: 40px;
}
.save-item:active { background: rgba(68, 200, 120, 0.1); }
@media (min-width: 768px) {
  .save-item:hover { background: rgba(68, 200, 120, 0.08); border-color: rgba(68, 200, 120, 0.3); }
}
.save-item .save-info { flex: 1; cursor: pointer; }
.save-item .save-name { font-size: 12px; color: #66ddaa; font-weight: 600; }
.save-item .save-detail { font-size: 10px; color: #667; margin-top: 2px; }
.save-item .save-delete {
  font-size: 16px; color: #ff6666; cursor: pointer; opacity: 0.5;
  background: none; border: none; padding: 4px 8px; font-family: inherit;
  min-width: 32px; min-height: 32px; display: flex; align-items: center; justify-content: center;
}
.save-item .save-delete:hover { opacity: 1; }

/* Player scoreboard */
.scoreboard-player {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: rgba(6, 6, 15, 0.75);
  border-radius: 6px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  min-width: 120px;
}
.scoreboard-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.scoreboard-name {
  font-size: 11px;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 80px;
}
.scoreboard-stats {
  font-size: 10px;
  color: #8888aa;
  white-space: nowrap;
}
.scoreboard-player.eliminated {
  opacity: 0.3;
  text-decoration: line-through;
}
.scoreboard-player.disconnected {
  opacity: 0.5;
}

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

#difficulty-select { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.diff-label { font-size: 10px; color: var(--text-secondary); letter-spacing: 2px; text-transform: uppercase; font-weight: 600; }
.diff-buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; width: 100%; }
.diff-btn { padding: 10px 16px !important; font-size: 12px !important; letter-spacing: 1px; min-height: 40px; flex: 1; min-width: 70px; }
.diff-btn.active, .camp-diff-btn.active, #mp-mode .active { background: rgba(68, 136, 255, 0.35) !important; box-shadow: 0 0 12px rgba(68, 136, 255, 0.3); border-color: rgba(68, 136, 255, 0.6) !important; }

/* ============ HINT BAR ============ */
#hint-bar {
  position: absolute;
  bottom: 60px; left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: clamp(12px, 3vw, 13px);
  color: var(--glow-cyan);
  letter-spacing: 0.3px;
  text-align: center;
  max-width: 90vw;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
  text-shadow: 0 0 8px rgba(68, 136, 255, 0.3);
  line-height: 1.4;
  z-index: 3;
}

#hint-bar.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(10px);
}

@media (max-width: 767px) {
  #hint-bar { bottom: 110px; }
}

/* ============ TOASTS ============ */
#toast-container {
  position: absolute;
  top: 42px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  z-index: 10;
}

.toast {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: clamp(11px, 2.8vw, 12px);
  color: var(--text-primary);
  white-space: nowrap;
  animation: toast-in 0.3s ease, toast-out 0.4s ease 2.6s forwards;
  text-shadow: 0 0 6px rgba(68, 136, 255, 0.2);
}

.toast.conquest { border-color: rgba(68, 200, 120, 0.5); color: #66ddaa; }
.toast.enemy    { border-color: rgba(255, 59, 92, 0.5); color: #ff8899; }
.toast.build    { border-color: rgba(255, 204, 0, 0.5); color: #ffdd55; }
.toast.upgrade  { border-color: rgba(136, 68, 255, 0.5); color: #aa88ff; }
.toast.event    { border-color: rgba(255, 170, 50, 0.5); color: #ffbb66; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateY(-10px); }
}

/* ============ FLEET BANNER ============ */
#fleet-banner {
  position: absolute;
  top: 40px; left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 204, 0, 0.12);
  border: 1px solid rgba(255, 204, 0, 0.4);
  border-radius: 8px;
  padding: 8px 18px;
  font-size: clamp(10px, 2.5vw, 12px);
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #ffdd66;
  text-shadow: 0 0 8px rgba(255, 204, 0, 0.3);
  white-space: nowrap;
  transition: opacity 0.3s;
  z-index: 5;
}

#fleet-banner.hidden {
  opacity: 0;
  pointer-events: none !important;
}

/* ============ PAUSE OVERLAY ============ */
#pause-overlay {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(32px, 8vw, 64px);
  font-weight: 200;
  letter-spacing: 12px;
  color: var(--glow-cyan);
  text-shadow: 0 0 40px rgba(68, 136, 255, 0.5);
  pointer-events: none;
  opacity: 0.7;
  z-index: 5;
}

/* Now Playing indicator */
#now-playing {
  position: absolute;
  bottom: 12px; left: 12px;
  background: var(--panel-bg);
  border: 1px solid rgba(136, 68, 255, 0.2);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 10px;
  color: #aa88cc;
  letter-spacing: 0.3px;
  pointer-events: none;
  z-index: 3;
  transition: opacity 0.5s;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#now-playing.hidden { opacity: 0; }

/* Objectives panel — centered on screen */
#objectives-panel {
  width: 320px;
  padding: 16px;
  z-index: 25 !important;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 14px;
}
#objectives-panel.hidden {
  transform: translate(-50%, -50%) scale(0.95);
}
@media (max-width: 767px) {
  #objectives-panel { width: 90%; max-width: 340px; }
}

/* Settings panel — centered on screen */
#settings-panel {
  width: 280px;
  padding: 20px;
  z-index: 25 !important;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 14px;
}
#settings-panel.hidden {
  transform: translate(-50%, -50%) scale(0.95);
}
@media (max-width: 767px) {
  #settings-panel {
    width: 90%;
    max-width: 320px;
  }
}

/* Picking overlay — prominent top-center banner */
#picking-overlay {
  position: absolute;
  top: 60px; left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 16px 32px;
  font-size: clamp(16px, 4vw, 22px);
  font-weight: 600;
  letter-spacing: 2px;
  text-align: center;
  color: var(--glow-cyan);
  text-shadow: 0 0 15px rgba(68, 136, 255, 0.5);
  pointer-events: none;
  z-index: 10;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  min-width: 280px;
}
#picking-overlay.hidden { display: none; }
#picking-overlay.my-turn {
  color: #ffcc00;
  border-color: rgba(255, 204, 0, 0.4);
  text-shadow: 0 0 10px rgba(255, 204, 0, 0.4);
}

#pause-overlay.hidden { display: none; }

/* Lobby screen */
#lobby-screen { display: flex; }
#lobby-screen.hidden { display: none !important; }

/* Styled dropdowns — 44px min touch target */
.styled-select {
  min-height: 36px;
  padding: 6px 28px 6px 10px;
  font-size: 13px;
  background: rgba(10, 10, 30, 0.8);
  border: 1px solid rgba(68, 136, 255, 0.3);
  border-radius: 8px;
  color: #d0d8f0;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2388ccff'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.styled-select option {
  background: #0a0a1a;
  color: #d0d8f0;
  padding: 8px;
  font-size: 14px;
}

/* Lobby toggle buttons */
.lobby-toggle {
  border-color: rgba(68, 136, 255, 0.15);
  background: rgba(255, 255, 255, 0.02);
  transition: background 0.15s, border-color 0.15s;
}
.lobby-toggle:active {
  background: rgba(68, 136, 255, 0.1);
}

/* Lobby tabs */
.lobby-tab.active {
  color: #88ccff !important;
  border-bottom-color: #4488ff !important;
}

/* Mobile lobby — single column with tabs */
@media (max-width: 767px) {
  #lobby-tabs { display: flex !important; }
  #lobby-content { flex-direction: column !important; }
  #lobby-left {
    flex: 1 1 auto !important;
    border-right: none !important;
  }
  #lobby-chat-section { display: none; }
  #lobby-left.show-settings #lobby-players-section { display: none; }
  #lobby-left.show-chat { display: none !important; }
  #lobby-chat-section.show-chat {
    display: flex !important;
    flex: 1;
  }
}

/* Landscape phone — wider left panel */
@media (max-height: 500px) {
  #lobby-left { flex: 0 0 320px !important; }
  #lobby-settings { overflow-y: auto; max-height: 45vh; }
}

/* Disabled settings for non-host */
#lobby-settings.guest-view .glow-btn,
#lobby-settings.guest-view .styled-select,
#lobby-settings.guest-view input[type="range"],
#lobby-settings.guest-view input[type="text"],
#lobby-settings.guest-view .shape-btn,
#lobby-settings.guest-view #lobby-reseed {
  pointer-events: none;
  opacity: 0.5;
}
#lobby-settings.guest-view #lobby-start-picking { display: none; }

.shape-btn.active {
  background: rgba(68, 136, 255, 0.3) !important;
  border-color: rgba(68, 136, 255, 0.5) !important;
  color: var(--glow-cyan) !important;
}

/* Lobby in picking mode — left side panel, full height */
#lobby-screen.picking-mode {
  top: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
  right: auto !important;
  width: 260px !important;
  height: 100vh !important;
  max-height: 100vh !important;
  background: rgba(6,6,15,0.95) !important;
  border-right: 1px solid rgba(68,136,255,0.2);
  border-radius: 0;
  flex-direction: column;
  z-index: 20;
  overflow: hidden !important;
}

/* Picking mode header — compact for narrow panel */
#lobby-screen.picking-mode > div:first-child {
  padding: 6px 10px;
  gap: 6px;
}
/* Hide spacer in header, let title fill remaining space */
#lobby-screen.picking-mode > div:first-child > div:last-child {
  display: none !important;
}
/* Hide tabs during picking */
#lobby-screen.picking-mode #lobby-tabs {
  display: none !important;
}
#lobby-screen.picking-mode #lobby-leave {
  min-height: 32px;
  padding: 0 10px;
  font-size: 11px;
  flex-shrink: 0;
}
#lobby-screen.picking-mode #lobby-code {
  font-size: 14px;
  letter-spacing: 4px;
}

/* Content wrapper becomes a simple column stretcher */
#lobby-screen.picking-mode #lobby-content {
  flex: 1 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  padding: 0 !important;
  min-height: 0 !important;
}

/* Left column fills full height — override ALL inline styles */
#lobby-screen.picking-mode #lobby-left {
  flex: 1 1 0 !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  padding: 10px !important;
  border-right: none !important;
  width: 100% !important;
}

/* Players section fills the middle */
#lobby-screen.picking-mode #lobby-players-section {
  flex: 1 1 auto !important;
  overflow-y: auto !important;
  min-height: 0 !important;
}
/* Player list scrolls if too many players */
#lobby-screen.picking-mode #lobby-players {
  overflow-y: auto;
  flex-shrink: 1;
  min-height: 0;
}

/* Pick status pinned at bottom — contained within panel */
#lobby-screen.picking-mode #lobby-pick-status {
  flex-shrink: 0;
  display: flex !important;
  box-sizing: border-box;
  max-width: 100%;
  overflow: hidden;
  flex-direction: column;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid rgba(68,136,255,0.15);
}

#lobby-screen.picking-mode #lobby-confirm-start {
  margin-top: 8px;
  box-sizing: border-box;
  max-width: 100%;
  width: 100%;
  padding-left: 10px;
  padding-right: 10px;
}

/* Hide chat and settings during picking — just show players + instructions */
#lobby-screen.picking-mode #lobby-chat,
#lobby-screen.picking-mode #chat-input,
#lobby-screen.picking-mode #chat-send,
#lobby-screen.picking-mode #lobby-settings {
  display: none !important;
}

/* Hide the right chat column during picking */
#lobby-screen.picking-mode #lobby-chat-section {
  display: none !important;
}

@media (max-width: 767px) {
  #lobby-screen.picking-mode {
    width: 200px !important;
  }
}

/* ============ UPGRADES PANEL ============ */
#upgrades-panel {
  width: 340px;
  max-height: 70vh;
  padding: 16px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(68,136,255,0.2) transparent;
}

@media (max-width: 767px) {
  #upgrades-panel {
    bottom: calc(52px + var(--safe-bottom));
    left: 0; right: 0;
    width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 50vh;
  }
  #upgrades-panel.hidden { transform: translateY(100%); }

  #upgrades-panel::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    margin: 0 auto 10px;
  }
}

@media (min-width: 768px) {
  #upgrades-panel { top: 50px; left: 12px; }
  #upgrades-panel.hidden { transform: translateX(-20px); }
}

.upgrade-branch-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin: 14px 0 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(68, 136, 255, 0.15);
}

.upgrade-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  margin: 4px 0;
  border-radius: 8px;
  border: 1px solid rgba(68, 136, 255, 0.1);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, opacity 0.15s;
  cursor: default;
  min-height: 48px;
}

.upgrade-item.available { border-color: rgba(136, 68, 255, 0.4); cursor: pointer; }
.upgrade-item.available:active { background: rgba(136, 68, 255, 0.15); box-shadow: 0 0 12px rgba(136, 68, 255, 0.15); }
@media (min-width: 768px) {
  .upgrade-item.available:hover { background: rgba(136, 68, 255, 0.1); box-shadow: 0 0 12px rgba(136, 68, 255, 0.15); }
}
.upgrade-item.unlocked { border-color: rgba(68, 200, 120, 0.3); background: rgba(68, 200, 120, 0.05); }
.upgrade-item.cant-afford { border-color: rgba(255, 102, 102, 0.2); opacity: 0.65; cursor: default; }
.upgrade-item.locked { opacity: 0.35; }

.upgrade-icon { font-size: 24px; width: 32px; text-align: center; flex-shrink: 0; line-height: 1.2; }
.upgrade-details { flex: 1; min-width: 0; }
.upgrade-name { font-size: 12px; font-weight: 700; color: var(--text-primary); margin-bottom: 2px; }
.upgrade-desc { font-size: 11px; color: var(--text-secondary); line-height: 1.3; }
.upgrade-cost { font-size: 10px; font-weight: 600; margin-top: 3px; }
.upgrade-status { font-size: 10px; font-weight: 700; letter-spacing: 0.5px; flex-shrink: 0; align-self: center; }

/* ============ SOUND TOGGLE ============ */
#sound-toggle { line-height: 1; }
#sound-toggle.muted { opacity: 0.4; }

/* ============ CONQUEST FLASH ============ */
.conquest-flash {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 6;
  animation: flash 0.5s ease-out forwards;
}

@keyframes flash {
  0% { opacity: 0.15; }
  100% { opacity: 0; }
}

/* Fleet slider */
#fleet-slider {
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  border-radius: 4px;
  background: rgba(255,170,50,0.15);
  outline: none;
}
#fleet-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #ffaa44;
  cursor: pointer;
  box-shadow: 0 0 10px rgba(255,170,50,0.4);
}
#fleet-slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #ffaa44;
  cursor: pointer;
  border: none;
  box-shadow: 0 0 10px rgba(255,170,50,0.4);
}

/* ============ MOBILE OVERRIDES ============ */
@media (max-width: 767px) {
  /* All buttons: minimum 44px touch target */
  .glow-btn { min-height: 44px; }
  .action-btn { min-height: 48px; padding: 12px; font-size: 13px; }
  .scrap-btn { min-height: 40px; padding: 8px 14px; font-size: 11px; }
  .diff-btn { min-height: 44px !important; padding: 10px 16px !important; }

  /* Bottom nav: bigger buttons */
  .nav-btn { min-width: 48px; min-height: 46px; padding: 6px 10px; }
  .speed-btn { min-height: 40px; min-width: 36px; font-size: 12px; }

  /* Slider thumb: bigger for fat fingers */
  #fleet-slider::-webkit-slider-thumb { width: 34px; height: 34px; }
  #fleet-slider::-moz-range-thumb { width: 34px; height: 34px; }
  #fleet-slider { height: 10px; }

  /* Structure items: taller */
  .structure-item { min-height: 40px; padding: 8px 0; }

  /* Upgrade items: taller tap area */
  .upgrade-item { min-height: 56px; padding: 12px; }

  /* Resource bar: still readable on small screens */
  #resource-bar { gap: clamp(6px, 2vw, 16px); padding: 0 6px; height: 40px; }
  .resource { font-size: 14px; gap: 4px; }

  /* Panels: more padding for fat fingers */
  #star-panel { padding: 14px 16px; }
  .panel-header { font-size: 15px; }
}

/* ============ WEBKIT SCROLLBAR ============ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(68,136,255,0.2); border-radius: 3px; }

/* ============ SMALL SCREEN OVERRIDES ============ */
/* Phones: the full 13-button row is ~740px wide and scrolled half of it off
   screen with no hint it existed. Drop what a touch screen doesn't need
   (pinch zooms, edge-scroll/scroll-speed are mouse features, volume and
   fullscreen live in Settings/the browser) and tighten the rest so every
   remaining control is visible at 360px. */
/* Touch screens of any size: edge-scroll and scroll speed are cursor features. */
@media (hover: none) and (pointer: coarse) {
  #edge-scroll-btn, #scroll-speed-control { display: none !important; }
}
@media (max-width: 480px) {
  #zoom-controls, #edge-scroll-btn, #scroll-speed-control, #sound-toggle, #fullscreen-btn { display: none !important; }
  #bottom-nav { gap: 3px; }
  .nav-btn { min-width: 44px; padding: 6px 4px; }
  .nav-btn span, .nav-btn .nav-label { font-size: 9px; letter-spacing: 0; }
  .speed-btn { min-width: 32px; padding: 0 6px; }
}
@media (max-width: 380px) {
  #resource-bar { font-size: 12px; gap: 6px; }
  .res-icon-svg { width: 14px; height: 14px; }
}


/* ============ FOCUS-VISIBLE ============ */
.nav-btn:focus-visible, .glow-btn:focus-visible, .speed-btn:focus-visible {
  outline: 2px solid #4488ff;
  outline-offset: 2px;
}

/* ============ FPS OVERLAY ============ */
/* Toggled from Settings. JS accumulates values and writes textContent at most
   every 500ms — this element must never trigger layout of the game UI. */
#fps-overlay {
  position: fixed;
  bottom: 70px;
  left: 10px;
  z-index: 60;
  padding: 3px 8px;
  font-family: Consolas, 'Courier New', monospace;
  font-size: 11px;
  color: #66ddaa;
  background: rgba(6, 6, 15, 0.7);
  border: 1px solid rgba(68, 136, 255, 0.2);
  border-radius: 6px;
  pointer-events: none;
  white-space: nowrap;
}

/* ============ LOW GRAPHICS MODE ============ */
/* body.gfx-low is set by main.js when NOVA_GFX.low is on (Settings → Low, or
   Auto on weak hardware / sustained slow frames). Drops the GPU-heavy backdrop
   blurs — compensated with a more opaque background — and stops infinite CSS
   animations. Default/High mode is pixel-identical to before. */
body.gfx-low .panel,
body.gfx-low .scoreboard-player,
body.gfx-low #hint-bar,
body.gfx-low #picking-overlay {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  background: rgba(10, 12, 24, 0.95);
}
/* Inline-styled blur dialogs in index.html — inline styles need !important */
body.gfx-low #pick-confirm-popup > div,
body.gfx-low #campaign-dialogue > div {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
/* Build-bar shimmer sweep — static fill instead */
body.gfx-low .build-progress-fill {
  animation: none;
  background-image: none;
}
/* Tutorial pulse — keep the static glow from .tutorial-glow, stop the loop */
body.gfx-low .tutorial-glow {
  animation: none !important;
}

/* ============ REDUCED MOTION ============ */
/* Decorative HUD motion only — the map itself is the game and keeps moving.
   Users who ask for less motion get static toasts/dialogues/pulses and no
   screen flash on conquest. */
@media (prefers-reduced-motion: reduce) {
  .tutorial-glow, .scroll-indicator, .conquest-flash, .toast, #campaign-dialogue, .menu-page, .shimmer {
    animation: none !important;
    transition: none !important;
  }
  .conquest-flash { display: none !important; }
}

/* ============ PHONE: keep corner chips off the bottom nav ============ */
/* On narrow screens the bottom nav is full-width and scrolls, so the
   now-playing label and the bug-report chip would sit on top of its buttons.
   Lift them above the nav and shrink the chip to its icon. */
/* Up to ~1100px the nav row still reaches the left edge (tablets, small
   laptops) and covered the speed buttons with the now-playing label. */
@media (max-width: 1100px) {
  #now-playing { bottom: calc(60px + var(--safe-bottom)); left: 8px; }
}
@media (max-width: 767px) {
  #now-playing { font-size: 9px; padding: 4px 8px; max-width: 150px; }
  #bug-hint { bottom: calc(60px + var(--safe-bottom)) !important; right: 8px !important; padding: 4px 7px !important; }
  /* the star bottom sheet slides up over this corner; don't float the bug
     button on top of the build list */
  body:has(#star-panel:not(.hidden)) #bug-hint { display: none !important; }
  #bug-hint span:not(:first-child) { display: none; }
}
