:root {
  --bg: #0a0c11;
  --panel: #11141b;
  --card: #171b24;
  --line: #262b37;
  --text: #e9ebf1;
  --muted: #98a0b3;
  --accent: #ff8a3d;
  --accent-ink: #1a0f06;
  --blue: #5aa9e6;
  --grey: #8791a6;
  --radius: 10px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 14px; line-height: 1.45; }
button, select, input { font: inherit; color: inherit; }

#app { display: grid; grid-template-columns: minmax(0, 1fr) clamp(400px, 40vw, 560px); height: 100vh; height: 100dvh; }
#mapwrap { position: relative; min-height: 0; }
#app { position: relative; }
#panelTab { position: absolute; top: 50%; right: clamp(400px, 40vw, 560px); transform: translate(0, -50%); z-index: 9; width: 18px; height: 56px; min-height: 0; padding: 0;
  border-radius: 8px 0 0 8px; border: 1px solid var(--line); border-right: 0; background: var(--panel); display: grid; place-items: center; color: var(--muted); }
#panelTab:hover { color: var(--text); background: #1d222d; }
#panelTab svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
body.panel-hidden #app { grid-template-columns: minmax(0, 1fr) 0; }
body.panel-hidden #panel { display: none; }
body.panel-hidden #panelTab { right: 0; }
body.panel-hidden #panelTab svg { transform: scaleX(-1); }
#map { position: absolute; inset: 0; background: #06070a; }

#brand { position: absolute; left: 16px; top: 14px; pointer-events: none; text-shadow: 0 1px 8px #000c; }
#brand h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; display: flex; align-items: center; gap: 9px; }
#brand .mark { width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 50% 60%, #f8f39a 0 22%, #f6850f 45%, #bb3654 75%, #5c126e 100%); box-shadow: 0 0 14px #f6850f99; }
#brand p { margin: 2px 0 0; color: #cfd4e0; font-size: 12.5px; }

.card { background: color-mix(in srgb, var(--card) 92%, transparent); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; backdrop-filter: blur(6px); }
#maptools { position: absolute; left: 16px; top: 74px; width: min(370px, calc(100% - 32px)); display: grid; gap: 8px; }
.cellrow { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line); padding-top: 8px; font-size: 12px; color: var(--muted); line-height: 1.35; }
.cellrow b { color: var(--text); font-weight: 600; font-size: 13px; }
.cellwrap { width: 46px; height: 46px; flex: none; display: grid; place-items: center; border: 1px dashed #3a4152; border-radius: 6px; background: #0c0e13; }
#cellSq { display: block; background: var(--accent); box-shadow: 0 0 0 1px #fff8; }
.toolhead { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.toolhead .hint { margin: 0; }
.lbl.strong { color: var(--text); font-weight: 600; font-size: 13px; }
.tools { display: grid; grid-template-columns: 1.5fr 1fr; gap: 6px; }
.tools button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 7px 10px; }
.tools svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tools svg .dot { fill: currentColor; stroke: none; }
.ico { display: inline-flex; }
.split { position: relative; display: flex; }
.split .tool-main { flex: 1; border-radius: 8px 0 0 8px; justify-content: flex-start; background: #262c39; font-weight: 600; }
.split .tool-more { width: 34px; padding: 0; border-radius: 0 8px 8px 0; border-left-color: #11141b; background: #262c39; }
.split .tool-main.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 0 0 3px #ff8a3d33; }
.split .tool-main.on + .tool-more { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); border-left-color: #c96a2c; }
.menu { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30; background: #1a1f29; border: 1px solid #3a4152; border-radius: 10px; padding: 4px; box-shadow: 0 12px 32px #000b; display: grid; gap: 2px; }
.menu button { justify-content: flex-start; border: 0; background: transparent; padding: 8px 10px; border-radius: 7px; text-align: left; }
.menu button:hover, .menu button:focus-visible { background: #262c39; }
.menu button[aria-checked="true"] { background: #2b2219; color: #ffb37a; }
.menu b { display: block; font-weight: 600; }
.menu small { display: block; color: var(--muted); font-size: 11.5px; }
[hidden] { display: none !important; }
#coords { display: grid; gap: 8px; }
#coords select { width: 100%; }
#coords .primary { flex: none; }
#coordMsg { color: #ffb37a; margin: 0; }
#drawHint.warn { background: #ffd2b0; }
#clearChip { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 5; display: inline-flex; align-items: center; gap: 7px;
  background: #11141bee; border: 1px solid #4a5163; border-radius: 999px; padding: 6px 8px 6px 11px; font-weight: 600; box-shadow: 0 4px 18px #0009; }
#clearChip:hover { background: #1d222d; border-color: #6a7286; }
#clearChip svg, .xbtn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
kbd { font: 600 11px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); border: 1px solid #3a4152; border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; background: #0c0e13; }
#areaRow { display: flex; align-items: center; gap: 8px; }
.xbtn { display: inline-grid; place-items: center; width: 26px; height: 26px; min-height: 0; padding: 0; border-radius: 50%; color: var(--muted); }
.xbtn:hover { color: var(--text); border-color: #6a7286; }
#coordBox summary { color: var(--muted); font-size: 12.5px; cursor: pointer; user-select: none; }
#coordBox summary:hover { color: var(--text); }
#coordBox[open] summary { margin-bottom: 8px; }
#layerbar { position: absolute; left: 16px; bottom: 28px; width: min(360px, calc(100% - 32px)); display: grid; gap: 8px; }
#drawHint { position: absolute; left: 50%; top: 16px; transform: translateX(-50%); background: var(--accent); color: var(--accent-ink); font-weight: 600; padding: 7px 12px; border-radius: 999px; box-shadow: 0 4px 18px #0008; }

.row { display: flex; gap: 6px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.lbl { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.row .hint { margin: 0; }

button, select, input[type=number] {
  background: #1d222d; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; min-height: 32px;
}
button { cursor: pointer; white-space: nowrap; }
button:hover, select:hover { border-color: #3a4152; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary.active { background: #fff; border-color: #fff; }
button.ghost { background: transparent; }
select { min-width: 0; flex: 1; }
.coords label { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; flex: 1; min-width: 0; }
.coords input { width: 100%; min-width: 0; padding: 5px 6px; }

.legend { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.legend > div { flex: 1; height: 10px; border-radius: 5px; border: 1px solid var(--line); }

#panel { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 16px 16px 28px; min-height: 0; container-type: inline-size; }
@container (max-width: 500px) {
  .calendar { grid-template-columns: 38px repeat(12, minmax(0, 1fr)) 44px; }
  .calendar .c { font-size: 0; }
  .calendar .h { font-size: 10px; letter-spacing: -0.03em; }
  .kpi .v { font-size: 18px; }
}
#panel header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.eyebrow { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; }
#panel h2 { margin: 2px 0 0; font-size: 20px; letter-spacing: -0.01em; }
.sub { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.controls { display: grid; gap: 8px; margin: 14px 0 4px; }
.range select { flex: 0 0 auto; }

.seg { display: flex; background: #1d222d; border: 1px solid var(--line); border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 7px; padding: 5px 8px; min-height: 28px; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg.small { flex: 0 0 auto; }
.seg.small button { font-size: 12px; padding: 3px 8px; min-height: 24px; }

.status { display: flex; gap: 12px; align-items: flex-start; margin: 12px 0 0; padding: 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); border-left-width: 4px; }
.status b { font-size: 14.5px; }
.status .m { color: var(--muted); font-size: 12px; margin-top: 3px; }
.badge { flex: none; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 4px 8px; border-radius: 999px; white-space: nowrap; }
.lvl-high { border-left-color: #ff5a3d; } .lvl-high .badge { background: #ff5a3d; color: #1a0703; }
.lvl-up { border-left-color: #ff8a3d; } .lvl-up .badge { background: #ff8a3d; color: #1a0f06; }
.lvl-flat { border-left-color: #8791a6; } .lvl-flat .badge { background: #3a4152; color: #e9ebf1; }
.lvl-down { border-left-color: #5aa9e6; } .lvl-down .badge { background: #5aa9e6; color: #06131d; }
.cmp { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; margin-bottom: 10px; }
.cmp th, .cmp td { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.cmp thead th { color: var(--text); font-weight: 600; }
.cmp tbody th { color: var(--muted); font-weight: 400; white-space: nowrap; }
.cmp .up { color: #ffb37a; } .cmp .down { color: #8fc3f0; }
.sw { display: inline-block; width: 14px; height: 0; border-top: 3px solid; margin: 0 5px 3px 0; vertical-align: middle; }
.sw.a { border-color: #ff8a3d; } .sw.b { border-color: #fff; border-top-style: dashed; } .sw.u { border-color: #5aa9e6; }
button.small { min-height: 26px; padding: 3px 9px; font-size: 12px; }
#panel header .row { flex-wrap: wrap; justify-content: flex-end; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 4px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.kpi .k { color: var(--muted); font-size: 12px; }
.kpi .v { font-size: 21px; font-weight: 650; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; margin-top: 1px; }
.kpi .d { color: var(--muted); font-size: 12px; margin-top: 1px; }
.kpi .up { color: #ffb37a; }
.kpi .down { color: #8fc3f0; }

.block { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.blockhead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.blockhead h3 { margin: 0; font-size: 14.5px; }
.blockhead select { flex: 0 0 auto; padding: 3px 8px; min-height: 26px; font-size: 12.5px; }

.calendar { display: grid; grid-template-columns: 44px repeat(12, minmax(0, 1fr)) 50px; gap: 2px; font-variant-numeric: tabular-nums; }
.calendar .h { color: var(--muted); font-size: 11px; text-align: center; padding-bottom: 2px; }
.calendar .y { color: var(--muted); font-size: 11.5px; display: flex; align-items: center; }
.calendar .t { color: var(--muted); font-size: 11px; display: flex; align-items: center; justify-content: flex-end; }
.calendar .c { height: 22px; border-radius: 3px; cursor: pointer; border: 0; padding: 0; min-height: 0; background: #1a1e27; font-size: 9.5px; line-height: 22px; text-align: center; overflow: hidden; white-space: nowrap; letter-spacing: -0.02em; }
.calendar .c.norm { cursor: default; margin-top: 6px; }
.calendar .y.norm { margin-top: 6px; font-size: 11px; }
.calendar .c:hover, .calendar .c.sel { outline: 2px solid #fff; outline-offset: 0; position: relative; z-index: 1; }
.calendar .c.na { cursor: default; background: repeating-linear-gradient(135deg, #171b23 0 3px, #20252f 3px 6px); }
.calendar .c.part { background-image: repeating-linear-gradient(135deg, transparent 0 3px, #0006 3px 6px); }
.calendar .era { grid-column: 1 / -1; color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.07em; border-top: 1px dashed #3a4152; margin-top: 3px; padding-top: 2px; }
.cal-legend { margin-top: 8px; }

.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .axis { stroke: var(--line); }
.chart .grid { stroke: #1e232d; }

#tip { position: fixed; z-index: 50; pointer-events: none; background: #05070bf2; border: 1px solid #3a4152; border-radius: 8px; padding: 7px 10px; font-size: 12.5px; max-width: 280px; box-shadow: 0 6px 24px #000a; }
#tip b { font-variant-numeric: tabular-nums; }
#tip .m { color: var(--muted); }

footer { margin-top: 20px; color: var(--muted); font-size: 11.5px; border-top: 1px solid var(--line); padding-top: 12px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; max-width: 640px; width: calc(100% - 32px); padding: 22px 24px; }
dialog::backdrop { background: #000a; }
dialog h2 { margin: 0 0 8px; }
dialog p, dialog li { color: #d5d9e3; }
dialog .close { float: right; }

.maplibregl-ctrl-attrib { font-size: 10.5px; }

select:disabled { opacity: 0.45; }

/* Narrow or short windows: stack everything, nothing floats over the map */
@media (max-width: 900px), (max-height: 520px) {
  #panelTab { display: none; }
  body.panel-hidden #panel { display: block; }
  html, body { height: auto; }
  #app { display: block; height: auto; }
  #mapwrap { display: flex; flex-direction: column; }
  #brand { position: static; padding: 12px 14px 2px; order: 0; text-shadow: none; }
  #brand h1 { font-size: 19px; }
  #brand p { font-size: 12px; color: var(--muted); }
  #maptools { position: static; width: auto; margin: 8px 12px; order: 1; }
  #map { position: relative; inset: auto; height: clamp(300px, 58vh, 560px); order: 2; }
  #layerbar { position: static; width: auto; margin: 8px 12px 12px; order: 3; }
  #clearChip { position: static; transform: none; order: 1; align-self: flex-start; margin: 0 12px 8px; }
  #drawHint { position: fixed; top: 10px; z-index: 20; white-space: nowrap; font-size: 12.5px; }
  #panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .card { backdrop-filter: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
