/* ==========================================================================
   Design system v2 — tokens + base components
   Direction: "Kept Time" (base) + Apple-native borrowings (grouped rows,
   segmented control, giant numeral) + a progress ring borrowed from
   "Small Ritual". See design/DESIGN_SYSTEM.md for the full spec and
   design/CHANGELOG.md for the v1 → v2 rationale.

   Import this file once per product. Do not fork it — extend via new
   tokens/components in this file, propose the change in both places it's
   consumed.
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* ---- Type ------------------------------------------------------------ */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;

  /* ---- Colour — light (default) ----------------------------------------
     Brand teal #0f6b64 on paper #fafaf9 = 6.08:1. White on brand = 6.35:1.
     Both exceed WCAG AA (4.5:1 body, 3:1 large/UI). */
  --paper: #fafaf9;               /* page background */
  --paper-raised: #ffffff;        /* cards, grouped-row surface */
  --paper-sunken: #f2f2f2;        /* group background behind grouped rows */
  --ink: #14181a;                 /* primary text — 17.1:1 on paper */
  --ink-secondary: #6b7278;       /* secondary text/captions — 4.67:1 on paper */
  --border: #e3e2df;              /* hairlines, row dividers */
  --border-strong: #c8c7c3;       /* input borders at rest */

  --accent: #0f6b64;              /* brand teal — 6.08:1 on paper */
  --accent-ink: #ffffff;          /* text/icon on accent fill — 6.35:1 */
  --accent-tint: #e8f2f0;         /* selected-row / chip-selected background */
  --accent-pressed: #0c534e;      /* active/pressed state of accent fill */

  --success: #1a7f37;             /* 4.86:1 on paper */
  --success-tint: #e9f6ec;
  --warning: #8a5a00;             /* 5.67:1 on paper */
  --warning-tint: #fbf1de;
  --destructive: #c4291c;         /* 5.46:1 on paper */
  --destructive-tint: #fbeae8;

  /* ---- Spacing — 4px base, no arbitrary values -------------------------- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 56px;
  --space-10: 72px;

  /* ---- Radius ------------------------------------------------------------ */
  --radius-s: 10px;   /* inputs, chips, small controls */
  --radius-m: 14px;   /* buttons, rows-as-standalone-cards */
  --radius-group: 12px; /* grouped inset row list container */
  --radius-full: 999px; /* segmented control, pill/thumb */

  /* ---- Motion — feedback only -------------------------------------------- */
  --motion-fast: 120ms;
  --motion-base: 200ms;
  --motion-ease: cubic-bezier(0.4, 0, 0.2, 1);
  --motion-spring: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Designed dark mode, not inverted: paper is a near-black warm-neutral
       (not pure #000), raised surfaces step UP in lightness (elevation via
       lightness, matching iOS), and the accent brightens + desaturates
       slightly for legibility on dark rather than staying the light value. */
    --paper: #101312;
    --paper-raised: #1a1e1d;
    --paper-sunken: #0a0c0b;
    --ink: #f4f5f4;                 /* 17.1:1 on paper */
    --ink-secondary: #98a19d;       /* 7.05:1 on paper */
    --border: #2a2f2d;
    --border-strong: #3c433f;

    --accent: #4fc3b8;              /* 8.75:1 on paper */
    --accent-ink: #0a1615;          /* 8.63:1 on accent fill */
    --accent-tint: #172624;
    --accent-pressed: #6fd0c6;

    --success: #3fb950;             /* 7.36:1 on paper */
    --success-tint: #10231a;
    --warning: #d4a72c;             /* 8.33:1 on paper */
    --warning-tint: #241f10;
    --destructive: #ff7b6b;         /* 7.38:1 on paper */
    --destructive-tint: #2a1613;
  }
}

/* Manual override hooks — a product can force a theme regardless of OS
   setting with data-theme="light" / "dark" on <html>. */
:root[data-theme="dark"] {
  color-scheme: dark;
}
:root[data-theme="light"] {
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, h4, p, figure { margin: 0; }
button { font-family: inherit; }

/* ==========================================================================
   Type scale — size, weight, tracking and leading move together.
   Big text: tight tracking, tight leading. Small text: loose tracking,
   loose leading. Never one fixed letter-spacing for everything.
   ========================================================================== */

.text-giant   { font-size: 56px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.05; }
.text-display { font-size: 34px; font-weight: 700; letter-spacing: -0.02em;  line-height: 1.1; }
.text-title   { font-size: 22px; font-weight: 700; letter-spacing: -0.01em;  line-height: 1.2; }
.text-headline{ font-size: 17px; font-weight: 600; letter-spacing: -0.005em; line-height: 1.3; }
.text-body    { font-size: 16px; font-weight: 400; letter-spacing: 0;        line-height: 1.45; }
.text-callout { font-size: 15px; font-weight: 400; letter-spacing: 0;        line-height: 1.4; }
.text-caption { font-size: 13px; font-weight: 500; letter-spacing: 0.01em;   line-height: 1.35; }
.text-footnote{ font-size: 12px; font-weight: 400; letter-spacing: 0.015em;  line-height: 1.4; }

.text-secondary { color: var(--ink-secondary); }
.text-tabular    { font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .text-giant   { font-size: 44px; }
  .text-display { font-size: 28px; }
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  font: 600 16px/1.2 var(--font);
  padding: 13px 20px;
  border-radius: var(--radius-m);
  border: 1px solid transparent;
  cursor: pointer;
  min-height: 44px;
  transition: background var(--motion-fast) var(--motion-ease),
              transform var(--motion-fast) var(--motion-ease),
              opacity var(--motion-fast) var(--motion-ease);
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  width: 100%;
}
.btn-primary:hover { background: var(--accent-pressed); }
.btn-primary:disabled { background: var(--border-strong); color: var(--ink-secondary); cursor: not-allowed; transform: none; }

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--paper-sunken); }

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Text link — the destructive/exit affordance. Never filled, never the
   loudest thing on screen. */
.link {
  background: none;
  border: none;
  padding: 0;
  font: 400 14px/1.3 var(--font);
  color: var(--ink-secondary);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link:hover { color: var(--ink); }
.link-destructive { color: var(--destructive); }

/* ==========================================================================
   Input with inline error
   ========================================================================== */

.field { display: block; }
.field + .field { margin-top: var(--space-4); }
.field label {
  display: block;
  font: 500 14px/1.3 var(--font);
  color: var(--ink);
  margin-bottom: var(--space-2);
}
.field input {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  padding: 12px 14px;
  font: 400 16px/1.3 var(--font);
  color: var(--ink);
  background: var(--paper-raised);
  min-height: 44px;
}
.field input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.field-hint {
  display: block;
  font: 400 13px/1.4 var(--font);
  color: var(--ink-secondary);
  margin-top: var(--space-2);
}
.field.has-error input {
  border-color: var(--destructive);
}
.field-error {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font: 400 13px/1.4 var(--font);
  color: var(--destructive);
  margin-top: var(--space-2);
}
.field-error svg { flex: none; margin-top: 1px; }

/* ==========================================================================
   Grouped inset row list — iOS-Settings style. Allowed by SLOP_RULES v2
   (see design/SLOP_RULES.md S15 amendment); this is a functional grouping
   pattern, not a decorative default card border.
   ========================================================================== */

.group-label {
  font: 500 13px/1.3 var(--font);
  color: var(--ink-secondary);
  padding: 0 var(--space-4) var(--space-2);
  margin-top: var(--space-6);
}
.group-label:first-child { margin-top: 0; }

.group {
  background: var(--paper-raised);
  border-radius: var(--radius-group);
  overflow: hidden;
  border: 1px solid var(--border);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 44px;
  padding: 12px var(--space-4);
  border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: none; }
.row-label { font: 400 16px/1.3 var(--font); color: var(--ink); }
.row-value { font: 400 16px/1.3 var(--font); color: var(--ink-secondary); font-variant-numeric: tabular-nums; }

.row-link {
  color: inherit;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.row-chevron { color: var(--ink-secondary); flex: none; }
.row-chevron svg { display: block; width: 8px; height: 14px; }

.row-toggle { cursor: pointer; }

/* ==========================================================================
   Segmented control
   ========================================================================== */

.segmented {
  display: flex;
  background: var(--paper-sunken);
  border-radius: var(--radius-s);
  padding: 3px;
  gap: 2px;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  flex: 1;
  text-align: center;
  font: 600 14px/1.3 var(--font);
  color: var(--ink-secondary);
  padding: 8px 10px;
  border-radius: calc(var(--radius-s) - 3px);
  cursor: pointer;
  transition: background var(--motion-fast) var(--motion-ease), color var(--motion-fast) var(--motion-ease);
}
.segmented input:checked + label {
  background: var(--paper-raised);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.segmented input:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ==========================================================================
   Toggle switch
   ========================================================================== */

.toggle { position: relative; width: 51px; height: 31px; flex: none; }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle .track {
  display: block; width: 100%; height: 100%;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  transition: background var(--motion-base) var(--motion-ease);
}
.toggle input:checked + .track { background: var(--success); }
.toggle .thumb {
  position: absolute; top: 2px; left: 2px; width: 27px; height: 27px;
  border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform var(--motion-base) var(--motion-spring);
}
.toggle input:checked ~ .thumb { transform: translateX(20px); }
.toggle input:focus-visible ~ .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ==========================================================================
   Chip — one-tap preset
   ========================================================================== */

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 16px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-strong);
  background: var(--paper-raised);
  color: var(--ink);
  font: 500 14px/1.2 var(--font);
  cursor: pointer;
}
.chip[aria-pressed="true"] {
  background: var(--accent-tint);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ==========================================================================
   Big numeral block — label + giant number + one sentence
   ========================================================================== */

.numeral-block { text-align: left; }
.numeral-block .label { font: 500 14px/1.3 var(--font); color: var(--ink-secondary); }
.numeral-block .value { display: block; margin-top: var(--space-1); }
.numeral-block .sentence { margin-top: var(--space-2); font: 400 16px/1.4 var(--font); color: var(--ink-secondary); }
.numeral-block .sentence strong { color: var(--ink); font-weight: 600; }

/* ==========================================================================
   Progress ring — SVG, animated stroke with a static reduced-motion
   fallback. Borrowed from direction B, re-themed to the teal accent.
   ========================================================================== */

.progress-ring { position: relative; width: 220px; height: 220px; }
.progress-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.progress-ring circle {
  fill: none;
  stroke-width: 10;
}
.progress-ring .track { stroke: var(--border); }
.progress-ring .fill {
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset var(--motion-base) var(--motion-ease);
}
.progress-ring .center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
}
@media (prefers-reduced-motion: reduce) {
  .progress-ring .fill { transition: none; }
}

/* ==========================================================================
   Empty state
   ========================================================================== */

.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-5);
}
.empty-state p { font: 400 15px/1.4 var(--font); color: var(--ink-secondary); margin-bottom: var(--space-4); }
.empty-state .btn-primary { width: auto; padding-left: 24px; padding-right: 24px; }

/* ==========================================================================
   Collapsible details section
   ========================================================================== */

.disclosure {
  border-top: 1px solid var(--border);
  padding-top: var(--space-4);
  margin-top: var(--space-5);
}
.disclosure summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font: 600 15px/1.3 var(--font);
  color: var(--ink);
}
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary .chev { color: var(--ink-secondary); transition: transform var(--motion-base) var(--motion-ease); }
.disclosure[open] summary .chev { transform: rotate(180deg); }
.disclosure .disclosure-body { margin-top: var(--space-4); }
@media (prefers-reduced-motion: reduce) {
  .disclosure summary .chev { transition: none; }
}

/* ==========================================================================
   Footer / independence note
   ========================================================================== */

.footer {
  border-top: 1px solid var(--border);
  margin-top: var(--space-9);
  padding: var(--space-6) 0;
  font: 400 13px/1.4 var(--font);
  color: var(--ink-secondary);
  text-align: center;
}
.footer a { color: var(--ink-secondary); }
.footer a:hover { color: var(--ink); }
