:root {
  --bg: #0a0e13;
  --rail: #0d1218;
  --panel: #10161d;
  --card: #151d26;
  --card-2: #1a2430;
  --line: #243142;
  --text: #dde7f0;
  --muted: #8494a6;
  --accent: #f2a93b;
  --accent-2: #4fc3e8;
  --ok: #46d39a;
  --radius: 12px;
  --touch: 48px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", "Noto Sans", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.app { display: grid; grid-template-columns: 64px 1fr 520px; height: 100vh; }

/* Rail */
.rail { background: var(--rail); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 6px; }
.rail-logo { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--accent); border: 1.5px solid var(--accent); margin-bottom: 14px; }
.rail-logo svg { width: 24px; height: 24px; }
.rail-btn { width: 56px; min-height: 58px; border: 0; background: none; border-radius: 10px; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; font-size: 11px; }
.rail-btn svg { width: 24px; height: 24px; }
.rail-btn:hover { color: var(--text); background: var(--card); }
.rail-btn.on { color: var(--accent); background: var(--card-2); }
.rail-spacer { flex: 1; }

/* Stage and maps */
.stage { position: relative; overflow: hidden; background: #000; }
.map { position: absolute; inset: 0; }
.inset-host { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.inset-host .map { pointer-events: none; }
.reticle { position: absolute; left: 50%; top: 50%; width: 28px; height: 28px; margin: -14px 0 0 -14px; z-index: 3; pointer-events: none; opacity: 0.8; }
.reticle::before, .reticle::after { content: ""; position: absolute; background: #fff; box-shadow: 0 0 2px #000; }
.reticle::before { left: 13px; top: 0; width: 2px; height: 28px; }
.reticle::after { top: 13px; left: 0; height: 2px; width: 28px; }

.card-glass { background: rgba(12, 20, 28, 0.82); backdrop-filter: blur(8px); border: 1px solid rgba(255,255,255,0.08); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,0.35); }
.tag { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; padding: 2px 6px; border-radius: 4px; }
.tag.sim { color: #1a1206; background: var(--accent); }
.tag.live { color: #05130d; background: var(--ok); }

.hud-top { position: absolute; top: 14px; left: 16px; right: 16px; z-index: 6; display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; gap: 12px; }
.title-block { background: rgba(12,20,28,0.82); border: 1px solid rgba(255,255,255,0.08); border-radius: var(--radius); padding: 8px 14px; }
.title { font-weight: 650; font-size: 16px; }
.subtitle { color: var(--muted); font-size: 12px; }
.readout { display: flex; gap: 18px; background: rgba(12,20,28,0.82); border: 1px solid rgba(255,255,255,0.08); border-radius: var(--radius); padding: 9px 14px; font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; margin-right: 52px; }
.readout .k { color: var(--muted); font-size: 10px; letter-spacing: 0.1em; margin-right: 6px; }

.wx { font-size: 12px; }
.wx-head { display: flex; justify-content: space-between; color: var(--muted); }
.wx-main { display: flex; align-items: baseline; gap: 10px; margin: 4px 0 6px; }
.wx-temp { font-size: 26px; font-weight: 300; }
.wx-desc { color: var(--muted); }
.wx-grid { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.wx-grid span { color: var(--muted); }
.wx-grid b { font-weight: 500; text-align: right; }

/* Inset window */
.inset-window { position: absolute; z-index: 7; display: none; flex-direction: column; border-radius: var(--radius); overflow: hidden; background: #000; border: 1px solid rgba(255,255,255,0.18); box-shadow: 0 16px 40px rgba(0,0,0,0.55); }
.mode-window .inset-window { display: flex; }
.iw-head { display: flex; align-items: center; gap: 8px; padding: 0 6px 0 12px; height: 40px; background: rgba(12,20,28,0.92); cursor: grab; touch-action: none; user-select: none; font-size: 13px; }
.iw-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iw-btn { width: 36px; height: 32px; border: 0; border-radius: 8px; background: var(--card-2); cursor: pointer; font-size: 16px; }
.iw-body { position: relative; flex: 1; }
.iw-resize, .lens-resize { position: absolute; right: 0; bottom: 0; width: 34px; height: 34px; cursor: nwse-resize; touch-action: none; z-index: 2; }
.iw-resize::after, .lens-resize::after { content: ""; position: absolute; right: 7px; bottom: 7px; width: 12px; height: 12px; border-right: 2.5px solid rgba(255,255,255,0.8); border-bottom: 2.5px solid rgba(255,255,255,0.8); }

/* Lens */
.lens { position: absolute; z-index: 5; display: none; border: 2px solid var(--accent); border-radius: 12px; box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 10px 30px rgba(0,0,0,0.4); cursor: move; touch-action: none; }
.mode-lens .lens { display: block; }
.lens-tag, .swipe-tag { position: absolute; top: -1px; left: -1px; background: var(--accent); color: #1a1206; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 10px 0 8px 0; white-space: nowrap; }

/* Swipe */
.swipe { position: absolute; top: 0; bottom: 0; width: 0; z-index: 5; display: none; border-left: 2px solid var(--accent); }
.mode-swipe .swipe { display: block; }
.swipe-knob { position: absolute; top: 50%; left: -26px; width: 52px; height: 52px; margin-top: -26px; border-radius: 50%; background: var(--accent); color: #1a1206; display: grid; place-items: center; font-size: 22px; font-weight: 700; cursor: ew-resize; touch-action: none; box-shadow: 0 4px 16px rgba(0,0,0,0.5); }
.swipe-tag { top: auto; bottom: 46px; border-radius: 6px; }
.swipe-tag.left { left: auto; right: 10px; }
.swipe-tag.right { left: 10px; }

.draw-hint { position: absolute; z-index: 8; left: 50%; bottom: 40px; transform: translateX(-50%); display: none; padding: 10px 10px 10px 16px; border-radius: 30px; background: var(--accent); color: #1a1206; font-weight: 600; align-items: center; gap: 10px; }
.drawing .draw-hint { display: flex; }
.draw-hint button { border: 0; border-radius: 20px; padding: 8px 16px; background: #1a1206; color: var(--accent); font-weight: 700; cursor: pointer; }
.drawing #map-main .maplibregl-canvas { cursor: crosshair; }

[hidden] { display: none !important; }

/* Control panel hidden (rail button, or panel=0 in the link): the map takes the space. */
@media (min-width: 821px) { .app.panel-closed { grid-template-columns: 64px 1fr; } }
.app.panel-closed .panel { display: none; }

/* Layer and graphics notices */
.status { position: absolute; z-index: 8; left: 50%; top: 78px; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 9px 16px; border-radius: 10px; background: rgba(40, 22, 6, 0.94); border: 1px solid var(--accent); color: #ffe2b0; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,0.5); }
.status[hidden] { display: none; }
.status b { color: var(--accent); }
.status button { margin-left: 8px; border: 0; border-radius: 8px; min-height: 36px; padding: 6px 14px; background: var(--accent); color: #1a1206; font-weight: 700; cursor: pointer; }

/* Panel */
.panel { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: stretch; }
.pcol { display: flex; flex-direction: column; gap: 10px; min-width: 0; height: 100%; }
.pcol > .card:last-child { flex: 1 1 auto; }
#card-profile { display: flex; flex-direction: column; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card h2 { font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.card h2.mt { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.delta { color: var(--accent); font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.scenes { display: grid; grid-template-columns: 1fr; gap: 6px; }
.scene { text-align: left; border: 1px solid var(--line); background: var(--card-2); border-radius: 10px; padding: 8px 10px; min-height: 52px; cursor: pointer; min-width: 0; }
.scene b { display: block; font-size: 13px; font-weight: 600; }
.scene small { color: var(--muted); font-size: 11px; line-height: 1.3; display: block; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scene.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.field { display: flex; flex-direction: column; align-items: stretch; gap: 4px; margin-bottom: 8px; }
.field > span { color: var(--muted); font-size: 11px; }
.field.col { flex-direction: column; align-items: stretch; }
.field.col > span { width: auto; }
.field small { color: var(--muted); opacity: 0.8; }
select, input[type=password], input[type=text] { flex: 1; min-height: 44px; background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; min-width: 0; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 30px; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; margin: 4px 0 12px; }
.seg button { border: 0; background: none; min-height: 40px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.seg-4 { grid-template-columns: repeat(4, 1fr); }
.mt-s { margin-top: 12px; }
.seg button.on { background: var(--accent); color: #1a1206; font-weight: 650; }

.slider { margin-top: 6px; }
.slider-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.slider-head b { color: var(--text); font-weight: 600; }
input[type=range] { width: 100%; height: 36px; accent-color: var(--accent); }

.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tg { display: flex; align-items: center; gap: 8px; min-height: var(--touch); padding: 0 8px; white-space: nowrap; font-size: 12.5px; background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 13px; }
.tg input { display: none; }
.tg i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); flex: none; }
.tg input:checked + i { background: var(--accent-2); border-color: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); }
.tg input:disabled ~ span { opacity: 0.5; }

.chart { width: 100%; height: auto; flex: 1 1 124px; min-height: 124px; display: block; margin-top: 4px; touch-action: none; }
.legend { display: flex; gap: 14px; font-size: 11px; color: var(--muted); margin-top: 6px; white-space: nowrap; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.stats { display: grid; grid-template-columns: 1fr; gap: 4px; margin: 8px 0 10px; }
.stats div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; background: var(--card-2); border-radius: 8px; padding: 5px 8px; }
.stats span { font-size: 10px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.stats b { font-size: 13px; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; }
.btn { min-height: 44px; padding: 0 16px; border: 0; border-radius: 10px; background: var(--accent); color: #1a1206; font-weight: 650; cursor: pointer; flex: 1; }
.btn.ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }

.sources { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; font-size: 12px; }
.sources li { display: flex; justify-content: space-between; gap: 8px; }
.sources li span { color: var(--muted); }
.sources li b { font-weight: 500; text-align: right; }

.maplibregl-ctrl-group { background: rgba(12,20,28,0.88) !important; border: 1px solid rgba(255,255,255,0.1); }
.maplibregl-ctrl-group button { width: 40px !important; height: 40px !important; }
.maplibregl-ctrl-group button + button { border-top-color: rgba(255,255,255,0.1) !important; }
.maplibregl-ctrl-icon { filter: invert(1); }
.maplibregl-ctrl-top-right { top: 74px !important; }
.maplibregl-ctrl-scale { background: rgba(12,20,28,0.75); color: var(--text); border-color: var(--text); }
.maplibregl-ctrl-attrib { background: rgba(12,20,28,0.75) !important; color: var(--muted); }
.maplibregl-ctrl-attrib a { color: var(--muted); }
.maplibregl-ctrl-attrib-button { filter: invert(1); }

@media (max-width: 1350px) { .app { grid-template-columns: 64px 1fr 300px; } .panel { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  html, body { overflow: auto; }
  .app { grid-template-columns: 1fr; grid-template-rows: 64px 62vh auto; height: auto; }
  .rail { flex-direction: row; justify-content: space-around; padding: 0 8px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .rail-logo, .rail-spacer { display: none; }
  .rail-btn { min-height: 56px; width: 56px; }
  .panel { border-left: 0; overflow: visible; }
  .readout { display: none; }
}

/* Data sources sheet (opened from the rail) */
.sheet { position: absolute; inset: 0; z-index: 9; display: none; place-items: center; background: rgba(5, 9, 13, 0.55); }
.sheet.show { display: grid; }
.sheet-card { width: min(460px, calc(100% - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,0.5); }
.sheet-card .card-head { margin-bottom: 6px; }
