/* Contraction Timer. Colors are tokens on :root; dark mode is its own set (system setting or the in-app choice). */

:root {
  color-scheme: light;
  --bg: #f7f2f0;
  --surface: #ffffff;
  --surface-2: #f2eae7;
  --line: #e7dcdc;
  --text: #2b1f2c;
  --text-2: #5f5262;
  --muted: #7d7180;
  --start: #74396a;
  --start-ink: #ffffff;
  --start-glow: rgb(116 57 106 / 0.35);
  --stop: #b23c57;
  --stop-ink: #ffffff;
  --stop-glow: rgb(178 60 87 / 0.35);
  --bar: #8b4a80;
  --bar-live: #b23c57;
  --grid: #ece3e3;
  --focus: #2f6fdb;
  --met-bg: #fbe9e6;
  --met-line: #e3a49a;
  --met-ink: #6e1f1a;
  --close-bg: #f3ecf6;
  --close-line: #d6c2de;
  --close-ink: #4a2c55;
  --warn-bg: #fff4d6;
  --warn-ink: #5b4300;
  --danger: #a32a2a;
  --shadow: 0 1px 2px rgb(43 31 44 / 0.06), 0 4px 16px rgb(43 31 44 / 0.05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141018;
    --surface: #1e1823;
    --surface-2: #29212f;
    --line: #362c3d;
    --text: #f4eef5;
    --text-2: #cabfcd;
    --muted: #a297a6;
    --start: #8a4a80;
    --start-ink: #ffffff;
    --start-glow: rgb(138 74 128 / 0.35);
    --stop: #b4475f;
    --stop-ink: #ffffff;
    --stop-glow: rgb(180 71 95 / 0.35);
    --bar: #d39bc7;
    --bar-live: #f08ea0;
    --grid: #2c2432;
    --focus: #8fb4ff;
    --met-bg: #3a1c1f;
    --met-line: #7a3a3a;
    --met-ink: #ffd9d3;
    --close-bg: #2a2033;
    --close-line: #4b3a57;
    --close-ink: #e9d9f0;
    --warn-bg: #3a3014;
    --warn-ink: #ffe7a6;
    --danger: #ff9b9b;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141018;
  --surface: #1e1823;
  --surface-2: #29212f;
  --line: #362c3d;
  --text: #f4eef5;
  --text-2: #cabfcd;
  --muted: #a297a6;
  --start: #8a4a80;
  --start-ink: #ffffff;
  --start-glow: rgb(138 74 128 / 0.35);
  --stop: #b4475f;
  --stop-ink: #ffffff;
  --stop-glow: rgb(180 71 95 / 0.35);
  --bar: #d39bc7;
  --bar-live: #f08ea0;
  --grid: #2c2432;
  --focus: #8fb4ff;
  --met-bg: #3a1c1f;
  --met-line: #7a3a3a;
  --met-ink: #ffd9d3;
  --close-bg: #2a2033;
  --close-line: #4b3a57;
  --close-ink: #e9d9f0;
  --warn-bg: #3a3014;
  --warn-ink: #ffe7a6;
  --danger: #ff9b9b;
  --shadow: none;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

h1, h2, p { margin: 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); }

.app {
  max-width: 520px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 8px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 96px)
    calc(env(safe-area-inset-left) + 16px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.top h1 { font-size: 1rem; font-weight: 600; color: var(--text-2); letter-spacing: 0.01em; }

.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent; color: var(--text-2);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Banners and cards */
.banner { padding: 12px 14px; border-radius: 12px; font-size: 0.9375rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }

.card {
  background: var(--surface);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 0.8125rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }

.tip { display: flex; flex-direction: column; gap: 8px; }
.tip h2 { margin-bottom: 0; }
.tip p { font-size: 0.9375rem; color: var(--text-2); }
.kbd { display: inline-block; padding: 0 6px; border-radius: 6px; background: var(--surface-2); color: var(--text); font-weight: 600; }

/* Timer */
.timer { text-align: center; padding-top: 4px; }
.timer-label { font-size: 0.9375rem; color: var(--text-2); font-weight: 500; }
.timer-value {
  font-size: clamp(4rem, 22vw, 6.25rem);
  line-height: 1.05;
  font-weight: 300;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin: 2px 0 4px;
}
.timer-sub { font-size: 0.9375rem; color: var(--muted); min-height: 1.45em; }

/* The big button */
.control { display: flex; flex-direction: column; align-items: center; gap: 4px; }

.big-btn {
  position: relative;
  width: min(62vw, 248px);
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  background: var(--start);
  color: var(--start-ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 14px 36px -14px var(--start-glow), 0 0 0 10px var(--start-glow);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
  transition: transform 120ms ease, background-color 200ms ease, box-shadow 200ms ease;
}
.big-btn:active { transform: scale(0.97); }
.big-btn-text { font-size: 2.25rem; font-weight: 650; letter-spacing: 0.01em; line-height: 1.1; }
.big-btn-hint { font-size: 0.9375rem; opacity: 0.85; }

.big-btn[aria-pressed="true"] {
  background: var(--stop);
  color: var(--stop-ink);
  box-shadow: 0 14px 36px -14px var(--stop-glow), 0 0 0 10px var(--stop-glow);
  animation: breathe 4s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 14px 36px -14px var(--stop-glow), 0 0 0 8px var(--stop-glow); }
  50% { box-shadow: 0 14px 36px -14px var(--stop-glow), 0 0 0 22px var(--stop-glow); }
}
@media (prefers-reduced-motion: reduce) {
  .big-btn[aria-pressed="true"] { animation: none; }
  .big-btn { transition: none; }
}

.link-btn {
  margin-top: 8px; min-height: 44px; padding: 0 12px;
  border: 0; background: transparent; color: var(--text-2);
  text-decoration: underline; text-underline-offset: 3px; font-size: 0.9375rem;
}

/* Strength chips */
.strength { text-align: center; display: flex; flex-direction: column; gap: 10px; }
.strength p { color: var(--text-2); font-size: 0.9375rem; }
.chips { display: flex; gap: 8px; justify-content: center; }
.chip {
  min-height: 44px; padding: 0 18px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-weight: 500;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

/* Pattern alert */
.pattern { border-radius: 16px; padding: 16px; border: 1px solid; display: flex; flex-direction: column; gap: 8px; }
.pattern h2 { font-size: 1.0625rem; font-weight: 650; }
.pattern p { font-size: 0.9375rem; }
.pattern.met { background: var(--met-bg); border-color: var(--met-line); color: var(--met-ink); }
.pattern.close { background: var(--close-bg); border-color: var(--close-line); color: var(--close-ink); }
.pattern .call { align-self: flex-start; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.tile dt { font-size: 0.8125rem; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile dd { margin: 2px 0 0; font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Segmented control (chart range, appearance) */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button, .seg label span {
  display: block; min-height: 32px; padding: 4px 12px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text-2); font-size: 0.875rem; font-weight: 500;
}
.seg button[aria-pressed="true"], .seg input:checked + span {
  background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12);
}
.seg label { position: relative; flex: 1; text-align: center; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; }
.seg.wide { display: flex; }
.seg.wide label span { min-height: 40px; display: grid; place-items: center; }

/* Chart */
.chart-wrap { position: relative; }
#chart { display: block; width: 100%; height: 168px; overflow: visible; }
#chart .grid { stroke: var(--grid); stroke-width: 1; }
#chart .axis-text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
#chart .bar { fill: var(--bar); }
#chart .bar.live { fill: var(--bar-live); }
#chart .bar.selected { fill: var(--text); }
#chart .hit { fill: transparent; }
.chart-empty {
  position: absolute; inset: 0 0 22px 34px; display: grid; place-items: center;
  color: var(--muted); font-size: 0.9375rem; pointer-events: none;
}
.chart-tip {
  position: absolute; top: 0; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  border-radius: 10px; padding: 8px 10px; font-size: 0.8125rem; line-height: 1.35;
  white-space: nowrap; pointer-events: none; font-variant-numeric: tabular-nums;
}
.small-print { font-size: 0.8125rem; margin-top: 8px; }

/* History */
.history { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.history th { text-align: left; font-size: 0.75rem; font-weight: 600; color: var(--muted); padding: 0 4px 6px; }
.history td { padding: 0 4px; height: 48px; border-top: 1px solid var(--line); }
.history td:first-child, .history th:first-child { padding-left: 0; }
.history td:last-child, .history th:last-child { padding-right: 0; width: 44px; text-align: right; }
.history .day th {
  padding: 14px 0 6px; font-size: 0.8125rem; color: var(--text-2); font-weight: 600; text-transform: none;
  text-align: left; width: auto;
}
.history tr.day + tr td { border-top: 0; }
.history .event td { color: var(--text-2); }
.history .event .event-name { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; color: var(--text); }
.history .event svg { width: 14px; height: 14px; fill: var(--bar); }
.history .first { color: var(--muted); }

.strength-btn {
  min-height: 44px; min-width: 44px; padding: 0; border: 0; background: transparent;
  display: inline-flex; align-items: center; color: var(--muted); font-size: 0.8125rem;
}
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--bar); }

.row-delete {
  width: 44px; height: 44px; border: 0; background: transparent; color: var(--muted);
  display: inline-grid; place-items: center; border-radius: 10px;
}
.row-delete:active { background: var(--surface-2); }
.row-delete svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* Buttons */
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn:active { background: var(--surface-2); }
.btn.small { min-height: 40px; align-self: flex-start; }
.btn.call { background: var(--met-ink); border-color: var(--met-ink); color: var(--met-bg); }
.btn.danger { color: var(--danger); width: 100%; margin-top: 8px; }

.footnote { font-size: 0.8125rem; color: var(--muted); }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  width: min(calc(100% - 32px), 488px);
  display: flex; align-items: center; gap: 12px;
  background: var(--text); color: var(--bg);
  border-radius: 14px; padding: 6px 6px 6px 16px; min-height: 52px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);
  z-index: 10;
}
.toast span { flex: 1; font-size: 0.9375rem; }
.toast-btn {
  min-height: 40px; padding: 0 14px; border: 0; border-radius: 10px;
  background: transparent; color: var(--bg); font-weight: 700;
}

/* Settings sheet */
dialog {
  width: min(100%, 520px); max-width: 100%; max-height: 92dvh;
  margin: auto auto 0; padding: 0; border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(10 6 12 / 0.5); }
.sheet {
  display: flex; flex-direction: column; gap: 18px;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 20px);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 1.125rem; }
.field { display: flex; flex-direction: column; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field-label { font-weight: 600; font-size: 0.9375rem; padding: 0; }
.field-help { font-size: 0.8125rem; color: var(--muted); }
.field select, .field input[type="tel"] {
  min-height: 48px; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); width: 100%;
  font-size: 1rem;
}
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; font-size: 0.9375rem; }
.check input { width: 22px; height: 22px; accent-color: var(--start); flex: none; }
details { border-top: 1px solid var(--line); padding-top: 12px; }
details summary { font-weight: 600; font-size: 0.9375rem; min-height: 32px; cursor: pointer; }
details p { font-size: 0.9375rem; color: var(--text-2); margin-top: 8px; }
