:root {
  --ink: #ece2cb;
  --muted: #b9ab8d;
  --dim: #847762;
  --panel: rgba(18, 20, 18, 0.86);
  --panel-solid: #171916;
  --line: rgba(236, 226, 203, 0.16);
  --accent: #b44530;
  --accent-2: #9ea75e;
  --accent-3: #5f8790;
  --field: rgba(255, 249, 226, 0.07);
  --shadow: rgba(0, 0, 0, 0.42);
  font-family: "Segoe UI", "Inter", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  background: #0b0704;
  overflow: hidden;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -2;
  content: "";
  background:
    radial-gradient(circle at 8% 10%, rgba(159, 78, 31, 0.24), transparent 24rem),
    radial-gradient(circle at 82% 84%, rgba(0, 0, 0, 0.58), transparent 28rem),
    repeating-linear-gradient(7deg, rgba(96, 54, 25, 0.18) 0 1px, transparent 1px 9px),
    linear-gradient(90deg, rgba(7, 4, 2, 0.96), rgba(48, 29, 15, 0.68) 46%, rgba(7, 4, 2, 0.95)),
    linear-gradient(180deg, #1a0f08, #080604);
  filter: saturate(0.86) contrast(1.12);
}

body::after {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  background-image:
    radial-gradient(circle at 18% 15%, rgba(180, 69, 48, 0.1), transparent 23rem),
    radial-gradient(circle at 82% 72%, rgba(95, 135, 144, 0.10), transparent 20rem),
    repeating-linear-gradient(90deg, rgba(255, 210, 130, 0.025) 0 1px, transparent 1px 54px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.012) 0 1px, transparent 1px 4px);
  mix-blend-mode: screen;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 2.5rem;
  padding: 0.58rem 0.82rem;
  color: var(--ink);
  cursor: pointer;
  background: rgba(236, 226, 203, 0.08);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: transform 130ms ease, background 130ms ease, border-color 130ms ease;
}

button:hover {
  background: rgba(236, 226, 203, 0.13);
  border-color: rgba(236, 226, 203, 0.32);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid rgba(158, 167, 94, 0.88);
  outline-offset: 2px;
}

.primary-action {
  color: #fff4dc;
  background: linear-gradient(180deg, #a83d2b, #6e251d);
  border-color: rgba(239, 141, 94, 0.45);
}

.primary-action:hover {
  background: linear-gradient(180deg, #b74732, #7b2a20);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(17rem, 20rem) minmax(0, 1fr) minmax(18rem, 23rem);
  gap: 1rem;
  width: 100%;
  height: 100vh;
  padding: 1rem;
}

.panel,
.map-stage {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1.25rem 3rem var(--shadow);
  backdrop-filter: blur(10px);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow: auto;
  scrollbar-color: rgba(236, 226, 203, 0.28) rgba(0, 0, 0, 0.16);
}

.controls-panel,
.details-panel {
  padding: 1rem;
}

.brand {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
  align-items: start;
  padding-bottom: 0.8rem;
  text-align: center;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: block;
  justify-self: center;
  width: min(100%, 15.5rem);
  height: auto;
  max-height: 9.6rem;
  object-fit: contain;
  filter: drop-shadow(0 0.65rem 1rem rgba(0, 0, 0, 0.42));
}

.brand-copy {
  display: grid;
  gap: 0.1rem;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--accent-2);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: 1.28rem;
  line-height: 1.1;
}

h2 {
  margin: 0 0 0.75rem;
  color: #f2e9d5;
  font-size: 0.95rem;
}

h3 {
  margin: 0.9rem 0 0.35rem;
  color: #f2e9d5;
  font-size: 0.92rem;
}

.control-section {
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.control-section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.field {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.field span {
  color: var(--muted);
  font-size: 0.82rem;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 2.4rem;
  padding: 0.56rem 0.66rem;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
}

select {
  cursor: pointer;
}

select option {
  color: #f5ead1;
  background: #1f211d;
}

input[type="number"] {
  appearance: textfield;
}

.split-fields,
.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

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

.button-row button {
  min-width: 0;
  white-space: nowrap;
}

.export-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.single-action-row {
  grid-template-columns: 1fr;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
  padding: 0.25rem;
  background: rgba(236, 226, 203, 0.06);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.segmented-control button {
  min-height: 2.25rem;
  border-color: transparent;
  background: transparent;
}

.segmented-control button.is-active {
  color: #fff4dc;
  background: rgba(180, 69, 48, 0.74);
  border-color: rgba(239, 141, 94, 0.38);
}

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

.tool-grid button {
  min-height: 2.35rem;
  min-width: 0;
}

.tool-grid button.is-active {
  color: #fff4dc;
  background: rgba(95, 135, 144, 0.54);
  border-color: rgba(151, 194, 202, 0.46);
}

.tool-hint {
  min-height: 2.35rem;
  margin: 0.65rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.map-stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.stage-toolbar {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
}

.stage-toolbar h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

.stage-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 0.5rem;
  align-items: center;
  min-width: 0;
}

.language-toggle {
  min-width: 3.1rem;
  min-height: 2.15rem;
  padding: 0.35rem 0.55rem;
  color: #f5ead1;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: rgba(236, 226, 203, 0.08);
  border-color: rgba(236, 226, 203, 0.22);
}

.status-pill {
  flex: 0 0 auto;
  max-width: 12rem;
  padding: 0.36rem 0.6rem;
  overflow: hidden;
  color: #d7e2bd;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: rgba(158, 167, 94, 0.14);
  border: 1px solid rgba(158, 167, 94, 0.28);
  border-radius: 999px;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(232, 217, 174, 0.05), rgba(0, 0, 0, 0.12)),
    #141512;
}

#mapCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

#mapCanvas.is-panning {
  cursor: grabbing;
}

#mapCanvas.is-drawing-edge {
  cursor: cell;
}

.stats-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.48rem 0.75rem;
  margin: 0;
}

.stats-list dt {
  color: var(--muted);
}

.stats-list dd {
  margin: 0;
  color: #f5ead1;
  font-weight: 700;
}

.hex-details {
  color: var(--muted);
  line-height: 1.45;
}

.hex-editor {
  display: grid;
  gap: 0.75rem;
  color: var(--muted);
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.65rem;
}

.editor-field {
  margin-bottom: 0;
}

.editor-checks,
.editor-subsection {
  display: grid;
  gap: 0.5rem;
}

.editor-subsection {
  padding: 0.68rem;
  background: rgba(236, 226, 203, 0.045);
  border: 1px solid rgba(236, 226, 203, 0.11);
  border-radius: 6px;
}

.check-field {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  align-items: center;
  min-height: 2.1rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.check-field input {
  width: 1.05rem;
  min-height: auto;
  margin: 0;
  accent-color: var(--accent-2);
}

.subtle-action {
  width: 100%;
  color: #e7d9b9;
  background: rgba(180, 69, 48, 0.16);
  border-color: rgba(180, 69, 48, 0.32);
}

.subtle-action:hover {
  background: rgba(180, 69, 48, 0.24);
}

.hex-title {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.55rem;
}

.hex-title strong {
  color: #f4ead5;
  font-size: 1.1rem;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.55rem 0;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 1.55rem;
  padding: 0.18rem 0.44rem;
  color: #f4ead5;
  background: rgba(236, 226, 203, 0.08);
  border: 1px solid rgba(236, 226, 203, 0.14);
  border-radius: 999px;
  font-size: 0.78rem;
}

.detail-list {
  display: grid;
  gap: 0.34rem;
  margin: 0;
}

.detail-list div {
  display: grid;
  grid-template-columns: 7.8rem minmax(0, 1fr);
  gap: 0.5rem;
}

.detail-list dt {
  color: var(--dim);
}

.detail-list dd {
  margin: 0;
  color: var(--ink);
}

.legend-list {
  display: grid;
  gap: 0.42rem;
}

.legend-heading {
  margin-top: 0.35rem;
  color: #f2e9d5;
  font-size: 0.78rem;
  font-weight: 700;
}

.legend-heading:first-child {
  margin-top: 0;
}

.legend-item {
  display: grid;
  grid-template-columns: 2.15rem 1fr;
  gap: 0.6rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.86rem;
}

.legend-icon {
  display: block;
  width: 2rem;
  height: 1.36rem;
}

.legend-terrain {
  border: 1px solid rgba(236, 226, 203, 0.35);
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16);
}

.legend-symbol {
  border: 1px solid rgba(236, 226, 203, 0.18);
  border-radius: 3px;
  background: rgba(236, 226, 203, 0.04);
}

.legend-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.legend-river-shadow,
.legend-road-shadow,
.legend-rail-shadow {
  fill: none;
  stroke-linecap: round;
}

.legend-river-shadow {
  stroke: rgba(12, 23, 25, 0.9);
  stroke-width: 8;
}

.legend-river {
  fill: none;
  stroke: rgba(87, 126, 132, 0.92);
  stroke-linecap: round;
  stroke-width: 4;
}

.legend-road-shadow {
  stroke: rgba(24, 17, 12, 0.82);
  stroke-width: 6;
}

.legend-road {
  fill: none;
  stroke: rgba(186, 153, 101, 0.9);
  stroke-dasharray: 6 4;
  stroke-linecap: round;
  stroke-width: 2;
}

.legend-rail-shadow {
  stroke: rgba(7, 7, 6, 0.92);
  stroke-width: 6;
}

.legend-rail {
  fill: none;
  stroke: rgba(132, 78, 55, 0.94);
  stroke-width: 2;
}

.legend-sleeper,
.legend-bridge {
  fill: none;
  stroke-linecap: round;
}

.legend-sleeper {
  stroke: rgba(18, 12, 9, 0.95);
  stroke-width: 2;
}

.legend-bridge {
  stroke: rgba(232, 211, 164, 0.98);
  stroke-width: 3;
}

.legend-house-live,
.legend-house-dead {
  stroke-width: 1.3;
}

.legend-house-live {
  fill: rgba(226, 193, 127, 0.92);
  stroke: rgba(52, 30, 20, 0.88);
}

.legend-house-dead {
  fill: rgba(91, 89, 82, 0.86);
  stroke: rgba(25, 24, 22, 0.9);
}

.legend-large-ring {
  fill: none;
  stroke: rgba(236, 226, 203, 0.82);
  stroke-width: 2;
}

.legend-ruin-slash {
  fill: none;
  stroke: rgba(236, 226, 203, 0.62);
  stroke-linecap: round;
  stroke-width: 2;
}

.legend-feature {
  fill: rgba(221, 199, 148, 0.78);
  stroke: rgba(31, 22, 15, 0.9);
  stroke-width: 1.5;
}

.legend-feature-badge {
  fill: rgba(221, 199, 148, 0.78);
  stroke: rgba(31, 22, 15, 0.9);
  stroke-width: 1.35;
}

.legend-feature-line,
.legend-feature-fill,
.legend-feature-dark,
.legend-feature-water,
.legend-feature-fire {
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.legend-feature-line {
  fill: none;
  stroke: #1c130e;
}

.legend-feature-fill {
  fill: #1c130e;
  stroke: #1c130e;
}

.legend-feature-dark {
  fill: #110d0b;
  stroke: #1c130e;
}

.legend-feature-water {
  fill: #5f8790;
  stroke: #1c130e;
}

.legend-feature-fire {
  fill: none;
  stroke: rgba(141, 43, 34, 0.92);
}

.legend-crater {
  fill: rgba(58, 28, 20, 0.72);
  stroke: rgba(31, 19, 14, 0.9);
  stroke-width: 1.5;
}

.legend-trench,
.legend-wire {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.legend-trench {
  stroke: rgba(16, 11, 9, 0.95);
  stroke-width: 2.2;
}

.legend-wire {
  stroke: rgba(225, 202, 151, 0.7);
  stroke-width: 1.35;
}

.empty-note {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 1180px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 18rem minmax(0, 1fr);
    grid-template-rows: minmax(34rem, 1fr) auto;
    height: auto;
    min-height: 100vh;
  }

  .details-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    padding: 0.75rem;
  }

  .map-stage {
    min-height: 72vh;
  }

  .stage-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .controls-panel,
  .details-panel {
    padding: 0.85rem;
  }
}
