/* =====================================================================
   Treeni — komponentit. BEM-tyyli: .komponentti, .komponentti__osa,
   .komponentti--muunnelma, tila: .is-* / aria-*.  Dokumentaatio:
   css/DESIGN_SYSTEM.md
   ===================================================================== */

/* ------------------------------------------------------------------
   IKONIT  <svg class="icon"><use href="#i-plus"/></svg> tai Treeni.ui.icon('plus')
   ------------------------------------------------------------------ */
.icon {
  width: var(--icon-size, 22px); height: var(--icon-size, 22px);
  flex: none; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon--sm { --icon-size: 18px; }
.icon--lg { --icon-size: 28px; }

/* ------------------------------------------------------------------
   PAINIKKEET
   ------------------------------------------------------------------ */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-bd: var(--line-strong);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--touch-lg);
  padding: 0 var(--sp-5);
  border-radius: var(--r-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid var(--btn-bd);
  font-family: var(--font-display);
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  letter-spacing: -.01em;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
  isolation: isolate;
  transition:
    transform var(--dur-fast) var(--ease-spring),
    background-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    opacity var(--dur-fast);
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .4; cursor: not-allowed; }

.btn--primary {
  --btn-bg: var(--lime);
  --btn-fg: var(--text-on-accent);
  --btn-bd: transparent;
  background-image: linear-gradient(180deg, rgba(255,255,255,.28), rgba(255,255,255,0) 55%);
  box-shadow: 0 1px 0 rgba(255,255,255,.5) inset, 0 8px 28px -10px rgba(182,255,59,.75), 0 0 0 1px rgba(182,255,59,.4);
}
.btn--primary:hover:not(:disabled) { box-shadow: 0 1px 0 rgba(255,255,255,.5) inset, var(--glow-lime); }
.btn--primary:active:not(:disabled) { background-color: var(--lime-2); }

.btn--secondary {
  --btn-bg: var(--surface-2);
  --btn-bd: var(--line-strong);
  box-shadow: var(--shadow-1);
}
.btn--secondary:hover:not(:disabled) { --btn-bd: var(--line-hi); --btn-bg: var(--surface-3); }

.btn--ghost {
  --btn-bg: transparent;
  --btn-bd: transparent;
  --btn-fg: var(--text-2);
}
.btn--ghost:hover:not(:disabled) { --btn-bg: rgba(255,255,255,.05); --btn-fg: var(--text); }

.btn--outline { --btn-bg: transparent; --btn-bd: var(--lime); --btn-fg: var(--lime); }
.btn--outline:hover:not(:disabled) { box-shadow: var(--glow-soft); --btn-bg: var(--lime-a10); }

.btn--danger { --btn-bg: var(--red-a10); --btn-bd: rgba(255,77,94,.4); --btn-fg: #FF8E99; }
.btn--danger:hover:not(:disabled) { --btn-bg: rgba(255,77,94,.2); }

.btn--sm { min-height: 40px; padding: 0 var(--sp-4); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn--lg { min-height: var(--touch-xl); font-size: var(--fs-lg); padding: 0 var(--sp-6); border-radius: var(--r-lg); }
.btn--block { display: flex; width: 100%; }
.btn--icon { width: var(--touch-min); min-height: var(--touch-min); padding: 0; border-radius: var(--r-pill); }
.btn--icon.btn--lg { width: var(--touch-xl); }
.btn__sub { font-family: var(--font-mono); font-size: var(--fs-micro); font-weight: var(--fw-medium); opacity: .7; letter-spacing: .06em; text-transform: uppercase; }

.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid currentColor; border-color: var(--btn-fg) var(--btn-fg) transparent transparent;
  animation: spin .7s linear infinite;
  color: var(--btn-fg);
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-row { display: flex; gap: var(--sp-3); }
.btn-row > .btn { flex: 1; }

/* ------------------------------------------------------------------
   KORTIT
   ------------------------------------------------------------------ */
.card {
  position: relative;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.card::before { /* yläreunan valoreunus */
  content: ""; position: absolute; inset: 0 0 auto 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.10), transparent);
  pointer-events: none;
}
.card--raised { background: var(--surface-2); }
.card--flat { box-shadow: none; }
.card--tight { padding: var(--sp-4); }
.card--interactive { cursor: pointer; transition: transform var(--dur-fast) var(--ease-spring), border-color var(--dur-fast); }
.card--interactive:hover { border-color: var(--line-strong); }
.card--interactive:active { transform: scale(.985); }
/* Sankarikortti: neon-kulma + värihehku yläkulmassa */
.card--hero {
  --hero-c: var(--lime);
  background:
    radial-gradient(140% 90% at 100% 0%, color-mix(in srgb, var(--hero-c) 16%, transparent), transparent 55%),
    linear-gradient(180deg, var(--surface-2), var(--surface-1));
  border-color: color-mix(in srgb, var(--hero-c) 22%, transparent);
  padding: var(--sp-6) var(--sp-5);
}
.card--hero::after { /* hienovarainen diagonaaliviivoitus */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(-55deg, rgba(255,255,255,.018) 0 2px, transparent 2px 9px);
  mask-image: linear-gradient(200deg, #000 10%, transparent 60%);
  -webkit-mask-image: linear-gradient(200deg, #000 10%, transparent 60%);
}
.card--hero.card--cyan { --hero-c: var(--cyan); }
.card--hero.card--magenta { --hero-c: var(--magenta); }
.card--accent { border-left: 3px solid var(--lime); }
.card--warn { background: linear-gradient(180deg, var(--orange-a10), transparent), var(--surface-1); border-color: rgba(255,138,61,.28); }
.card__header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.card__title { font-size: var(--fs-lg); font-weight: var(--fw-bold); letter-spacing: -.015em; }
.card__subtitle { color: var(--text-muted); font-size: var(--fs-sm); margin-top: 2px; }
.card__footer { margin-top: var(--sp-5); display: flex; gap: var(--sp-3); }
.card > * { position: relative; z-index: 1; }

/* Tunnuslukuruutu */
.stat { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.stat__label { font-family: var(--font-mono); font-size: var(--fs-micro); letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--text-muted); }
.stat__value { font-family: var(--font-display); font-variant-numeric: tabular-nums; font-size: var(--fs-2xl); font-weight: var(--fw-heavy); letter-spacing: var(--ls-num); line-height: 1; }
.stat__value small { font-family: var(--font-mono); font-size: .45em; font-weight: var(--fw-medium); color: var(--text-muted); letter-spacing: .02em; margin-left: .3em; }
.stat__delta { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--lime); }
.stat__delta.is-down { color: var(--magenta); }
.stat-tile { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-4); }

/* ------------------------------------------------------------------
   BADGE / PILL / TAG
   ------------------------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px; border-radius: var(--r-pill);
  font-family: var(--font-mono); font-size: var(--fs-micro); font-weight: var(--fw-semi);
  letter-spacing: .08em; text-transform: uppercase; line-height: 1;
  background: var(--surface-3); color: var(--text-2); border: 1px solid var(--line);
  white-space: nowrap;
}
.badge--lime    { background: var(--lime-a10); color: var(--lime); border-color: rgba(182,255,59,.25); }
.badge--cyan    { background: var(--cyan-a10); color: var(--cyan); border-color: rgba(39,232,255,.25); }
.badge--magenta { background: var(--magenta-a10); color: #FF7DBA; border-color: rgba(255,61,154,.25); }
.badge--orange  { background: var(--orange-a10); color: var(--orange); border-color: rgba(255,138,61,.28); }
.badge--solid   { background: var(--lime); color: var(--text-on-accent); border-color: transparent; }
.badge__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; box-shadow: 0 0 6px currentColor; }

/* ------------------------------------------------------------------
   CHIPIT (monivalinta, suodattimet)  <button class="chip" aria-pressed="true">
   ------------------------------------------------------------------ */
.chip-group { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  min-height: var(--touch-min); padding: 0 var(--sp-4);
  border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--line-strong);
  font-size: var(--fs-sm); font-weight: var(--fw-semi);
  transition: background-color var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast), box-shadow var(--dur-base), transform var(--dur-fast) var(--ease-spring);
  user-select: none; cursor: pointer;
}
.chip:active { transform: scale(.95); }
.chip .icon { --icon-size: 16px; }
.chip[aria-pressed="true"], .chip.is-selected, .chip:has(input:checked) {
  background: var(--lime-a10); color: var(--lime); border-color: var(--lime);
  box-shadow: 0 0 16px -6px rgba(182,255,59,.6);
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:focus-visible) { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ------------------------------------------------------------------
   VALINTAKORTTI (onboardingin isot vaihtoehdot)
   <label class="choice"><input type="radio" name="goal">
     <span class="choice__icon">…</span><span class="choice__body">
     <span class="choice__title">…</span><span class="choice__desc">…</span></span>
     <span class="choice__check"></span></label>
   ------------------------------------------------------------------ */
.choice-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.choice {
  position: relative; display: flex; align-items: center; gap: var(--sp-4);
  min-height: 72px; padding: var(--sp-4);
  background: var(--surface-1); border: 1px solid var(--line-strong);
  border-radius: var(--r-lg); cursor: pointer;
  transition: border-color var(--dur-fast), background-color var(--dur-fast), box-shadow var(--dur-base), transform var(--dur-fast) var(--ease-spring);
}
.choice:active { transform: scale(.985); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice__icon {
  width: 48px; height: 48px; flex: none; border-radius: var(--r-md);
  display: grid; place-items: center; background: var(--surface-3); color: var(--text-2);
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.choice__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.choice__title { font-weight: var(--fw-bold); font-size: var(--fs-md); letter-spacing: -.01em; }
.choice__desc { color: var(--text-muted); font-size: var(--fs-sm); line-height: 1.4; }
.choice__check {
  width: 24px; height: 24px; flex: none; border-radius: 50%;
  border: 2px solid var(--line-hi); display: grid; place-items: center;
  transition: all var(--dur-base) var(--ease-spring);
}
.choice input[type="checkbox"] ~ .choice__check { border-radius: 7px; }
.choice:has(input:checked) {
  border-color: var(--lime); background: linear-gradient(90deg, var(--lime-a10), transparent 70%), var(--surface-1);
  box-shadow: 0 0 0 1px rgba(182,255,59,.25), 0 10px 30px -14px rgba(182,255,59,.55);
}
.choice:has(input:checked) .choice__icon { background: var(--lime); color: var(--text-on-accent); }
.choice:has(input:checked) .choice__check {
  border-color: var(--lime); background: var(--lime);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230A0B10' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
  background-size: 15px; background-repeat: no-repeat; background-position: center;
}
.choice:has(input:focus-visible) { outline: 2px solid var(--cyan); outline-offset: 3px; }
.choice--compact { min-height: 56px; padding: var(--sp-3) var(--sp-4); }

/* ------------------------------------------------------------------
   SEGMENTED CONTROL
   <div class="segmented" role="radiogroup"><label><input type=radio name=u checked><span>kg</span></label>…</div>
   tai <div class="segmented"><button aria-pressed="true">…</button>…</div>
   ------------------------------------------------------------------ */
.segmented {
  display: flex; padding: 4px; gap: 4px;
  background: var(--bg-deep); border: 1px solid var(--line-strong);
  border-radius: var(--r-md); position: relative;
}
.segmented > label, .segmented > button {
  flex: 1 1 0; position: relative; min-width: 0;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span, .segmented > button {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 var(--sp-3);
  border-radius: calc(var(--r-md) - 4px);
  font-size: var(--fs-sm); font-weight: var(--fw-semi); color: var(--text-muted);
  cursor: pointer; white-space: nowrap;
  transition: background-color var(--dur-base) var(--ease-out), color var(--dur-fast), box-shadow var(--dur-base);
}
.segmented input:checked + span, .segmented > button[aria-pressed="true"], .segmented > button[aria-selected="true"] {
  background: var(--surface-3); color: var(--text);
  box-shadow: 0 1px 0 rgba(255,255,255,.08) inset, 0 4px 12px -4px rgba(0,0,0,.7), 0 0 0 1px var(--line-strong);
}
.segmented--accent input:checked + span, .segmented--accent > button[aria-pressed="true"] {
  background: var(--lime); color: var(--text-on-accent); box-shadow: 0 0 18px -6px rgba(182,255,59,.8);
}
.segmented input:focus-visible + span { outline: 2px solid var(--cyan); outline-offset: 1px; }

/* ------------------------------------------------------------------
   TOGGLE  <label class="toggle"><input type="checkbox" role="switch"><span class="toggle__track"></span><span class="toggle__label">…</span></label>
   ------------------------------------------------------------------ */
.toggle { display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; min-height: var(--touch-min); }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle__track {
  position: relative; width: 52px; height: 32px; flex: none; border-radius: var(--r-pill);
  background: var(--surface-3); border: 1px solid var(--line-strong);
  transition: background-color var(--dur-base) var(--ease-out), box-shadow var(--dur-base), border-color var(--dur-base);
}
.toggle__track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--text-2); box-shadow: 0 2px 6px rgba(0,0,0,.5);
  transition: transform var(--dur-base) var(--ease-spring), background-color var(--dur-base);
}
.toggle input:checked + .toggle__track { background: var(--lime-a20); border-color: var(--lime); box-shadow: 0 0 16px -4px rgba(182,255,59,.6); }
.toggle input:checked + .toggle__track::after { transform: translateX(20px); background: var(--lime); }
.toggle input:focus-visible + .toggle__track { outline: 2px solid var(--cyan); outline-offset: 3px; }
.toggle__label { font-weight: var(--fw-medium); }

/* ------------------------------------------------------------------
   SLIDER  <input type="range" class="slider">  (Treeni.ui.enhance päivittää --fill)
   ------------------------------------------------------------------ */
.slider {
  --fill: 50%;
  -webkit-appearance: none; appearance: none; width: 100%; height: var(--touch-min);
  background: transparent; cursor: pointer; margin: 0;
}
.slider::-webkit-slider-runnable-track {
  height: 8px; border-radius: 4px;
  background: linear-gradient(90deg, var(--cyan) 0%, var(--lime) var(--fill), var(--surface-3) var(--fill));
  box-shadow: 0 0 14px -4px rgba(182,255,59,.5);
}
.slider::-moz-range-track { height: 8px; border-radius: 4px; background: var(--surface-3); }
.slider::-moz-range-progress { height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--cyan), var(--lime)); }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 28px; height: 28px; margin-top: -10px; border-radius: 50%;
  background: var(--text); border: 4px solid var(--lime);
  box-shadow: 0 0 0 6px rgba(182,255,59,.12), 0 0 16px rgba(182,255,59,.6);
  transition: transform var(--dur-fast) var(--ease-spring);
}
.slider:active::-webkit-slider-thumb { transform: scale(1.15); }
.slider::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--text); border: 4px solid var(--lime); box-shadow: 0 0 16px rgba(182,255,59,.6); }
.slider:focus-visible { outline: none; box-shadow: none; }
.slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--cyan); }
.slider-field__head { display: flex; justify-content: space-between; align-items: baseline; }
.slider-field__value { font-family: var(--font-display); font-variant-numeric: tabular-nums; font-weight: var(--fw-heavy); font-size: var(--fs-xl); letter-spacing: -.03em; color: var(--lime); }
.slider-field__scale { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: var(--fs-micro); color: var(--text-muted); }

/* ------------------------------------------------------------------
   STEPPER (numerosyöttö, iso peukalokohde)
   <div class="stepper" data-step="2.5"><button class="stepper__btn" data-dir="-1">−</button>
     <input class="stepper__input" inputmode="decimal" value="80"><span class="stepper__unit">kg</span>
     <button class="stepper__btn" data-dir="1">+</button></div>
   ------------------------------------------------------------------ */
.stepper {
  display: flex; align-items: stretch; gap: 0;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: var(--r-lg); overflow: hidden; height: var(--touch-xl);
  transition: border-color var(--dur-fast), box-shadow var(--dur-base);
}
.stepper:focus-within { border-color: var(--lime); box-shadow: 0 0 0 4px var(--lime-a10); }
.stepper__btn {
  width: var(--touch-xl); flex: none; display: grid; place-items: center;
  color: var(--text); font-size: 28px; font-weight: var(--fw-medium); line-height: 1;
  background: rgba(255,255,255,.02);
  transition: background-color var(--dur-instant), color var(--dur-fast);
}
.stepper__btn:first-child { border-right: 1px solid var(--line); }
.stepper__btn:last-child  { border-left: 1px solid var(--line); }
.stepper__btn:active { background: var(--lime-a20); color: var(--lime); }
.stepper__btn:disabled { opacity: .3; }
.stepper__center { flex: 1; display: flex; align-items: baseline; justify-content: center; gap: 4px; min-width: 0; }
.stepper__input {
  width: 4.6ch; min-width: 2ch; max-width: 100%; field-sizing: content; text-align: center; background: transparent; border: 0; outline: 0;
  font-family: var(--font-display); font-variant-numeric: tabular-nums; font-size: 28px;
  font-weight: var(--fw-heavy); letter-spacing: -.03em; color: var(--text); padding: 0;
  align-self: center;
}
.stepper__unit { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-muted); align-self: center; }
.stepper__center { cursor: text; }
.stepper--sm { height: var(--touch-lg); border-radius: var(--r-md); }
.stepper--sm .stepper__btn { width: 48px; font-size: 22px; }
.stepper--sm .stepper__input { font-size: 22px; }
.stepper.is-bump .stepper__input { animation: bump var(--dur-base) var(--ease-spring); }
@keyframes bump { 40% { transform: scale(1.12); color: var(--lime); } }

/* Sarjataulukko (treeninäkymä): kg × toistot × RIR */
.set-table { display: flex; flex-direction: column; gap: var(--sp-2); }
.set-row {
  display: grid; grid-template-columns: 36px minmax(0,1.3fr) minmax(0,1fr) minmax(0,.8fr) 52px;
  align-items: center; gap: var(--sp-2);
  padding: var(--sp-2); border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line);
  transition: background-color var(--dur-base), border-color var(--dur-base);
}
.set-row__n { font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--text-muted); text-align: center; }
.set-row__cell {
  height: 52px; border-radius: var(--r-sm); background: var(--bg-deep); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.set-row__cell input { width: 100%; text-align: center; background: transparent; border: 0; outline: 0; font-family: var(--font-display); font-variant-numeric: tabular-nums; font-weight: var(--fw-bold); font-size: var(--fs-lg); }
.set-row__cell:focus-within { border-color: var(--lime); }
.set-row__done {
  width: 52px; height: 52px; border-radius: var(--r-sm); display: grid; place-items: center;
  border: 2px solid var(--line-hi); color: var(--text-muted);
  transition: all var(--dur-base) var(--ease-spring);
}
.set-row.is-done { background: var(--lime-a10); border-color: rgba(182,255,59,.3); }
.set-row.is-done .set-row__done { background: var(--lime); border-color: var(--lime); color: var(--text-on-accent); box-shadow: var(--glow-soft); }
.set-row__head { background: none; border: 0; padding-top: 0; padding-bottom: 0; }
.set-row__head > * { font-family: var(--font-mono); font-size: var(--fs-micro); letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--text-muted); text-align: center; }
.set-row__prev { font-family: var(--font-mono); font-size: var(--fs-micro); color: var(--text-muted); text-align: center; }

/* ------------------------------------------------------------------
   LOMAKEKENTÄT
   ------------------------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field__label { font-size: var(--fs-sm); font-weight: var(--fw-semi); color: var(--text-2); }
.field__hint { font-size: var(--fs-xs); color: var(--text-muted); }
.field__error { font-size: var(--fs-xs); color: #FF8E99; display: flex; gap: 6px; align-items: center; }
.input, .select, .textarea {
  width: 100%; min-height: var(--touch-lg); padding: 0 var(--sp-4);
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  color: var(--text); font-size: var(--fs-md); outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-base), background-color var(--dur-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-hi); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--lime); box-shadow: 0 0 0 4px var(--lime-a10); background: #1B1F2B; }
.input[aria-invalid="true"], .field.is-error .input { border-color: var(--red); box-shadow: 0 0 0 4px var(--red-a10); }
.textarea { min-height: 112px; padding: var(--sp-3) var(--sp-4); resize: vertical; line-height: var(--lh-body); }
.select {
  -webkit-appearance: none; appearance: none; padding-right: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238B90A5' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 18px;
}
.input--num { font-family: var(--font-display); font-variant-numeric: tabular-nums; font-weight: var(--fw-bold); font-size: var(--fs-lg); }
.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-right: 56px; }
.input-group__suffix { position: absolute; right: var(--sp-4); font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--text-muted); pointer-events: none; }
.input-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }

/* ------------------------------------------------------------------
   ALERT (varoitukset warn.*)
   ------------------------------------------------------------------ */
.alert {
  --alert-c: var(--cyan);
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: var(--sp-4); border-radius: var(--r-md);
  background: color-mix(in srgb, var(--alert-c) 9%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--alert-c) 30%, transparent);
  font-size: var(--fs-sm); line-height: 1.5; color: var(--text-2);
}
.alert__icon { color: var(--alert-c); flex: none; margin-top: 1px; }
.alert__title { display: block; color: var(--text); font-weight: var(--fw-bold); font-size: var(--fs-sm); margin-bottom: 2px; }
.alert--warn { --alert-c: var(--orange); }
.alert--critical { --alert-c: var(--magenta); }
.alert--success { --alert-c: var(--lime); }

/* ------------------------------------------------------------------
   PROGRESS
   ------------------------------------------------------------------ */
.progress {
  --value: 0; --pc: var(--lime);
  position: relative; height: 8px; border-radius: var(--r-pill);
  background: var(--surface-3); overflow: hidden;
}
.progress__bar {
  position: absolute; inset: 0 auto 0 0; width: calc(var(--value) * 1%);
  border-radius: inherit; background: linear-gradient(90deg, color-mix(in srgb, var(--pc) 55%, transparent), var(--pc));
  box-shadow: 0 0 12px color-mix(in srgb, var(--pc) 70%, transparent);
  transition: width var(--dur-slow) var(--ease-out);
}
.progress--thin { height: 4px; }
.progress--cyan { --pc: var(--cyan); }
.progress--magenta { --pc: var(--magenta); }
.progress--orange { --pc: var(--orange); }
/* Askelpalkki (onboarding) <div class="progress-steps" style="--steps:7;--current:3"> */
.progress-steps { display: grid; grid-template-columns: repeat(var(--steps, 7), 1fr); gap: 5px; }
.progress-steps > i {
  height: 4px; border-radius: 2px; background: var(--surface-3); position: relative; overflow: hidden;
}
.progress-steps > i::after {
  content: ""; position: absolute; inset: 0; background: var(--lime);
  transform: scaleX(0); transform-origin: left;
  transition: transform var(--dur-slow) var(--ease-out);
}
.progress-steps > i.is-done::after { transform: scaleX(1); }
.progress-steps > i.is-current::after { transform: scaleX(1); box-shadow: 0 0 10px var(--lime); }

/* ------------------------------------------------------------------
   TABIT  <div class="tabs" role="tablist"><button role="tab" aria-selected="true">…</button></div>
   ------------------------------------------------------------------ */
.tabs {
  display: flex; gap: var(--sp-5); border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs > [role="tab"], .tabs > button {
  position: relative; min-height: var(--touch-min); padding: 0 2px;
  color: var(--text-muted); font-weight: var(--fw-semi); font-size: var(--fs-sm); white-space: nowrap;
  transition: color var(--dur-fast);
}
.tabs > [aria-selected="true"] { color: var(--text); }
.tabs > [role="tab"]::after, .tabs > button::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; border-radius: 2px;
  background: var(--lime); box-shadow: 0 0 10px var(--lime);
  transform: scaleX(0); transition: transform var(--dur-base) var(--ease-spring);
}
.tabs > [aria-selected="true"]::after { transform: scaleX(1); }

/* ------------------------------------------------------------------
   ALANAVIGAATIO (kelluva lasipalkki)
   ------------------------------------------------------------------ */
.bottom-nav {
  position: fixed; z-index: var(--z-nav);
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 10px);
  width: min(calc(100% - 2 * var(--sp-3)), calc(var(--app-max-w) - 2 * var(--sp-3)));
  height: var(--nav-h);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px;
  background: var(--surface-glass);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  backdrop-filter: blur(20px) saturate(1.6);
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  box-shadow: 0 1px 0 rgba(255,255,255,.07) inset, 0 20px 40px -10px rgba(0,0,0,.9), 0 0 0 1px rgba(0,0,0,.4);
  transition: transform var(--dur-slow) var(--ease-out), opacity var(--dur-base);
}
.bottom-nav.is-hidden { transform: translate(-50%, calc(100% + 30px)); opacity: 0; pointer-events: none; }
.nav-item {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 0; border-radius: 16px; color: var(--text-muted); text-decoration: none;
  font-size: 10.5px; font-weight: var(--fw-semi); letter-spacing: .01em;
  transition: color var(--dur-fast), background-color var(--dur-base);
}
.nav-item .icon { --icon-size: 22px; transition: transform var(--dur-base) var(--ease-spring), filter var(--dur-base); }
.nav-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item:hover { color: var(--text-2); }
.nav-item[aria-current="page"] { color: var(--lime); background: linear-gradient(180deg, var(--lime-a10), rgba(182,255,59,.02)); }
.nav-item[aria-current="page"] .icon { filter: var(--dropglow-lime); transform: translateY(-1px); }
.nav-item[aria-current="page"]::before {
  content: ""; position: absolute; top: -7px; left: 50%; width: 22px; height: 3px; margin-left: -11px;
  border-radius: 0 0 3px 3px; background: var(--lime); box-shadow: 0 0 10px var(--lime), 0 0 2px var(--lime);
}

/* ------------------------------------------------------------------
   APP HEADER (näkymän yläpalkki)
   ------------------------------------------------------------------ */
.app-header {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; gap: var(--sp-2);
  min-height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) var(--gutter) 0;
  margin: 0 calc(-1 * var(--gutter));
  background: linear-gradient(180deg, rgba(10,11,16,.92) 60%, rgba(10,11,16,0));
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.app-header__title { flex: 1; min-width: 0; font-size: var(--fs-lg); font-weight: var(--fw-bold); text-align: center; }
.app-header__side { width: var(--touch-min); flex: none; }

/* ------------------------------------------------------------------
   LISTARIVIT
   ------------------------------------------------------------------ */
.list { display: flex; flex-direction: column; background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.list--plain { background: none; border: 0; border-radius: 0; }
.list-row {
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: 60px; padding: var(--sp-3) var(--sp-4);
  color: inherit; text-decoration: none; text-align: left; width: 100%;
  border-bottom: 1px solid var(--line);
  transition: background-color var(--dur-fast);
}
.list-row:last-child { border-bottom: 0; }
a.list-row:active, button.list-row:active, .list-row--interactive:active { background: rgba(255,255,255,.04); }
.list-row__lead {
  width: 40px; height: 40px; flex: none; border-radius: var(--r-sm);
  display: grid; place-items: center; background: var(--surface-3); color: var(--text-2);
  font-family: var(--font-mono); font-size: var(--fs-sm); font-weight: var(--fw-semi);
}
.list-row__lead--lime { background: var(--lime-a10); color: var(--lime); }
.list-row__lead--cyan { background: var(--cyan-a10); color: var(--cyan); }
.list-row__lead--magenta { background: var(--magenta-a10); color: var(--magenta); }
.list-row__lead--orange { background: var(--orange-a10); color: var(--orange); }
.list-row__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.list-row__title { font-weight: var(--fw-semi); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row__meta { font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row__trail { flex: none; color: var(--text-muted); display: flex; align-items: center; gap: var(--sp-2); font-family: var(--font-mono); font-size: var(--fs-sm); }
.list-row__value { font-family: var(--font-display); font-variant-numeric: tabular-nums; font-weight: var(--fw-bold); color: var(--text); font-size: var(--fs-md); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin: var(--sp-6) 0 var(--sp-3); }
.section-head:first-child { margin-top: 0; }
.section-head__title { font-size: var(--fs-lg); font-weight: var(--fw-bold); }
.section-head__action { font-size: var(--fs-sm); color: var(--lime); font-weight: var(--fw-semi); min-height: var(--touch-min); display: inline-flex; align-items: center; }

/* ------------------------------------------------------------------
   TYHJÄTILA
   ------------------------------------------------------------------ */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-3);
  padding: var(--sp-8) var(--sp-5);
  border: 1px dashed var(--line-strong); border-radius: var(--r-lg);
  background: radial-gradient(60% 60% at 50% 0%, rgba(39,232,255,.06), transparent 70%);
}
.empty__art {
  width: 72px; height: 72px; border-radius: 22px; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line-strong); color: var(--cyan);
  box-shadow: 0 0 30px -8px rgba(39,232,255,.5); margin-bottom: var(--sp-2);
}
.empty__art .icon { --icon-size: 32px; filter: var(--dropglow-cyan); }
.empty__title { font-size: var(--fs-lg); font-weight: var(--fw-bold); }
.empty__text { color: var(--text-muted); font-size: var(--fs-sm); max-width: 30ch; }

/* ------------------------------------------------------------------
   SKELETON
   ------------------------------------------------------------------ */
.skeleton {
  position: relative; overflow: hidden; border-radius: var(--r-sm);
  background: var(--surface-2); min-height: 14px;
}
.skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent);
  animation: shimmer 1.4s var(--ease-in-out) infinite;
}
.skeleton--text { height: 14px; width: 70%; border-radius: 4px; }
.skeleton--title { height: 22px; width: 45%; border-radius: 6px; }
.skeleton--circle { border-radius: 50%; }
.skeleton--card { height: 120px; border-radius: var(--r-lg); }
@keyframes shimmer { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .skeleton::after { animation: none; } }

/* ------------------------------------------------------------------
   BOTTOM SHEET  (Treeni.ui.sheet({...}))
   ------------------------------------------------------------------ */
.backdrop {
  position: fixed; inset: 0; z-index: var(--z-sheet); background: var(--overlay);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  opacity: 0; transition: opacity var(--dur-base) var(--ease-out);
}
.backdrop.is-open { opacity: 1; }
.sheet {
  position: fixed; z-index: calc(var(--z-sheet) + 1);
  left: 50%; bottom: 0; width: 100%; max-width: var(--app-max-w);
  max-height: 88dvh; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--surface-2), var(--surface-1) 120px);
  border: 1px solid var(--line-strong); border-bottom: 0;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: 0 -20px 60px -10px rgba(0,0,0,.8);
  padding: var(--sp-2) var(--gutter) calc(var(--sp-5) + var(--safe-bottom));
  transform: translate(-50%, 100%);
  transition: transform var(--dur-slow) var(--ease-out);
}
.sheet.is-open { transform: translate(-50%, 0); }
.sheet__grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line-hi); margin: 4px auto var(--sp-4); flex: none; }
.sheet__title { font-size: var(--fs-xl); font-weight: var(--fw-heavy); margin-bottom: var(--sp-2); }
.sheet__body { overflow-y: auto; overscroll-behavior: contain; flex: 1; min-height: 0; padding-bottom: var(--sp-2); }
.sheet__actions { display: flex; gap: var(--sp-3); padding-top: var(--sp-4); flex: none; }
.sheet__actions > .btn { flex: 1; }

/* ------------------------------------------------------------------
   MODAL (Treeni.ui.modal / confirm)
   ------------------------------------------------------------------ */
.modal {
  position: fixed; z-index: var(--z-modal); left: 50%; top: 50%;
  width: min(calc(100% - 2 * var(--sp-5)), 400px);
  max-height: 80dvh; overflow: auto;
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--r-xl);
  padding: var(--sp-6) var(--sp-5) var(--sp-5);
  box-shadow: var(--shadow-3);
  transform: translate(-50%, -46%) scale(.96); opacity: 0;
  transition: transform var(--dur-base) var(--ease-spring), opacity var(--dur-base) var(--ease-out);
}
.modal.is-open { transform: translate(-50%, -50%) scale(1); opacity: 1; }
.modal__icon { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--orange-a10); color: var(--orange); margin-bottom: var(--sp-4); }
.modal__title { font-size: var(--fs-xl); font-weight: var(--fw-heavy); margin-bottom: var(--sp-2); }
.modal__text { color: var(--text-2); font-size: var(--fs-sm); }
.modal__actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-6); }
.modal__actions > .btn { flex: 1; }
.backdrop--modal { z-index: calc(var(--z-modal) - 1); }

/* ------------------------------------------------------------------
   TOAST (Treeni.ui.toast(msg, {type}))
   ------------------------------------------------------------------ */
.toast-region {
  position: fixed; z-index: var(--z-toast); left: 0; right: 0;
  top: calc(var(--safe-top) + var(--sp-3));
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  pointer-events: none; padding: 0 var(--sp-4);
}
.toast {
  --toast-c: var(--lime);
  pointer-events: auto; display: flex; align-items: center; gap: var(--sp-3);
  max-width: 420px; width: 100%; min-height: 52px; padding: var(--sp-3) var(--sp-4);
  background: rgba(24, 27, 38, .94);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  box-shadow: 0 16px 40px -10px rgba(0,0,0,.8), inset 3px 0 0 var(--toast-c);
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
  animation: toast-in var(--dur-slow) var(--ease-spring) both;
}
.toast.is-leaving { animation: toast-out var(--dur-base) var(--ease-out) both; }
.toast__icon { color: var(--toast-c); filter: drop-shadow(0 0 6px var(--toast-c)); }
.toast--info { --toast-c: var(--cyan); }
.toast--warn { --toast-c: var(--orange); }
.toast--error { --toast-c: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-16px) scale(.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px) scale(.98); } }

/* ------------------------------------------------------------------
   KAAVIOT (Treeni.charts) — yhteiset tyylit
   ------------------------------------------------------------------ */
.chart { position: relative; width: 100%; color: var(--text-muted); }
.chart svg { width: 100%; height: auto; }
.chart text { font-family: var(--font-mono); fill: var(--text-muted); font-size: 10px; }
.chart .chart__grid { stroke: rgba(255,255,255,.06); stroke-width: 1; }
.chart .chart__axis { stroke: rgba(255,255,255,.12); }
.chart-ring { position: relative; display: inline-grid; place-items: center; }
.chart-ring__center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; pointer-events: none; }
.chart-ring__value { font-family: var(--font-display); font-variant-numeric: tabular-nums; font-weight: var(--fw-heavy); letter-spacing: var(--ls-num); line-height: 1; color: var(--text); }
.chart-ring__label { font-family: var(--font-mono); font-size: var(--fs-micro); letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--text-muted); margin-top: 4px; }
.chart-ring__sub { font-family: var(--font-mono); font-size: var(--fs-micro); color: var(--text-muted); margin-top: 2px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); font-size: var(--fs-xs); color: var(--text-2); }
.chart-legend__item { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend__swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--sw); box-shadow: 0 0 8px var(--sw); }
.chart-legend__swatch--line { height: 3px; border-radius: 2px; width: 16px; }
.chart-legend__swatch--dash { height: 0; width: 16px; border-top: 2px dashed var(--sw); background: none; box-shadow: none; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 2; transform: translate(-50%, calc(-100% - 10px));
  padding: 6px 10px; border-radius: 8px; background: rgba(6,7,10,.92); border: 1px solid var(--line-strong);
  font-family: var(--font-mono); font-size: 11px; color: var(--text); white-space: nowrap;
  box-shadow: 0 8px 20px -6px rgba(0,0,0,.8); opacity: 0; transition: opacity var(--dur-fast);
}
.chart-tip.is-on { opacity: 1; }
.macro-bars { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }
.macro-bar__head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; gap: var(--sp-2); }
.macro-bar__name { font-weight: var(--fw-semi); font-size: var(--fs-sm); display: inline-flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.macro-bar__name::before { flex: none; }
.macro-bar__label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.macro-bar__name::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--mc); box-shadow: 0 0 8px var(--mc); }
.macro-bar__val { white-space: nowrap; flex: none; font-family: var(--font-display); font-variant-numeric: tabular-nums; font-weight: var(--fw-bold); font-size: var(--fs-sm); }
.macro-bar__val small { color: var(--text-muted); font-family: var(--font-mono); font-weight: var(--fw-regular); font-size: var(--fs-xs); }
.macro-bar__track { position: relative; height: 10px; border-radius: 5px; background: var(--surface-3); overflow: hidden; }
.macro-bar__fill {
  position: absolute; inset: 0 auto 0 0; border-radius: inherit; width: 0;
  background: linear-gradient(90deg, color-mix(in srgb, var(--mc) 40%, transparent), var(--mc));
  box-shadow: 0 0 14px color-mix(in srgb, var(--mc) 80%, transparent);
  transition: width var(--dur-chart) var(--ease-out);
}
.macro-bar__over { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); opacity: .6; }
.heatmap { display: flex; flex-direction: column; gap: var(--sp-3); }
.heatmap__figs { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.heatmap__fig { text-align: center; }
.heatmap__cap { font-family: var(--font-mono); font-size: var(--fs-micro); letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--text-muted); margin-top: 4px; }
.heatmap .m { transition: fill var(--dur-chart) var(--ease-out), filter var(--dur-base); cursor: pointer; }
.heatmap .m:hover, .heatmap .m.is-active { stroke: var(--text); stroke-width: 1.6; }
.heatmap__scale { display: flex; align-items: center; gap: var(--sp-2); font-family: var(--font-mono); font-size: var(--fs-micro); color: var(--text-muted); }
.heatmap__grad { flex: 1; height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--heat-0), var(--heat-1), var(--heat-2), var(--heat-3), var(--heat-4)); }
.streak { display: inline-flex; align-items: center; gap: var(--sp-2); }
.streak__count { font-family: var(--font-display); font-weight: var(--fw-heavy); font-variant-numeric: tabular-nums; font-size: var(--fs-2xl); letter-spacing: var(--ls-num); line-height: 1; }
.confetti-canvas { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: var(--z-confetti); }
