:root {
  --space-black: #0a0a0f;
  --panel-metal: #1a1a2e;
  --panel-dark: #121220;
  --panel-soft: rgba(26, 26, 46, 0.86);
  --edge-cyan: #00d4ff;
  --edge-amber: #ffa500;
  --text-amber: #ffa500;
  --text-green: #00ff41;
  --text-white: #eef7ff;
  --text-muted: #a8b6cc;
  --alert-red: #ff4444;
  --bg-blur: rgba(10, 10, 15, 0.55);
  --shadow-cyan: 0 0 18px rgba(0, 212, 255, 0.22);
  --shadow-amber: 0 0 18px rgba(255, 165, 0, 0.22);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  position: relative;
  font-family: 'Space Grotesk', 'Segoe UI', sans-serif;
  color: var(--text-amber);
  background-color: var(--space-black);
  background-image:
    radial-gradient(circle at 18% 22%, rgba(0, 212, 255, 0.1), transparent 35%),
    radial-gradient(circle at 80% 7%, rgba(255, 165, 0, 0.1), transparent 28%),
    url('/assets/backgrounds/desktop-bg.png');
  background-size: auto, auto, cover;
  background-position: center, center, center;
  background-attachment: fixed;
  line-height: 1.4;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.11;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.06),
    rgba(255, 255, 255, 0.06) 1px,
    transparent 1px,
    transparent 3px
  );
}

.starfield,
.scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
}

.starfield {
  z-index: 0;
  background-image:
    radial-gradient(1px 1px at 8% 22%, rgba(255, 255, 255, 0.65), transparent 70%),
    radial-gradient(1px 1px at 30% 75%, rgba(255, 255, 255, 0.75), transparent 70%),
    radial-gradient(1.5px 1.5px at 46% 15%, rgba(0, 212, 255, 0.65), transparent 70%),
    radial-gradient(1.5px 1.5px at 68% 44%, rgba(255, 165, 0, 0.75), transparent 70%),
    radial-gradient(1px 1px at 84% 80%, rgba(255, 255, 255, 0.65), transparent 70%),
    radial-gradient(1px 1px at 92% 18%, rgba(0, 212, 255, 0.7), transparent 70%);
  animation: starDrift 90s linear infinite;
}

.scanlines {
  z-index: 1;
}

@keyframes starDrift {
  0% {
    transform: translateY(0);
  }
  100% {
    transform: translateY(-140px);
  }
}

.frame {
  position: relative;
  z-index: 2;
  width: min(1320px, 96vw);
  margin: 0.75rem auto 6rem;
}

h1,
h2,
h3,
h4,
h5,
summary {
  margin: 0;
  font-family: 'Chakra Petch', 'Space Grotesk', sans-serif;
  letter-spacing: 0.06em;
  color: var(--text-white);
}

p {
  margin: 0.45rem 0;
}

a {
  color: var(--edge-cyan);
  text-decoration: none;
}

a:hover,
a:focus-visible {
  text-shadow: var(--shadow-cyan);
}

.panel,
.metric,
.panel-lite,
.auth-grid > div,
details.manual-section {
  background: linear-gradient(165deg, rgba(29, 31, 55, 0.9), rgba(15, 16, 29, 0.95));
  border: 1px solid rgba(0, 212, 255, 0.35);
  border-top-color: rgba(255, 165, 0, 0.5);
  border-left-color: rgba(255, 255, 255, 0.14);
  border-right-color: rgba(0, 212, 255, 0.22);
  border-bottom-color: rgba(255, 165, 0, 0.2);
  box-shadow: inset 0 0 24px rgba(255, 255, 255, 0.02), 0 0 12px rgba(0, 212, 255, 0.1);
  backdrop-filter: blur(4px);
  border-radius: var(--radius);
}

.panel {
  padding: 0.9rem;
  margin-bottom: 0.8rem;
}

.panel-lite,
.metric,
.auth-grid > div {
  padding: 0.75rem;
}

.sub {
  margin-top: 0.35rem;
  color: var(--edge-cyan);
  font-size: 0.93rem;
}

.resource-gold {
  color: var(--text-amber);
}

.resource-crystal {
  color: var(--edge-cyan);
}

.resource-plutonium {
  color: #ba68ff;
}

.roid-rate {
  color: var(--text-muted);
}

.topbar {
  display: grid;
  gap: 0.8rem;
}

.topbar-side {
  display: grid;
  gap: 0.65rem;
}

.tick-box {
  display: grid;
  gap: 0.2rem;
  padding: 0.6rem;
  border-radius: 10px;
  font-family: 'Chakra Petch', monospace;
  color: var(--text-green);
  border: 1px solid rgba(0, 255, 65, 0.4);
  background: linear-gradient(180deg, rgba(0, 20, 0, 0.6), rgba(0, 10, 0, 0.85));
  text-shadow: 0 0 8px rgba(0, 255, 65, 0.65);
  box-shadow: inset 0 0 24px rgba(0, 255, 65, 0.1), 0 0 14px rgba(0, 255, 65, 0.15);
}

.push-box {
  display: grid;
  gap: 0.35rem;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-title {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--text-white);
  text-shadow: 0 0 12px rgba(0, 212, 255, 0.5), 0 0 24px rgba(0, 212, 255, 0.2);
  margin: 0;
}

.beta-badge {
  display: inline-block;
  font-size: 0.55rem;
  font-family: 'Chakra Petch', monospace;
  letter-spacing: 0.15em;
  color: var(--text-amber);
  border: 1px solid var(--text-amber);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  margin-left: 0.4rem;
  vertical-align: super;
  opacity: 0.85;
}

.resource-bar {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  font-family: 'Chakra Petch', monospace;
  font-size: 0.9rem;
}

.resource-item {
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(10, 10, 15, 0.7);
}

.auth-grid,
.grid-2,
.grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.auth-grid {
  max-width: 920px;
  margin: 0 auto;
}

.auth-grid > div {
  background:
    radial-gradient(circle at 90% 5%, rgba(0, 212, 255, 0.09), transparent 35%),
    radial-gradient(circle at 10% 100%, rgba(255, 165, 0, 0.08), transparent 38%),
    linear-gradient(165deg, rgba(24, 26, 45, 0.92), rgba(14, 14, 26, 0.92));
}

.form-stack {
  display: grid;
  gap: 0.5rem;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: end;
}

label {
  display: grid;
  gap: 0.15rem;
  color: var(--text-muted);
}

input,
textarea,
select {
  width: 100%;
  min-height: 2.4rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 165, 0, 0.42);
  background: rgba(7, 10, 18, 0.88);
  color: var(--text-white);
  padding: 0.48rem 0.6rem;
  font-size: 0.95rem;
  font-family: 'Space Grotesk', sans-serif;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--edge-cyan);
  box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.22), 0 0 10px rgba(255, 165, 0, 0.2);
}

button,
.manual-link {
  border: 1px solid rgba(0, 212, 255, 0.5);
  border-top-color: rgba(255, 255, 255, 0.3);
  border-left-color: rgba(255, 255, 255, 0.2);
  border-right-color: rgba(0, 212, 255, 0.35);
  border-bottom-color: rgba(255, 165, 0, 0.35);
  border-radius: 8px;
  padding: 0.48rem 0.7rem;
  min-height: 2.4rem;
  background: linear-gradient(180deg, rgba(45, 54, 82, 0.95), rgba(20, 26, 43, 0.95));
  color: var(--edge-cyan);
  font-family: 'Chakra Petch', sans-serif;
  letter-spacing: 0.04em;
  text-align: center;
  cursor: pointer;
  text-transform: uppercase;
}

button:hover,
button:focus-visible,
.manual-link:hover,
.manual-link:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 0 0 1px rgba(0, 212, 255, 0.45), var(--shadow-cyan);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.danger {
  border-color: rgba(255, 68, 68, 0.6);
  color: var(--alert-red);
  background: linear-gradient(180deg, rgba(68, 23, 27, 0.95), rgba(35, 12, 14, 0.95));
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav button,
.nav .manual-link {
  width: 100%;
}

.nav button.active {
  color: var(--text-white);
  border-color: rgba(0, 212, 255, 0.75);
  box-shadow: 0 0 0 1px rgba(255, 165, 0, 0.32), var(--shadow-cyan);
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.nav-group-toggle {
  display: none; /* hidden on desktop */
}

.nav-group-items {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

/* Desktop: show label as before */
.nav-group-toggle + .nav-group-items::before {
  content: attr(data-label);
}

.nav-group[data-collapsible]::before {
  content: attr(data-label);
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 0.1rem 0.4rem;
  font-family: 'Chakra Petch', sans-serif;
}

.nav-chevron {
  font-size: 0.6rem;
  transition: transform 0.2s ease;
  display: inline-block;
  pointer-events: none;
}

.nav-group-toggle[aria-expanded="true"] .nav-chevron {
  transform: rotate(90deg);
}

/* Mobile: collapsible dropdown nav */
@media (max-width: 719px) {
  .nav {
    display: flex !important;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0.4rem;
  }

  /* Hide the desktop ::before label on mobile */
  .nav-group[data-collapsible]::before {
    display: none;
  }

  .nav-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    text-transform: uppercase;
    font-family: 'Chakra Petch', sans-serif;
    padding: 0.5rem 0.6rem;
    border: 1px solid rgba(0, 212, 255, 0.15);
    border-radius: 4px;
    background: rgba(0, 212, 255, 0.04);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
  }

  .nav-group-toggle:hover,
  .nav-group-toggle[aria-expanded="true"] {
    background: rgba(0, 212, 255, 0.08);
    border-color: rgba(0, 212, 255, 0.35);
    color: var(--text-white, #e0e0e0);
  }

  .nav-group-items {
    display: none;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.25rem 0 0 0.6rem;
  }

  .nav-group-items.open {
    display: flex;
  }

  .nav-group-items button {
    font-size: 0.72rem;
    padding: 0.35rem 0.5rem;
  }

  .nav > button,
  .nav .manual-link,
  .nav #logoutBtn {
    font-size: 0.72rem;
    padding: 0.35rem 0.3rem;
  }

  .nav .manual-link,
  .nav #logoutBtn {
    text-align: center;
  }
}

.hidden {
  display: none;
}

.view {
  display: none;
  animation: panelIn 0.25s ease;
}

.view.active {
  display: block;
}

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

.metric {
  color: var(--text-white);
}

.terminal {
  background: rgba(5, 9, 12, 0.94);
  border: 1px solid rgba(0, 255, 65, 0.35);
  border-radius: 8px;
  color: var(--text-green);
  font-family: 'Courier New', monospace;
  font-size: 0.88rem;
  text-shadow: 0 0 10px rgba(0, 255, 65, 0.45);
  max-height: 380px;
  overflow: auto;
  padding: 0.6rem;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.table th,
.table td {
  border: 1px solid rgba(112, 128, 168, 0.35);
  padding: 0.45rem;
  text-align: left;
  vertical-align: top;
}

.table thead th {
  background: linear-gradient(180deg, rgba(0, 212, 255, 0.18), rgba(10, 28, 43, 0.75));
  color: var(--text-white);
  letter-spacing: 0.05em;
}

.table tbody tr:nth-child(odd) td {
  background: rgba(11, 15, 27, 0.72);
}

.table tbody tr:nth-child(even) td {
  background: rgba(16, 20, 34, 0.72);
}

.wave-box {
  border: 1px dashed rgba(0, 212, 255, 0.45);
  border-radius: 8px;
  padding: 0.55rem;
}

.ship-input-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
}

.ship-field {
  display: grid;
  gap: 0.15rem;
  font-size: 0.82rem;
}

.shipyard-shell {
  display: grid;
  gap: 0.75rem;
}

.shipyard-queue-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.shipyard-queue-list {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.shipyard-queue-item,
.shipyard-queue-empty,
.shipyard-unlisted-note {
  border-radius: 8px;
  border: 1px solid rgba(0, 212, 255, 0.3);
  background: rgba(5, 12, 20, 0.72);
  padding: 0.42rem 0.5rem;
}

.shipyard-queue-item {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.shipyard-class-section {
  border-radius: var(--radius);
  border: 1px solid rgba(0, 212, 255, 0.28);
  overflow: hidden;
  background: rgba(12, 15, 27, 0.8);
}

.shipyard-class-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(180deg, rgba(31, 41, 67, 0.8), rgba(17, 23, 35, 0.78));
}

.shipyard-class-header h3 {
  font-size: 1rem;
}

.shipyard-class-table-wrap {
  overflow-x: auto;
}

.ship-summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 240px;
}

.ship-icon {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid rgba(0, 212, 255, 0.45);
  background: rgba(4, 8, 16, 0.8);
}

.ship-role {
  margin-top: 0.2rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.ship-class-badge {
  display: inline-block;
  margin-top: 0.2rem;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--text-white);
  border: 1px solid currentColor;
}

.ship-class-light,
.shipyard-class-header.ship-class-light {
  color: #00ff41;
}

.ship-class-medium,
.shipyard-class-header.ship-class-medium {
  color: #2ea7ff;
}

.ship-class-specialist,
.shipyard-class-header.ship-class-specialist {
  color: #ba68ff;
}

.ship-class-capital,
.shipyard-class-header.ship-class-capital {
  color: #ff4444;
}

.ship-class-economy,
.shipyard-class-header.ship-class-economy {
  color: #ffa500;
}

.research-lock {
  color: var(--alert-red);
  font-weight: 700;
}

.research-ready {
  color: var(--text-green);
}

.ship-locked td {
  opacity: 0.86;
}

.ship-lock-note {
  margin-top: 0.3rem;
  color: var(--alert-red);
  font-size: 0.76rem;
}

.ship-owned-count {
  font-weight: 700;
}

.build-form {
  display: grid;
  gap: 0.28rem;
}

.build-controls {
  display: grid;
  grid-template-columns: 34px minmax(70px, 1fr) 34px 1fr;
  gap: 0.3rem;
  align-items: center;
}

.build-controls button,
.build-controls input {
  min-height: 2rem;
}

.step-btn {
  font-size: 1rem;
  font-weight: 700;
}

.eta-line {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.cv-tag {
  color: var(--edge-cyan);
}

.fleet-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.35rem;
  margin-bottom: 0.6rem;
}

.ship-inventory-lines {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.ship-inventory-line {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: 8px;
  border: 1px solid rgba(0, 212, 255, 0.3);
  background: rgba(5, 12, 20, 0.72);
  padding: 0.3rem 0.45rem;
}

.ship-inline-icon {
  width: 20px;
  height: 20px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid rgba(0, 212, 255, 0.35);
  background: rgba(4, 8, 16, 0.8);
}

.fleet-summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid currentColor;
  border-radius: 8px;
  padding: 0.28rem 0.42rem;
  background: rgba(6, 12, 20, 0.78);
}

.fleet-summary-count {
  font-weight: 700;
}

.fleet-summary-empty {
  margin-bottom: 0.6rem;
  color: var(--text-muted);
}

.planet-id-cell {
  white-space: nowrap;
}

.galaxy-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.mini-scout {
  min-height: 1.85rem;
  padding: 0.25rem 0.55rem;
  font-size: 0.76rem;
}

.mini-attack {
  min-height: 1.85rem;
  padding: 0.25rem 0.55rem;
  font-size: 0.76rem;
}

#flash {
  position: fixed;
  left: 50%;
  bottom: 0.9rem;
  transform: translateX(-50%);
  min-width: min(92vw, 560px);
  max-width: min(92vw, 560px);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(0, 212, 255, 0.45);
  background: rgba(4, 10, 18, 0.9);
  color: var(--edge-cyan);
  text-align: center;
  z-index: 9;
  opacity: 0;
  pointer-events: none;
}

#flash:not(:empty) {
  opacity: 1;
  animation: flashPulse 4.8s ease;
}

.flash {
  border-color: rgba(255, 68, 68, 0.7) !important;
  color: var(--alert-red) !important;
  box-shadow: 0 0 12px rgba(255, 68, 68, 0.3);
}

@keyframes flashPulse {
  0% {
    transform: translateX(-50%) translateY(6px);
    opacity: 0;
  }
  12% {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }
  82% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* Manual */
.manual-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.manual-intro {
  color: var(--text-white);
}

.manual-list {
  margin: 0.5rem 0 0;
  padding-left: 1rem;
}

.manual-list li {
  margin: 0.2rem 0;
}

details.manual-section {
  margin-bottom: 0.6rem;
  overflow: hidden;
}

details.manual-section summary {
  list-style: none;
  cursor: pointer;
  padding: 0.6rem 0.75rem;
  background: linear-gradient(180deg, rgba(0, 212, 255, 0.1), rgba(5, 11, 18, 0.45));
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

details.manual-section[open] summary {
  box-shadow: inset 0 -1px 0 rgba(255, 165, 0, 0.28);
}

.manual-body {
  padding: 0.75rem;
  color: var(--text-white);
}

.manual-note {
  border-left: 3px solid var(--edge-amber);
  padding-left: 0.6rem;
  color: var(--text-muted);
}

.manual-code {
  display: block;
  margin: 0.35rem 0;
  padding: 0.4rem 0.5rem;
  border: 1px solid rgba(0, 255, 65, 0.35);
  border-radius: 8px;
  background: rgba(8, 15, 10, 0.65);
  color: var(--text-green);
  font-family: 'Courier New', monospace;
}

@media (min-width: 720px) {
  .ship-input-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .topbar {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

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

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

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

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .nav button,
  .nav .manual-link {
    width: auto;
    flex: 1 1 auto;
  }

  .nav-group {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
  }

  .nav-group-items {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
  }
}

@media (min-width: 980px) {
  .panel {
    padding: 1rem;
  }

  .shipyard-shell {
    gap: 0.95rem;
  }
}

/* Research UI improvements */
.research-active {
  border-left: 3px solid #00d4ff;
  background: rgba(0, 212, 255, 0.05);
}

.research-maxed {
  opacity: 0.6;
}

.research-level {
  color: #00d4ff;
  font-weight: 600;
}

.research-cost {
  color: #a0a0b0;
  font-size: 0.85em;
}

.research-maxed-label {
  color: #4caf50;
  font-weight: 600;
}

.research-progress {
  position: relative;
  height: 20px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  margin: 0.4rem 0;
  overflow: hidden;
}

.research-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #00d4ff, #0088cc);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.research-progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.75em;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  white-space: nowrap;
}

.research-unlocks {
  font-size: 0.8em;
  margin: 0.3rem 0;
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
}

.research-unlocks.next {
  background: rgba(0, 212, 255, 0.1);
  color: #00d4ff;
}

.research-unlocks.future {
  background: rgba(255, 255, 255, 0.03);
  color: #666;
}
