/* Rondo — base + components. Colours, radii and fonts come from tokens.css. */

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

html { -webkit-text-size-adjust: 100%; background: var(--bg); }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

input, textarea, select, [contenteditable] { user-select: text; -webkit-user-select: text; }
button, a, label, summary, [role="button"] { touch-action: manipulation; }
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.15; text-transform: var(--heading-transform); font-style: var(--heading-style); }
p { margin: 0; }
[hidden] { display: none !important; }

.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--fg-muted); }
.faint { color: var(--fg-faint); }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--fg-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- App shell ---------- */

.shell { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  min-height: calc(var(--tap) + 16px);
  padding: calc(env(safe-area-inset-top) + 8px) max(var(--gutter), env(safe-area-inset-right)) 8px max(var(--gutter), env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 28px; font-weight: 750; letter-spacing: -.02em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px max(var(--gutter), env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px max(12px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tap);
  color: var(--fg-faint);
  font-size: 12px; font-weight: 600; letter-spacing: .02em;
  border-radius: var(--radius-sm);
}
.tab svg { width: 26px; height: 26px; }
.tab[aria-current="page"] { color: var(--fg); }
.tab[aria-current="page"] svg { color: var(--accent); }

.wordmark { display: inline-flex; align-items: baseline; gap: 2px; font-weight: var(--wordmark-weight); letter-spacing: -.035em; font-size: 40px; }
.wordmark .dot { width: .26em; height: .26em; border-radius: 50%; background: var(--accent); display: inline-block; transform: translateY(-.02em); }

/* ---------- Flash ---------- */

.flash {
  margin: 0 0 16px; padding: 14px 18px;
  border-radius: var(--radius); background: var(--bg-elev-2); color: var(--fg);
  font-weight: 600;
}
.flash.alert { background: var(--danger-soft); color: var(--danger); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); min-width: var(--tap);
  padding: 0 22px;
  border: 0; border-radius: var(--radius);
  background: var(--bg-elev-2); color: var(--fg);
  font: 650 17px/1 var(--font);
  cursor: pointer;
  transition: transform .12s ease, background .15s ease, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 22px; height: 22px; flex: none; }
.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-ghost { background: transparent; color: var(--fg-muted); }
.btn-ghost:hover { color: var(--fg); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-lg { min-height: 72px; padding: 0 34px; font-size: 22px; border-radius: var(--radius-lg); }
.btn-icon { padding: 0; width: var(--tap); }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .35; pointer-events: none; }
form.button_to { display: contents; }

/* ---------- Chips ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px;
  border-radius: 999px;
  background: var(--bg-elev-2); color: var(--fg-muted);
  font-size: 13px; font-weight: 650; white-space: nowrap;
  text-transform: capitalize;
}
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.rest { background: var(--rest-soft); color: var(--rest); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.mono { text-transform: none; font-weight: 600; }
.chip.plain { text-transform: none; }

/* Selectable chips (filters, "counts as") */
.chip-toggle { position: relative; }
.chip-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.chip-toggle span, a.chip-link {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border-radius: 999px; border: 1px solid var(--line-strong);
  color: var(--fg-muted); font-size: 15px; font-weight: 600;
  text-transform: capitalize; cursor: pointer; white-space: nowrap;
}
.chip-toggle input:checked + span, a.chip-link[aria-current="true"] { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chip-toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip-toggle small, a.chip-link small { font-family: var(--mono); font-size: 12px; opacity: .7; }
.chip-scroll { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; margin: 0 calc(-1 * var(--gutter)); padding-inline: var(--gutter); }
.chip-scroll::-webkit-scrollbar { display: none; }

/* ---------- Cards & grids ---------- */

.card { background: var(--bg-elev); border-radius: var(--radius-lg); padding: 20px; border: 1px solid var(--line); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (min-width: 1000px) { .grid-2.wide-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.section-title { margin: 32px 0 12px; }

/* Workout cards (library) */
.workout-card { display: flex; flex-direction: column; gap: 14px; min-height: 220px; position: relative; }
.workout-card .card-link { position: absolute; inset: 0; border-radius: inherit; }
.workout-card h2 { font-size: 22px; font-weight: 720; letter-spacing: -.01em; }
.workout-card .meta { color: var(--fg-muted); font-size: 15px; }
.workout-card .card-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.workout-card .btn { position: relative; z-index: 1; }

.empty {
  text-align: center; padding: 64px 24px; color: var(--fg-muted);
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius-lg);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.empty h2 { color: var(--fg); font-size: 22px; }
.empty p { max-width: 460px; }
.empty code { font-family: var(--mono); font-size: 14px; color: var(--fg); background: var(--bg-elev-2); padding: 2px 6px; border-radius: 6px; }

/* ---------- Workout detail ---------- */

.detail-head { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: end; margin-bottom: 28px; }
.detail-head h2 { font-size: 40px; font-weight: 780; letter-spacing: -.025em; margin: 12px 0 8px; }
.detail-head .notes { color: var(--fg-muted); max-width: 640px; white-space: pre-line; }

.block-card { position: relative; padding: 18px 18px 8px 26px; overflow: hidden; }
.block-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--kind-circuit); }
.block-card[data-kind="straight"]::before { background: var(--kind-straight); }
.block-card[data-kind="interval"]::before { background: var(--kind-interval); }
.block-card header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.block-card h3 { font-size: 19px; font-weight: 700; margin-right: auto; }

.step-row { display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.step-row:first-of-type { border-top: 0; }
.step-row .name { font-weight: 650; font-size: 17px; }
.step-row .sub { color: var(--fg-muted); font-size: 14px; text-transform: none; }
.step-row .dose { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 16px; text-align: right; white-space: nowrap; }
.step-row .dose small { display: block; color: var(--fg-faint); font-size: 13px; }

.thumb {
  width: 64px; height: 64px; border-radius: 12px; overflow: hidden; flex: none;
  background: var(--bg-elev-2);
  display: grid; place-items: center; color: var(--fg-faint);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.empty-thumb { background: var(--bg-elev-2); }
.thumb.empty-thumb svg { width: 26px; height: 26px; }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 8px; }
.field > label, .label { font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-muted); }
.input, .textarea {
  width: 100%; min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--bg-elev); color: var(--fg);
  font: 500 18px/1.3 var(--font);
  outline: none;
  transition: border-color .15s;
}
.textarea { padding: 14px 16px; min-height: 110px; resize: vertical; }
.input:focus, .textarea:focus { border-color: var(--accent); }
.input::placeholder, .textarea::placeholder { color: var(--fg-faint); }
.input-sm { min-height: 48px; font-size: 16px; padding: 0 12px; border-radius: 12px; }
.input.mono { font-family: var(--mono); }
.errors { background: var(--danger-soft); color: var(--danger); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 18px; }
.errors ul { margin: 6px 0 0; padding-left: 20px; }

/* Segmented control (radio buttons) */
.segmented { display: inline-flex; padding: 4px; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 14px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; min-width: 52px; padding: 0 14px;
  border-radius: 10px; color: var(--fg-muted);
  font-size: 15px; font-weight: 650; cursor: pointer; white-space: nowrap;
}
.segmented input:checked + span { background: var(--bg-elev-2); color: var(--fg); box-shadow: 0 1px 0 var(--line-strong) inset; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

/* Stepper: − value + */
.stepper { display: inline-flex; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 14px; }
.stepper button { width: 48px; height: 48px; border: 0; background: none; color: var(--fg); font-size: 24px; font-weight: 500; cursor: pointer; border-radius: 12px; }
.stepper button:active { background: var(--bg-elev-2); }
.stepper input {
  width: 58px; height: 48px; border: 0; background: none; color: var(--fg); text-align: center;
  font: 600 18px var(--mono); font-variant-numeric: tabular-nums; outline: none;
  -moz-appearance: textfield; appearance: textfield;
}
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper .unit { padding-right: 10px; color: var(--fg-faint); font-size: 13px; font-family: var(--mono); margin-left: -6px; }
.stepper-field { display: flex; flex-direction: column; gap: 6px; }
.stepper-field > span { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-faint); }

/* Switch (checkbox) */
.switch { position: relative; display: inline-block; width: 64px; height: 38px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--bg-elev-2); border: 1px solid var(--line-strong); transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 4px; left: 4px; width: 28px; height: 28px; border-radius: 50%; background: var(--fg-muted); transition: transform .2s, background .2s; }
.switch input:checked + span { background: var(--accent); border-color: transparent; }
.switch input:checked + span::after { transform: translateX(26px); background: var(--accent-fg); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Settings-style list */
.list { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 16px; min-height: 72px; padding: 12px 20px; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 650; font-size: 17px; }
.list-row .sub { color: var(--fg-muted); font-size: 14px; }
.list-row code, .code {
  display: block; font-family: var(--mono); font-size: 14px; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  overflow-wrap: anywhere; user-select: all; -webkit-user-select: all; margin-top: 8px;
}

/* ---------- Exercises ---------- */

.searchbar { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; }
.searchbar .row { gap: 12px; }
.search-input { position: relative; flex: 1; }
.search-input svg { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); width: 22px; height: 22px; color: var(--fg-faint); pointer-events: none; }
.search-input .input { padding-left: 50px; }
.toggle-label { display: inline-flex; align-items: center; gap: 12px; font-weight: 600; color: var(--fg-muted); white-space: nowrap; }
.result-count { color: var(--fg-faint); font-size: 14px; margin: 0 0 12px; font-family: var(--mono); }

.ex-card {
  display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: center;
  padding: 12px; text-align: left; width: 100%;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--fg); font: inherit; cursor: pointer;
}
.ex-card:active { transform: scale(.99); }
.ex-card .thumb { width: 96px; height: 96px; }
.ex-card .name { font-weight: 680; font-size: 16px; line-height: 1.25; margin-bottom: 4px; }
.ex-card .sub { color: var(--fg-muted); font-size: 14px; text-transform: capitalize; margin-bottom: 8px; }
.ex-card .chip { height: 26px; font-size: 12px; padding: 0 10px; }
.load-more { display: flex; justify-content: center; margin-top: 18px; }

.ex-frames { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 20px 0; }
.ex-frames .frame { background: var(--bg-elev-2); border-radius: var(--radius-lg); overflow: hidden; aspect-ratio: 3 / 2; display: grid; place-items: center; }
.ex-frames img { width: 100%; height: 100%; object-fit: cover; }
.howto { margin: 0; padding: 0; list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 14px; }
.howto li { counter-increment: step; display: grid; grid-template-columns: 36px 1fr; gap: 12px; color: var(--fg); font-size: 17px; line-height: 1.5; }
.howto li::before { content: counter(step); font-family: var(--mono); font-weight: 700; color: var(--accent); background: var(--accent-soft); width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 15px; }

/* ---------- History ---------- */

.history-row { display: grid; grid-template-columns: 1fr auto auto; gap: 16px; align-items: center; }
.history-row .notes { color: var(--fg-muted); font-size: 15px; margin-top: 4px; white-space: pre-line; user-select: text; -webkit-user-select: text; }

/* ---------- Login ---------- */

.login {
  min-height: 100dvh; display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
}
.login form { width: min(400px, 100%); display: flex; flex-direction: column; gap: 18px; align-items: stretch; }
.login .wordmark { font-size: 64px; align-self: center; margin-bottom: 18px; }
.login .tagline { text-align: center; color: var(--fg-faint); margin-top: -18px; margin-bottom: 18px; }
.login .error { color: var(--danger); font-weight: 600; text-align: center; }

/* ---------- Bottom sheet (picker) ---------- */

dialog.sheet {
  margin: auto auto 0; padding: 0; border: 0;
  width: 100%; max-width: 900px; height: min(88dvh, 980px);
  background: var(--bg); color: var(--fg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-top: 1px solid var(--line-strong);
  overscroll-behavior: contain;
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: sheet-in .22s ease-out; }
dialog.sheet::backdrop { background: rgba(4, 8, 14, .6); backdrop-filter: blur(2px); }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 16px var(--gutter) 8px; }
.sheet-head h2 { flex: 1; font-size: 22px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 8px var(--gutter) calc(24px + env(safe-area-inset-bottom)); }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }

/* ---------- Icons ---------- */
.icon { width: 24px; height: 24px; flex: none; }

/* ---------- Editor ---------- */

.ed-blocks { margin-top: 20px; }
.ed-block { padding: 18px 18px 18px 26px; display: flex; flex-direction: column; gap: 16px; }
.ed-block-head { display: flex; gap: 12px; align-items: center; }
.ed-block-name { font-weight: 700; font-size: 19px; flex: 1; }
.ed-tools { display: flex; gap: 2px; flex: none; }
.ed-tools .btn { min-width: 48px; width: 48px; min-height: 48px; }
.ed-block-fields, .ed-step-fields { display: flex; flex-wrap: wrap; gap: 14px 18px; align-items: flex-end; }
.ed-steps { display: flex; flex-direction: column; gap: 12px; }
.ed-steps:empty::before {
  content: "No exercises yet. Add one below.";
  color: var(--fg-faint); padding: 18px; text-align: center;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius);
}
.ed-step { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 12px; }
.ed-step-head { display: flex; gap: 12px; align-items: center; }
.ed-step-head .thumb { width: 56px; height: 56px; }
.ed-step-head .thumb svg { width: 24px; height: 24px; }
.ed-step-head .grow { flex: 1; min-width: 0; }
.ed-step-head .name { font-weight: 680; font-size: 17px; }
.ed-step-head .sub { color: var(--fg-muted); font-size: 14px; text-transform: capitalize; }
.ed-kg { width: 96px; height: 50px; }
.ed-cue { flex: 1 1 220px; }
.ed-cue .input { height: 50px; }
.ed-add-step { align-self: flex-start; }
.ed-add-block { margin-top: 16px; border: 1.5px dashed var(--line-strong); background: transparent; color: var(--fg-muted); }
.ed-hint { margin-top: 12px; color: var(--warn); }
.editor .topbar h1 { font-size: 22px; }
