* {
  box-sizing: border-box;
}

html,
body {
  min-width: 280px;
  margin: 0;
}

body {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(0.5rem, 3vw, 1.25rem);
  overflow-x: hidden;
  color: var(--game-text);
  background:
    radial-gradient(
      circle at 16% 8%,
      rgba(20, 184, 166, 0.08),
      transparent 28rem
    ),
    var(--game-surface);
  font-family: var(--game-font);
}

button,
output {
  font: inherit;
}

.lab {
  width: min(100%, 420px);
  min-width: 0;
  padding: clamp(0.75rem, 3vw, 1.15rem);
  border: 1px solid var(--game-divider);
  border-radius: calc(var(--game-radius) * 3);
  background: var(--game-bg);
  box-shadow: var(--game-shadow);
}

.lab-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem;
  min-width: 0;
}

.lab-header > div {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 0.22rem;
  color: var(--game-accent);
  font-family: var(--game-mono);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

h1 {
  margin: 0;
  font-size: clamp(1.15rem, 5vw, 1.55rem);
  line-height: 1.13;
  overflow-wrap: anywhere;
}

.method-badge {
  flex: 0 0 auto;
  padding: 0.34rem 0.46rem;
  border: 1px solid var(--game-divider);
  border-radius: 999px;
  color: var(--game-muted);
  background: var(--game-surface);
  font-family: var(--game-mono);
  font-size: 0.59rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.intro {
  margin: 0.58rem 0 0.7rem;
  color: var(--game-muted);
  font-size: 0.78rem;
  line-height: 1.42;
  overflow-wrap: anywhere;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.42rem;
  margin-bottom: 0.58rem;
}

.metric {
  min-width: 0;
  padding: 0.48rem 0.4rem;
  border: 1px solid var(--game-divider);
  border-radius: calc(var(--game-radius) * 2);
  background: var(--game-surface);
  text-align: center;
}

.metric span {
  display: block;
  min-width: 0;
  color: var(--game-muted);
  font-size: 0.61rem;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.metric output {
  display: block;
  margin-top: 0.12rem;
  color: var(--game-text);
  font-family: var(--game-mono);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.1;
}

.field-figure {
  min-width: 0;
  margin: 0;
}

#field {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border: 1px solid var(--game-divider);
  border-radius: calc(var(--game-radius) * 2.5);
  background: var(--game-surface-strong);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.field-background {
  fill: var(--game-surface-strong);
}

.field-grid {
  fill: url("#field-grid");
  pointer-events: none;
}

.grid-line {
  fill: none;
  stroke: var(--game-divider);
  stroke-width: 0.18;
}

.heat-cell {
  pointer-events: none;
  transition: opacity 110ms linear;
}

.heat-cell.covered {
  fill: #14b8a6;
}

.heat-cell.interfered {
  fill: #f97316;
}

.beam {
  pointer-events: none;
  stroke-width: 0.25;
  transition: opacity 90ms linear;
}

.beam-a0 {
  fill: rgba(20, 184, 166, 0.095);
  stroke: rgba(13, 148, 136, 0.35);
}

.beam-a1 {
  fill: rgba(59, 130, 246, 0.08);
  stroke: rgba(37, 99, 235, 0.3);
}

.beam-a2 {
  fill: rgba(168, 85, 247, 0.075);
  stroke: rgba(147, 51, 234, 0.28);
}

.station-halo {
  fill: var(--game-bg);
  stroke: var(--game-divider);
  stroke-width: 0.75;
}

.station-core {
  fill: var(--game-text);
  stroke: var(--game-bg);
  stroke-width: 0.55;
  filter: url("#soft-glow");
}

.station-label {
  fill: var(--game-text);
  font-family: var(--game-mono);
  font-size: 2.5px;
  font-weight: 800;
  pointer-events: none;
  text-anchor: middle;
}

.sector-guide {
  fill: none;
  stroke-width: 0.8;
  stroke-linecap: round;
  opacity: 0.42;
  pointer-events: none;
}

.sector-a0,
.antenna-a0 {
  stroke: #0d9488;
}

.sector-a1,
.antenna-a1 {
  stroke: #2563eb;
}

.sector-a2,
.antenna-a2 {
  stroke: #9333ea;
}

.antenna-handle {
  outline: none;
  cursor: grab;
  touch-action: none;
}

.antenna-handle:active {
  cursor: grabbing;
}

.antenna-hit {
  stroke: transparent;
  stroke-width: 7;
  stroke-linecap: round;
  pointer-events: stroke;
}

.antenna-line {
  stroke-width: 1.05;
  stroke-linecap: round;
  pointer-events: none;
}

.antenna-knob {
  fill: var(--game-bg);
  stroke-width: 1.25;
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
}

.antenna-handle:hover .antenna-knob,
.antenna-handle.is-active .antenna-knob {
  fill: var(--game-accent-soft);
}

.antenna-handle:focus-visible .antenna-knob {
  stroke: var(--game-text);
  stroke-width: 2;
  filter: url("#soft-glow");
}

#field[data-optimizing="true"] .antenna-handle.is-searching .antenna-knob {
  animation: search-pulse 620ms ease-in-out infinite alternate;
}

@keyframes search-pulse {
  from {
    transform: scale(0.85);
    fill: var(--game-bg);
  }
  to {
    transform: scale(1.45);
    fill: var(--game-accent-soft);
  }
}

.user {
  stroke-width: 0.55;
  pointer-events: none;
  transition:
    fill 100ms linear,
    stroke 100ms linear;
}

.user.served {
  fill: #22c55e;
  stroke: #166534;
}

.user.interfered {
  fill: #fb923c;
  stroke: #9a3412;
}

.user.uncovered {
  fill: var(--game-bg);
  stroke: var(--game-muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem 0.72rem;
  padding: 0.42rem 0 0;
  color: var(--game-muted);
  font-size: 0.63rem;
}

.legend > span {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.legend-swatch,
.legend-user {
  display: inline-block;
  width: 0.68rem;
  height: 0.68rem;
  flex: 0 0 auto;
}

.legend-swatch {
  border-radius: 2px;
}

.coverage-swatch {
  background: rgba(20, 184, 166, 0.55);
}

.interference-swatch {
  background: rgba(249, 115, 22, 0.72);
}

.legend-user {
  border: 1px solid #166534;
  border-radius: 50%;
  background: #22c55e;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.button {
  min-width: 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.38rem;
  padding: 0.55rem 0.6rem;
  border: 1px solid transparent;
  border-radius: calc(var(--game-radius) * 2);
  font-size: 0.74rem;
  font-weight: 750;
  line-height: 1.2;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.button-primary {
  color: var(--game-on-accent);
  background: var(--game-accent);
}

.button-primary:hover:not(:disabled) {
  background: var(--game-accent-strong);
}

.button-secondary {
  border-color: var(--game-divider);
  color: var(--game-text);
  background: var(--game-surface);
}

.button-secondary:hover:not(:disabled) {
  border-color: var(--game-accent);
  color: var(--game-accent-strong);
}

.button:focus-visible {
  outline: 3px solid var(--game-accent-soft);
  outline-offset: 2px;
}

.button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.status {
  min-height: 2.6em;
  margin: 0.58rem 0 0;
  color: var(--game-muted);
  font-size: 0.7rem;
  line-height: 1.35;
  text-align: center;
  overflow-wrap: anywhere;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html[data-embed="true"] body {
  min-height: 100%;
  padding: 0;
  background: transparent;
}

html[data-embed="true"] .lab {
  width: min(100%, 420px);
  min-height: 100svh;
  border-color: transparent;
  border-radius: 0;
  box-shadow: none;
}

@media (max-width: 320px) {
  body {
    padding: 0.35rem;
  }

  .lab {
    padding: 0.62rem;
  }

  .method-badge {
    padding-inline: 0.34rem;
    font-size: 0.54rem;
  }

  .metrics {
    gap: 0.28rem;
  }

  .metric {
    padding-inline: 0.2rem;
  }

  .controls {
    gap: 0.35rem;
  }

  .button {
    padding-inline: 0.38rem;
    font-size: 0.68rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .heat-cell,
  .beam,
  .user {
    transition: none;
  }

  #field[data-optimizing="true"] .antenna-handle.is-searching .antenna-knob {
    animation: none;
    fill: var(--game-accent-soft);
  }
}
