:root {
  --bg: #0e1a1f;
  --panel: #13242b;
  --panel-2: #1a3038;
  --line: #2b4651;
  --text: #eef4f5;
  --muted: #a9bcc2;
  --accent: #4cc3d9;
  --accent-ink: #062027;
  --warn: #ffd166;
  --danger: #e5484d;
  --ok: #5bd18b;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

#map { position: fixed; inset: 0; overflow: hidden; background: #cfd8d4; }
/* Karttasäiliö on näkymän lävistäjän kokoinen ja kääntyy keskipisteensä ympäri (rotate.js). */
#mapView { position: absolute; inset: 0; z-index: 0; background: #cfd8d4; }
/* Mittakaava ja tekijätiedot pysyvät pystyssä näkymän reunoilla. */
.mk-map-ui { position: absolute; inset: 0; z-index: 1; pointer-events: none; background: transparent !important; }
/* Tekstit ja tupakuvakkeet pysyvät pystyssä, vaikka kartta on käännetty. */
.mk-rot .dist-label span, .mk-rot .hut-icon svg { transform: rotate(var(--mk-unrot, 0deg)); }
.mk-rot .wind-icon .lbl { transform: translateX(-50%) rotate(var(--mk-unrot, 0deg)); }
.north-btn { position: fixed; right: 10px; top: calc(60px + var(--safe-t)); z-index: 1000; }
.north-btn svg { width: 30px; height: 30px; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { font-size: 10.5px; }

.topbar { position: fixed; top: calc(8px + var(--safe-t)); left: 8px; right: 8px; display: flex; gap: 8px;
  align-items: center; z-index: 1000; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.brand { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-weight: 700; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px;
  max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.fabs { position: fixed; right: 10px; bottom: calc(28px + var(--safe-b)); display: flex; flex-direction: column;
  gap: 10px; z-index: 1000; }
.fab { width: 50px; height: 50px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel);
  display: grid; place-items: center; padding: 0; }
.fab svg { width: 26px; height: 26px; }
.fab.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.compass { position: fixed; top: calc(60px + var(--safe-t)); left: 8px; z-index: 1000; display: flex; gap: 10px;
  align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px 8px 8px; }
.compass .rose { width: 84px; height: 84px; color: var(--text); }
.compass .big { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.compass .small { color: var(--muted); font-size: 13px; max-width: 160px; }

.measure-bar { position: fixed; left: 8px; right: 70px; bottom: calc(28px + var(--safe-b)); z-index: 1000;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.measure-bar .row { display: flex; gap: 8px; margin-top: 8px; }

.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 72vh; z-index: 1100; background: var(--panel);
  border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; display: flex; flex-direction: column;
  padding-bottom: var(--safe-b); box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 6px 16px; }
.sheet-head h2 { font-size: 18px; margin: 0; }
.sheet-body { overflow-y: auto; padding: 4px 16px 18px; -webkit-overflow-scrolling: touch; }
.icon-btn { width: 40px; height: 40px; border: 0; background: transparent; display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; }

h3 { font-size: 15px; margin: 16px 0 6px; color: var(--muted); font-weight: 600; text-transform: none; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.warn { color: var(--warn); }
.btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 9px 12px; min-height: 40px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { border-color: var(--danger); color: #ffc9cb; }
.btn[disabled] { opacity: 0.5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px; padding: 7px 12px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.input, select.input { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; min-height: 40px; }
label.check { display: flex; gap: 10px; align-items: center; padding: 8px 0; }
label.check input { width: 20px; height: 20px; }

table.wx { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.wx th, table.wx td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.wx th { color: var(--muted); font-weight: 600; font-size: 13px; }
.arrow { display: inline-block; width: 18px; height: 18px; vertical-align: -4px; }
.ring-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.ring-grid .cell { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; font-size: 13px; }
.ring-grid .cell b { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.ring-grid .center { border-color: var(--accent); }

.card { display: flex; gap: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px; margin: 8px 0; }
.card img { width: 112px; height: 70px; flex: none; border-radius: 8px; }
.card .t { font-weight: 700; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--bg);
  border: 1px solid var(--line); color: var(--muted); margin: 2px 4px 2px 0; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-variant-numeric: tabular-nums; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.progress { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.progress > div { height: 100%; width: 0; background: var(--accent); }

.toast { position: fixed; left: 50%; top: calc(62px + var(--safe-t)); transform: translateX(-50%); z-index: 1200;
  background: #0b1418; color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px;
  max-width: 88vw; }

.wind-icon { width: 34px; height: 34px; margin-left: -17px; margin-top: -17px; }
.wind-icon .wbox { width: 34px; height: 34px; border-radius: 50%; background: rgba(14, 26, 31, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.4); display: grid; place-items: center; color: #fff; position: relative; }
.wind-icon svg { width: 22px; height: 22px; }
.wind-icon .lbl { position: absolute; top: 32px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 700;
  color: #0b1418; background: rgba(255, 255, 255, 0.85); border-radius: 6px; padding: 0 4px; white-space: nowrap; }
.dist-label { background: none; border: 0; box-shadow: none; }
.dist-label span { display: inline-block; background: rgba(255, 255, 255, 0.9); color: #0b1418; border-radius: 6px; padding: 1px 5px;
  font-size: 12px; font-weight: 700; white-space: nowrap; }
.dist-label::before { display: none; }
.leaflet-popup-content { margin: 10px 12px; }
.pop-t { font-weight: 700; }

.credit { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.credit a { color: var(--accent); }
.card img { object-fit: cover; background: #eef3ee; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0; }
.legend .li { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.legend .sw { width: 22px; height: 6px; border-radius: 3px; border: 1px solid #fff; display: inline-block; }
.sw-alhainen { background: #e5484d; }
.sw-normaali { background: #2fb35a; }
.sw-korkea { background: #0b3d91; }
.sw-tuntematon { background: #8a9aa0; }

/* Solmuanimaatiot */
.knot-svg { display: block; width: 100%; height: auto; margin-top: 8px; background: #0b1519; border: 1px solid var(--line); border-radius: 12px; }
.knot-cap { min-height: 3em; margin: 8px 0; font-weight: 600; }
.knot-ctrl .btn { flex: 1; }
.knot-steps { margin: 12px 0 0; padding-left: 22px; }
.knot-steps li { padding: 5px 0; color: var(--muted); cursor: pointer; }
.knot-steps li.on { color: var(--text); font-weight: 600; }
.knot-tips { margin: 0; padding-left: 18px; }
.knot-tips li { margin: 4px 0; }

/* Autiotuvat */
.hut-icon { background: none; border: 0; }
.hut-icon svg { display: block; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55)); }
.hut-compass { display: flex; gap: 16px; align-items: center; margin: 8px 0 14px; }
.hut-dial { width: 150px; height: 150px; flex: none; }
.hut-read .d { font-size: 30px; font-weight: 800; line-height: 1.1; }
.hut-read .b { font-weight: 600; margin-top: 4px; }
.hut-read .s { color: var(--muted); font-size: 13px; margin-top: 6px; }
