:root {
  color-scheme: light;
  --bg: #f3efe2;
  --panel: rgba(253, 250, 240, 0.88);
  --panel-border: rgba(78, 62, 36, 0.15);
  --ink: #2e2619;
  --muted: #64563f;
  --accent: #466b45;
  --accent-soft: #cedbbf;
  --shadow: 0 24px 80px rgba(60, 44, 22, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Iowan Old Style", "Palatino Linotype", "URW Palladio L", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.72), transparent 30%),
    linear-gradient(135deg, #e7e0c7 0%, #f7f3e8 50%, #e4ead9 100%);
}

body {
  min-height: 100vh;
  min-height: 100svh;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  min-height: 100vh;
  gap: 1rem;
  padding: 1rem;
}

.panel {
  padding: 1.5rem;
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

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

h1 {
  margin: 0.4rem 0 1rem;
  font-size: clamp(2.2rem, 4vw, 3.6rem);
  line-height: 0.95;
}

.intro,
.notes {
  color: var(--muted);
  line-height: 1.5;
}

.visibility-panel {
  margin-top: 1.5rem;
}

.visibility-panel h2 {
  margin: 0 0 0.65rem;
  color: var(--ink);
  font-size: 1rem;
}

#visibility-tree {
  --checkbox-tree-indent: 16px;
  --checkbox-tree-hover-color: var(--accent);
  max-height: min(45vh, 28rem);
  overflow: auto;
  padding: 0.65rem;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(255, 253, 246, 0.62);
}

.notes h2 {
  margin-bottom: 0.6rem;
  color: var(--ink);
  font-size: 1rem;
}

pre {
  margin: 0;
  padding: 0.9rem;
  overflow-x: auto;
  border-radius: 16px;
  background: rgba(70, 107, 69, 0.08);
}

code {
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 0.86rem;
}

main,
.map-frame {
  display: flex;
  min-width: 0;
}

.map-frame {
  position: relative;
  flex: 1;
}

#map {
  flex: 1;
  min-height: calc(100vh - 2rem);
  min-height: calc(100svh - 2rem);
  border-radius: 28px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.maplibregl-popup-content {
  border-radius: 14px;
}

.maplibregl-popup-content {
  font-family: "Iowan Old Style", "Palatino Linotype", "URW Palladio L", serif;
}

.map-status {
  position: absolute;
  z-index: 2;
  top: 1rem;
  left: 50%;
  margin: 0;
  transform: translateX(-50%);
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  background: rgba(253, 250, 240, 0.94);
  box-shadow: 0 8px 24px rgba(60, 44, 22, 0.16);
}

.map-status[hidden] {
  display: none;
}

.measurement-table-block {
  margin-top: 0.35rem;
}

.measurement-table {
  width: 100%;
  margin-top: 0.15rem;
  border-collapse: collapse;
  font-size: 0.92em;
}

.measurement-table th,
.measurement-table td {
  padding: 0.12rem 0.35rem 0.12rem 0;
  border-bottom: 1px solid rgba(87, 68, 38, 0.18);
  text-align: left;
  white-space: nowrap;
}

.measurement-table th {
  font-weight: 700;
}

.measurement-table tbody tr:last-child td {
  border-bottom: 0;
}

.timeline-control {
  display: grid;
  gap: 0.45rem;
  min-width: 12rem;
  padding: 0.7rem;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: rgba(253, 250, 240, 0.94);
  box-shadow: 0 12px 36px rgba(60, 44, 22, 0.16);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", "URW Palladio L", serif;
}

.timeline-control-title {
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.timeline-buttons {
  display: grid;
  gap: 0.35rem;
}

.timeline-buttons button {
  width: 100%;
  border: 1px solid rgba(70, 107, 69, 0.28);
  border-radius: 6px;
  padding: 0.42rem 0.55rem;
  background: #fffdf6;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.timeline-buttons button:hover,
.timeline-buttons button:focus-visible {
  border-color: rgba(70, 107, 69, 0.58);
  outline: none;
}

.timeline-buttons button.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}

.error-overlay {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 10000;
  width: min(42rem, calc(100vw - 2rem));
  max-height: min(28rem, calc(100vh - 2rem));
  overflow: auto;
  border: 1px solid rgba(111, 23, 23, 0.32);
  border-radius: 8px;
  background: #fff7f4;
  box-shadow: 0 18px 60px rgba(59, 20, 20, 0.22);
  color: #331514;
}

.error-overlay[hidden] {
  display: none;
}

.error-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid rgba(111, 23, 23, 0.18);
  background: #f6d5ce;
}

.error-overlay-actions {
  display: flex;
  gap: 0.45rem;
}

.error-overlay button {
  border: 1px solid rgba(111, 23, 23, 0.28);
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
  background: #fffaf8;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.error-overlay pre {
  margin: 0;
  border-radius: 0;
  background: transparent;
  white-space: pre-wrap;
}

.error-overlay-copy-buffer {
  position: fixed;
  top: -100vh;
  left: -100vw;
}

@media (max-width: 900px) {
  body {
    min-height: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    min-height: auto;
    padding: 0.75rem;
    padding:
      max(0.75rem, env(safe-area-inset-top))
      max(0.75rem, env(safe-area-inset-right))
      max(0.75rem, env(safe-area-inset-bottom))
      max(0.75rem, env(safe-area-inset-left));
  }

  main {
    order: -1;
    min-height: min(72svh, 46rem);
  }

  .panel {
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 12px 36px rgba(60, 44, 22, 0.14);
  }

  h1 {
    margin-bottom: 0.65rem;
    font-size: clamp(2rem, 12vw, 3rem);
  }

  .intro {
    margin-bottom: 0;
  }

  #map {
    min-height: min(72svh, 46rem);
    border-radius: 12px;
  }

  .timeline-control {
    width: min(18rem, calc(100vw - 2rem));
    max-width: calc(100vw - 2rem);
  }

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

  .timeline-buttons button {
    min-height: 2.65rem;
    padding: 0.38rem 0.45rem;
    text-align: center;
    overflow-wrap: anywhere;
  }

  .maplibregl-ctrl-top-left,
  .maplibregl-ctrl-top-right {
    top: 0.5rem;
  }

  .maplibregl-ctrl-top-right,
  .maplibregl-ctrl-bottom-right {
    right: 0.5rem;
  }

  .maplibregl-ctrl-bottom-left,
  .maplibregl-ctrl-bottom-right {
    bottom: 0.5rem;
  }

  .maplibregl-popup-content {
    max-width: min(16rem, calc(100vw - 5rem));
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 0;
  }

  main,
  #map {
    min-height: 68svh;
  }

  #map {
    border-radius: 0;
  }

  .panel {
    margin: 0 0.75rem 0.75rem;
  }

  .timeline-control {
    padding: 0.55rem;
  }
}
