
  :root {
    --forest: var(--brand-primary);
    --forest-dark: var(--brand-primary-hover);
    --orange: #f97316;
    --orange-dark: #ea6a0a;
    --cream: var(--surface-secondary);
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; margin: 0; }
  body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--cream);
    color: var(--ui-text-primary);
  }

  /* ---- Onboarding / asetukset ---- */
  #onboarding, .overlay {
    position: fixed; inset: 0; z-index: 2000;
    background: var(--cream);
    display: none;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: 24px 16px 40px;
  }
  .overlay { background: var(--overlay-backdrop); padding-top: 40px; }
  .overlay .onboard-card { box-shadow: var(--shadow-sheet); }

  .overlay-close {
    position: fixed; top: 16px; right: 16px; z-index: 2100;
    width: 36px; height: 36px; border-radius: 50%;
    border: none; background: var(--surface-primary); color: var(--forest);
    font-size: 1.375rem; line-height: 1; cursor: pointer;
    box-shadow: var(--shadow-control);
  }

  .onboard-card {
    width: 100%; max-width: 420px;
    background: var(--cream);
  }
  .overlay .onboard-card { background: var(--ui-surface); border-radius: 16px; padding: 20px; }

  .onboard-logo { width: 100%; max-width: 300px; display: block; margin: 0 auto 6px; }
  .onboard-tagline {
    text-align: center; color: var(--forest); font-weight: 600;
    font-size: 1.125rem; margin: 0 0 18px;
  }

  .form-block {
    background: var(--ui-surface); border-radius: 14px; padding: 20px;
    box-shadow: var(--shadow-control);
  }
  .overlay .form-block { box-shadow: none; padding: 0; margin-top: 4px; }

  .form-block label {
    display: block; font-size: 1.125rem; color: var(--ui-text-secondary); margin: 12px 0 4px;
  }
  .form-block label:first-child { margin-top: 0; }
  .form-block input {
    width: 100%; padding: 10px; border: 1px solid var(--ui-border); border-radius: 8px;
    font-size: 1.125rem;
  }

  .role-toggle { display: flex; align-items: stretch; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
  .role-option {
    flex: 1 1 0; display: flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 48px; box-sizing: border-box;
    border: 2px solid var(--ui-border); border-radius: 10px; padding: 12px 8px;
    font-size: 1.125rem; font-weight: 600; color: var(--ui-text-secondary);
    cursor: pointer; position: relative;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
  }
  .role-option input[type="radio"] {
    position: absolute; opacity: 0; pointer-events: none;
  }
  .role-dot {
    display: inline-block;
    width: 14px; height: 14px; border-radius: 50%;
    border: 2px solid var(--ui-border); background: transparent; flex-shrink: 0;
    transition: background 0.15s ease, border-color 0.15s ease;
  }
  .role-option:has(input:checked) {
    border-color: var(--forest); background: var(--surface-selected); color: var(--forest);
  }
  .role-option:has(input:checked) .role-dot {
    background: var(--forest); border-color: var(--forest);
  }
  .role-option-dog:has(input:checked) {
    border-color: var(--orange); background: var(--surface-selected); color: var(--orange-dark);
  }
  .role-option-dog:has(input:checked) .role-dot {
    background: var(--orange); border-color: var(--orange);
  }
  .role-option-hunter:has(input:checked) {
    border-color: var(--forest); background: var(--surface-selected); color: var(--forest);
  }

  .hint { font-size: 1.125rem; color: var(--ui-text-secondary); margin: 6px 0; }
  .hint-ok { color: var(--ui-control); }

  .advanced-section { margin-top: 4px; }

  .btn {
    width: 100%; padding: 14px; margin-top: 14px; border: none; border-radius: 10px;
    font-size: 1.125rem; font-weight: 700; cursor: pointer;
  }
  .btn-primary { background: linear-gradient(135deg, var(--forest), var(--forest-dark)); color: var(--text-inverse); }
  .btn-secondary { background: var(--ui-background); color: var(--ui-text-primary); border: 1px solid var(--ui-border); font-size: 1.125rem; font-weight: 600; }
  .btn:disabled { opacity: 0.45; cursor: not-allowed; }

  .footnote {
    font-size: 1.125rem; color: var(--ui-text-secondary); text-align: center; margin-top: 18px; line-height: 1.5;
  }

  /* ---- Teaser (etusivu ilman ryhmää/konfiguraatiota) ---- */
  #teaser {
    display: none;
    min-height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 28px 20px 40px;
    text-align: center;
  }
  .teaser-wordmark {
    width: 100%; max-width: 420px; margin: 0 auto 10px;
  }
  .teaser-text {
    max-width: 380px; color: var(--forest); font-weight: 600;
    font-size: 1.125rem; line-height: 1.5; margin: 0 0 24px;
  }
  .teaser-ig-btn {
    display: inline-flex; align-items: center; gap: 8px;
    background: linear-gradient(135deg, var(--orange), var(--orange-dark));
    color: var(--text-inverse); text-decoration: none;
    font-weight: 700; font-size: 1.125rem;
    padding: 13px 24px; border-radius: 10px;
    box-shadow: var(--shadow-control);
  }
  .teaser-footnote {
    font-size: 1.125rem; color: var(--ui-text-secondary); margin-top: 22px; max-width: 380px; line-height: 1.5;
  }
  .teaser-version {
    display: block; font-size: 1.125rem; color: var(--ui-text-secondary); font-weight: 600; margin-top: 18px;
  }

  #app { display: none; height: 100%; flex-direction: column; }

  #appHeader {
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 8px 14px;
    background: var(--ui-surface);
    box-shadow: var(--shadow-control);
    z-index: 1500;
  }
  #appHeader img { height: 32px; flex-shrink: 0; }

  .header-left { display: flex; align-items: center; gap: 8px; }
  .header-version { font-size: 1.125rem; color: var(--ui-text-secondary); font-weight: 600; }

  .header-right { display: flex; align-items: center; gap: 12px; }

  .header-group {
    display: flex; align-items: center; gap: 6px;
    font-size: 1.125rem; font-weight: 700; color: var(--ui-text-primary);
  }
  .topbar-dot {
    width: 10px; height: 10px; border-radius: 50%;
    display: inline-block; flex-shrink: 0;
  }

  #settingsBtn {
    background: none; border: none; padding: 4px;
    font-size: 1.375rem; line-height: 1; cursor: pointer; color: var(--forest);
  }

  #mapWrap { position: relative; flex: 1 1 auto; min-height: 0; }
  #map { height: 100%; }

  #status {
    position: absolute; top: 8px; left: 8px; z-index: 1000;
    display: flex; align-items: center; gap: 8px;
    background: var(--surface-primary); padding: 6px 10px; border-radius: 6px;
    font-size: 1.125rem; max-width: 80%;
  }
  #pauseBtn {
    flex-shrink: 0;
    background: var(--forest); color: var(--text-inverse); border: none;
    padding: 4px 10px; border-radius: 5px; font-size: 1.125rem; font-weight: 700;
    cursor: pointer;
  }

  #listenBtn {
    flex-shrink: 0;
    background: var(--orange); color: var(--text-inverse); border: none;
    padding: 4px 10px; border-radius: 5px; font-size: 1.125rem; font-weight: 700;
    cursor: pointer;
  }

  /* Kohta 20, päätös 4 (hauku-android-kaare-valmistusohje.md): natiivin
     tausta-seurannan pysäytysnappi. Näkyy VAIN wrapper-visible+headless-
     yhdistelmässä (molemmat roolit, ks. kohta 16) korvaamassa Pysäytä/
     Jatka- ja Kuuntele ääntä -nappeja täsmälleen samassa paikassa - katso
     shared.js:n startPackTracker. Punertava sävy erottaa sen visuaalisesti
     tavallisesta Pysäytä-napista, koska se pysäyttää KOKO taustapalvelun/
     ilmoituksen, ei vain lähetystä. */
  #nativeStopBtn {
    flex-shrink: 0;
    background: var(--ui-danger); color: var(--text-inverse); border: none;
    padding: 4px 10px; border-radius: 5px; font-size: 1.125rem; font-weight: 700;
    cursor: pointer;
  }

  .alert-ring {
    position: absolute; top: -8px; left: -8px; width: 53px; height: 53px;
    border-radius: 50%; border: 3px solid var(--ui-danger);
    animation: alertPulse 1s ease-out infinite;
  }
  @keyframes alertPulse {
    0% { transform: scale(0.6); opacity: 1; }
    100% { transform: scale(1.7); opacity: 0; }
  }
  .alert-badge {
    position: absolute; bottom: -3px; right: -3px;
    background: var(--ui-danger); color: var(--text-inverse); border-radius: 50%;
    width: 19px; height: 19px; display: flex; align-items: center; justify-content: center;
    font-size: 1.125rem; border: 2px solid var(--ui-surface); box-shadow: 0 1px 3px rgba(0,0,0,0.4);
  }

  .battery-badge {
    position: absolute; bottom: -3px; left: -3px;
    background: var(--ui-warning); color: var(--text-inverse); border-radius: 50%;
    width: 19px; height: 19px; display: flex; align-items: center; justify-content: center;
    font-size: 1.125rem; border: 2px solid var(--ui-surface); box-shadow: 0 1px 3px rgba(0,0,0,0.4);
  }

  .marker-label {
    background: var(--surface-primary);
    border: none;
    border-radius: 5px;
    padding: 2px 7px;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--ui-text-primary);
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  }
  .marker-label::before { display: none; }

  .popup-info { font-size: 1.125rem; line-height: 1.6; }
  .popup-info strong { font-size: 1.125rem; }

  .popup-actions {
    margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--ui-border);
    display: flex; flex-direction: column; gap: 6px;
  }
  .popup-btn {
    width: 100%; padding: 8px; border: none; border-radius: 6px;
    background: var(--forest); color: var(--text-inverse);
    font-size: 1.125rem; font-weight: 700; cursor: pointer;
  }
  .popup-btn-active { background: var(--orange); }

  .distance-label {
    display: inline-block;
    background: rgba(255,255,255,0.85);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--ui-text-secondary);
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
  }

  .locate-control a {
    display: flex; align-items: center; justify-content: center;
    width: 30px; height: 30px;
    font-size: 1.125rem; color: var(--forest);
    text-decoration: none;
    background: var(--ui-surface);
  }
  .locate-control a:hover { background: var(--ui-background); }

.service-overlay { z-index: 2000; overflow-y: auto; padding: 24px 12px; box-sizing: border-box; }
.service-overlay .onboard-card {
  position: relative; max-height: calc(100dvh - 48px);
  overflow: hidden; padding: 0;
}
.service-overlay .service-card-scroll {
  max-height: calc(100dvh - 48px); overflow-y: auto;
  box-sizing: border-box; padding: 20px;
  scrollbar-gutter: stable;
}
.service-overlay h1 { color: var(--forest); font-size: 1.5rem; }
.service-overlay label { display: block; margin: 12px 0 6px; font-size: 1.125rem; }
.service-overlay input:not([type=checkbox]), .service-overlay select {
  width: 100%; box-sizing: border-box; padding: 12px; border: 1px solid var(--ui-border);
  border-radius: 8px; font: inherit; background: var(--ui-surface);
}
.service-overlay button { margin-top: 10px; }
.service-overlay .overlay-close {
  position: absolute; margin-top: 0; width: 40px; height: 40px;
  top: 10px; right: 10px; z-index: 1;
}
.service-overlay button:disabled { opacity: .55; }
#serviceMessage { overflow-wrap: anywhere; color: var(--forest); line-height: 1.5; }
/* Retken kesto pysyy näkyvissä myös kartan tilaviestien vaihtuessa. */
#trackingBar { flex-shrink: 0; padding: 8px 12px; background: var(--ui-selected); color: var(--ui-text-primary); font-size: 1.125rem; }
#trackingBar[hidden] { display: none; }
#trackingSummary, #trackingReminder { display: block; }
#trackingReminder:not(:empty) { font-weight: 700; margin: 6px 0; }
#trackingBar button, .tracking-duration-dialog button { padding: 9px 12px; margin: 6px 6px 0 0; border: 1px solid var(--ui-border); border-radius: 8px; background: var(--ui-surface); color: var(--ui-text-primary); cursor: pointer; }
#trackingStop { font-weight: 700; }
.tracking-duration-dialog { width: min(90vw, 380px); box-sizing: border-box; border: 0; border-radius: 16px; padding: 24px; }
.tracking-duration-dialog::backdrop { background: var(--ui-backdrop); }
.tracking-duration-dialog select { display: block; width: 100%; padding: 12px; margin-top: 8px; }

.oma-riista-focus {
  background: var(--ui-surface);
  color: var(--ui-text-primary);
  padding: 8px 12px;
  font: 600 14px/1.4 system-ui, sans-serif;
  cursor: pointer;
}
.oma-riista-focus:focus-visible { outline: 3px solid var(--ui-warning); outline-offset: 2px; }

/* HES v1.0: semantic roles, shared dimensions and responsive field controls. */
:root {
  /* HES 1.5: semantic roles, with stable aliases for existing components. */
  --brand-primary: #1b4332;
  --role-dog: var(--orange);
  --brand-primary-hover: #10291f;
  --surface-primary: #ffffff;
  --surface-secondary: #f7f5f0;
  --surface-elevated: #ffffff;
  --text-primary: #172c22;
  --text-secondary: #47564d;
  --text-inverse: #ffffff;
  --border-default: #75877b;
  --border-subtle: #d4ded7;
  --action-primary: var(--brand-primary);
  --action-secondary: var(--surface-primary);
  --status-active: #1b4332;
  --status-inactive: #47564d;
  --status-warning: #854d0e;
  --status-error: #b91c1c;
  --focus-ring: #1d4ed8;
  --surface-selected: #e0eee5;
  --overlay-backdrop: #0008;
  --shadow-control-color: #10291f24;
  --shadow-sheet-color: #10291f33;
  --radius-control: .75rem;
  --radius-card: 1rem;
  --radius-sheet: 1.5rem;
  --radius-pill: 9999px;
  --shadow-none: none;
  --shadow-control: 0 2px 6px var(--shadow-control-color);
  --shadow-sheet: 0 6px 24px var(--shadow-sheet-color);
  --font-weight-body: 400;
  --font-weight-action: 600;
  --font-weight-heading: 700;
  --line-body: 1.5;
  --line-heading: 1.3;
  --line-status: 1.25;
  --letter-spacing-ui: normal;
  --icon-size: 1.5rem;
  --icon-stroke: 2;
  --ui-background: var(--surface-secondary);
  --ui-surface: var(--surface-primary);
  --ui-text-primary: var(--text-primary);
  --ui-text-secondary: var(--text-secondary);
  --ui-control: var(--action-primary);
  --ui-control-active: var(--brand-primary-hover);
  --ui-border: var(--border-default);
  --ui-warning: var(--status-warning);
  --ui-danger: var(--status-error);
  --ui-focus: var(--focus-ring);
  --ui-selected: var(--surface-selected);
  --ui-backdrop: var(--overlay-backdrop);
  --ui-radius: var(--radius-control);
  --ui-touch: 3.5rem;
  --ui-primary-height: 4rem;
  --marker-hit-size: 64px;
}
body { font-size: 1.125rem; line-height: 1.5; color: var(--ui-text-primary); background: var(--ui-background); }
button, input, select, textarea { font: inherit; }
button, a, input, select { touch-action: manipulation; }
button { white-space: normal; overflow-wrap: anywhere; }
button, .btn, .popup-btn, .role-option, .teaser-ig-btn,
.leaflet-bar a, .leaflet-bar button, .oma-riista-focus {
  min-width: var(--ui-touch); min-height: var(--ui-touch); font-size: 1.125rem;
}
.btn-primary { min-height: var(--ui-primary-height); background: var(--ui-control); }
.btn-primary:hover { background: var(--ui-control-active); }
.teaser-ig-btn { background: var(--ui-control); }
.hint-ok { color: var(--ui-control); }
.local-place-symbol { width: 1.75rem; height: 1.75rem; display: grid; place-items: center; border: 2px solid var(--ui-control); border-radius: .25rem; background: var(--ui-surface); color: var(--ui-control); font-size: 1.125rem; }
.leaflet-popup-content { font-size: 1.125rem; color: var(--ui-text-primary); overflow-wrap: anywhere; }
.leaflet-popup-content-wrapper { background: var(--ui-surface); max-height: 60dvh; overflow-y: auto; padding-top: var(--ui-touch); }
.leaflet-container a.leaflet-popup-close-button { width: var(--ui-touch); height: var(--ui-touch); font-size: 1.5rem; line-height: var(--ui-touch); color: var(--ui-control); }
.btn-secondary, .popup-btn, .follow-bar button, .target-panel button,
#trackingBar button, .tracking-duration-dialog button {
  border: 1px solid var(--ui-border); border-radius: var(--ui-radius);
  background: var(--ui-surface); color: var(--ui-control); padding: .75rem 1rem;
}
.popup-btn-active, .target-panel [aria-pressed=true] { background: var(--ui-selected); border: 2px solid var(--ui-control); }
:focus-visible { outline: 3px solid var(--ui-focus); outline-offset: 3px; }
.hint, .footnote, .teaser-footnote, .header-version, .teaser-version { color: var(--ui-text-secondary); }
.form-block input, .service-overlay input:not([type=checkbox]), .service-overlay select,
.tracking-duration-dialog select { min-height: var(--ui-touch); font-size: 1.125rem; color: var(--ui-text-primary); border-color: var(--ui-border); }
.role-option { color: var(--ui-text-primary); }
.role-option input[type=radio] { pointer-events: auto; }
.role-option:focus-within { outline: 3px solid var(--ui-focus); outline-offset: 3px; }
.role-option-dog:has(input:checked) { color: var(--ui-text-primary); }
#app { height: 100vh; height: 100dvh; }
#appHeader { padding: max(.5rem, env(safe-area-inset-top)) max(.75rem, env(safe-area-inset-right)) .5rem max(.75rem, env(safe-area-inset-left)); flex-wrap: wrap; background: var(--ui-surface); }
.header-left, .header-right { min-width: 0; }
.header-right { flex: 1; justify-content: flex-end; }
.header-group { overflow-wrap: anywhere; min-width: 0; }
#settingsBtn, .overlay-close, .service-overlay .overlay-close {
  width: var(--ui-touch); height: var(--ui-touch); padding: .5rem;
  background: var(--ui-surface); color: var(--ui-control); flex-shrink: 0;
}
.service-overlay .onboard-card { width: min(100%, 32rem); }
.service-overlay .service-card-scroll { padding: 1.25rem; padding-top: 4.5rem; }
.service-overlay h1 { font-size: 1.5rem; overflow-wrap: anywhere; }
.overlay, #onboarding { padding-left: max(.75rem, env(safe-area-inset-left)); padding-right: max(.75rem, env(safe-area-inset-right)); padding-bottom: max(1.5rem, env(safe-area-inset-bottom)); }
.tracking-duration-dialog { max-height: 85vh; overflow-y: auto; color: var(--ui-text-primary); background: var(--ui-surface); }
.tracking-duration-dialog::backdrop { background: var(--ui-backdrop); }
#trackingBar { font-size: 1.125rem; color: var(--ui-text-primary); background: var(--ui-selected); max-height: 30dvh; overflow-y: auto; }
#trackingSummary { font-size: 1.25rem; }
#mapWrap { min-height: 12rem; display: flex; flex-direction: column; }
#status { position: static; flex: 0 0 auto; flex-wrap: wrap; max-width: none; border-radius: 0; font-size: 1.125rem; color: var(--ui-text-primary); background: var(--ui-surface); }
#statusText { flex: 1 1 12rem; overflow-wrap: anywhere; }
#pauseBtn, #listenBtn, #nativeStopBtn { padding: .5rem .75rem; }
#pauseBtn { background: var(--ui-control); }
#listenBtn { background: var(--ui-warning); }
#nativeStopBtn { background: var(--ui-danger); }
#map { flex: 1 1 auto; min-height: 12rem; height: auto; }
.follow-bar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .5rem .75rem; background: var(--ui-surface); border-top: 1px solid var(--ui-border); max-height: 30dvh; overflow-y: auto; }
#followStatus { flex: 1 1 10rem; }
[hidden], .target-panel[hidden], .follow-bar [hidden] { display: none !important; }
.leaflet-bar a, .locate-control a { width: var(--ui-touch); height: var(--ui-touch); line-height: var(--ui-touch); color: var(--ui-control); background: var(--ui-surface); }
.leaflet-control-layers { font-size: 1.125rem; max-width: min(80vw, 24rem); }
.leaflet-control-layers-toggle { width: var(--ui-touch); height: var(--ui-touch); }
.leaflet-control-layers label { min-height: var(--ui-touch); display: flex; align-items: center; gap: .5rem; }
.leaflet-control-layers input { width: 1.5rem; height: 1.5rem; }
.leaflet-bottom { bottom: env(safe-area-inset-bottom); }
.leaflet-control-attribution { max-width: 100%; font-size: .875rem; }
.marker-label { font-size: 1.125rem; color: var(--ui-text-primary); background: var(--ui-surface); max-width: 12rem; overflow: hidden; text-overflow: ellipsis; }
.distance-label { font-size: 1.125rem; color: var(--ui-text-primary); background: var(--ui-surface); }
.popup-info, .popup-info strong { font-size: 1.125rem; }
.target-hit { display: grid; place-items: center; background: transparent; border: 0; }
.target-hit > div { pointer-events: none; }
.target-panel { position: relative; z-index: 1100; flex: 0 0 auto; max-height: 45dvh; overflow-y: auto; padding: .75rem max(.75rem, env(safe-area-inset-right)) max(.75rem, env(safe-area-inset-bottom)) max(.75rem, env(safe-area-inset-left)); background: var(--ui-surface); color: var(--ui-text-primary); border-top: 2px solid var(--ui-border); }
.target-panel h2 { font-size: 1.25rem; margin: 0; overflow-wrap: anywhere; }
.target-panel header { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; }
.target-panel header h2 { flex: 1; min-width: 0; }
.target-panel header { flex-wrap: wrap; }
.target-panel header h2 { flex: 1 1 10rem; }
.target-panel header button { flex: 0 0 auto; min-width: 5rem; overflow-wrap: normal; }
.follow-bar button { flex: 1 1 8rem; }
.follow-bar { display: flex; flex-wrap: wrap; flex-shrink: 0; max-height: none; overflow: visible; }
#followStatus { flex: 1 0 100%; }
.header-group { flex: 1; }
#headerGroupText { overflow-wrap: anywhere; }
#mapWrap { min-height: 240px; flex-shrink: 0; }
#map { min-height: max(216px, calc(var(--ui-touch) * 3 + 3rem)); }
#app { overflow-y: auto; }
@media (max-width: 380px) {
  .header-left { display: none; }
  .header-right { width: 100%; }
  .target-panel { max-height: 65dvh; }
}
.target-panel .popup-actions { display: flex; flex-direction: row; flex-wrap: wrap; }
.target-panel .popup-btn { flex: 1 1 10rem; width: auto; }
.target-choice { display: block; width: 100%; margin-top: .5rem; text-align: left; }
.target-freshness { font-weight: 700; }
.target-panel p { margin: .5rem 0; }
@media (max-height: 600px) {
  #app { overflow-y: auto; }
  .header-version, .header-left img { display: none; }
  .target-panel { max-height: 55dvh; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* HES 1.1: space is reclaimed by disclosure, not smaller touch targets. */
:root {
  --space-1: .25rem; --space-2: .5rem; --space-3: .75rem;
  --space-4: 1rem; --space-6: 1.5rem; --space-8: 2rem;
  --type-title: 1.5rem; --type-section: 1.25rem;
  --type-body: 1.125rem; --type-button: 1.125rem; --type-support: 1rem;
  --control-height: 3.5rem; --control-field-height: 4rem;
  --control-border: 1px; --control-weight: var(--font-weight-action);
}
#appHeader { padding-top: max(var(--space-1), env(safe-area-inset-top)); padding-bottom: var(--space-1); }
.control-summary { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-1); flex-shrink: 0; text-align: left; width: 100%; min-height: var(--control-height); padding: var(--space-2) var(--space-3); border: 0; border-bottom: var(--control-border) solid var(--ui-border); border-radius: 0; color: var(--ui-text-primary); background: var(--ui-surface); font-size: var(--type-body); }
.control-summary .summary-action { font-weight: var(--control-weight); color: var(--ui-control); }
#trackingCompact { font-weight: var(--control-weight); }
#compactFollowState { font-size: var(--type-body); }
#statusText { flex: none; }
#mapWrap { flex: 1 1 auto; min-height: 240px; }
#map { min-height: 240px; }
.map-controls-panel { position: absolute; top: var(--space-2); left: max(var(--space-2), env(safe-area-inset-left)); right: max(var(--space-2), env(safe-area-inset-right)); max-height: min(75dvh, 42rem); overflow-y: auto; z-index: 1600; padding: var(--space-3); border: var(--control-border) solid var(--ui-border); border-radius: var(--ui-radius); background: var(--ui-surface); color: var(--ui-text-primary); box-shadow: var(--shadow-sheet); }
.map-controls-panel header { display: flex; align-items: center; gap: var(--space-2); }
.map-controls-panel h2 { font-size: var(--type-section); flex: 1; margin: 0; }
.map-controls-panel #trackingBar { max-height: none; overflow: visible; padding: var(--space-2) 0; background: var(--ui-surface); }
.map-controls-panel #trackingSummary { font-size: var(--type-body); }
.map-controls-panel #status { padding: var(--space-2) 0; }
.map-controls-panel .follow-bar { padding: var(--space-2) 0; }
.map-controls-panel button, .target-panel button, .tracking-duration-dialog button, .btn { border-width: var(--control-border); border-radius: var(--ui-radius); font-size: var(--type-button); font-weight: var(--control-weight); }
.map-controls-panel button { min-height: var(--control-height); background: var(--ui-surface); color: var(--ui-control); border: var(--control-border) solid var(--ui-border); padding: var(--space-2) var(--space-3); }
.map-controls-panel #trackingExtend { background: var(--ui-control); color: var(--text-inverse); }
.map-controls-panel #trackingStop, .map-controls-panel #nativeStopBtn { color: var(--ui-danger); border-color: var(--ui-danger); background: var(--ui-surface); }
.map-controls-panel #trackingBar:not([hidden]) ~ #status :is(#pauseBtn, #nativeStopBtn) { display: none !important; }
.map-controls-panel #trackingBar > div { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.map-controls-panel #trackingBar button { flex: 1 1 9rem; margin: 0; }
.icon-button { width: var(--ui-touch); height: var(--ui-touch); flex-shrink: 0; padding: var(--space-2); }
.btn { min-height: var(--control-field-height); }
.tracking-duration-dialog button { min-height: var(--control-height); }

/* MenuRow: navigation and infrequent actions share a compact, scalable row. */
.service-panel-compact .service-card-scroll { padding: var(--space-4); }
.service-panel-compact h1 { padding-right: var(--ui-touch); margin: 0 0 var(--space-4); min-height: var(--ui-touch); display: flex; align-items: center; }
.settings-section { margin: 0 0 var(--space-6); }
.settings-section h2 { font-size: var(--type-section); margin: 0 0 var(--space-2); color: var(--ui-text-primary); }
.menu-list { border-top: var(--control-border) solid var(--ui-border); }
.service-overlay .menu-row { width: 100%; min-height: var(--control-height); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin: 0; padding: var(--space-3) var(--space-2); border: 0; border-bottom: var(--control-border) solid var(--ui-border); border-radius: 0; text-align: left; background: var(--ui-surface); color: var(--ui-text-primary); font-size: var(--type-body); font-weight: var(--control-weight); line-height: 1.5; }
.menu-row > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.menu-row-chevron { flex-shrink: 0; color: var(--ui-text-secondary); font-size: var(--type-section); }
.service-overlay .menu-row-destructive { color: var(--ui-danger); }
.menu-row:hover, .menu-row:active { background: var(--ui-selected); }
.menu-row:disabled { opacity: .55; cursor: wait; }
.settings-note { font-size: var(--type-body); margin: var(--space-2) 0 var(--space-3); color: var(--ui-text-secondary); }

/* Shared task dialogs retain the platform select and semantic button roles. */
.action-dialog { width: min(calc(100vw - 2rem), 28rem); max-height: calc(100dvh - max(2rem, env(safe-area-inset-top)) - max(2rem, env(safe-area-inset-bottom))); padding: var(--space-4); border: var(--control-border) solid var(--ui-border); border-radius: var(--ui-radius); }
.action-dialog header { display: flex; align-items: flex-start; gap: var(--space-2); margin-bottom: var(--space-3); }
.action-dialog h2 { flex: 1; min-width: 0; margin: 0; font-size: var(--type-section); overflow-wrap: anywhere; }
.action-dialog [data-close] { margin: 0; border: var(--control-border) solid var(--ui-border); border-radius: var(--ui-radius); background: var(--ui-surface); color: var(--ui-control); }
.action-dialog .dialog-body:empty { display: none; }
.action-dialog label { display: block; font-size: var(--type-body); }
.action-dialog select { margin: var(--space-2) 0; border: var(--control-border) solid var(--ui-border); border-radius: var(--ui-radius); background: var(--ui-surface); font: inherit; }
.action-dialog #tripPreview { margin: var(--space-3) 0; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }
.action-dialog .dialog-actions button { flex: 1 1 9rem; margin: 0; min-height: var(--control-field-height); }
.action-dialog .btn-primary { background: var(--ui-control); color: var(--text-inverse); border-color: var(--ui-control); }
.action-dialog .btn-secondary { background: var(--ui-surface); color: var(--ui-control); border-color: var(--ui-border); }
.action-dialog .btn-destructive { background: var(--ui-danger); border-color: var(--ui-danger); }

/* Leaflet owns map behavior; Hauku owns shared control presentation. */
.leaflet-bar, .leaflet-control-layers { border: var(--control-border) solid var(--ui-border) !important; border-radius: var(--ui-radius); background: var(--ui-surface); box-shadow: var(--shadow-control); }
.leaflet-bar a, .leaflet-bar button, .leaflet-control-layers-toggle { box-sizing: border-box; min-width: var(--ui-touch); min-height: var(--ui-touch); background-color: var(--text-inverse); color: var(--ui-control); }
.leaflet-bar a:first-child { border-radius: var(--ui-radius) var(--ui-radius) 0 0; }
.leaflet-bar a:last-child { border-radius: 0 0 var(--ui-radius) var(--ui-radius); }
.leaflet-bar a { border-bottom-color: var(--ui-border); }
.leaflet-bar a:hover, .leaflet-bar button:hover { background: var(--ui-selected); color: var(--ui-control); }
.leaflet-bar .map-icon-button { display: grid; place-items: center; width: var(--ui-touch); height: var(--ui-touch); padding: var(--space-2); border: 0; border-radius: var(--ui-radius); font: inherit; font-size: 1.5rem; cursor: pointer; }
.leaflet-control-zoom a { font-size: 1.5rem; font-weight: var(--control-weight); }
.leaflet-container .leaflet-disabled { color: var(--ui-text-secondary); background: var(--ui-background); cursor: default; }
.leaflet-bar :focus-visible, .leaflet-control-layers-toggle:focus-visible { outline: 3px solid var(--ui-focus); outline-offset: 3px; }
.leaflet-control-layers-expanded { padding: var(--space-2) var(--space-3); color: var(--ui-text-primary); }
.leaflet-control-layers-list { max-height: 50dvh; overflow-y: auto; }
.oma-riista-focus { border-radius: var(--ui-radius); font-size: var(--type-button); font-weight: var(--control-weight); }

.app-information { margin: var(--space-2) 0; color: var(--ui-text-secondary); font-size: var(--type-body); }

/* HES 1.2: the same view shell and tokens serve every active task. */
:root {
  --view-padding: var(--space-4); --view-gap: var(--space-6);
  --field-gap: var(--space-4); --button-gap: var(--space-2);
  --menu-padding: var(--space-3); --header-height: var(--control-height);
  --view-radius: var(--ui-radius); --view-border: var(--control-border) solid var(--ui-border);
  --view-shadow: var(--shadow-sheet);
}
.service-overlay {
  padding: max(var(--space-4), env(safe-area-inset-top)) max(var(--space-3), env(safe-area-inset-right)) max(var(--space-4), env(safe-area-inset-bottom)) max(var(--space-3), env(safe-area-inset-left));
  align-items: center; background: var(--ui-backdrop); overflow: hidden;
}
.service-overlay .onboard-card {
  display: flex; flex-direction: column; padding: 0; border: var(--view-border);
  border-radius: var(--view-radius); box-shadow: var(--view-shadow);
  max-height: 100%; min-height: 0;
}
.view-header, .action-dialog header, .map-controls-panel header, .target-panel header {
  display: flex; align-items: flex-start; flex-wrap: nowrap; gap: var(--space-2); min-height: var(--header-height);
}
.service-overlay .view-header { padding: var(--view-padding); border-bottom: var(--view-border); flex-shrink: 0; }
.service-overlay .view-header h1, .service-panel-compact .view-header h1,
.action-dialog header h2, .map-controls-panel header h2, .target-panel header h2 {
  font-size: var(--type-title); line-height: 1.3; margin: 0; padding: 0;
  min-width: 0; min-height: 0; flex: 1; overflow-wrap: anywhere;
}
.service-overlay .overlay-close, .service-overlay .header-back {
  position: static; margin: 0; flex: 0 0 auto; border: var(--view-border); border-radius: var(--view-radius);
  box-shadow: none; font-size: var(--type-button); width: auto;
}
.service-overlay .overlay-close { width: var(--ui-touch); }
.service-overlay .header-back { padding: var(--space-2); min-height: var(--control-height); }
.service-overlay .service-card-scroll, .service-panel-compact .service-card-scroll {
  padding: var(--view-padding); max-height: none; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
}
.service-overlay h2 { font-size: var(--type-section); margin: var(--space-6) 0 var(--space-2); }
.service-overlay p, .dialog-body p { margin: 0 0 var(--space-4); }
.service-overlay label, .action-dialog label { display: block; font-size: var(--type-body); margin: var(--field-gap) 0 var(--space-2); }
.service-overlay label:first-child, .dialog-body label:first-child { margin-top: 0; }
.service-overlay input:not([type=checkbox]), .service-overlay select,
.action-dialog input:not([type=checkbox]), .action-dialog select {
  width: 100%; max-width: 100%; min-width: 0; min-height: var(--control-height);
  padding: var(--space-3); border: var(--view-border); border-radius: var(--view-radius);
  background: var(--ui-surface); color: var(--ui-text-primary); font-size: var(--type-body);
}
.service-overlay input[type=checkbox] { width: var(--space-6); height: var(--space-6); vertical-align: middle; }
.service-overlay label:has(input[type=checkbox]) { min-height: var(--control-height); }
.service-overlay .btn { margin-top: var(--button-gap); }
.btn, .popup-btn { padding: var(--space-3) var(--space-4); }
.btn-primary { background: var(--ui-control); border: var(--control-border) solid var(--ui-control); color: var(--text-inverse); }
.btn-secondary { background: var(--ui-surface); border: var(--view-border); color: var(--ui-control); }
.btn.btn-destructive { color: var(--ui-danger); border-color: var(--ui-danger); background: var(--ui-surface); }
.action-dialog .btn-primary.btn-destructive { background: var(--ui-danger); color: var(--text-inverse); }
.danger-zone { border-top: var(--view-border); padding-top: var(--space-4); margin-top: var(--space-6); }
.service-overlay .menu-row { font-weight: 400; padding: var(--menu-padding) var(--space-2); }
.service-overlay .settings-section h2 { margin-top: 0; }
.service-overlay .settings-note, .app-information { font-size: var(--type-support); }
button:active:not(:disabled) { filter: brightness(.93); }
button:disabled { opacity: .55; cursor: not-allowed; }
[aria-busy=true] { cursor: wait; }
[aria-invalid=true] { border-color: var(--ui-danger) !important; }
#secondFactorError { color: var(--ui-danger); overflow-wrap: anywhere; }
#serviceMessage:empty, #secondFactorError:empty { display: none; }
#serviceMessage { margin: var(--space-4) 0 0; padding: var(--space-3); background: var(--ui-selected); color: var(--ui-text-primary); }
.action-dialog { box-shadow: var(--view-shadow); padding: var(--view-padding); }
.control-summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0 var(--space-2); }
#trackingCompact { font-size: var(--type-body); }
.control-summary .summary-action { grid-column: 2; grid-row: 1; font-size: var(--type-section); }
.control-summary #statusText { grid-column: 1 / -1; font-size: var(--type-body); }
.map-navigation-toggle {
  position: absolute; top: var(--space-3); left: var(--space-3); z-index: 1200;
  width: auto; min-width: var(--ui-touch); height: auto; max-width: calc(100% - 7rem);
  border: var(--view-border); border-radius: var(--view-radius); box-shadow: var(--view-shadow);
  background: var(--ui-surface); color: var(--ui-control); font-size: var(--type-body);
}
#compactFollowState { display: block; font-size: var(--type-body); }
.map-controls-panel { box-shadow: var(--view-shadow); padding: var(--view-padding); }
.target-panel header button.icon-button { width: var(--ui-touch); min-width: var(--ui-touch); }
.map-controls-panel {
  position: fixed; top: auto; bottom: max(var(--space-4), env(safe-area-inset-bottom));
  left: 0; right: 0; margin: 0 auto; width: min(calc(100% - 2rem), 32rem);
  max-height: calc(100dvh - 2rem); overflow-y: auto; overscroll-behavior: contain;
}
.map-controls-panel::backdrop { background: var(--ui-backdrop); }
/* Expanded Leaflet layers must remain above the neighbouring map shortcut. */
.leaflet-top { z-index: 1300; }
/* Let a tall header scroll too, so 200% text and a keyboard cannot consume the task area. */
.service-overlay .onboard-card { display: block; overflow-y: auto; overscroll-behavior: contain; }
.service-overlay .service-card-scroll { overflow: visible; }
.service-overlay .view-header { flex-wrap: wrap; }
.service-overlay .view-header h1 { flex: 1 1 12rem; }
.service-overlay .view-header .overlay-close, .service-overlay .view-header .header-back { margin-left: auto; }
.startup-status { padding: var(--view-padding); max-width: 32rem; margin: auto; color: var(--ui-text-primary); background: var(--ui-surface); }
.map-navigation-toggle { font-size: var(--type-title); }
.service-overlay .overlay-close { font-size: var(--type-title); }
.view-header .icon-button, .action-dialog header .icon-button, .map-controls-panel header .icon-button { font-size: var(--type-title); }
.service-overlay .settings-note { font-size: var(--type-body); }
.settings-section { margin-bottom: var(--view-gap); }
.target-panel { padding: var(--view-padding); }
.target-panel p { margin: var(--space-2) 0; }
.map-control-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--space-3); margin: var(--space-4) 0; }
.map-control-actions .leaflet-control { float: none; clear: none; margin: 0; }
.map-controls-panel .leaflet-disabled { color: var(--ui-text-secondary); background: var(--ui-background); cursor: default; }
#mapNavigationNotice { margin: var(--space-3) 0; overflow-wrap: anywhere; }
#mapNavigationNotice:empty { display: none; }

/* HES 1.3: three distinct main-map controls, using the existing view system. */
#appHeader { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: min(var(--space-2), 8px); padding: max(var(--space-1), env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) var(--space-1) max(12px, env(safe-area-inset-left)); background: var(--ui-control); color: var(--text-inverse); }
#appHeader #settingsBtn { width: 56px; height: 56px; min-width: 56px; min-height: 56px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: var(--view-radius); -webkit-appearance: none; appearance: none; }
#appHeader .header-content { min-width: 0; }
#appHeader .header-identity { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
#appHeader .header-left { display: flex; }
#appHeader .header-left img { width: 32px; height: 32px; object-fit: contain; background: var(--ui-surface); border-radius: var(--space-1); }
#appHeader .header-group { font-size: var(--type-body); color: inherit; }
#appHeader #settingsBtn, #appHeader .control-summary { background: transparent; color: inherit; box-shadow: none; }
#appHeader .control-summary { grid-template-columns: 12px minmax(0, 1fr) auto; min-height: var(--control-height); padding: var(--space-1) 0; border: 0; line-height: 1.25; align-content: center; }
#appHeader #trackingStateSymbol { font-size: .75em; line-height: calc(1.25 / .75); align-self: start; }
#appHeader .tracking-state, #appHeader .tracking-remaining, #appHeader .tracking-reminder { display: inline-block; max-width: 100%; vertical-align: top; }
#appHeader .control-summary .summary-action, #appHeader #statusText { color: inherit; }
#appHeader :is(#settingsBtn, .control-summary):hover { background: var(--ui-control-active); }
#appHeader :is(#settingsBtn, .control-summary):focus-visible { outline-color: var(--text-inverse); outline-offset: -3px; }
#appHeader #trackingCompact { grid-column: 2; font-weight: 400; align-self: start; display: flex; flex-wrap: wrap; column-gap: var(--space-2); row-gap: 0; }
#appHeader .tracking-state { flex-basis: 100%; }
#appHeader .tracking-reminder { font-weight: var(--control-weight); }
#appHeader .summary-action { grid-column: 3; grid-row: 1; align-self: start; line-height: 1.125; }
#appHeader #statusText { grid-column: 1 / -1; }
.ui-icon { width: var(--space-6); height: var(--space-6); flex: 0 0 auto; }
.map-navigation-toggle { display: flex; flex-direction: column; align-items: center; gap: var(--space-1); font-size: var(--type-button); padding: var(--space-2); }
.map-control-actions { gap: var(--space-2); margin: var(--space-3) 0; }
.map-control-actions .leaflet-control-zoom { display: flex; border: 0 !important; box-shadow: none; gap: var(--space-2); }
.map-control-actions .leaflet-control-zoom a { border: var(--view-border); border-radius: var(--view-radius); }
.map-control-actions .locate-control { flex: 1; }
.map-control-actions .locate-control .map-icon-button { width: 100%; height: auto; display: flex; justify-content: center; align-items: center; gap: var(--space-2); font-size: var(--type-title); }
.map-tool-label { font-size: var(--type-button); }
#mapNavigationPanel .follow-bar { border: 0; padding: 0; gap: var(--space-2); }
#mapNavigationPanel #groupOverview { flex-basis: 100%; min-height: var(--control-field-height); background: var(--ui-control); color: var(--text-inverse); }
#mapControlsPanel #trackingStop { flex-basis: 100%; order: 2; margin-top: var(--space-4); }

/* Tilin tunniste on sisältötietoa, ei navigointirivi. */
.service-overlay .account-identity { margin-bottom: var(--view-gap); }
.service-overlay .account-identity h2 { margin: 0 0 var(--space-2); font-size: var(--type-support); color: var(--ui-text-secondary); font-weight: 400; }
.service-overlay .account-identity p { margin: 0; overflow-wrap: anywhere; color: var(--ui-text-primary); }

/* HES 1.5: shared visual treatment; dimensions and interaction remain owned by HUX. */
body { font-weight: var(--font-weight-body); line-height: var(--line-body); letter-spacing: var(--letter-spacing-ui); }
h1, h2, h3 { font-weight: var(--font-weight-heading); line-height: var(--line-heading); }
.btn, .popup-btn, .header-back, .teaser-ig-btn { border-radius: var(--radius-control); font-weight: var(--font-weight-action); line-height: var(--line-body); box-shadow: var(--shadow-none); }
.btn-primary, .teaser-ig-btn { background: var(--action-primary); color: var(--text-inverse); }
.btn-primary:hover { background: var(--brand-primary-hover); }
.btn-secondary { background: var(--action-secondary); color: var(--ui-control); }
.form-block { border-radius: var(--radius-card); box-shadow: var(--shadow-none); }
.form-block input, .role-option, .icon-button, .overlay-close, .oma-riista-focus { border-radius: var(--radius-control); }
.service-overlay .onboard-card, .overlay .onboard-card, .action-dialog { background: var(--surface-elevated); border-radius: var(--radius-card); box-shadow: var(--shadow-sheet); }
.service-overlay .view-header { border-bottom-color: var(--border-subtle); }
.service-overlay .menu-row { font-weight: var(--font-weight-body); border-bottom-color: var(--border-subtle); }
.menu-list, .danger-zone { border-color: var(--border-subtle); }
.service-overlay label, .service-overlay input, .service-overlay select, .action-dialog label, .action-dialog select { font-weight: var(--font-weight-body); line-height: var(--line-body); }
.icon-button, .service-overlay .overlay-close, .action-dialog [data-close] { display: inline-flex; align-items: center; justify-content: center; }
.ui-icon { width: var(--icon-size); height: var(--icon-size); stroke-width: var(--icon-stroke); stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.menu-row-chevron { display: inline-flex; align-items: center; }
.map-navigation-toggle, .leaflet-bar, .leaflet-control-layers, .oma-riista-focus { border-radius: var(--radius-control); background: var(--surface-primary); box-shadow: var(--shadow-control); }
.map-controls-panel { border-radius: var(--radius-sheet); background: var(--surface-elevated); box-shadow: var(--shadow-sheet); }
.map-controls-panel header, .action-dialog header, .target-panel header { align-items: center; }
.map-controls-panel #trackingExtend, #mapNavigationPanel #groupOverview { min-height: var(--ui-primary-height); background: var(--action-primary); color: var(--text-inverse); border-color: var(--action-primary); }
.map-controls-panel #trackingStop, .map-controls-panel #nativeStopBtn { color: var(--status-error); border-color: var(--status-error); }
#appHeader { background: var(--brand-primary); color: var(--text-inverse); box-shadow: var(--shadow-none); }
#appHeader .control-summary { font-weight: var(--font-weight-body); line-height: var(--line-status); }
#appHeader .summary-action { display: inline-flex; }
#statusDetails { overflow-wrap: anywhere; }
#statusDetails:empty { display: none; }
#statusText[data-severity=critical], #statusText[data-severity=error] { font-weight: var(--font-weight-action); }
button:disabled { opacity: .55; cursor: not-allowed; }
@media (hover: hover) { button:not(:disabled):hover { filter: brightness(.97); } }
button:active:not(:disabled) { filter: brightness(.93); }

.leaflet-control-layers:not(.leaflet-control-layers-expanded) .leaflet-control-layers-toggle:has(.ui-icon) { display: grid; place-items: center; background-image: none; border-radius: var(--radius-control); }
.map-control-actions .leaflet-bar { box-shadow: var(--shadow-none); }
#statusDetails[data-severity=error], #statusDetails[data-severity=critical] { color: var(--status-error); }

/* Expanded layers show only the selectable rows, never a second opener. */
.leaflet-control-layers-expanded .leaflet-control-layers-toggle { display: none; }

#omaAreaLayers .leaflet-control-layers { float: none; margin: 0; max-width: 100%; border: 0 !important; padding: 0; box-shadow: var(--shadow-none); background: transparent; }
#omaAreaLayers .leaflet-control-layers-list { max-height: none; overflow: visible; }
#omaAreaLayers label span { overflow-wrap: anywhere; min-width: 0; }
#omaAreaLayers input { flex-shrink: 0; accent-color: var(--action-primary); }
