:root {
  color-scheme: light;
  --bg: #f3f6f4;
  --panel: #ffffff;
  --ink: #1d252c;
  --muted: #5c6670;
  --line: #cfd7dc;
  --map-water: #d8e7ee;
  --map-land: #eef2ee;
  --accent: #0f766e;
  --danger: #b64242;
  --shadow: 0 18px 50px rgba(31, 36, 42, 0.16);
}

:root.dark {
  color-scheme: dark;
  --bg: #161819;
  --panel: #202326;
  --ink: #f3f1ea;
  --muted: #a5a8aa;
  --line: #393d40;
  --map-water: #10171d;
  --map-land: #1b2124;
  --accent: #61b6a6;
  --danger: #e26a6a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
label.file-button {
  font: inherit;
}

button,
label.file-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 6px;
  cursor: pointer;
  min-height: 38px;
  padding: 0 12px;
}

button:hover,
label.file-button:hover {
  border-color: var(--accent);
}

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

.map-pane {
  position: relative;
  min-height: 100vh;
  background: var(--map-water);
}

#map {
  position: absolute;
  inset: 0;
  background: var(--map-water);
}

.leaflet-container {
  background: var(--map-water);
  font: inherit;
}

.leaflet-interactive:focus {
  outline: none;
}

.region-label {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(40, 42, 44, 0.15);
  border-radius: 4px;
  color: #20242a;
  padding: 2px 6px;
  box-shadow: none;
}

.selected-region-pattern {
  fill: url("#selectedRegionPattern");
  filter: drop-shadow(0 0 5px rgba(17, 24, 32, 0.45));
}

.hover-region-pattern {
  fill: url("#hoverRegionPattern");
}

.map-tools {
  position: absolute;
  z-index: 800;
  top: 16px;
  left: 58px;
}

.map-tools button {
  background: rgba(255, 255, 255, 0.92);
  color: #20242a;
  min-height: 34px;
}

.loading {
  position: absolute;
  z-index: 900;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.loading.hidden {
  display: none;
}

.panel {
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: 100vh;
  overflow: auto;
  padding: 22px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: 0;
}

.icon-button {
  width: 38px;
  padding: 0;
}

.live-score-panel {
  display: grid;
  gap: 10px;
}

.live-score-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.live-score-box {
  display: grid;
  align-content: center;
  min-height: 78px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--accent), var(--line) 50%);
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent), var(--panel) 90%);
  text-align: left;
}

.live-score-box strong {
  display: block;
  margin-top: 7px;
  color: var(--accent);
  font-size: 28px;
  line-height: 1;
}

.tier-box {
  width: 100%;
}

.tier-box strong {
  font-size: 22px;
}

.tier-standards {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.tier-standards[hidden] {
  display: none;
}

#tierRows {
  display: grid;
  gap: 6px;
}

.tier-row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 28px;
  color: var(--muted);
  font-size: 12px;
}

.tier-row strong {
  color: var(--ink);
}

.tier-row.reached strong,
.tier-row.reached span {
  color: var(--accent);
}

.score-card {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.score-card > div {
  min-width: 0;
  padding: 14px 12px;
  background: var(--panel);
}

.label,
.section-title,
label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.score-card strong {
  display: block;
  margin-top: 5px;
  font-size: 22px;
  line-height: 1;
}

.control-group,
.legend,
.achievements,
.route-assistant {
  display: grid;
  gap: 10px;
}

.foldable-control {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

.foldable-control summary {
  cursor: pointer;
  padding: 11px 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.foldable-control .filter-grid {
  padding: 0 12px 12px;
}

.search-row,
.data-actions {
  display: flex;
  gap: 8px;
}

input[type="search"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 11px;
  background: var(--bg);
  color: var(--ink);
}

select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 11px;
  background: var(--bg);
  color: var(--ink);
}

.search-results {
  display: grid;
  gap: 6px;
  max-height: 160px;
  overflow: auto;
}

.result-button {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 34px;
  text-align: left;
}

.route-assistant {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.route-assistant summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.route-assistant[open] summary {
  margin-bottom: 10px;
}

.route-stops {
  display: grid;
  gap: 6px;
  max-height: 190px;
  overflow: auto;
}

.route-stop {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: auto;
  padding: 8px 10px;
  line-height: 1.25;
  text-align: left;
  white-space: normal;
}

.route-stop > span:first-child {
  min-width: 0;
}

.route-stop strong {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.route-city {
  display: block;
  font-weight: 800;
}

.route-station-list {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.route-stop.missing {
  opacity: 0.55;
  cursor: not-allowed;
}

.route-actions {
  display: flex;
  gap: 8px;
}

.route-range {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.route-range label {
  display: grid;
  gap: 5px;
}

.route-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.selected-name {
  font-size: 20px;
  font-weight: 800;
}

.selected-meta {
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
}

.level-grid,
.filter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.level-button,
.filter-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.level-button.active,
.filter-button.active {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent), transparent 72%);
}

.swatch {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 4px;
}

.legend-row {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: var(--muted);
  font-size: 13px;
}

.achievement-summary {
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
}

.achievement-browser {
  display: grid;
  gap: 8px;
}

.achievement-browser summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.achievement-rows {
  display: grid;
  gap: 8px;
}

.compact-list {
  max-height: 220px;
  overflow: auto;
}

.achievement-card {
  display: grid;
  gap: 7px;
  width: 100%;
  min-height: auto;
  padding: 10px 11px;
  text-align: left;
}

.achievement-card.compact .achievement-detail {
  display: none;
}

.achievement-card.compact.open .achievement-detail {
  display: block;
}

.achievement-card.unlocked {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent), var(--panel) 88%);
}

.achievement-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.achievement-name {
  font-weight: 800;
}

.achievement-state {
  color: var(--muted);
  font-size: 12px;
}

.achievement-detail {
  display: none;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.achievement-card.open .achievement-detail {
  display: block;
}

.empty-achievement {
  padding: 10px 0;
  color: var(--muted);
  font-size: 13px;
}

input[type="file"] {
  display: none;
}

.file-button {
  display: inline-flex;
  align-items: center;
}

#clearButton {
  color: var(--danger);
}

.note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(58vh, 1fr) auto;
  }

  .map-pane {
    min-height: 58vh;
  }

  .panel {
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 480px) {
  .panel {
    padding: 16px;
  }

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

  .live-score-card,
  .tier-row,
  .route-range {
    grid-template-columns: 1fr;
  }

  .level-grid,
  .filter-grid {
    grid-template-columns: 1fr;
  }

}
