:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --ink: #1d1b19;
  --muted: #6b655d;
  --line: #e6e0d6;
  --accent: #c4532d;
  --accent-soft: #f6e3da;
  --s0: #e8f1ef;
  --s1: #a8d0c6;
  --s2: #5ea89a;
  --s3: #2c7a6c;
  --s4: #114b42;
  --shadow: 0 1px 2px rgba(29, 27, 25, .06), 0 8px 24px rgba(29, 27, 25, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151412; --surface: #1f1d1a; --ink: #f1ece4; --muted: #a59d92; --line: #34302b;
    --accent: #e57a52; --accent-soft: #3a2519;
    --s0: #1c2b28; --s1: #23534a; --s2: #2f8270; --s3: #55b39e; --s4: #9fe0cf;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: 'Commissioner', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; }

.top {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 18px 24px 10px; flex-wrap: wrap;
}
.brand { display: flex; gap: 14px; align-items: center; }
.logo {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  background:
    radial-gradient(circle at 50% 50%, var(--accent) 0 5px, transparent 6px),
    radial-gradient(circle at 50% 50%, transparent 0 10px, var(--accent) 11px 12.5px, transparent 13.5px),
    radial-gradient(circle at 50% 50%, transparent 0 16px, var(--accent) 17px 18.5px, transparent 19.5px),
    var(--accent-soft);
}
h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; font-weight: 800; }
h1 span { color: var(--accent); font-weight: 700; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.status {
  font-size: 13px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}
.status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #3aa673; vertical-align: 1px; }
.status.warn { color: var(--accent); border-color: var(--accent); }
.status.warn .dot { background: var(--accent); }

.profiles {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px;
  padding: 6px 24px 14px;
}
.profiles button {
  text-align: left; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1.5px solid var(--line);
  display: flex; flex-direction: column; gap: 2px; transition: border-color .15s, transform .15s;
}
.profiles button:hover { border-color: var(--s2); }
.profiles button[aria-selected="true"] { border-color: var(--ink); box-shadow: var(--shadow); }
.profiles small { color: var(--muted); font-size: 12.5px; }

.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 14px;
  padding: 0 24px 16px; position: relative; height: calc(100vh - 190px); min-height: 520px;
}
.mapwrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: var(--surface); }
#map { position: absolute; inset: 0; }
.nomap { position: absolute; inset: 0; display: grid; place-items: center; padding: 32px; text-align: center; color: var(--muted); }
.legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 500;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 12px; color: var(--muted); box-shadow: var(--shadow);
}
.legend .bar { display: flex; height: 8px; width: 160px; border-radius: 4px; overflow: hidden; margin: 4px 0 2px; }
.legend .bar i { flex: 1; }
.legend .ends { display: flex; justify-content: space-between; }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; min-height: 0;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 8px; gap: 8px; }
.panel-head h2 { font-size: 16px; margin: 0; }
.seg { display: inline-flex; background: var(--bg); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 999px; font-size: 13px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
#search {
  margin: 0 16px 8px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit; font-size: 14px;
}
.ranking { list-style: none; margin: 0; padding: 0 8px 8px; overflow: auto; flex: 1; counter-reset: r; }
.ranking li {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) 44px; gap: 10px; align-items: center;
  padding: 9px 8px; border-radius: 10px; cursor: pointer;
}
.ranking li:hover, .ranking li.active { background: var(--bg); }
.ranking .pos { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; text-align: right; }
.ranking .nm { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ranking .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ranking .meter { height: 4px; background: var(--bg); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.ranking .meter i { display: block; height: 100%; border-radius: 2px; }
.ranking .sc { font-weight: 800; font-size: 18px; text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 20px; text-align: center; font-size: 14px; }

.detail {
  position: absolute; top: 12px; right: 450px; bottom: 28px; width: 380px; z-index: 900;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 18px 20px; overflow: auto; z-index: 1100;
}
.detail .close {
  position: absolute; top: 10px; right: 12px; border: 0; background: var(--bg);
  width: 32px; height: 32px; border-radius: 50%; font-size: 20px; line-height: 1;
}
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: 11.5px; color: var(--muted); margin: 0; }
.detail h2 { margin: 4px 40px 8px 0; font-size: 20px; letter-spacing: -.01em; }
.score-big { display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.score-big span { font-size: 44px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.score-big small { color: var(--muted); font-size: 13px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.kpi { background: var(--bg); border-radius: 10px; padding: 9px 10px; }
.kpi b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12px; color: var(--muted); }
.kpi em { font-style: normal; font-size: 11.5px; color: var(--muted); display: block; margin-top: 2px; }
.detail h3 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
.chart { position: relative; height: 160px; }
.chart.small { height: 130px; }
.why { font-size: 13.5px; color: var(--muted); margin: 14px 0 0; }

.foot { padding: 8px 24px 28px; font-size: 13px; color: var(--muted); }
.foot summary { cursor: pointer; color: var(--ink); font-weight: 600; }
.foot ul { padding-left: 18px; max-width: 860px; }
.foot .by { margin-top: 4px; }

.leaflet-container { font-family: inherit; background: var(--bg); }
.leaflet-tooltip { font-family: inherit; font-size: 12.5px; border-radius: 8px; }

@media (max-width: 960px) {
  .top { padding: 14px 16px 8px; }
  .profiles { padding: 4px 16px 12px; gap: 8px; grid-template-columns: 1fr; }
  .profiles button { flex-direction: row; justify-content: space-between; align-items: baseline; padding: 10px 12px; }
  .layout { grid-template-columns: 1fr; height: auto; padding: 0 16px 16px; }
  .mapwrap { height: 46vh; min-height: 300px; }
  .panel { max-height: 70vh; }
  .detail { position: fixed; inset: auto 0 0 0; width: auto; max-height: 85vh; border-radius: 18px 18px 0 0; right: 0; bottom: 0; }
  .foot { padding: 8px 16px 24px; }
}

.tiles-muted { filter: grayscale(.55) contrast(.92) brightness(1.04); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tiles-muted { filter: invert(1) hue-rotate(180deg) grayscale(.5) brightness(.85) contrast(.9); }
}

.hist-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 14px 0 6px; }
.hist-head h3 { margin: 0; }
.hist-note { font-size: 11.5px; color: var(--muted); margin: 6px 0 0; min-height: 0; }
.hist-note:empty { display: none; }
.seg button { white-space: nowrap; }
.hist-head h3 { min-width: 0; }

.env-bar { background: #b8860b; color: #fff; text-align: center; font-size: 13px; font-weight: 600; padding: 6px 16px; }
