/* Sprikl design system. See DESIGN.md. Tokens first, then components. */

:root,
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #eeece6;
  --line: #e2dfd7;
  --text: #1b1d1f;
  --muted: #62666d;
  --accent: #2f6b5e;
  --accent-ink: #ffffff;
  --accent-soft: #e1eeea;
  --danger: #a93a2a;
  --warn: #8a5a0b;
  --warn-soft: #f6ecd7;
  --shadow: 0 1px 2px rgb(27 29 31 / 0.05);
  --scrim: rgb(20 22 24 / 0.38);
  --raised: #ffffff;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121314;
  --surface: #1b1d1f;
  --surface-2: #26292c;
  --line: #303437;
  --text: #ecebe6;
  --muted: #a0a4aa;
  --accent: #86c9b4;
  --accent-ink: #0d2a23;
  --accent-soft: #1d3530;
  --danger: #ee8b7a;
  --warn: #e3b866;
  --warn-soft: #3a3020;
  --shadow: none;
  --scrim: rgb(0 0 0 / 0.6);
  --raised: #3b3f43;
}

:root {
  --radius: 16px;
  --radius-small: 10px;
  --gap: 16px;
  --tabs-height: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p, ul, ol { margin: 0; }
h1 { font-size: 1.5rem; line-height: 1.2; font-weight: 650; letter-spacing: -0.01em; text-wrap: balance; }
h2 { font-size: 1.125rem; line-height: 1.3; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; align-self: center; }
.pad { padding: 12px 0; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.icon { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

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

/* ---- layout ---------------------------------------------------------- */

#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px
    calc(var(--tabs-height) + env(safe-area-inset-bottom) + 32px);
}

.view-enter { animation: rise 0.2s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.page { display: flex; flex-direction: column; gap: var(--gap); }
.page-head { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.page-head > .icon-btn:first-child { margin-left: -10px; }
.page-title { flex: 1; min-width: 0; }
.section { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; align-items: stretch; }
.section > .btn { align-self: flex-start; }
.section-title, .eyebrow {
  font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.form { display: flex; flex-direction: column; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; align-items: end; }

/* ---- buttons --------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--text); font-weight: 550;
  white-space: nowrap;
}
.btn:active { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:active { background: var(--accent); filter: brightness(0.94); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn-small { min-height: 36px; padding: 0 14px; font-size: 0.875rem; }
.btn-block { width: 100%; min-height: 50px; font-size: 1.0625rem; }

.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px; border: 0; border-radius: 999px;
  background: none; color: var(--muted);
}
.icon-btn:active { background: var(--surface-2); }
.icon-dots { stroke-width: 3; }

.link {
  border: 0; background: none; padding: 10px 0; min-height: 44px;
  color: var(--accent); font-weight: 550;
}
.danger { color: var(--danger); }

.row-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.row-actions.wrap { justify-content: flex-start; flex-wrap: wrap; }
.sheet .row-actions > .btn { flex: 1; }

.save-bar {
  position: sticky; bottom: calc(var(--tabs-height) + env(safe-area-inset-bottom) + 12px);
  display: flex; gap: 10px; padding: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.12);
}
.save-bar .btn { flex: 1; }
.card > .save-bar { position: static; padding: 0; border: 0; box-shadow: none; background: none; }

/* ---- forms ----------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 0.875rem; font-weight: 550; }
.field-hint { font-size: 0.8125rem; color: var(--muted); }

input:not([type="checkbox"]):not([type="file"]), select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-small);
}
textarea { resize: vertical; line-height: 1.45; }
select { appearance: none; padding-right: 32px; text-overflow: ellipsis; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
input[type="file"] { font-size: 0.875rem; max-width: 100%; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.8; }

.segmented {
  display: flex; padding: 3px; gap: 2px;
  background: var(--surface-2); border-radius: 12px;
}
.segmented button {
  flex: 1 1 0; min-width: 0; min-height: 40px; padding: 0 2px; border: 0; border-radius: 9px; white-space: nowrap;
  background: none; color: var(--muted); font-size: 0.875rem; font-weight: 550;
}
.segmented button.on { background: var(--raised); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 44px; }
.toggle > span { display: flex; flex-direction: column; gap: 2px; }
.toggle-label { font-weight: 550; font-size: 0.9375rem; }
.toggle input {
  appearance: none; flex: none; width: 50px; height: 30px; margin: 0;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line);
  position: relative; cursor: pointer; transition: background 0.15s;
}
.toggle input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
  transition: transform 0.15s;
}
.toggle input:checked { background: var(--accent); border-color: var(--accent); }
.toggle input:checked::after { transform: translateX(20px); }

.stepper { display: flex; align-items: center; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-small); }
.stepper input:not([type="checkbox"]) {
  flex: 1; min-width: 0; border: 0; background: none; text-align: center; padding: 0;
  font-variant-numeric: tabular-nums; font-weight: 600;
}
.stepper-big { border-radius: 14px; }
.stepper-big input:not([type="checkbox"]) { font-size: 1.75rem; min-height: 56px; letter-spacing: -0.01em; }
.stepper-big .icon-btn { width: 52px; height: 52px; }

.form-error { color: var(--danger); font-size: 0.9375rem; }

/* ---- lists ----------------------------------------------------------- */

.list { display: flex; flex-direction: column; }
.list.card, .card.entries, .card.checks { padding: 0 16px; }
.list-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 60px; padding: 10px 0;
  border: 0; border-bottom: 1px solid var(--line);
  background: none; text-align: left; color: var(--text);
}
.list-row:last-child { border-bottom: 0; }
.list-row > .icon { color: var(--muted); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; border: 0; background: none; text-align: left; padding: 0; }
.row-title { font-weight: 550; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-sub { font-size: 0.875rem; color: var(--muted); }
.row-controls { display: flex; flex: none; }
.row-controls .icon-btn { width: 40px; }

.badge {
  font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 0.875rem; font-weight: 550;
}
.chip.on { background: var(--text); border-color: var(--text); color: var(--bg); }

.preview { list-style: none; padding: 0; display: flex; flex-direction: column; }
.preview li { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.preview li:last-child { border-bottom: 0; }
.preview li > :last-child { text-align: right; flex: none; max-width: 60%; }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.empty h3 { color: var(--text); }

.notice {
  padding: 12px 14px; border-radius: var(--radius-small);
  background: var(--warn-soft); color: var(--warn); font-size: 0.9375rem;
}

/* ---- today ----------------------------------------------------------- */

.hero { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.hero h2 { font-size: 1.625rem; letter-spacing: -0.015em; line-height: 1.15; }
.hero-links { display: flex; justify-content: space-between; gap: 12px; margin: -4px 0 -10px; }

.week { display: flex; flex-direction: column; gap: 10px; }
.week-days { display: grid; grid-template-columns: repeat(7, 1fr); }
.week-day { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.week-name { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.week-dot {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  border: 1.5px solid var(--line); color: var(--accent-ink);
}
.week-day.trained .week-dot { background: var(--accent); border-color: var(--accent); }
.week-day.is-today .week-name { color: var(--text); }
.week-day.is-today:not(.trained) .week-dot { border-color: var(--muted); }
.week-note { text-align: center; font-size: 0.875rem; }

/* ---- workout --------------------------------------------------------- */

.block { gap: 12px; }
.check-row { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.check-row:last-child { border-bottom: 0; }
.check-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px;
  min-height: 60px; padding: 10px 0; border: 0; background: none; text-align: left;
}
.check-box {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  border: 1.5px solid var(--muted); display: grid; place-items: center; color: var(--accent-ink);
}
.check-row.done .check-box { background: var(--accent); border-color: var(--accent); }
.check-row.done .row-title { color: var(--muted); text-decoration: line-through; }

.lift { display: flex; flex-direction: column; gap: 12px; }
.lift.skipped { opacity: 0.75; }
.lift-head { display: flex; align-items: center; justify-content: space-between; margin: -6px -8px -10px 0; }
.lift-name {
  border: 0; background: none; padding: 8px 0; min-height: 44px; text-align: left;
  font-size: 1.1875rem; font-weight: 650; letter-spacing: -0.01em;
}
.lift-cue { font-size: 0.9375rem; }
.lift-cue .num { color: var(--text); font-weight: 600; }
.lift-load { display: flex; align-items: center; gap: 12px; }
.lift-load .stepper { flex: 1; }
.lift-unit { flex: none; min-width: 2.5em; font-size: 0.9375rem; }
.lift-extras { display: flex; flex-direction: column; gap: 10px; }
.lift-extras:empty { display: none; }
.plates { font-size: 0.9375rem; font-variant-numeric: tabular-nums; }

.ramp { display: flex; flex-direction: column; gap: 6px; }
.ramp-label { font-size: 0.8125rem; font-weight: 550; }
.ramp-sets { display: flex; flex-wrap: wrap; gap: 6px; }
.ramp-set {
  min-height: 36px; padding: 0 12px; border-radius: 999px; font-size: 0.875rem;
  border: 1px dashed var(--muted); background: none; color: var(--text);
}
.ramp-set.done { border: 1px solid var(--accent-soft); background: var(--accent-soft); color: var(--muted); text-decoration: line-through; }

.sets { display: flex; flex-wrap: wrap; gap: 10px; }
.set {
  width: 54px; height: 54px; border-radius: 50%;
  border: 1.5px solid var(--line); background: var(--bg); color: var(--muted);
  font-size: 1.125rem; font-weight: 600;
  transition: background 0.12s, transform 0.12s;
}
.set:active { transform: scale(0.94); }
.set.done { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.set.done.short { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }

.rest-pill {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  width: min(528px, calc(100vw - 24px));
  display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 18px;
  background: var(--text); color: var(--bg); border-radius: 999px;
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.28); z-index: 5;
}
.rest-main { display: flex; flex-direction: column; line-height: 1.1; min-width: 64px; }
.rest-label { font-size: 0.75rem; opacity: 0.75; }
.rest-time { font-size: 1.375rem; font-weight: 650; }
.rest-bar { flex: 1; height: 4px; border-radius: 2px; background: rgb(128 128 128 / 0.4); overflow: hidden; }
.rest-bar span { display: block; height: 100%; background: var(--bg); width: 100%; transition: width 0.5s linear; }
.rest-pill .btn { background: transparent; color: var(--bg); border-color: rgb(128 128 128 / 0.55); }
.rest-pill.over { background: var(--accent); color: var(--accent-ink); }
.rest-pill.over .btn { color: var(--accent-ink); }
.rest-pill.over .rest-bar span { background: var(--accent-ink); }

/* ---- routine editor --------------------------------------------------- */

.entry { border-bottom: 1px solid var(--line); padding: 4px 0; }
.entry:last-child { border-bottom: 0; }
.entry-head { display: flex; align-items: center; gap: 8px; min-height: 60px; }
.entry-head .row-main { min-height: 52px; justify-content: center; color: var(--text); }
.entry-edit { display: flex; flex-direction: column; gap: 14px; padding: 6px 0 4px; }
.entry.open { padding-bottom: 8px; }

/* ---- exercise detail --------------------------------------------------- */

.exercise-info { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.lead { font-size: 1.0625rem; }
.steps { padding-left: 1.3em; display: flex; flex-direction: column; gap: 8px; }
.steps li::marker { color: var(--muted); font-variant-numeric: tabular-nums; }
.media, .video { width: 100%; border-radius: var(--radius-small); background: var(--surface-2); }
.media { max-height: 60vh; object-fit: contain; }
.video { aspect-ratio: 16 / 9; overflow: hidden; position: relative; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-play {
  position: absolute; inset: 0; width: 100%; border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  color: var(--muted); font-weight: 550;
}
.video-icon { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); }
.video-icon .icon { fill: currentColor; stroke: none; margin-left: 3px; }

/* ---- history ---------------------------------------------------------- */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 12px; display: flex; flex-direction: column; gap: 2px; }
.stat-value { font-size: 1.75rem; font-weight: 650; line-height: 1.1; letter-spacing: -0.02em; }
.stat-label { font-size: 0.8125rem; color: var(--muted); }

.cal-head { display: flex; align-items: center; justify-content: space-between; margin: -6px -8px 8px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-name { text-align: center; font-size: 0.75rem; font-weight: 600; color: var(--muted); padding-bottom: 4px; }
.cal-cell { aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; font-size: 0.9375rem; color: var(--muted); border: 1.5px solid transparent; max-width: 44px; width: 100%; justify-self: center; }
.cal-cell.main { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.cal-cell.side { border-color: var(--accent); color: var(--text); font-weight: 600; }
.cal-cell.is-today:not(.main):not(.side) { border-color: var(--line); color: var(--text); font-weight: 600; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 0.8125rem; margin-top: 12px; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--accent); }
.legend-dot.main { background: var(--accent); }
.legend-dot.side { margin-left: 12px; }

/* ---- auth -------------------------------------------------------------- */

.auth { max-width: 380px; margin: 8vh auto 0; display: flex; flex-direction: column; gap: 16px; }
.auth-mark { width: 60px; height: 60px; border-radius: 18px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.auth h1 { font-size: 2rem; }

/* ---- tabs -------------------------------------------------------------- */

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; max-width: 112px; height: var(--tabs-height);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 0.6875rem; font-weight: 600; color: var(--muted);
}
.tabs a.on { color: var(--accent); }

/* ---- sheet and toast --------------------------------------------------- */

#sheet-root { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: var(--scrim); animation: fade 0.18s ease-out; }
.sheet {
  position: relative; width: 100%; max-width: 560px; max-height: 88dvh;
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: slide 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 8px 6px 20px; }
.sheet-body { overflow-y: auto; padding: 6px 20px 22px; display: flex; flex-direction: column; gap: 14px; }
@keyframes slide { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.menu { display: flex; flex-direction: column; }
.menu-item {
  display: flex; align-items: center; gap: 12px; min-height: 54px;
  border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; font-weight: 550;
}
.menu-item:last-child { border-bottom: 0; }
.menu-item .icon { color: var(--muted); }
.menu-item.danger .icon { color: inherit; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--tabs-height) + env(safe-area-inset-bottom) + 16px);
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-size: 0.9375rem; font-weight: 550;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.25); text-align: center;
}

@media (min-width: 700px) {
  #sheet-root { align-items: center; }
  .sheet { border-radius: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
