@import url('../shared/theme.css');

:root {
  --bob: #2563eb;
  --bob-soft: rgba(37, 99, 235, 0.08);
  --eve: #c2413b;
  --eve-soft: rgba(194, 65, 59, 0.07);
  --beam-color: #0f766e;
  --reflection: #64748b;
  --field-bg: #ffffff;
  --heatmap-low: #ffffff;
  --heatmap-low-mid: #f8fafe;
  --heatmap-mid: #ecf1fd;
  --heatmap-high-mid: #dde7fc;
  --heatmap-high: #d2dffb;
  --heatmap-peak: #c6d6fa;
}

html[data-theme='dark'] {
  --bob: #60a5fa;
  --bob-soft: rgba(96, 165, 250, 0.1);
  --eve: #fca5a5;
  --eve-soft: rgba(252, 165, 165, 0.08);
  --beam-color: #5eead4;
  --reflection: #94a3b8;
  --field-bg: #171b1d;
  --heatmap-low: #171b1d;
  --heatmap-low-mid: #192024;
  --heatmap-mid: #1d2731;
  --heatmap-high-mid: #22303f;
  --heatmap-high: #26374a;
  --heatmap-peak: #2a3f56;
}

* {
  box-sizing: border-box;
}

body {
  display: grid;
  min-width: 280px;
  min-height: 100svh;
  margin: 0;
  place-items: stretch center;
  color: var(--game-text);
  background: var(--game-bg);
  font-family: var(--game-font);
}

button {
  font: inherit;
}

.game {
  display: grid;
  align-content: start;
  width: min(100%, 420px);
  min-height: 100svh;
  padding: 0.85rem;
  gap: 0.65rem;
}

.game-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 0.75rem;
}

.eyebrow {
  margin: 0 0 0.18rem;
  color: var(--game-accent);
  font-family: var(--game-mono);
  font-size: 0.56rem;
  font-weight: 800;
  letter-spacing: 0.13em;
}

h1 {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 620;
  line-height: 1.15;
}

.score-card {
  display: grid;
  min-width: 92px;
  padding: 0.42rem 0.55rem;
  gap: 0.1rem;
  color: var(--game-muted);
  background: var(--game-surface);
  border: 1px solid var(--game-divider);
  border-radius: var(--game-radius);
  text-align: right;
}

.score-card-label {
  font-size: 0.54rem;
  white-space: nowrap;
}

.score-value {
  display: flex;
  align-items: baseline;
  justify-content: end;
  gap: 0.2rem;
}

#secrecy-rate {
  color: var(--game-accent);
  font-family: var(--game-mono);
  font-size: 1rem;
  font-weight: 800;
}

.score-unit {
  color: var(--game-muted);
  font-family: var(--game-mono);
  font-size: 0.48rem;
  font-weight: 700;
  white-space: nowrap;
}

.field {
  position: relative;
  min-width: 0;
  overflow: hidden;
  color: var(--beam-color);
  background:
    linear-gradient(var(--game-divider) 1px, transparent 1px),
    linear-gradient(90deg, var(--game-divider) 1px, transparent 1px), var(--field-bg);
  background-size: 30px 30px;
  border: 1px solid var(--game-divider);
  border-radius: calc(var(--game-radius) + 2px);
  cursor: crosshair;
  touch-action: none;
}

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

#energy-map,
#scene {
  display: block;
  width: 100%;
  aspect-ratio: 12 / 7;
  overflow: hidden;
}

#energy-map {
  position: absolute;
  inset: 0;
  z-index: 0;
  height: 100%;
  background: var(--heatmap-low);
  image-rendering: auto;
  pointer-events: none;
}

#scene {
  position: relative;
  z-index: 1;
}

.room-walls {
  fill: none;
  stroke: color-mix(in srgb, var(--reflection) 72%, var(--game-divider));
  stroke-dasharray: 3 2;
  stroke-linejoin: round;
  stroke-opacity: 0.36;
  stroke-width: 1.25;
  transition:
    stroke-opacity 180ms ease,
    stroke-width 180ms ease;
}

.field[data-walls='true'] .room-walls {
  stroke-dasharray: none;
  stroke-opacity: 0.92;
  stroke-width: 2.2;
}

.surface,
.reflector {
  stroke: var(--reflection);
  stroke-linecap: round;
  stroke-width: 5;
}

.reflector-dot {
  fill: var(--field-bg);
  stroke: var(--reflection);
  stroke-width: 1.5;
}

.reflector-label {
  fill: var(--reflection);
  font: 700 8px var(--game-mono);
  text-anchor: middle;
}

.node text {
  fill: var(--game-text);
  font: 700 9px var(--game-mono);
  text-anchor: middle;
}

.node-core {
  fill: var(--field-bg);
  stroke-width: 2;
}

.node-halo {
  fill: transparent;
  stroke-width: 1;
}

.alice .node-core,
.alice .node-halo {
  stroke: var(--beam-color);
}

.bob .node-core,
.bob .node-halo {
  stroke: var(--bob);
}

.eve .node-core,
.eve .node-halo {
  stroke: var(--eve);
}

.node path,
.node line {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.bob {
  color: var(--bob);
}

.eve {
  color: var(--eve);
}

.antenna-tip {
  fill: var(--beam-color);
  stroke: none !important;
}

.node.is-active .node-halo {
  animation: signal-pulse 1.35s ease-out infinite;
  fill: currentColor;
  fill-opacity: 0.08;
}

.bearing-chip {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  display: flex;
  align-items: center;
  padding: 0.26rem 0.38rem;
  gap: 0.32rem;
  color: var(--game-muted);
  background: color-mix(in srgb, var(--game-bg) 88%, transparent);
  border: 1px solid var(--game-divider);
  border-radius: var(--game-radius);
  font-size: 0.58rem;
  pointer-events: none;
  z-index: 2;
}

#bearing {
  color: var(--game-text);
  font-family: var(--game-mono);
  font-weight: 750;
}

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

.energy-legend {
  display: grid;
  grid-template-columns: auto minmax(72px, 1fr);
  align-items: center;
  margin-top: -0.3rem;
  column-gap: 0.48rem;
  color: var(--game-muted);
  font-family: var(--game-mono);
  font-size: 0.54rem;
}

.energy-legend-label {
  grid-row: 1 / span 2;
  font-weight: 750;
  white-space: nowrap;
}

.energy-ramp {
  display: block;
  height: 0.42rem;
  background: linear-gradient(
    90deg,
    var(--heatmap-low) 0%,
    var(--heatmap-low-mid) 22%,
    var(--heatmap-mid) 45%,
    var(--heatmap-high-mid) 68%,
    var(--heatmap-high) 84%,
    var(--heatmap-peak) 100%
  );
  border: 1px solid color-mix(in srgb, var(--game-divider) 74%, transparent);
  border-radius: 999px;
}

.energy-legend-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 0.03rem;
  font-size: 0.48rem;
}

.link-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  min-width: 0;
  min-height: 68px;
  padding: 0.45rem 0.55rem;
  gap: 0.16rem;
  border: 1px solid var(--game-divider);
  border-radius: var(--game-radius);
  font-size: 0.66rem;
}

.bob-link-card {
  background: var(--bob-soft);
}

.eve-link-card {
  background: var(--eve-soft);
}

.link-card strong {
  font-family: var(--game-mono);
  font-weight: 800;
}

.link-metric {
  display: flex;
  min-width: 0;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem;
  color: var(--game-muted);
  font-size: 0.54rem;
  line-height: 1.2;
}

.link-metric output {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--game-text);
  font-family: var(--game-mono);
  font-size: 0.55rem;
  font-weight: 750;
  text-align: right;
}

.wall-toggle {
  position: relative;
  display: grid;
  grid-template-columns: 2.7rem minmax(0, 1fr);
  align-items: center;
  min-height: 48px;
  padding: 0.4rem 0.55rem;
  gap: 0.5rem;
  color: var(--game-text);
  background: var(--game-surface);
  border: 1px solid var(--game-divider);
  border-radius: var(--game-radius);
  cursor: pointer;
}

.wall-toggle input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.toggle-track {
  position: relative;
  display: block;
  width: 2.45rem;
  height: 1.4rem;
  background: color-mix(in srgb, var(--game-muted) 32%, transparent);
  border: 1px solid var(--game-divider);
  border-radius: 999px;
  transition:
    background 160ms ease,
    border-color 160ms ease;
}

.toggle-thumb {
  position: absolute;
  top: 50%;
  left: 0.16rem;
  width: 0.94rem;
  height: 0.94rem;
  background: var(--game-surface);
  border-radius: 50%;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.2);
  transform: translateY(-50%);
  transition: transform 160ms ease;
}

.wall-toggle input:checked + .toggle-track {
  background: var(--game-accent);
  border-color: var(--game-accent);
}

.wall-toggle input:checked + .toggle-track .toggle-thumb {
  transform: translate(1.02rem, -50%);
}

.wall-toggle:has(input:focus-visible) {
  outline: 3px solid var(--game-accent);
  outline-offset: 2px;
}

.wall-toggle:has(input:disabled) {
  cursor: wait;
  opacity: 0.7;
}

.wall-toggle-copy {
  display: grid;
  min-width: 0;
  gap: 0.05rem;
}

.wall-toggle-text {
  font-size: 0.68rem;
  line-height: 1.15;
}

.wall-toggle-copy small {
  color: var(--game-muted);
  font-size: 0.57rem;
  line-height: 1.24;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 0.55rem;
}

.controls button {
  min-width: 0;
  min-height: 46px;
  padding: 0.55rem 0.5rem;
  border-radius: var(--game-radius);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 780;
}

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

.controls button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.primary {
  color: var(--game-on-accent);
  background: var(--game-accent);
  border: 1px solid var(--game-accent);
}

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

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

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

.status {
  min-height: 2.6em;
  margin: 0;
  color: var(--game-text);
  font-size: 0.7rem;
  font-weight: 650;
  line-height: 1.3;
  text-align: center;
}

.status[data-state='secure'] {
  color: var(--game-accent-strong);
}

.status[data-state='exposed'] {
  color: var(--game-danger);
}

.help {
  margin: -0.2rem auto 0;
  color: var(--game-muted);
  font-size: 0.61rem;
  line-height: 1.35;
  text-align: center;
}

@keyframes signal-pulse {
  from {
    opacity: 0.8;
    transform: scale(0.72);
  }
  to {
    opacity: 0;
    transform: scale(1.38);
  }
}

@media (max-width: 320px) {
  .game {
    padding: 0.7rem;
    gap: 0.55rem;
  }

  .game-header {
    gap: 0.4rem;
  }

  h1 {
    font-size: 1rem;
  }

  .score-card {
    min-width: 86px;
    padding-inline: 0.42rem;
  }

  .links,
  .controls {
    gap: 0.4rem;
  }

  .link-card {
    padding-inline: 0.42rem;
  }

  .wall-toggle {
    grid-template-columns: 2.55rem minmax(0, 1fr);
    padding-inline: 0.46rem;
    gap: 0.38rem;
  }

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

@media (prefers-reduced-motion: reduce) {
  .node.is-active .node-halo {
    animation: none;
  }
}
