:root {
  --paper: #f3efe7;
  --panel: #eae4d6;
  --ink: #211e19;
  --ink-soft: #5d5647;
  --rule: #cdc4b1;
  --accent: #9c3618;

  --label: 0.6875rem;
  --step: 0.9375rem;

  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--paper);
  color: var(--ink);
  font: var(--step) / 1.5 ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

/* Beschriftungen im Idiom einer Kartenlegende: klein, gesperrt, versal. */
h2,
.control label,
.control-label,
.panel legend,
.column-heads {
  font-size: var(--label);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0;
}

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 1.25rem;
  padding: 1.75rem 2rem 1.25rem;
  border-bottom: 1px solid var(--rule);
}

.masthead h1 {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 620;
  letter-spacing: -0.015em;
}

.picker select {
  margin: 0;
  font-size: 0.9375rem;
}

.dataset-note {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.875rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

main {
  display: grid;
  grid-template-columns: minmax(340px, 28rem) 1fr;
  align-items: start;
  min-height: 0;
}

/* ---------- Register ---------- */

.register {
  border-right: 1px solid var(--rule);
  padding: 1.5rem 1.75rem 2rem;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
}

.register-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.75rem;
}

.presets {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0;
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

.presets .link + .link::before {
  content: "·";
  margin-right: 0.5rem;
  color: var(--rule);
  text-decoration: none;
  display: inline-block;
}

.link {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: var(--accent);
  text-transform: none;
  letter-spacing: 0.01em;
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.link:hover {
  color: var(--ink);
}

.column-heads {
  display: flex;
  justify-content: flex-end;
  padding: 0 0.5rem 0.375rem;
  margin: 0 -0.5rem;
  border-bottom: 1px solid var(--rule);
}

.col-value {
  width: 5.25rem;
  text-align: right;
}

.col-value + .col-value {
  width: 3.75rem;
  margin-left: 0.375rem;
}

.col-hex {
  width: 2.75rem;
  text-align: right;
}

.entries {
  list-style: none;
  margin: 0;
  padding: 0;
}

.entries li:first-child {
  margin-top: 0.375rem;
}

.entries li {
  display: flex;
  align-items: baseline;
  gap: 0;
  padding: 0.3125rem 0.5rem;
  margin: 0 -0.5rem;
  border-radius: 3px;
}

.entries li.is-active {
  background: var(--panel);
}

/* Der Name gibt nach, nicht die Zahlenspalten — sonst springt die ganze Liste,
   sobald ein Gebiet einen langen Namen trägt. */
.entries label {
  flex: 0 1 auto;
  min-width: 3rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9375rem;
  cursor: pointer;
}

.leader {
  flex: 1 1 auto;
  min-width: 0.75rem;
  margin: 0 0.5rem 0.3em;
  border-bottom: 1px dotted var(--rule);
}

.entries input {
  flex: none;
  width: 5.25rem;
  padding: 0.1875rem 0.4375rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: #fbf9f5;
  color: inherit;
  font: inherit;
  font-size: 0.875rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.entries input.tint {
  width: 3.75rem;
  margin-left: 0.375rem;
}

/* Der Farbwert ist die Nebengröße — er tritt zurück, solange nichts drinsteht. */
.entries input.tint:placeholder-shown {
  color: var(--ink-soft);
  background: transparent;
  border-style: dashed;
}

.entries input:hover {
  border-color: var(--ink-soft);
}

.entries input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

/* Die abgeleitete Hexagonzahl — die eigentliche Rückmeldung auf die Eingabe. */
.hexes {
  width: 2.75rem;
  text-align: right;
  font-size: 0.8125rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.hexes.is-zero {
  color: #a09781;
}

.hexes.is-off {
  color: var(--accent);
  font-weight: 600;
}

.tally {
  margin: 1rem 0 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--rule);
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.tally strong {
  color: var(--ink);
  font-weight: 620;
}

.upload {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}

.upload h2 {
  padding-bottom: 0.375rem;
}

.upload .hint {
  margin: 0 0 0.625rem;
}

.upload-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin: 0;
}

.filebutton input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.filebutton span {
  display: inline-block;
  padding: 0.3125rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: #fbf9f5;
  font-size: 0.875rem;
  cursor: pointer;
}

.filebutton span:hover {
  border-color: var(--ink-soft);
}

.filebutton input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.upload-status {
  margin: 0.625rem 0 0;
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

.upload-status.is-error {
  color: var(--accent);
}

/* ---------- Karte ---------- */

.stage {
  padding: 1.5rem 2rem 2rem;
  display: grid;
  gap: 1.5rem;
}

.plate {
  margin: 0;
  transition: opacity 180ms ease-out;
}

.plate[aria-busy="true"] {
  opacity: 0.45;
}

.canvas svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 52vh;
}

.canvas g {
  transition: opacity 150ms ease-out;
}

.canvas g.is-muted {
  opacity: 0.32;
}

.canvas g.is-active .edge {
  stroke: var(--accent);
  stroke-width: 4;
}

figcaption {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

#caption.is-warning {
  color: var(--accent);
}

.legend[hidden] {
  display: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
}

.legend-title {
  font-size: var(--label);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.legend-step {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-variant-numeric: tabular-nums;
}

.legend-step::before {
  content: "";
  width: 0.75rem;
  height: 0.75rem;
  background: var(--tone);
  border: 1px solid rgb(0 0 0 / 0.18);
}

/* ---------- Bedienfeld ---------- */

.panels {
  display: grid;
  gap: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
}

.panel {
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem 2.5rem;
  align-items: end;
}

.panel legend {
  grid-column: 1 / -1;
  padding: 0;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  margin-top: 0.5rem;
}

.control output {
  min-width: 4rem;
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.hint {
  margin: 0.375rem 0 0;
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 1.25rem;
  margin: 0;
  background: none;
  appearance: none;
  cursor: grab;
}

input[type="range"]:active {
  cursor: grabbing;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--rule);
}

input[type="range"]::-moz-range-track {
  height: 2px;
  background: var(--rule);
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 0.875rem;
  height: 0.875rem;
  margin-top: -0.4375rem;
  border-radius: 50%;
  background: var(--accent);
}

input[type="range"]::-moz-range-thumb {
  width: 0.875rem;
  height: 0.875rem;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
}

input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 2px;
}

.segmented {
  display: inline-flex;
  margin-top: 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  overflow: hidden;
}

.segmented button {
  padding: 0.3125rem 0.75rem;
  border: 0;
  background: #fbf9f5;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 140ms ease-out, color 140ms ease-out;
}

.segmented button + button {
  border-left: 1px solid var(--rule);
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button[aria-checked="true"] {
  background: var(--panel);
  color: var(--ink);
  font-weight: 550;
}

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

select {
  margin-top: 0.5rem;
  padding: 0.3125rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: #fbf9f5;
  color: inherit;
  font: inherit;
  font-size: 0.875rem;
}

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

.control label.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9375rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  cursor: pointer;
}

.control label.check input {
  width: 0.9375rem;
  height: 0.9375rem;
  accent-color: var(--accent);
}

.actions {
  display: flex;
  gap: 0.625rem;
  justify-content: flex-end;
  padding-top: 0.25rem;
}

.actions button {
  padding: 0.4375rem 0.9375rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: #fbf9f5;
  color: var(--ink);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 140ms ease-out, border-color 140ms ease-out;
}

.actions button:hover {
  border-color: var(--ink-soft);
}

.actions button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fbf6ef;
}

.actions button.primary:hover {
  background: #85290f;
  border-color: #85290f;
}

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

.actions button[disabled] {
  opacity: 0.5;
  cursor: default;
}

footer {
  padding: 1.25rem 2rem 2rem;
  border-top: 1px solid var(--rule);
  font-size: 0.75rem;
  color: var(--ink-soft);
}

footer p {
  margin: 0;
  max-width: 70ch;
}

footer a {
  color: inherit;
}

@media (max-width: 60rem) {
  main {
    grid-template-columns: 1fr;
  }

  .register {
    position: static;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    order: 2;
  }

  .stage {
    order: 1;
    padding-inline: 1.25rem;
  }

  .masthead,
  footer {
    padding-inline: 1.25rem;
  }

  .canvas svg {
    max-height: none;
  }

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

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 1ms !important;
  }
}
