:root {
  color-scheme: dark;
  --bg: #080d0a;
  --panel: #101713;
  --panel-2: #151d18;
  --line: #334039;
  --line-soft: #253129;
  --text: #f2f4ef;
  --muted: #a0ada5;
  --faint: #718077;
  --accent: #c6db54;
  --cyan: #72d1d5;
  --danger: #f17865;
  --warning: #efb75b;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(114, 209, 213, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(114, 209, 213, 0.025) 1px, transparent 1px);
  background-size: 24px 24px;
  overflow-x: hidden;
}

button,
input { font: inherit; }

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.topbar,
main {
  width: min(1480px, calc(100% - 32px));
  margin-inline: auto;
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
  font-weight: 900;
}

.brand img { width: 34px; height: 34px; border: 1px solid var(--line); }
.topbar > span { color: var(--faint); font: 11px ui-monospace, SFMono-Regular, Consolas, monospace; }

main { padding: 34px 0 48px; }

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

.page-head > p { max-width: 520px; margin: 0 0 3px; color: var(--muted); line-height: 1.55; }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: 11px; font-weight: 900; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(27px, 4vw, 42px); line-height: 1.08; letter-spacing: 0; }

.selectors {
  min-height: 66px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 30px;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: rgba(16, 23, 19, 0.95);
}

.selector-group { display: flex; align-items: center; gap: 10px; }
.selector-group > span,
.panel h2 {
  color: var(--faint);
  font: 800 10px ui-monospace, SFMono-Regular, Consolas, monospace;
  text-transform: uppercase;
}

.segmented { display: inline-flex; border: 1px solid var(--line); background: #0b110d; }
.segmented button {
  min-width: 0;
  min-height: 38px;
  padding: 0 17px;
  border: 0;
  border-right: 1px solid var(--line);
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}
.segmented button:last-child { border-right: 0; }
.segmented button:hover { color: var(--text); background: var(--panel-2); }
.segmented button.is-active { color: #0a0d0b; background: var(--accent); }
.segmented.compact button { min-height: 34px; padding: 0 12px; font-size: 11px; }

.calculator {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 12px;
}

.map-stage {
  min-height: 680px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0b100d;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}
.map-stage.is-panning { cursor: grabbing; }

.map-world {
  width: 100%;
  aspect-ratio: 1;
  position: absolute;
  left: 0;
  top: 0;
  overflow: hidden;
  transform-origin: 0 0;
  background: #131914;
}

.map-preview,
.map-tiles,
.map-overlay,
.map-markers { position: absolute; inset: 0; width: 100%; height: 100%; }
.map-preview { background-position: center; background-size: cover; filter: contrast(1.06) brightness(.74); }
.map-tiles img { position: absolute; display: block; filter: saturate(.75) contrast(1.08) brightness(.72); }
.map-overlay { overflow: visible; pointer-events: none; }
.map-markers { pointer-events: none; }

.map-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at center, transparent 50%, rgba(3, 6, 4, .36) 100%);
}

.marker {
  width: calc(34px * var(--inverse-zoom, 1));
  height: calc(34px * var(--inverse-zoom, 1));
  position: absolute;
  z-index: 3;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  border: calc(2px * var(--inverse-zoom, 1)) solid currentColor;
  border-radius: 50%;
  color: var(--accent);
  background: rgba(6, 10, 7, .92);
  pointer-events: auto;
  cursor: grab;
  font-size: calc(15px * var(--inverse-zoom, 1));
  font-weight: 900;
  line-height: 1;
}
.marker.target { color: var(--danger); }
.marker span {
  position: absolute;
  left: 50%;
  top: calc(39px * var(--inverse-zoom, 1));
  transform: translateX(-50%);
  padding: calc(2px * var(--inverse-zoom, 1)) calc(5px * var(--inverse-zoom, 1));
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, .18);
  background: rgba(5, 9, 6, .9);
  font: 800 calc(9px * var(--inverse-zoom, 1)) ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: nowrap;
}

.map-toolbar {
  position: absolute;
  z-index: 5;
  left: 12px;
  top: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border: 1px solid var(--line);
  background: rgba(7, 12, 9, .92);
  backdrop-filter: blur(6px);
}
.map-toolbar > button {
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  color: var(--cyan);
  background: var(--panel-2);
  cursor: pointer;
  font-size: 18px;
}
.map-toolbar > button:hover { border-color: var(--cyan); }
.map-toolbar > i { width: 1px; height: 22px; margin: 0 2px; background: var(--line); }
.map-toolbar > span { min-width: 44px; color: var(--muted); font: 10px ui-monospace, SFMono-Regular, Consolas, monospace; text-align: center; }

.map-legend {
  position: absolute;
  z-index: 4;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(7, 12, 9, .88);
  font-size: 10px;
}
.map-legend span { display: flex; align-items: center; gap: 5px; }
.map-legend i { width: 16px; border-top: 2px solid; }
.map-legend .max { color: var(--accent); }
.map-legend .min { color: var(--danger); border-top-style: dashed; }
.map-legend .low { color: var(--cyan); border-top-style: dashed; }

.side-panel { display: flex; flex-direction: column; gap: 12px; }
.panel { min-width: 0; padding: 16px; border: 1px solid var(--line); background: rgba(16, 23, 19, .96); }
.panel h2 { margin: 0 0 13px; letter-spacing: .12em; }
.empty-result { margin: 20px 0; color: var(--muted); text-align: center; }
.empty-result b { color: var(--accent); }

.readouts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.readouts.single { grid-template-columns: 1fr; }
.fire-command { margin-bottom: 9px; padding: 12px 14px; border: 1px solid rgba(198, 219, 84, .75); background: rgba(198, 219, 84, .09); }
.fire-command span { display: block; color: var(--faint); font: 800 9px ui-monospace, SFMono-Regular, Consolas, monospace; text-transform: uppercase; }
.fire-values { display: flex; align-items: end; justify-content: space-between; gap: 14px; }
.fire-command strong { display: block; margin-top: 3px; color: var(--accent); font-size: 34px; line-height: 1; }
.fire-command strong small { margin-left: 5px; color: var(--muted); font-size: 13px; }
.fire-command .fire-bearing { color: var(--text); font-size: 27px; text-align: right; }
.fire-command .fire-bearing small:first-child { display: block; margin: 0 0 4px; color: var(--faint); font: 800 9px ui-monospace, SFMono-Regular, Consolas, monospace; text-transform: uppercase; }
.fire-command em { display: block; margin-top: 6px; color: var(--text); font-size: 11px; font-style: normal; }
.readout { padding: 10px 12px; border: 1px solid var(--line-soft); background: linear-gradient(var(--panel-2), var(--panel)); }
.readout span,
.arc span { display: block; color: var(--faint); font: 800 9px ui-monospace, SFMono-Regular, Consolas, monospace; text-transform: uppercase; }
.readout strong { display: block; margin-top: 4px; font-size: 27px; line-height: 1; }
.readout strong small { margin-left: 3px; color: var(--muted); font-size: 12px; }

.arcs { margin-top: 9px; display: grid; gap: 5px; }
.arc { padding: 10px 12px; border: 1px solid rgba(198, 219, 84, .55); background: rgba(198, 219, 84, .06); }
.arc.high { border-color: rgba(114, 209, 213, .5); background: rgba(114, 209, 213, .06); }
.arc strong { margin-top: 3px; display: block; color: var(--accent); font-size: 22px; }
.arc.high strong { color: var(--cyan); }
.arc em { margin-top: 4px; display: block; color: var(--muted); font-size: 11px; font-style: normal; }
.arc em b { color: var(--text); }

.terrain-line { margin: 10px 0 0; padding-top: 9px; border-top: 1px solid var(--line-soft); color: var(--muted); font-size: 12px; line-height: 1.45; }
.terrain-line b { color: var(--text); }
.warning { margin: 9px 0 0; padding: 9px 11px; border: 1px solid rgba(241, 120, 101, .45); color: #f3c0b8; background: rgba(241, 120, 101, .08); font-size: 12px; }
.copy-result { width: 100%; min-height: 38px; margin-top: 10px; border: 1px solid var(--line); color: var(--accent); background: var(--panel-2); cursor: pointer; font-weight: 800; }
.copy-result:hover { border-color: var(--accent); }

.coordinate { margin-bottom: 9px; display: grid; grid-template-columns: 66px 1fr; align-items: center; gap: 8px; }
.coordinate > span { color: var(--muted); font: 800 9px ui-monospace, SFMono-Regular, Consolas, monospace; text-transform: uppercase; }
.gun-coordinate > span { color: var(--accent); }
.target-coordinate > span { color: var(--danger); }
input {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--text);
  background: #0a100c;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}
input[aria-invalid="true"] { border-color: var(--danger); }
.hint { margin: 8px 0 0; color: var(--faint); font-size: 11px; line-height: 1.5; }

.impact-coordinate { margin-top: 11px; display: grid; gap: 6px; }
.impact-coordinate > span { color: var(--danger); font: 800 9px ui-monospace, SFMono-Regular, Consolas, monospace; text-transform: uppercase; }

.correction-row { margin-top: 9px; display: grid; grid-template-columns: 1fr 92px; gap: 8px; }
.correction-row .segmented { display: grid; grid-template-columns: 1fr 1fr; }
.correction-row label { display: flex; align-items: center; gap: 5px; color: var(--faint); font-size: 11px; }
.correction-output { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line-soft); }
.correction-output p { margin: 0 0 6px; color: var(--muted); font-size: 12px; }
.correction-output strong { color: var(--text); }
.correction-output .impact-summary { margin-bottom: 9px; color: var(--text); font-size: 13px; }
.correction-output div { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; color: var(--muted); font-size: 12px; }
.correction-output div b { color: var(--accent); }
.copy-correction { width: 100%; min-height: 36px; margin-top: 8px; border: 1px solid var(--line); color: var(--cyan); background: var(--panel-2); cursor: pointer; font-weight: 800; }
.copy-correction:hover { border-color: var(--cyan); }

.spec-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.spec-title strong { font-size: 17px; }
.tag { padding: 3px 6px; color: var(--warning); border: 1px solid rgba(239, 183, 91, .4); font: 800 9px ui-monospace, SFMono-Regular, Consolas, monospace; }
.spec-row { padding: 7px 0; display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line-soft); color: var(--muted); font-size: 12px; }
.spec-row b { color: var(--text); }
.spec-note { margin: 10px 0 0; color: var(--faint); font-size: 11px; line-height: 1.45; }

.notes { margin-top: 12px; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); background: rgba(16, 23, 19, .94); }
.notes article { padding: 19px 21px; }
.notes article + article { border-left: 1px solid var(--line); }
.notes h2 { margin: 0 0 7px; font-size: 16px; }
.notes p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.notes a { color: var(--cyan); }

@media (max-width: 1050px) {
  .calculator { grid-template-columns: 1fr; }
  .map-stage { min-height: auto; aspect-ratio: 1; }
  .side-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .topbar,
  main { width: min(100% - 20px, 1480px); }
  main { padding-top: 24px; }
  .page-head { align-items: flex-start; flex-direction: column; gap: 10px; }
  .selectors { align-items: stretch; flex-direction: column; gap: 12px; }
  .selector-group { align-items: stretch; flex-direction: column; }
  .selector-group .segmented { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .selector-group .segmented button { padding-inline: 8px; }
  .map-toolbar { right: 8px; left: 8px; top: 8px; overflow-x: auto; }
  .map-legend { display: none; }
  .side-panel,
  .notes { grid-template-columns: 1fr; }
  .notes article + article { border-top: 1px solid var(--line); border-left: 0; }
}

@media (max-width: 470px) {
  .topbar > span { display: none; }
  .map-stage { aspect-ratio: 4 / 5; }
  .map-toolbar .compact button { padding-inline: 8px; }
  .readouts { grid-template-columns: 1fr 1fr; }
  .coordinate { grid-template-columns: 1fr; gap: 5px; }
}
