/* Design-tokenit, reset, typografia ja jaetut komponentit.
   Kontrastit tarkistettu WCAG AA -tasolle valkoista/vaaleaa taustaa vasten. */
:root {
  --bg: #f2f4f9;
  --surface: #ffffff;
  --ink: #1a2233;
  --ink-soft: #46536b;
  --line: #c9d0dd;

  --nt: #0b6b6b;
  --nt-soft: #e0f2f2;
  --adhd: #a34700;
  --adhd-soft: #fdeedd;

  --accent: #2f4fae;
  --accent-soft: #e3e9f9;
  --ok: #1a7f37;
  --ok-soft: #dcfce7;
  /* Tehtävän edistymispalkin täyttöväri (day-scene): 25% matkaa
     vaaleasta "valmis"-vihreästä kohti kylläisempää --ok:ta, ei tumma. */
  --ok-mid: color-mix(in srgb, var(--ok) 25%, var(--ok-soft) 75%);
  --warn: #9a5b00;
  --warn-soft: #fef3c7;
  --danger: #b3261e;
  --danger-soft: #fde8e8;

  --dopamine: #6d28d9;
  --dopamine-faded: #94a3b8;

  --radius: 10px;
  /* --text-scale ja --ui-scale asetetaan devConfig/devPanel.js:stä —
     oletusarvo 1 jos kehittäjäasetuksia ei ole vielä ladattu. */
  --text-scale: 1;
  --ui-scale: 1;
  --touch: calc(44px * var(--ui-scale, 1));
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

html {
  font-size: calc(16px * var(--text-scale, 1));
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3 {
  margin: 0 0 0.35em;
  line-height: 1.2;
}

p {
  margin: 0.35em 0;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Painikkeet — kosketuskohde vähintään 44 px */
.btn {
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 2px solid var(--ink-soft);
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary,
.btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Sirupainikkeet (tilanteet, nopeudet) */
.chip {
  min-height: var(--touch);
  padding: 6px 12px;
  border-radius: 999px;
  border: 2px solid var(--ink-soft);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Mittari */
.meter {
  margin: 6px 0;
}

.meter-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.meter-track {
  position: relative;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background-color: #e6e9f0;
  /* Kynnyksen jälkeinen vyöhyke sävytetty hienovaraisesti — koko
     "onnistumisalue" näkyy heti, ei vain ohut viiva. --threshold-pct
     asetetaan JS:stä (meter.js); fallback 100% = ei näkyvä jos ei kynnystä. */
  background-image: linear-gradient(
    to right,
    transparent 0%,
    transparent var(--threshold-pct, 100%),
    rgba(26, 127, 55, 0.14) var(--threshold-pct, 100%),
    rgba(26, 127, 55, 0.14) 100%
  );
  overflow: hidden;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

/* Lyhyt reunavälähdys sitoutumistapahtumasta — pieni pinta-ala ja
   matala kontrasti, turvallisempi kuin täyttövälähdys valoherkille. */
.meter-track.pulse {
  border-color: var(--accent);
  border-width: 2px;
  box-shadow: 0 0 0 2px rgba(47, 79, 174, 0.25);
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: var(--ok);
  transition: width 0.15s linear;
}

.meter[data-state="under"] .meter-fill {
  background: var(--dopamine-faded);
}

.meter[data-state="low"] .meter-fill {
  background: var(--warn);
}

.meter[data-state="negative"] .meter-fill {
  background: repeating-linear-gradient(
    45deg,
    var(--danger),
    var(--danger) 6px,
    #7f1d1d 6px,
    #7f1d1d 12px
  );
}

.meter-threshold {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 4px;
  background: var(--ink);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.meter-value {
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

/* Tilamerkit — muoto + teksti, ei pelkkä väri */
.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 1.4em;
}

/* [hidden] ei muuten voittaisi author-tyylin display:flex-sääntöä
   (sama tunnettu bugi kuin .pause-overlay, ks. layout.css). */
.badge-row[hidden] {
  display: none;
}

.badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1.5px solid currentColor;
}

.badge-overloaded {
  color: var(--danger);
  background: var(--danger-soft);
}

.badge-underAroused {
  color: var(--ink-soft);
  background: #eceff5;
}

.badge-hyperfocus {
  color: #5b21b6;
  background: #ede9fe;
}

.badge-balanced {
  color: var(--ok);
  background: var(--ok-soft);
}

/* Tekstivastine ja faktalaatikko */
.explain {
  margin: 10px 0 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
}

.explain summary {
  font-weight: 700;
  cursor: pointer;
  min-height: 32px;
}

.facts {
  margin: 10px 0 0;
  background: var(--accent-soft);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius);
  padding: 8px 12px;
}

.facts h3 {
  font-size: 0.95rem;
}

.facts p {
  font-size: 0.9rem;
}

.insight {
  background: var(--warn-soft);
  border-left: 5px solid var(--warn);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-weight: 600;
}

/* Dialogi */
.info-dialog {
  max-width: 34rem;
  border: 2px solid var(--ink-soft);
  border-radius: var(--radius);
  padding: 16px;
}

.info-dialog::backdrop {
  background: rgba(26, 34, 51, 0.6);
}

.info-dialog .disclaimer {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

/* Kehittäjäasetukset — sama dialogi-perusta kuin info-dialog, DRY */
.dev-panel {
  max-width: 34rem;
  border: 2px solid var(--ink-soft);
  border-radius: var(--radius);
  padding: 16px;
}

.dev-panel::backdrop {
  background: rgba(26, 34, 51, 0.6);
}

.dev-panel-intro {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.dev-panel fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 10px 0;
  padding: 8px 12px 12px;
}

.dev-panel legend {
  font-weight: 700;
  padding: 0 6px;
}

.dev-panel-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
}

.dev-panel-row label {
  flex: 1;
  font-size: 0.85rem;
}

.dev-panel-undo {
  min-width: 32px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}

.dev-panel-undo:disabled {
  opacity: 0.35;
  cursor: default;
}

.dev-panel-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 4px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.dev-panel-toolbar .btn {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 0.8rem;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
