:root {
    --surface: #fbf8f1;
    --surface-2: #f2ece0;
    --ink: #1a1410;
    --ink-2: #4a3f34;
    --muted: #8a7b6a;
    --rule: #e0d8cc;
    --rubric: #8b2020;
    --gold: #a08030;
    --on-rubric: #fffaf0;
    --shadow: 0 6px 24px rgba(26, 20, 16, 0.22);
    --panel-w: 320px;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --surface: #1d1915;
        --surface-2: #2a241e;
        --ink: #f3ece0;
        --ink-2: #cfc3b2;
        --muted: #9a8b78;
        --rule: #3a3229;
        --rubric: #c0504a;
        --gold: #c9a24a;
        --on-rubric: #1d1915;
        --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    }
}
:root[data-theme="dark"] {
    --surface: #1d1915; --surface-2: #2a241e; --ink: #f3ece0; --ink-2: #cfc3b2; --muted: #9a8b78;
    --rule: #3a3229; --rubric: #c0504a; --gold: #c9a24a; --on-rubric: #1d1915;
}

html, body { height: 100%; margin: 0; }
[hidden] { display: none !important; }
body {
    font: 13.5px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--ink);
    background: #0b0b0d;
    overflow: hidden;
}
#map { position: absolute; inset: 0; }

/* ---------- panel ---------- */
#panel {
    position: absolute; top: 12px; left: 12px; bottom: 12px; width: var(--panel-w); z-index: 5;
    display: flex; flex-direction: column; overflow: hidden;
    background: var(--surface); border: 1px solid var(--rule); border-radius: 10px;
    box-shadow: var(--shadow); transition: transform 0.2s ease;
}
#panel.hidden { transform: translateX(calc(-100% - 16px)); }
#panel header {
    display: flex; align-items: center; gap: 6px;
    padding: 12px 12px 10px; border-bottom: 2px solid var(--rubric);
}
#panel .title { flex: 1; min-width: 0; }
#panel h1 { margin: 0; font: 700 18px/1.1 "Cinzel", Georgia, serif; letter-spacing: 0.04em; }
#panel h1 a { color: var(--ink); text-decoration: none; }
#panel .sub { color: var(--muted); font-size: 11.5px; margin-top: 3px; }
#panel .body { flex: 1; overflow-y: auto; padding: 4px 0 12px; }
section { padding: 8px 12px 4px; }
h2 {
    display: flex; align-items: baseline; margin: 6px 0 6px;
    font-size: 10.5px; font-weight: 650; letter-spacing: 0.09em; text-transform: uppercase; color: var(--gold);
}
h2 .right { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 11.5px; }
a { color: var(--rubric); }

.btn, .seg button, .grid button, .icon-btn {
    background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--rule); border-radius: 6px;
    padding: 6px 8px; font: 12px system-ui, sans-serif; cursor: pointer;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn:hover, .seg button:hover, .grid button:hover, .icon-btn:hover { border-color: var(--muted); }
.btn.on, .seg button.on, .grid button.on {
    background: var(--rubric); border-color: var(--rubric); color: var(--on-rubric); font-weight: 600;
}
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.row label { display: flex; gap: 5px; align-items: center; color: var(--ink-2); font-size: 12.5px; cursor: pointer; }
input[type="checkbox"], input[type="range"] { accent-color: var(--rubric); }
input[type="range"] { width: 84px; }
input[type="search"] {
    width: 100%; box-sizing: border-box; padding: 7px 9px;
    background: var(--surface-2); color: var(--ink); border: 1px solid var(--rule); border-radius: 6px;
    font: 13px system-ui, sans-serif;
}
input[type="search"]:focus { outline: 2px solid var(--gold); outline-offset: -1px; }

/* ---------- overlay catalog ---------- */
#overlays { margin-top: 6px; }
.group-name { margin: 12px 0 2px; font-size: 12px; font-weight: 650; color: var(--ink); }
.layer { padding: 5px 0 5px; border-bottom: 1px solid var(--rule); }
.layer:last-child { border-bottom: 0; }
.layer .line { display: flex; align-items: center; gap: 6px; }
.layer label { flex: 1; display: flex; gap: 6px; align-items: center; cursor: pointer; font-size: 13px; }
.layer .info {
    background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0 2px;
}
.layer .tip { display: none; margin: 4px 0 2px 22px; color: var(--ink-2); font-size: 12px; }
.layer.open .tip { display: block; }
.layer .op { display: none; margin: 4px 0 0 22px; color: var(--muted); font-size: 11.5px; gap: 6px; align-items: center; }
.layer.on .op { display: flex; }
.layer .badge { font-size: 10.5px; color: var(--muted); }
.layer.dim label { color: var(--muted); }
.foot { margin: 14px 12px 0; color: var(--muted); font-size: 11.5px; }

/* ---------- floating bits ---------- */
#show-panel { position: absolute; top: 12px; left: 12px; z-index: 4; font-size: 16px; padding: 6px 10px;
              background: var(--surface); box-shadow: var(--shadow); }
#toast {
    position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 9;
    background: var(--ink); color: var(--surface); padding: 8px 14px; border-radius: 6px;
    font-size: 13px; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
#toast.show { opacity: 1; }
.maplibregl-popup-content {
    background: var(--surface); color: var(--ink); border-radius: 8px; padding: 10px 12px;
    font: 12.5px/1.45 system-ui, sans-serif; box-shadow: var(--shadow);
}
.maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 16px; }
.pop b { font-variant-numeric: tabular-nums; }
.pop .dim { color: var(--muted); }

/* ---------- phone: panel becomes a bottom sheet ---------- */
@media (max-width: 700px) {
    #panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 58vh; }
    #panel.hidden { transform: translateY(calc(100% + 16px)); }
    .maplibregl-ctrl-bottom-right { bottom: 0; }
}
