:root {
  color-scheme: dark;
  --bg: #03050b;
  --panel: #080c16;
  --line: rgba(148, 170, 205, 0.16);
  --muted: #7f8ba3;
  --text: #edf3ff;
  --blue: #34b8ff;
  --blue-glow: rgba(52, 184, 255, 0.35);
  --red: #ff5a67;
  --red-glow: rgba(255, 90, 103, 0.35);
  --amber: #ffbf5b;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100svh;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 0%, rgba(21, 67, 112, 0.18), transparent 32rem),
    radial-gradient(circle at 90% 100%, rgba(83, 23, 57, 0.14), transparent 35rem),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button,
select {
  color: inherit;
}

button {
  cursor: pointer;
}

.game-shell {
  width: 100%;
  height: 100svh;
  min-height: 740px;
  padding: 0 24px;
  display: grid;
  grid-template-rows: 86px minmax(320px, 1fr) auto auto;
}

.topbar {
  position: relative;
  height: auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  gap: 13px;
  align-items: center;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  position: relative;
  box-shadow: inset 0 0 14px rgba(75, 183, 255, 0.3);
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 6px -5px;
  border: 1px solid var(--blue);
  border-radius: 50%;
  transform: rotate(-35deg);
}

.brand-mark::after {
  inset: 13px -8px;
  border-color: var(--red);
  transform: rotate(25deg);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.scoreboard {
  display: flex;
  align-items: center;
  gap: 16px;
}

.score {
  display: flex;
  align-items: baseline;
  gap: 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.score strong {
  color: var(--text);
  font-size: 26px;
  line-height: 1;
}

.score--blue strong {
  color: var(--blue);
}

.score--red strong {
  color: var(--red);
}

.score-divider {
  color: #445069;
}

.button {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 10px 16px;
  background: transparent;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-decoration: none;
  text-transform: uppercase;
  transition: 160ms ease;
  cursor: pointer;
}

.button:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.36);
  background: rgba(255, 255, 255, 0.04);
}

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

.button--ghost {
  justify-self: end;
}

.top-actions {
  position: relative;
  justify-self: end;
  display: flex;
  gap: 8px;
}

.share-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 4;
  display: none;
  width: min(34rem, calc(100vw - 3rem));
  padding: 14px;
  border: 1px solid #445069;
  border-radius: 4px;
  background: #0b111d;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.65);
}

.share-panel.open {
  display: block;
}

.share-panel label {
  display: block;
  margin-bottom: 8px;
  color: #aeb8c9;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.share-panel input {
  width: 100%;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--text);
  background: #03060d;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
}

.share-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.copy-status {
  min-height: 1.2em;
  margin-top: 6px;
  color: #82dca1;
  font-size: 10px;
  text-align: right;
}

.button--primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #00111d;
}

.button--secondary {
  background: rgba(255, 255, 255, 0.035);
}

.button--destructive {
  border-color: rgba(255, 90, 103, 0.5);
  color: var(--red);
  background: rgba(255, 90, 103, 0.08);
}

.button--destructive:hover:not(:disabled) {
  border-color: var(--red);
  background: rgba(255, 90, 103, 0.16);
}

.arena-panel {
  margin-top: 14px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #03060d;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

.statusbar {
  min-height: 43px;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 14, 25, 0.95);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.turn-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.turn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 9px var(--blue);
}

#status-message {
  margin: 0;
  color: #c0cada;
  text-align: center;
}

.legend {
  justify-self: end;
  display: flex;
  gap: 14px;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #7fc9d8;
}

.legend-dot--rock {
  background: #d98c5f;
}

.legend-dot--star {
  background: #ffd36a;
  box-shadow: 0 0 6px rgba(255, 211, 106, 0.6);
}

.canvas-wrap {
  position: relative;
  width: 100%;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

/* Both canvases occupy the same pixels; source order places actions on top. */
.game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.game-canvas--action {
  background: transparent;
}

.offscreen-indicator {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 9px;
  border: 1px solid rgba(255, 191, 91, 0.3);
  border-radius: 2px;
  background: rgba(4, 7, 13, 0.82);
  color: var(--amber);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.round-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  background: rgba(2, 4, 9, 0.72);
  backdrop-filter: blur(5px);
}

.round-overlay[hidden],
.offscreen-indicator[hidden] {
  display: none;
}

.round-overlay p {
  margin-bottom: 7px;
  color: var(--amber);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.25em;
}

.round-overlay h2 {
  margin-bottom: 24px;
  font-size: clamp(30px, 5vw, 64px);
  letter-spacing: -0.03em;
}

.control-deck {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px minmax(0, 1fr);
  gap: 1px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--line);
  overflow: hidden;
}

.control-group,
.fire-station {
  padding: 20px;
  background: var(--panel);
}

.control-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.control-heading h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.player-chip {
  padding: 5px 8px;
  border: 1px solid;
  border-radius: 2px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.15em;
}

.player-chip--blue {
  border-color: rgba(52, 184, 255, 0.3);
  color: var(--blue);
  background: rgba(52, 184, 255, 0.08);
}

.player-chip--red {
  border-color: rgba(255, 90, 103, 0.3);
  color: var(--red);
  background: rgba(255, 90, 103, 0.08);
}

.readout-grid,
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.dial-control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.dial-control > span,
.settings-grid label > span {
  color: #aeb8c9;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.dial-control small {
  display: block;
  margin-top: 3px;
  color: #566176;
  font-size: 8px;
  letter-spacing: 0.05em;
}

.power-value {
  color: #aeb8c9;
  font-family: "SFMono-Regular", Consolas, monospace;
}

output {
  color: var(--blue);
  font-family: "SFMono-Regular", Consolas, monospace;
  min-width: 47px;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}

.control-group--red output {
  color: var(--red);
}

.dial-control.power-insufficient output {
  color: var(--amber);
  text-shadow: 0 0 8px rgba(255, 191, 91, 0.38);
}

.dial-control.power-insufficient .value-stepper {
  border-color: rgba(255, 191, 91, 0.62);
}

.value-stepper {
  display: flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #080e18;
}

.value-stepper button {
  width: 25px;
  height: 27px;
  padding: 0;
  border: 0;
  color: #9eabc0;
  background: rgba(255, 255, 255, 0.035);
  font-size: 16px;
  line-height: 1;
}

.value-stepper button:first-child {
  border-right: 1px solid var(--line);
}

.value-stepper button:last-child {
  border-left: 1px solid var(--line);
}

.value-stepper button:hover:not(:disabled) {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.value-stepper button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  height: 3px;
  margin: 2px 0 0;
  border-radius: 3px;
  appearance: none;
  background: linear-gradient(90deg, var(--blue) var(--range-fill, 25%), #253047 var(--range-fill, 25%));
  outline: none;
}

input[type="range"]:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.control-group--red input[type="range"] {
  background: linear-gradient(90deg, var(--red) var(--range-fill, 25%), #253047 var(--range-fill, 25%));
}

input[type="range"]::-webkit-slider-thumb {
  width: 13px;
  height: 13px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  appearance: none;
  background: var(--blue);
  box-shadow: 0 0 0 1px var(--blue), 0 0 9px var(--blue-glow);
}

input[type="range"]::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 0 1px var(--blue), 0 0 9px var(--blue-glow);
}

.control-group--red input[type="range"]::-webkit-slider-thumb {
  background: var(--red);
  box-shadow: 0 0 0 1px var(--red), 0 0 9px var(--red-glow);
}

.control-group--red input[type="range"]::-moz-range-thumb {
  background: var(--red);
  box-shadow: 0 0 0 1px var(--red), 0 0 9px var(--red-glow);
}

.fire-station {
  display: grid;
  place-items: center;
}

.fire-button {
  width: 108px;
  height: 108px;
  border: 1px solid rgba(52, 184, 255, 0.5);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #eaf8ff;
  background:
    radial-gradient(circle, rgba(52, 184, 255, 0.2), rgba(52, 184, 255, 0.035) 58%, transparent 60%),
    #080e18;
  box-shadow: inset 0 0 0 8px #080c16, inset 0 0 0 9px rgba(52, 184, 255, 0.18), 0 0 28px rgba(52, 184, 255, 0.08);
  text-transform: uppercase;
  transition: 160ms ease;
}

.fire-button:hover:not(:disabled) {
  transform: scale(1.035);
  box-shadow: inset 0 0 0 8px #080c16, inset 0 0 0 9px rgba(52, 184, 255, 0.3), 0 0 35px var(--blue-glow);
}

.fire-button:disabled {
  cursor: wait;
  opacity: 0.42;
}

.fire-icon {
  color: var(--blue);
  font-size: 14px;
}

.fire-button > span:nth-child(2) {
  margin: 4px 0 2px;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.14em;
}

.fire-button small {
  color: var(--muted);
  font-size: 8px;
  letter-spacing: 0.12em;
}

.settings-grid {
  margin-bottom: 13px;
}

.control-group--universe {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(170px, 0.6fr) minmax(320px, 1fr) minmax(180px, 0.45fr);
  align-items: end;
  gap: 18px;
}

.control-group--universe h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control-group--universe .settings-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 0;
}

.control-group--universe .universe-reset-controls {
  grid-template-columns: minmax(120px, 1fr) auto;
  align-items: end;
  gap: 10px;
}

#new-universe {
  justify-self: end;
  padding-block: 9px;
}

.settings-grid label {
  display: grid;
  gap: 7px;
}

.settings-grid .setting--destructive > span {
  color: var(--red);
  font-weight: 900;
}

.setting--destructive select {
  border-color: rgba(255, 90, 103, 0.5);
  background:
    linear-gradient(45deg, transparent 50%, var(--red) 50%) calc(100% - 14px) 50% / 5px 5px no-repeat,
    linear-gradient(135deg, var(--red) 50%, transparent 50%) calc(100% - 10px) 50% / 5px 5px no-repeat,
    rgba(255, 90, 103, 0.08);
  font-weight: 700;
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 9px 28px 9px 10px;
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, #6e7c94 50%) calc(100% - 14px) 50% / 5px 5px no-repeat,
    linear-gradient(135deg, #6e7c94 50%, transparent 50%) calc(100% - 10px) 50% / 5px 5px no-repeat,
    #0b111d;
  font-size: 11px;
}

footer {
  min-height: 22px;
  padding: 4px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #475268;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

@media (max-width: 900px) {
  .game-shell {
    padding: 0 12px;
  }

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

  .scoreboard {
    justify-self: end;
  }

  #new-game-top {
    display: none;
  }

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

  #status-message {
    display: none;
  }

  .control-deck {
    grid-template-columns: 1fr 120px 1fr;
  }

  .control-group--universe {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1.5fr 1fr;
  }

  .fire-button {
    width: 88px;
    height: 88px;
  }
}

@media (max-width: 620px) {
  .game-shell {
    height: auto;
    min-height: 100svh;
    padding: 0;
    display: block;
  }

  .topbar {
    height: 70px;
    padding: 0 12px;
  }

  .top-actions .button {
    padding-right: 10px;
    padding-left: 10px;
  }

  .share-panel {
    position: fixed;
    top: 72px;
    right: 10px;
    width: calc(100vw - 20px);
  }

  .brand .eyebrow,
  .score span {
    display: none;
  }

  h1 {
    font-size: 16px;
  }

  .scoreboard {
    gap: 9px;
  }

  .score strong {
    font-size: 20px;
  }

  .arena-panel,
  .control-deck {
    margin-top: 0;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .statusbar {
    padding: 0 11px;
  }

  .legend {
    gap: 8px;
  }

  .legend span {
    font-size: 8px;
  }

  .canvas-wrap {
    height: 48vh;
    min-height: 340px;
    flex: none;
  }

  .control-deck {
    grid-template-columns: 1fr 88px 1fr;
  }

  .control-group,
  .fire-station {
    padding: 15px 12px;
  }

  .readout-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .dial-control {
    grid-template-columns: 1fr;
  }

  .value-stepper {
    justify-self: start;
  }

  .control-group--aim {
    padding-right: 8px;
    padding-left: 8px;
  }

  .control-group--aim .control-heading {
    align-items: flex-start;
    gap: 4px;
  }

  .control-group--aim h2 {
    font-size: 11px;
  }

  .player-chip {
    display: none;
  }

  .control-group--universe {
    grid-template-columns: 1fr;
  }

  .control-group--universe .settings-grid {
    grid-template-columns: 1fr;
  }

  .control-group--universe .universe-reset-controls {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .control-heading {
    margin-bottom: 13px;
  }

  .fire-button {
    width: 80px;
    height: 80px;
  }

  .fire-button > span:nth-child(2) {
    font-size: 13px;
  }

  footer {
    display: none;
  }
}
