:root {
  --void: #050711;
  --panel: rgba(8, 14, 28, 0.74);
  --panel-strong: rgba(11, 20, 38, 0.92);
  --line: rgba(153, 224, 255, 0.24);
  --text: #eef8ff;
  --muted: #8ca8bc;
  --hot: #ffb648;
  --cyan: #6ee7ff;
  --danger: #ff5568;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--text);
  font-family: "Trebuchet MS", "Lucida Sans Unicode", sans-serif;
  background:
    radial-gradient(circle at 18% 24%, rgba(55, 156, 255, 0.18), transparent 30rem),
    radial-gradient(circle at 82% 8%, rgba(255, 125, 72, 0.16), transparent 28rem),
    linear-gradient(135deg, #04050c 0%, #08111f 48%, #120816 100%);
  overflow-x: hidden;
}

.shell {
  width: calc(100vw - 8px);
  margin: 0 auto;
  padding: 10px 0 18px;
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--hot);
  font-size: 0.76rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.1rem, 4.4vw, 4.4rem);
  line-height: 0.9;
  letter-spacing: -0.06em;
  text-transform: uppercase;
}

.status {
  max-width: 420px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--cyan);
  background: rgba(6, 14, 24, 0.56);
  text-align: right;
  box-shadow: 0 0 40px rgba(110, 231, 255, 0.1);
}

.battle-layout {
  display: grid;
  grid-template-columns:
    clamp(190px, 14.5vw, 300px)
    minmax(720px, 1fr)
    clamp(190px, 14.5vw, 300px);
  gap: 10px;
  align-items: start;
}

.hud {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: inset 0 0 36px rgba(110, 231, 255, 0.06);
}

.arena-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 24px;
  overflow: hidden;
  min-height: 0;
  background: #03050d;
  box-shadow:
    0 22px 70px rgba(0, 0, 0, 0.48),
    inset 0 0 90px rgba(75, 149, 255, 0.12);
}

#arena {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
}

.hud-name {
  min-height: 2.15em;
  margin: 0 0 8px;
  color: var(--text);
  font-size: clamp(0.95rem, 1.2vw, 1.5rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.15;
  text-align: center;
  text-transform: uppercase;
}

.captain-panel {
  display: grid;
  grid-template-columns: clamp(16px, 1.5vw, 24px) 1fr clamp(16px, 1.5vw, 24px);
  gap: clamp(6px, 0.7vw, 10px);
  align-items: stretch;
}

.captain-portrait {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  background-image: var(--captain-url);
  background-size: 400% 300%;
  background-position:
    calc(var(--captain-col) * 100% / 3)
    calc(var(--captain-row) * 100% / 2);
  background-repeat: no-repeat;
  box-shadow:
    inset 0 0 28px rgba(0, 0, 0, 0.62),
    0 0 24px rgba(110, 231, 255, 0.1);
}

.captain-portrait.is-static {
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.16) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(90deg, rgba(110,231,255,0.12) 0 2px, rgba(0,0,0,0.72) 2px 5px),
    radial-gradient(circle at 40% 40%, rgba(255,255,255,0.3), transparent 12%),
    linear-gradient(135deg, #141922, #020306);
  background-size: auto;
  animation: static-flicker 90ms steps(2, end) infinite;
}

.captain-portrait.is-static::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(12deg, transparent 0 7px, rgba(255,255,255,0.18) 7px 8px),
    radial-gradient(circle at 68% 24%, rgba(255,80,80,0.18), transparent 22%);
  mix-blend-mode: screen;
}

.vertical-meter {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 4px;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.1) 0 2px, transparent 2px 10px),
    rgba(0, 0, 0, 0.42);
}

.vertical-meter > span {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: block;
  height: 50%;
  background: linear-gradient(0deg, #28df65, #cff15e, #ffb648);
  transition: height 120ms linear;
}

.battery-meter > span {
  background: linear-gradient(0deg, #ff3f58, #ffb648, #fff36c);
}

.meter-labels {
  display: flex;
  justify-content: space-between;
  margin: 6px 0 10px;
  color: var(--hot);
  font-size: clamp(0.84rem, 1.14vw, 1.18rem);
  font-weight: 900;
  letter-spacing: 0.12em;
}

.weapon-bars {
  display: grid;
  gap: 10px;
}

.weapon-row {
  display: grid;
  grid-template-columns: clamp(18px, 1.6vw, 26px) auto 1fr;
  gap: clamp(6px, 0.75vw, 10px);
  align-items: center;
  color: var(--muted);
  font-size: clamp(0.84rem, 1.18vw, 1.18rem);
}

.weapon-row .weapon-icon {
  width: clamp(18px, 1.6vw, 26px);
  height: clamp(18px, 1.6vw, 26px);
  flex-basis: clamp(18px, 1.6vw, 26px);
}

.weapon-row > span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.horizontal-meter {
  grid-column: 1 / -1;
  height: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.46);
}

.horizontal-meter > span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #335dff, #6ee7ff, #eaffff);
  transition: width 120ms linear;
}

.horizontal-meter.secondary > span {
  background: linear-gradient(90deg, #703bff, #ff70d7, #ffd36c);
}

.ai-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  color: var(--cyan);
  background: rgba(255, 255, 255, 0.07);
}

.ai-toggle input {
  accent-color: var(--cyan);
}

.ship-card p {
  display: flex;
  align-items: center;
  gap: 7px;
}

.weapon-icon {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(110, 231, 255, 0.22));
}

@keyframes static-flicker {
  from {
    filter: brightness(0.85) contrast(1.6);
    transform: translateY(0);
  }
  to {
    filter: brightness(1.3) contrast(2.1);
    transform: translateY(-1px);
  }
}

.select-card {
  position: absolute;
  left: 50%;
  top: 14px;
  width: calc(100% - 28px);
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-strong);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
  box-shadow: 0 32px 120px rgba(0, 0, 0, 0.62);
  max-height: none;
  overflow: visible;
}

.select-card.is-hidden {
  display: none;
}

.select-card h2 {
  display: inline-block;
  margin: 0 16px 10px 0;
  font-size: clamp(1.55rem, 2vw, 2.25rem);
  letter-spacing: -0.05em;
}

.select-card p {
  display: inline;
  margin: 0 10px 0 0;
  color: var(--muted);
  font-size: clamp(0.95rem, 1.2vw, 1.2rem);
}

.matchup {
  display: none;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: stretch;
}

.ship-card {
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.055);
}

.ship-card > img,
.ship-preview {
  display: block;
  width: 48px;
  height: 48px;
  min-height: 0;
  margin: 0 auto;
  object-fit: contain;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.35));
}

.question-preview,
.random-hud-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0 auto;
  border: 1px solid rgba(110, 231, 255, 0.46);
  border-radius: 8px;
  color: var(--cyan);
  background: rgba(110, 231, 255, 0.08);
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0 16px rgba(110, 231, 255, 0.58);
}

.random-hud-mark {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  margin-bottom: 8px;
  font-size: clamp(4rem, 8vw, 8rem);
}

.ship-card h3 {
  margin: 0 0 4px;
  color: var(--text);
  font-size: 0.96rem;
}

.ship-card p {
  margin: 3px 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.roster-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 8px;
  margin-top: 8px;
  align-items: stretch;
}

.roster-label {
  display: grid;
  place-items: center;
  min-width: 72px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  color: var(--hot);
  background: rgba(255, 255, 255, 0.055);
  font-size: clamp(0.76rem, 0.9vw, 0.96rem);
  font-weight: 900;
  letter-spacing: 0.1em;
  line-height: 1.1;
  text-align: center;
  text-transform: uppercase;
}

.roster-row {
  display: grid;
  grid-template-columns: repeat(17, 1fr);
  gap: 5px;
}

.roster-card {
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  min-width: 0;
  height: 82px;
  padding: 4px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
}

.roster-card.is-p1 {
  border-color: rgba(110, 231, 255, 0.82);
  box-shadow: inset 0 0 22px rgba(110, 231, 255, 0.12);
}

.roster-card.is-p2 {
  border-color: rgba(255, 182, 72, 0.82);
  box-shadow: inset 0 0 22px rgba(255, 182, 72, 0.12);
}

.roster-card.is-random {
  border-style: dashed;
}

.roster-card.is-used {
  cursor: not-allowed;
  color: rgba(238, 248, 255, 0.42);
  background: rgba(255, 255, 255, 0.025);
  filter: grayscale(1);
  opacity: 0.48;
}

.roster-card h4 {
  height: 2.15em;
  overflow: hidden;
  margin: 0;
  font-size: clamp(0.58rem, 0.66vw, 0.74rem);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 1.05;
  text-align: center;
}

.roster-card:hover {
  border-color: var(--cyan);
}

.roster-card.is-used:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

.roster-question {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin: 4px auto 0;
  border-radius: 6px;
  color: var(--cyan);
  background: rgba(110, 231, 255, 0.09);
  font-size: 1.15rem;
  font-weight: 900;
}

.versus {
  align-self: center;
  color: var(--hot);
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: -0.06em;
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.controls article {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(6, 13, 24, 0.58);
}

.controls h3 {
  margin: 0 0 8px;
  color: var(--hot);
}

.controls p {
  margin: 7px 0;
  color: var(--muted);
}

kbd {
  display: inline-block;
  min-width: 1.8em;
  padding: 2px 6px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
  text-align: center;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.28);
}

@media (max-width: 860px) {
  .hero,
  .controls {
    display: block;
  }

  .status,
  .controls article {
    margin-top: 12px;
  }

  .arena-wrap {
    min-height: 0;
  }

  #arena {
    height: auto;
  }

  .battle-layout {
    grid-template-columns: 1fr;
  }

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

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

  .roster-row {
    grid-template-columns: repeat(4, minmax(72px, 1fr));
  }

  .versus {
    text-align: center;
  }
}
