/* Look and feel taken from easy-matplayer (docs/projekt/design_handoff_styl.md): floating glass islands over the map, capsule
   player, iOS-like controls, accent #0a84ff. Dark first; the light variant keeps the same shapes.
   Desktop: islands (panel left, chart bottom-right corner, zoom capsule top-right). Phone: one bottom sheet (months + player, expands). */
:root {
  --glass: rgba(44, 44, 46, 0.72);
  --glass-line: rgba(255, 255, 255, 0.14);
  --solid: #1c1c1e;
  --fill: rgba(118, 118, 128, 0.28);
  --fill-active: #636366;
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.22);
  --ink: #f2f2f7;
  --ink-2: rgba(235, 235, 245, 0.72);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --grid: rgba(255, 255, 255, 0.12);
  --c-aug: #ff9f0a; --c-sep: #64d2ff; --c-oct: #bf5af2;
  --panel-w: 300px;
}
:root[data-theme="light"] {
  --glass: rgba(255, 255, 255, 0.78);
  --glass-line: rgba(0, 0, 0, 0.1);
  --solid: #f2f2f7;
  --fill: rgba(118, 118, 128, 0.16);
  --fill-active: #ffffff;
  --accent-soft: rgba(10, 132, 255, 0.16);
  --ink: #1c1c1e;
  --ink-2: rgba(60, 60, 67, 0.75);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
  --grid: rgba(0, 0, 0, 0.12);
  --c-aug: #d97706; --c-sep: #0a84ff; --c-oct: #8e3fc4;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: #121418; color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden;
}
:root[data-theme="light"] body { background: #e8eaee; }

#stage { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; background: #121418; }
:root[data-theme="light"] #map { background: #e8eaee; }
.maplibregl-ctrl-attrib, .maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right { display: none; }

.glass {
  background: var(--glass); border: 0.5px solid var(--glass-line); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(24px) saturate(1.8); backdrop-filter: blur(24px) saturate(1.8);
  color: var(--ink);
}
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.eyebrow { margin: 0 0 8px; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-2); }

/* Round icon buttons */
.fab { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; padding: 0; }
.fab svg { width: 20px; height: 20px; }
.fab[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.ib { all: unset; box-sizing: border-box; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--fill); color: var(--ink); cursor: pointer; flex: none; }
.ib:hover { background: var(--fill-active); }
.ib:focus-visible { outline: 2px solid var(--accent); }
.ib svg { width: 18px; height: 18px; }
.ib.sm { width: 26px; height: 26px; } .ib.sm svg { width: 15px; height: 15px; }

/* Panel island */
#panel {
  position: absolute; left: 12px; top: 12px; z-index: 600; width: var(--panel-w); max-height: calc(100% - 24px); overflow-y: auto;
  border-radius: 22px; padding: 16px 16px 12px; display: flex; flex-direction: column; gap: 14px;
}
#panel .hd { display: flex; align-items: center; gap: 8px; }
#panel h1 { margin: 0; font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; flex: 1; }
#panel .lead { margin: -6px 0 0; font-size: 0.86rem; line-height: 1.4; color: var(--ink-2); }
#panel .lead b { color: var(--ink); }
.note { margin: 6px 0 0; font-size: 0.75rem; line-height: 1.4; color: var(--ink-2); }
.note.small { font-size: 0.7rem; opacity: 0.9; }
.note a { color: #7eb6ff; }
:root[data-theme="light"] .note a { color: #0a64c8; }
/* collapsing = sliding out to the side, the round button pops in where the panel was */
#panel { transition: transform 0.38s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.25s ease, visibility 0s; }
body.panel-closed #panel { transform: translateX(calc(-100% - 24px)); opacity: 0; visibility: hidden; pointer-events: none; transition: transform 0.38s cubic-bezier(0.4, 0, 0.8, 0.4), opacity 0.25s ease, visibility 0s 0.38s; }
#panelToggle, #chartToggle { transition: opacity 0.25s ease 0.12s, transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) 0.12s; opacity: 0; transform: scale(0.5); pointer-events: none; }
#panelToggle { position: absolute; left: 12px; top: 12px; z-index: 650; }
body.panel-closed #panelToggle, body.chart-closed #chartToggle { opacity: 1; transform: none; pointer-events: auto; }
#grab { display: none; }

/* Segmented control */
.seg { display: flex; padding: 2px; gap: 2px; border-radius: 10px; background: var(--fill); }
.seg button {
  all: unset; box-sizing: border-box; flex: 1; text-align: center; padding: 7px 4px; border-radius: 8px; font-size: 0.82rem;
  font-weight: 600; cursor: pointer; color: var(--ink-2); transition: background 0.15s, color 0.15s; min-height: 32px;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--fill-active); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); }
.seg button:focus-visible { outline: 2px solid var(--accent); }
.seg.small button { padding: 5px 2px; font-size: 0.76rem; min-height: 28px; }
.subrow { margin-top: 8px; display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--ink-2); }
.subrow .seg { flex: 1; }

/* Appearance sliders */
.rngrow { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 0.8rem; color: var(--ink-2); }
.rngrow span { width: 112px; flex: none; } .rngrow em { font-style: normal; width: 34px; text-align: right; font-variant-numeric: tabular-nums; flex: none; }
.rngrow[hidden] { display: none; }
input[type="range"] { appearance: none; -webkit-appearance: none; background: transparent; margin: 0; width: 100%; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--fill-active); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--fill-active); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -8px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); border: 0; }
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); border: 0; }
.rngrow input { flex: 1; min-width: 0; height: 24px; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  all: unset; box-sizing: border-box; cursor: pointer; padding: 7px 12px; min-height: 34px; border-radius: 17px; font-size: 0.82rem; font-weight: 600;
  background: var(--fill); border: 1px solid transparent; color: var(--ink-2); transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chips button:hover { color: var(--ink); }
.chips button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.chips button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Legend */
.legend { display: flex; flex-direction: column; gap: 4px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 0.78rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.legend-row i { width: 22px; height: 12px; border-radius: 3px; flex: none; border: 0.5px solid var(--glass-line); }

/* Pill with the clock */
#pill {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 600; border-radius: 18px; min-height: 36px; padding: 0 16px;
  display: flex; align-items: center; gap: 10px; font-size: 0.9rem; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums;
  max-width: calc(100% - 24px);
}
#pillClock { font-size: 1.05rem; letter-spacing: 0.01em; }
#pill .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--ink-2); }
#pillMonth, #pillStat { color: var(--ink-2); font-weight: 500; }

/* Zoom capsule + 3D button (replaces the white Leaflet +/-) */
#mapTools { position: absolute; right: 12px; top: 12px; z-index: 600; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.zoomcap { display: flex; flex-direction: column; border-radius: 22px; overflow: hidden; width: 40px; }
.zoomcap button { all: unset; box-sizing: border-box; width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer; }
.zoomcap button:hover { background: var(--fill); }
.zoomcap button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.zoomcap svg { width: 20px; height: 20px; }
.zoomcap hr { margin: 0; border: 0; height: 0.5px; background: var(--glass-line); }

/* Chart island: bottom-right corner, hideable */
#chart { position: absolute; right: 12px; bottom: 12px; z-index: 600; width: 340px; border-radius: 22px; padding: 10px 14px 10px; }
.chart-hd { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.chart-hd .eyebrow { margin: 4px 0; }
#chartToggle { position: absolute; right: 12px; bottom: 12px; z-index: 600; }
#chart { transform-origin: 100% 100%; transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.25s ease, visibility 0s; }
body.chart-closed #chart { transform: translateY(24px) scale(0.85); opacity: 0; visibility: hidden; pointer-events: none; transition: transform 0.3s ease-in, opacity 0.22s ease, visibility 0s 0.3s; }
#chartSvg { width: 100%; height: auto; display: block; overflow: visible; cursor: pointer; }
#chartSvg text { fill: var(--ink-2); stroke: none; font-size: 9px; font-variant-numeric: tabular-nums; }
#chartSvg .grid { stroke: var(--grid); stroke-width: 0.6; }
#chartSvg .line { stroke-width: 1.8; }
#chartSvg .line.dim { opacity: 0.5; stroke-width: 1.2; }
#chartSvg .cursor { stroke: var(--ink); stroke-width: 0.8; stroke-dasharray: 2 2; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; font-size: 0.74rem; color: var(--ink-2); }
.chart-legend span::before { content: ""; display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; background: var(--c); }

/* Capsule player: narrower, centred in the free area right of the panel */
#capsule {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 600; width: min(420px, calc(100% - 24px));
  border-radius: 28px; padding: 8px 14px 8px 8px; display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 12px;
}
/* centred on the screen when there is room, otherwise pushed just right of the open panel */
body:not(.panel-closed) #capsule { left: max(50%, calc(var(--panel-w) + 24px + 210px)); width: min(420px, calc(100% - var(--panel-w) - 36px)); }
#capsule { transition: left 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), width 0.35s; }
#capsule .attrib { grid-column: 1 / -1; font-size: 0.64rem; color: var(--ink-2); text-align: center; margin-top: -2px; }
#capsule .attrib a { color: inherit; }
#playBtn { all: unset; box-sizing: border-box; width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; }
#playBtn:hover { filter: brightness(1.1); }
#playBtn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
#playBtn svg { width: 24px; height: 24px; }
#speedBtn { all: unset; box-sizing: border-box; min-width: 52px; height: 36px; padding: 0 12px; border-radius: 18px; background: var(--fill); text-align: center; line-height: 36px; font-size: 0.85rem; font-weight: 600; cursor: pointer; font-variant-numeric: tabular-nums; }
#speedBtn:focus-visible { outline: 2px solid var(--accent); }
#hourSlider { height: 28px; }

/* Loading screen: progress bar + rotating one-liners, fades out when the map is drawn */
.map-loading { position: absolute; inset: 0; z-index: 700; display: grid; place-items: center; background: var(--solid); color: var(--ink); transition: opacity 0.6s ease, visibility 0s; }
.map-loading.hidden { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity 0.6s ease, visibility 0s 0.6s; }
.ld { width: min(320px, calc(100% - 48px)); text-align: center; }
.ld-msg { margin: 0 0 16px; min-height: 2.6em; font-size: 1rem; font-weight: 600; transition: opacity 0.35s ease, transform 0.35s ease; }
.ld-msg.out { opacity: 0; transform: translateY(6px); }
.ld-bar { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.ld-bar i { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--accent); transition: width 0.4s ease; }
.ld-pct { display: block; margin-top: 8px; font-size: 0.78rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* Polish: press feedback, tooltip fade, bar-in animation for the sheet sections */
.fab, .ib, .zoomcap button, #playBtn, #speedBtn { transition: transform 0.12s ease, background 0.15s, filter 0.15s; }
.fab:active, .ib:active, #playBtn:active, #speedBtn:active { transform: scale(0.92); }
.zoomcap button:active { background: var(--fill-active); }
.hex-tip { animation: fadein 0.14s ease both; }
@keyframes fadein { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
#pill { transition: left 0.35s cubic-bezier(0.2, 0.8, 0.2, 1); }

.hex-tip { position: absolute; z-index: 800; pointer-events: none; transform: translate(-50%, -100%); margin-top: -12px; background: var(--glass); border: 0.5px solid var(--glass-line); color: var(--ink); border-radius: 12px; box-shadow: var(--shadow); font-size: 0.8rem; padding: 7px 10px; white-space: nowrap;
  -webkit-backdrop-filter: blur(24px) saturate(1.8); backdrop-filter: blur(24px) saturate(1.8); }
.hex-tip[hidden] { display: none; }
.hex-tip b { font-variant-numeric: tabular-nums; }

/* in-between widths (tablet): chart above the player, pill to the right of the open panel and shortened */
@media (min-width: 701px) and (max-width: 1180px) {
  #chart { width: 300px; bottom: 96px; } #chartToggle { bottom: 96px; }
  body:not(.panel-closed) #pill { left: calc(var(--panel-w) + 24px); transform: none; max-width: calc(100% - var(--panel-w) - 88px); }
  #pill > * { min-width: 0; } #pillStat { overflow: hidden; text-overflow: ellipsis; }
}

/* Phone: topbar in one row, tools in a vertical capsule top-right, one bottom sheet (months + player; expands to everything else) */
@media (max-width: 700px) {
  .topbar { flex-wrap: nowrap; }
  .topbar .brand .sub, .topbar .topnav-link[aria-current] { display: none; }
  #panelToggle, #panelHide, #chart, #chartToggle { display: none !important; }
  #pill { left: 12px; transform: none; max-width: calc(100% - 76px); font-size: 0.82rem; padding: 0 12px; gap: 6px; }
  #pill .dot, #pillMonth { display: none; }

  #mapTools { gap: 0; border-radius: 22px; background: var(--glass); border: 0.5px solid var(--glass-line); box-shadow: var(--shadow);
    -webkit-backdrop-filter: blur(24px) saturate(1.8); backdrop-filter: blur(24px) saturate(1.8); }
  #mapTools .glass { background: none; border: 0; box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
  #mapTools .fab { border-radius: 0 0 20px 20px; width: 40px; height: 42px; border-top: 0.5px solid var(--glass-line); }
  #mapTools .fab[aria-pressed="true"] { background: var(--accent); }

  #sheet { position: absolute; left: 0; right: 0; bottom: 0; z-index: 600; display: flex; flex-direction: column; gap: 10px; max-height: 68%; overflow-y: auto;
    padding: 4px 14px calc(14px + env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0; background: var(--glass); border: 0.5px solid var(--glass-line); border-bottom: 0; box-shadow: var(--shadow);
    -webkit-backdrop-filter: blur(24px) saturate(1.8); backdrop-filter: blur(24px) saturate(1.8); }
  #grab { display: block; all: unset; box-sizing: border-box; order: 0; align-self: stretch; height: 22px; cursor: pointer; display: grid; place-items: center; flex: none; }
  #grab i { width: 38px; height: 5px; border-radius: 3px; background: var(--ink-2); opacity: 0.5; }
  #panel, body.panel-closed #panel { display: contents; visibility: visible; opacity: 1; transform: none; pointer-events: auto; transition: none; }
  body.sheet-open #sheet .more { animation: rise 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
  #sheet > #panel > .sec:not(.more) { order: 1; } #sheet > #capsule { order: 2; } #sheet .more { order: 3; display: none; }
  body.sheet-open #sheet .sec.more, body.sheet-open #sheet .note.more { display: block; }
  #sheet .hd, #sheet .lead { display: none; }
  #capsule { position: static; transform: none; width: auto; left: auto; background: none; border: 0; box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; padding: 0; }
  body:not(.panel-closed) #capsule { left: auto; width: auto; }
  .leaflet-top { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
