:root {
  --bg: #faf6ec;
  --fg: #2a2418;
  --accent: #c5a000;
  --header-bg: #fff8df;
  --border: #d8cfb0;
  --legend-bg: rgba(255, 252, 240, 0.96);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1a13;
    --fg: #f0e8d0;
    --accent: #ffd400;
    --header-bg: #2b2618;
    --border: #4a4128;
    --legend-bg: rgba(40, 36, 24, 0.95);
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

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

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: relative;
  z-index: 1000;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-size: 1.05rem;
}
.brand .dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  align-self: center;
  box-shadow: 0 0 0 3px rgba(255, 212, 0, 0.25);
}
.brand .subtitle {
  font-size: 0.85rem;
  color: color-mix(in srgb, var(--fg) 65%, transparent);
}
@media (max-width: 700px) {
  .brand .subtitle { display: none; }
}

button {
  background: var(--accent);
  color: #1d1a13;
  border: none;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.92rem;
}
button:hover { filter: brightness(1.07); }

main {
  position: relative;
  height: calc(100vh - 53px);
}

#map {
  position: absolute;
  inset: 0;
}

#legend {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--legend-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  width: 240px;
  box-shadow: var(--shadow);
  z-index: 500;
  backdrop-filter: blur(6px);
}
#legend h3 {
  margin: 0 0 0.5rem 0;
  font-size: 0.95rem;
}
#legend ul {
  list-style: none;
  padding: 0; margin: 0 0 0.7rem 0;
  font-size: 0.85rem;
}
#legend li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 3px;
}
#legend .sw {
  width: 16px; height: 16px;
  border-radius: 3px;
  display: inline-block;
  border: 1px solid rgba(0, 0, 0, 0.15);
}
#legend label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}
#legend input[type="range"] {
  width: 100%;
}
.meta {
  margin-top: 0.7rem;
  font-size: 0.78rem;
  color: color-mix(in srgb, var(--fg) 75%, transparent);
}
.meta .att {
  font-size: 0.72rem;
  margin-top: 0.4rem;
  line-height: 1.35;
}
@media (max-width: 600px) {
  #legend {
    width: auto;
    left: 12px;
    right: 12px;
    top: auto;
    bottom: 12px;
  }
}

/* Popup */
.fb-popup {
  font-size: 0.88rem;
  min-width: 240px;
}
.fb-popup h3 {
  margin: 0 0 0.4rem 0;
  font-size: 1rem;
}
.fb-popup .row {
  display: flex;
  justify-content: space-between;
  margin: 2px 0;
}
.fb-popup .row .lbl {
  color: color-mix(in srgb, var(--fg) 70%, transparent);
}
.fb-popup .scores {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}
.fb-popup .score-bar {
  flex: 1;
  background: color-mix(in srgb, var(--fg) 15%, transparent);
  border-radius: 3px;
  position: relative;
  height: 6px;
}
.fb-popup .score-bar > span {
  position: absolute;
  inset: 0;
  background: var(--accent);
  border-radius: 3px;
}
.fb-popup .ts {
  margin-top: 8px;
  font-size: 0.78rem;
  color: color-mix(in srgb, var(--fg) 70%, transparent);
}

/* Info-Dialog */
dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  max-width: 600px;
  background: var(--bg);
  color: var(--fg);
  box-shadow: var(--shadow);
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}
dialog article {
  padding: 1.5rem;
}
dialog h2 {
  margin-top: 0;
}
dialog code {
  background: color-mix(in srgb, var(--fg) 10%, transparent);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.9em;
}
