:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2129;
  --muted: #5d6673;
  --line: #d9dee5;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --accent-soft: #e6eefb;
  --alice: #e4f1ec;
  --alice-line: #9ccab8;
  --bob: #f5ecdc;
  --bob-line: #d7bb85;
  --danger: #a4262c;
  --danger-soft: #fbeaea;
  --beam: #8a3ab9;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181e;
    --surface: #1d232b;
    --text: #e7eaef;
    --muted: #9da7b4;
    --line: #363f4b;
    --accent: #7fb0f5;
    --accent-text: #10151c;
    --accent-soft: #263650;
    --alice: #1f3a31;
    --alice-line: #3f7361;
    --bob: #3d3322;
    --bob-line: #80683c;
    --danger: #ff9b9b;
    --danger-soft: #472325;
    --beam: #c07be6;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.page {
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}

h1 {
  margin: 0 0 16px;
  font-size: 1.6rem;
  line-height: 1.25;
}

h2 {
  margin: 0 0 4px;
  font-size: 1.2rem;
}

h3 {
  margin: 24px 0 8px;
  font-size: 1rem;
}

p {
  margin: 0;
}

.scheme {
  display: block;
  width: 100%;
  max-width: 600px;
  height: auto;
}

.scheme text {
  fill: var(--text);
  font-size: 18px;
}

.beam {
  stroke: var(--beam);
  stroke-width: 6;
  stroke-linecap: round;
}

.plate ellipse {
  fill-opacity: 0.85;
  stroke-width: 1.5;
}

.plate line {
  stroke-width: 1;
}

.plate.alice ellipse,
.dot-alice {
  fill: var(--alice);
  stroke: var(--alice-line);
}

.plate.bob ellipse,
.dot-bob {
  fill: var(--bob);
  stroke: var(--bob-line);
}

.plate.alice line {
  stroke: var(--alice-line);
}

.plate.bob line {
  stroke: var(--bob-line);
}

.arc {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.5;
}

.arc-head {
  fill: var(--muted);
}

.optic,
.optic-box path {
  fill: var(--surface);
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-linejoin: round;
}

.laser-cap {
  fill: var(--muted);
}

.cube path {
  fill: var(--accent-soft);
  fill-opacity: 0.8;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-linejoin: round;
}

.cube line {
  stroke: var(--accent);
  stroke-width: 1.5;
}

footer {
  margin-top: 24px;
  color: var(--muted);
  font-size: 0.875rem;
}

.total,
.lead,
.hint,
.note {
  color: var(--muted);
}

.total {
  margin-top: 8px;
  font-size: 0.875rem;
}

#tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 24px 0 16px;
}

button {
  font: inherit;
  cursor: pointer;
}

.tab {
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.tab[aria-current="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.panel {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.panel[hidden] {
  display: none;
}

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  align-items: start;
  margin: 16px 0;
}

.field label {
  display: block;
  margin-bottom: 2px;
  font-size: 0.875rem;
  font-weight: 600;
}

.field input[type="text"],
.field select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.field input[aria-invalid="true"] {
  border-color: var(--danger);
}

.field.checkbox label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 26px;
  font-weight: 400;
}

.hint {
  margin-top: 2px;
  font-size: 0.8125rem;
  line-height: 1.35;
}

.submit {
  padding: 8px 18px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

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

.output {
  margin-top: 20px;
  border-top: 1px solid var(--line);
}

.output:empty {
  display: none;
}

.output > p {
  margin-top: 12px;
}

.alert {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--danger-soft);
  color: var(--danger);
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 32px;
  margin-top: 16px;
}

.stat-label {
  color: var(--muted);
  font-size: 0.875rem;
}

.stat-value {
  font-family: var(--mono);
  font-size: 1.75rem;
  line-height: 1.2;
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 100%;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th {
  font-size: 0.875rem;
  font-weight: 600;
}

td {
  font-family: var(--mono);
  font-size: 0.9375rem;
}

th:first-child,
td:first-child {
  text-align: left;
}

.ideal {
  color: var(--muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
}

.chips-label {
  margin-right: 4px;
  font-size: 0.875rem;
}

.chip {
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.875rem;
}

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.note {
  font-size: 0.875rem;
}

.bits {
  overflow-wrap: anywhere;
}

.bits code {
  font-family: var(--mono);
}

@media (max-width: 520px) {
  .page {
    padding-top: 20px;
  }

  .panel {
    padding: 16px;
  }

  .fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
