:root {
  --bg: #081018;
  --panel: #0e1924;
  --card: #132231;
  --card-2: #0f1c29;
  --line: #213549;
  --text: #d6e4f0;
  --muted: #7d97ad;
  --accent: #4fc3f7;
  --accent-ink: #04131c;
  --canopy: #3ddc84;
  --freefall: #ffb340;
  --surface: #ffd866;
  --warn: #ffb340;
  --bad: #ff6b6b;
  --good: #3ddc84;
  --panel-w: 380px;
  --top-h: 48px;
  --drawer-peek: 64px;
  --radius: 10px;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "IBM Plex Sans Condensed", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 15px;
  height: 100dvh; overflow: hidden; -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 8px; font-weight: 600; letter-spacing: .02em; }
h2 { font-size: 1rem; text-transform: uppercase; color: var(--muted); }
h3 { font-size: 1rem; margin-top: 14px; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.warn { color: var(--warn); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* top bar */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0; display: flex; align-items: center; justify-content: space-between;
  background: rgba(8, 16, 24, .92); border-bottom: 1px solid var(--line); z-index: 1200; backdrop-filter: blur(6px);
}
.brand { font-weight: 700; letter-spacing: .04em; display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-mark { color: var(--accent); }
.dz-chip { font-weight: 500; color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.top-actions { display: flex; gap: 4px; }
.icon-btn {
  background: none; border: 1px solid transparent; color: var(--text); font-size: 1.05rem;
  min-width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
}
.icon-btn:hover, .icon-btn:focus-visible { border-color: var(--line); background: var(--card); }

/* layout */
.layout { position: fixed; inset: calc(var(--top-h) + env(safe-area-inset-top)) 0 0 0; }
#map { position: absolute; inset: 0; background: #0b141c; }
.panel {
  position: absolute; z-index: 1100; background: var(--panel); border-left: 1px solid var(--line);
  top: 0; right: 0; bottom: 0; width: var(--panel-w); display: flex; flex-direction: column;
}
.panel-scroll { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.drawer-handle { display: none; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.label { display: block; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }

@media (max-width: 760px) {
  .panel {
    top: auto; left: 0; width: auto; height: 72dvh; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0; transform: translateY(calc(100% - var(--drawer-peek)));
    transition: transform .25s ease; padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.open { transform: translateY(0); }
  .drawer-handle {
    display: flex; justify-content: center; align-items: center; height: 28px; background: none; border: 0;
    cursor: grab; flex: none; touch-action: none;
  }
  .drawer-handle span { width: 44px; height: 5px; border-radius: 3px; background: var(--line); }
}

/* inputs */
input, select, button { font: inherit; }
input[type=search], input[type=number], input:not([type]), select {
  width: 100%; background: var(--card-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 10px; font-size: 16px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.btn {
  background: var(--card-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; cursor: pointer; font-weight: 600; text-align: left;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn[aria-pressed=true] { color: var(--surface); border-color: var(--surface); }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px 0; font-size: .85rem; }
.tools { display: grid; gap: 8px; }

/* dz picker */
.dz-search-row { display: flex; gap: 6px; }
.dz-search-row .btn { flex: none; width: 44px; text-align: center; font-size: 1.1rem; }
.dz-results {
  list-style: none; margin: 6px 0 0; padding: 0; max-height: 260px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card-2);
}
.dz-results li { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line); }
.dz-results li:last-child { border-bottom: 0; }
.dz-results li:hover, .dz-results li[aria-selected=true] { background: var(--card); }
.dz-results .sub { color: var(--muted); font-size: .8rem; }
.dz-current { margin-top: 8px; font-weight: 600; }

/* winds table */
table.winds { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .85rem; }
.winds th { color: var(--muted); font-weight: 400; font-size: .72rem; text-align: right; padding: 3px 4px; font-family: var(--sans); text-transform: uppercase; }
.winds th:first-child, .winds td:first-child { text-align: left; }
.winds td { text-align: right; padding: 4px; border-top: 1px solid var(--line); white-space: nowrap; }
.winds .dir-arrow { display: inline-block; width: 14px; text-align: center; color: var(--muted); }
.winds .spd-green { color: var(--good); } .winds .spd-orange { color: var(--warn); } .winds .spd-red { color: var(--bad); }
.winds .metar-tag { font-size: .65rem; color: var(--surface); margin-left: 2px; }
.agree { display: inline-block; width: 38px; height: 6px; background: var(--line); border-radius: 3px; vertical-align: middle; position: relative; overflow: hidden; }
.agree i { position: absolute; inset: 0 auto 0 0; background: var(--accent); }

/* wind widget */
.wind-widget {
  position: absolute; z-index: 1050; top: 12px; left: 12px; display: flex; gap: 6px; padding: 8px 30px 8px 8px;
  background: rgba(14, 25, 36, .94); border: 1px solid var(--line); border-radius: 12px; touch-action: none; cursor: grab;
  box-shadow: 0 6px 24px rgba(0,0,0,.45);
}
.ww-item { background: var(--card-2); border: 1px solid var(--line); border-radius: 8px; color: var(--text); padding: 6px 8px; min-width: 86px; text-align: left; cursor: pointer; display: grid; }
.ww-item.active { border-color: currentColor; }
.ww-item[data-layer=freefall] { color: var(--freefall); } .ww-item[data-layer=canopy] { color: var(--canopy); } .ww-item[data-layer=surface] { color: var(--surface); }
.ww-k { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; opacity: .9; }
.ww-v { font-family: var(--mono); font-size: .95rem; color: var(--text); }
.ww-s { font-family: var(--mono); font-size: .72rem; color: var(--muted); }
.ww-close { position: absolute; top: 4px; right: 4px; background: none; border: 0; color: var(--muted); cursor: pointer; }

/* modals */
.modal { position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; width: min(440px, 100%);
  max-height: 88dvh; overflow-y: auto; display: grid; gap: 10px;
}
.modal-box.wide { width: min(640px, 100%); }
.modal-box label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.modal-box label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; display: grid; gap: 8px; }
legend { color: var(--muted); font-size: .8rem; padding: 0 4px; }
details summary { cursor: pointer; color: var(--accent); margin: 4px 0; }
.guide-body p { color: var(--text); line-height: 1.45; margin: 4px 0; }

.toast {
  position: fixed; z-index: 3000; left: 50%; transform: translateX(-50%); bottom: calc(var(--drawer-peek) + 16px);
  background: var(--card); border: 1px solid var(--accent); color: var(--text); padding: 10px 14px; border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,.5); max-width: calc(100% - 32px);
}
.toast button { margin-left: 10px; }
.attrib { line-height: 1.5; padding: 4px 2px 12px; }

/* map labels */
.leaflet-container { font-family: var(--sans); }
.canopy-tip { background: rgba(14,25,36,.97); color: var(--text); border: 1px solid var(--canopy); border-radius: 8px; font-size: .8rem; }
.canopy-tip::before { display: none; }
.dz-pin { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; box-shadow: 0 0 0 3px rgba(79,195,247,.35); }
.leaflet-control-attribution { background: rgba(8,16,24,.75) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--accent) !important; }

@media (max-width: 760px) {
  .brand-text { display: none; }
  .dz-chip { max-width: 52vw; color: var(--text); font-weight: 600; }
  .wind-widget { top: 8px; left: 8px; right: 8px; padding-right: 28px; gap: 4px; }
  .ww-item { min-width: 0; flex: 1; padding: 5px 6px; }
  .ww-v { font-size: .85rem; }
  .ww-s { font-size: .66rem; }
  .leaflet-bottom.leaflet-left { bottom: calc(var(--drawer-peek) + 8px); }
}
