:root {
  --paper: #f3efe6;
  --panel: rgba(252, 249, 242, 0.96);
  --panel-strong: #f8f5ee;
  --ink: #201c17;
  --muted: #655f57;
  --line: rgba(74, 63, 50, 0.18);
  --accent: #8f3a32;
  --soviet: #8f3a32;
  --austrian: #516246;
  --western: #4b6178;
  --shadow: 0 10px 30px rgba(47, 38, 28, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0)),
    linear-gradient(180deg, #f5f1e9 0%, var(--paper) 100%);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
}

body {
  padding: 10px;
}

.app-shell {
  max-width: 1680px;
  margin: 0 auto;
}

.topbar {
  margin-bottom: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: rgba(249, 246, 239, 0.92);
  box-shadow: var(--shadow);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.15rem, 1.9vw, 1.6rem);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.topbar-question {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: clamp(0.82rem, 1.05vw, 0.95rem);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding: 10px 14px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 3.25fr) minmax(380px, 1.2fr);
  gap: 10px;
  min-height: calc(100vh - 128px);
}

.map-panel,
.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.map-panel {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#map {
  flex: 1 1 auto;
  min-height: calc(100vh - 220px);
}

.panel {
  padding: 14px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 0.96rem;
  font-weight: 600;
}

.field {
  display: block;
  margin-bottom: 0;
}

.field span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.77rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--ink);
  font: inherit;
}

.toolbar-field {
  min-width: 145px;
  flex: 0 1 auto;
}

.toolbar-phase {
  flex: 1 1 300px;
  min-width: 260px;
}

.toolbar-check {
  min-width: 180px;
}

.toolbar-meta {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.84rem;
  white-space: nowrap;
}

.compact-field select {
  min-width: 0;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 0.9rem;
}

.check-field input {
  accent-color: var(--accent);
}

.compact-check {
  padding-top: 20px;
}

.phase-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.phase-button {
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--ink);
  font: inherit;
  text-align: center;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.map-context {
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--line);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 0.82rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(32, 28, 23, 0.18);
}

.legend-soviet {
  background: var(--soviet);
}

.legend-austrian {
  background: var(--western);
}

.legend-transformation {
  background: #9b8d62;
}

.phase-button:hover,
.phase-button:focus-visible {
  border-color: rgba(143, 58, 50, 0.42);
  outline: none;
}

.phase-button.active {
  background: rgba(143, 58, 50, 0.08);
  border-color: rgba(143, 58, 50, 0.4);
}

.detail-panel {
  min-height: calc(100vh - 220px);
  max-height: calc(100vh - 220px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.site-detail {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-gutter: stable;
}

.detail-card {
  padding-bottom: 8px;
}

.detail-header {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.site-detail h3 {
  margin: 0 0 6px;
  font-size: 1.34rem;
  line-height: 1.2;
}

.detail-section {
  margin: 0 0 14px;
}

.detail-section h4 {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border: 1px solid var(--line);
  background: rgba(244, 239, 230, 0.7);
  font-size: 0.78rem;
  line-height: 1;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 16px 0 0;
}

.detail-grid div {
  padding: 10px;
  border: 1px solid var(--line);
  background: rgba(244, 239, 230, 0.7);
}

.detail-grid dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.detail-grid dd {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.35;
}

.detail-body {
  margin: 0;
  line-height: 1.55;
}

.detail-significance {
  margin: 0;
  line-height: 1.55;
  font-weight: 600;
}

.detail-subnote {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.detail-source p {
  margin: 0;
  line-height: 1.5;
}

.detail-source {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.detail-figure,
.image-placeholder {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  background: rgba(245, 241, 232, 0.9);
}

.detail-figure img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.detail-figure figcaption {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.image-source {
  margin: 0;
  padding: 0 10px 10px;
  font-size: 0.78rem;
}

.image-source a {
  color: var(--accent);
  text-decoration: none;
}

.image-source a:hover {
  text-decoration: underline;
}

.image-placeholder {
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.image-placeholder-inline {
  min-height: auto;
  aspect-ratio: 4 / 3;
}

.empty-state {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.method-note {
  margin-top: 10px;
  padding-top: 10px;
  padding-bottom: 10px;
}

.method-note p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.leaflet-popup-content-wrapper {
  border-radius: 0;
  box-shadow: 0 6px 20px rgba(47, 38, 28, 0.14);
}

.leaflet-popup-content {
  margin: 10px 12px;
  font-family: Georgia, "Times New Roman", serif;
}

.popup-card h3 {
  margin: 0 0 5px;
  font-size: 0.98rem;
}

.popup-card p {
  margin: 0;
  color: #4f4941;
  font-size: 0.84rem;
  line-height: 1.45;
}

.popup-instruction {
  margin-top: 6px;
  color: var(--accent);
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }

  #map {
    min-height: 58vh;
  }

  .detail-panel {
    min-height: 0;
    max-height: none;
  }

  .site-detail {
    overflow: visible;
  }
}

@media (min-width: 1360px) {
  .detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  body {
    padding: 10px;
  }

  .topbar-question {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

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

  .detail-figure figcaption {
    display: block;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar-field,
  .toolbar-phase,
  .toolbar-check,
  .toolbar-meta {
    min-width: 100%;
    flex-basis: 100%;
  }

  .compact-check {
    padding-top: 0;
  }

  .toolbar-meta {
    margin-left: 0;
  }
}
