/* ═══════════════════════════════════════════════════════════════════════════
   Training Log — v3 design system
   Dark, quiet surfaces. Session colors carry identity; mint means "done".
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    color-scheme: dark;
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --surface-3: #262b35;
    --line: rgba(255, 255, 255, 0.07);
    --line-strong: rgba(255, 255, 255, 0.14);
    --text: #f3f4f6;
    --text-2: #a9b0bb;
    --text-3: #6f7683;
    --done: #3ddc97;
    --done-ink: #06261a;
    --danger: #e66767;
    --sc: #6f7683;
    /* current session color (set inline per element) */

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-display: 'Barlow Condensed', 'Inter', system-ui, sans-serif;

    --r: 14px;
    --r-sm: 10px;
    --r-pill: 999px;
    --tab-h: 62px;
    --gutter: 16px;
    --maxw: 560px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    background: var(--bg);
}

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.4;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
    -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea {
    font: inherit;
    color: inherit;
}

button {
    background: none;
    border: 0;
    cursor: pointer;
    touch-action: manipulation;
}

a {
    color: inherit;
    text-decoration: none;
}

::placeholder {
    color: var(--text-3);
    opacity: 1;
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */

#view {
    max-width: var(--maxw);
    margin: 0 auto;
    /* bottom clearance: tab bar + the rest-timer pill that floats above it */
    padding: 12px var(--gutter) calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 84px);
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    min-height: 100vh;
    min-height: 100dvh;
}

.loading {
    display: grid;
    place-items: center;
    min-height: 60vh;
}

.spinner {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 3px solid var(--line-strong);
    border-top-color: var(--text);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ─── Screen header ──────────────────────────────────────────────────────── */

.screen-head {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    margin-bottom: 8px;
}

.screen-head .grow {
    flex: 1;
    min-width: 0;
}

.eyebrow {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
}

h1.title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 40px;
    line-height: 1;
    letter-spacing: 0.01em;
    text-transform: uppercase;
    margin: 6px 0 4px;
}

h1.title-sm {
    font-family: var(--font);
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.01em;
    text-transform: none;
    line-height: 1.15;
    margin: 4px 0 2px;
}

.subtitle {
    color: var(--text-2);
    font-size: 13.5px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    color: var(--text-2);
    flex: none;
}

.icon-btn:active {
    background: var(--surface-2);
}

.icon-btn[disabled] {
    opacity: 0.25;
    pointer-events: none;
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

.back-btn {
    margin-left: -8px;
}

.section-label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
    margin: 22px 0 8px;
}

/* ─── Cards & lists ──────────────────────────────────────────────────────── */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 14px;
}

.list {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    overflow: hidden;
}

.row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 54px;
    padding: 10px 14px;
    text-align: left;
    border-top: 1px solid var(--line);
}

.row:first-child {
    border-top: 0;
}

.row:active {
    background: var(--surface-2);
}

.row .grow {
    flex: 1;
    min-width: 0;
}

.row-title {
    font-weight: 600;
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.row-sub {
    color: var(--text-3);
    font-size: 12.5px;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.row-meta {
    color: var(--text-2);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    text-align: right;
    flex: none;
}

.chev {
    color: var(--text-3);
    flex: none;
}

.chev svg {
    width: 18px;
    height: 18px;
    display: block;
}

.empty {
    color: var(--text-3);
    text-align: center;
    padding: 28px 12px;
    font-size: 14px;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 0 18px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 15px;
    width: 100%;
    transition: transform 0.08s ease, opacity 0.15s ease;
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--text);
    color: var(--bg);
}

.btn-ghost {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--line);
}

.btn-quiet {
    background: transparent;
    color: var(--text-2);
    min-height: 44px;
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    min-height: 44px;
}

.btn[disabled] {
    opacity: 0.4;
    pointer-events: none;
}

.btn-row {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

/* ─── Pills / chips ──────────────────────────────────────────────────────── */

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 22px;
    padding: 0 9px;
    border-radius: var(--r-pill);
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.02em;
    background: var(--sc);
    color: #0b0d10;
    white-space: nowrap;
    vertical-align: middle;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--sc);
    flex: none;
    display: inline-block;
}

.chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 0 6px;
    margin: 2px 0 6px;
    scrollbar-width: none;
}

.chips::-webkit-scrollbar {
    display: none;
}

.chip {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 36px;
    padding: 0 14px;
    border-radius: var(--r-pill);
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--text-2);
    font-weight: 600;
    font-size: 14px;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chip .dot {
    opacity: 0.55;
}

.chip.on {
    background: color-mix(in srgb, var(--sc) 20%, var(--surface-2));
    border-color: color-mix(in srgb, var(--sc) 55%, transparent);
    color: var(--text);
}

.chip.on .dot {
    opacity: 1;
}

.chip .next-tag {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--sc);
    margin-left: 2px;
}

/* ─── Today: session block ───────────────────────────────────────────────── */

.session-block {
    margin: 4px 0 14px;
}

.session-block .status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-2);
    font-size: 13.5px;
}

.session-block .status.done {
    color: var(--done);
    font-weight: 600;
}

.status svg {
    width: 16px;
    height: 16px;
}

/* ─── Exercise card ──────────────────────────────────────────────────────── */

.ex-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
}

.ex {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 12px 12px 10px 14px;
    will-change: transform;
}

.ex::before {
    content: '';
    position: absolute;
    left: 0;
    top: 12px;
    bottom: 12px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--sc);
    opacity: 0;
    transition: opacity 0.2s;
}

.ex.picked::before {
    opacity: 1;
}

.ex.picked {
    border-color: color-mix(in srgb, var(--sc) 35%, var(--line));
}

.ex-head {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ex-name {
    flex: 1;
    min-width: 0;
    text-align: left;
    font-weight: 600;
    font-size: 16px;
    line-height: 1.25;
    padding: 4px 0;
    color: var(--text);
}

.ex-name:active {
    color: var(--text-2);
}

.ex-hint {
    flex: none;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-3);
    background: var(--surface-2);
    border-radius: 6px;
    padding: 3px 7px;
    font-variant-numeric: tabular-nums;
}

.ex-more {
    width: 36px;
    height: 36px;
    color: var(--text-3);
    font-size: 20px;
    line-height: 1;
    margin-right: -2px;
    border-radius: 10px;
}

.ex-more:active {
    background: var(--surface-2);
}

.drag-handle {
    flex: none;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    color: var(--text-3);
    cursor: grab;
    touch-action: none;
    border-radius: 10px;
    margin-right: -6px;
    -webkit-user-select: none;
    user-select: none;
}

.drag-handle:active {
    background: var(--surface-2);
    cursor: grabbing;
}

.drag-handle svg {
    width: 20px;
    height: 20px;
    pointer-events: none;
}

.ex-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    color: var(--text-3);
    font-size: 12.5px;
    margin: 0 0 4px;
    font-variant-numeric: tabular-nums;
}

.ex-meta .k {
    font-weight: 600;
    color: var(--text-3);
}

.ex-note {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    width: 100%;
    text-align: left;
    color: var(--text-2);
    font-size: 12.5px;
    line-height: 1.35;
    padding: 6px 8px;
    margin: 2px 0 6px;
    background: var(--surface-2);
    border-radius: 8px;
    white-space: pre-wrap;
}

.ex-note svg {
    width: 14px;
    height: 14px;
    flex: none;
    margin-top: 2px;
    color: var(--text-3);
}

.sets {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
}

.set {
    display: grid;
    grid-template-columns: 22px 1fr 16px 1fr 46px;
    align-items: center;
    gap: 8px;
}

.set-n {
    color: var(--text-3);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.set-in {
    height: 44px;
    width: 100%;
    min-width: 0;
    background: var(--surface-3);
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}

.set-in:focus {
    border-color: var(--line-strong);
    background: var(--surface-2);
}

.set-x {
    text-align: center;
    color: var(--text-3);
    font-size: 14px;
}

.set-check {
    width: 46px;
    height: 44px;
    border-radius: var(--r-sm);
    border: 1px solid var(--line-strong);
    background: var(--surface-2);
    color: var(--text-3);
    display: grid;
    place-items: center;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.set-check svg {
    width: 20px;
    height: 20px;
}

.set.done .set-check {
    background: var(--done);
    border-color: var(--done);
    color: var(--done-ink);
}

.set.done .set-in {
    background: color-mix(in srgb, var(--done) 12%, var(--surface-3));
    color: var(--text);
}

.set.done .set-n {
    color: var(--done);
}

.add-set {
    align-self: flex-start;
    height: 34px;
    padding: 0 10px 0 4px;
    margin-left: 26px;
    color: var(--text-3);
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
}

.add-set:active {
    background: var(--surface-2);
    color: var(--text-2);
}

/* drag state */
.ex-list.sorting .ex:not(.dragging) {
    transition: transform 0.16s ease;
}

.ex.dragging {
    z-index: 5;
    background: var(--surface-3);
    border-color: var(--line-strong);
    box-shadow: var(--shadow);
}

.add-ex-btn {
    margin-top: 12px;
}

.finish-wrap {
    margin-top: 18px;
}

.finished-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--r);
    background: color-mix(in srgb, var(--done) 12%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--done) 35%, transparent);
    color: var(--text);
    font-weight: 600;
}

.finished-banner svg {
    width: 20px;
    height: 20px;
    color: var(--done);
    flex: none;
}

.finished-banner .grow {
    flex: 1;
}

.finished-banner .sub {
    display: block;
    color: var(--text-2);
    font-weight: 500;
    font-size: 12.5px;
}

.finished-banner button {
    color: var(--text-2);
    font-weight: 600;
    font-size: 13px;
    padding: 6px 8px;
    border-radius: 8px;
}

/* ─── Calendar ───────────────────────────────────────────────────────────── */

.month-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 6px 0 10px;
}

.month-nav .month {
    font-family: var(--font-display);
    font-size: 30px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.01em;
    line-height: 1;
}

.month-nav .month small {
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: none;
    letter-spacing: 0;
    margin-left: 6px;
}

.cal {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.cal .dow {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    padding-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.cell {
    aspect-ratio: 1 / 1.25;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    padding: 5px 4px 4px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    min-width: 0;
    text-align: left;
    position: relative;
}

.cell.blank {
    background: transparent;
    border-color: transparent;
}

.cell.future {
    opacity: 0.35;
}

.cell .n {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    line-height: 1;
    padding-left: 2px;
    font-variant-numeric: tabular-nums;
}

.cell.rest .n {
    color: var(--text-3);
}

.cell.today {
    border-color: var(--line-strong);
}

.cell.today .n {
    color: var(--text);
}

.cell.today .n::after {
    content: '';
    display: inline-block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text);
    margin-left: 4px;
    vertical-align: 1px;
}

.cell .cpill {
    margin-top: auto;
    height: 20px;
    border-radius: 6px;
    background: var(--sc);
    color: #0b0d10;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 20px;
    padding: 0 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

.cell .rest-dot {
    margin-top: auto;
    align-self: center;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text-3);
    opacity: 0.5;
    margin-bottom: 7px;
}

.cell.trained:active {
    background: var(--surface-2);
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    margin: 12px 2px 0;
    color: var(--text-3);
    font-size: 12px;
}

.legend .li {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend b {
    color: var(--text-2);
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 16px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 12px 12px 10px;
    min-width: 0;
}

.stat .v {
    font-family: var(--font-display);
    font-size: 30px;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat .v small {
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-3);
    margin-left: 3px;
}

.stat .l {
    font-size: 11.5px;
    color: var(--text-3);
    margin-top: 6px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

/* ─── Day detail / exercise detail ───────────────────────────────────────── */

.note-card {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    width: 100%;
    text-align: left;
    background: var(--surface);
    border: 1px dashed var(--line-strong);
    border-radius: var(--r);
    padding: 12px 14px;
    color: var(--text-2);
    font-size: 14px;
    line-height: 1.4;
    white-space: pre-wrap;
    margin-top: 6px;
}

.note-card.empty-note {
    color: var(--text-3);
}

.note-card svg {
    width: 16px;
    height: 16px;
    flex: none;
    margin-top: 3px;
    color: var(--text-3);
}

.chart-card {
    padding: 12px 8px 4px;
}

.chart-card .chart-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-3);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 0 8px 4px;
}

.chart svg {
    width: 100%;
    height: auto;
    display: block;
}

.chart .grid {
    stroke: var(--line);
    stroke-width: 1;
}

.chart .line {
    fill: none;
    stroke: var(--sc);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.chart .pt {
    fill: var(--sc);
    stroke: var(--surface);
    stroke-width: 2;
}

.chart .lbl {
    fill: var(--text-2);
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font);
}

.chart .ax {
    fill: var(--text-3);
    font-size: 10px;
    font-family: var(--font);
}

.hist-sets {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin-top: 3px;
    font-size: 13.5px;
    font-variant-numeric: tabular-nums;
    color: var(--text-2);
}

.hist-sets b {
    color: var(--text);
    font-weight: 600;
}

.hist-sets .best b {
    color: var(--done);
}

/* ─── Search ─────────────────────────────────────────────────────────────── */

.search {
    position: relative;
    margin: 4px 0 12px;
}

.search input {
    width: 100%;
    height: 44px;
    padding: 0 14px 0 40px;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    outline: none;
    font-size: 16px;
    -webkit-appearance: none;
    appearance: none;
}

.search input:focus {
    border-color: var(--line-strong);
}

.search svg {
    position: absolute;
    left: 13px;
    top: 13px;
    width: 18px;
    height: 18px;
    color: var(--text-3);
    pointer-events: none;
}

/* ─── Forms (settings, session editor) ───────────────────────────────────── */

.field {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-top: 1px solid var(--line);
}

.field:first-child {
    border-top: 0;
}

.field .grow {
    flex: 1;
    min-width: 0;
}

.field .lbl {
    font-weight: 600;
}

.field .hint {
    color: var(--text-3);
    font-size: 12.5px;
    margin-top: 2px;
}

.stepper {
    display: inline-flex;
    align-items: center;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    flex: none;
}

.stepper button {
    width: 40px;
    height: 38px;
    font-size: 20px;
    color: var(--text-2);
}

.stepper button:active {
    background: var(--surface-3);
}

.stepper .val {
    min-width: 54px;
    text-align: center;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.seg {
    display: inline-flex;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 3px;
    gap: 3px;
    flex: none;
}

.seg button {
    min-width: 38px;
    height: 32px;
    border-radius: 8px;
    font-weight: 600;
    color: var(--text-2);
}

.seg button.on {
    background: var(--text);
    color: var(--bg);
}

.text-input {
    width: 100%;
    height: 44px;
    padding: 0 12px;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    outline: none;
    font-size: 16px;
    font-weight: 600;
}

.text-input:focus {
    border-color: var(--line-strong);
}

.title-input {
    font-family: var(--font-display);
    font-size: 32px;
    font-weight: 700;
    text-transform: uppercase;
    height: 52px;
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--line-strong);
    border-radius: 0;
    padding: 0;
}

textarea.text-area {
    width: 100%;
    min-height: 110px;
    padding: 12px;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    outline: none;
    font-size: 16px;
    line-height: 1.4;
    resize: vertical;
}

textarea.text-area:focus {
    border-color: var(--line-strong);
}

/* session editor rows */
.edit-row {
    display: grid;
    grid-template-columns: 40px 1fr 74px 36px;
    align-items: center;
    gap: 6px;
    padding: 6px 8px 6px 4px;
    border-top: 1px solid var(--line);
    background: var(--surface);
}

.edit-row:first-child {
    border-top: 0;
}

.edit-row .drag-handle {
    margin: 0;
}

.edit-row .name {
    font-weight: 600;
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.edit-row .reps-in {
    height: 36px;
    width: 100%;
    background: var(--surface-3);
    border: 1px solid transparent;
    border-radius: 8px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    outline: none;
}

.edit-row .reps-in:focus {
    border-color: var(--line-strong);
}

.edit-row .rm {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: var(--text-3);
    font-size: 18px;
}

.edit-row .rm:active {
    color: var(--danger);
    background: var(--surface-2);
}

.list.sortable .edit-row.dragging,
.list.sortable .row.dragging {
    background: var(--surface-3);
    box-shadow: var(--shadow);
    z-index: 5;
    position: relative;
}

.list.sortable.sorting > *:not(.dragging) {
    transition: transform 0.16s ease;
}

.list.sortable .row .drag-handle {
    margin: 0;
}

/* ─── Tab bar ────────────────────────────────────────────────────────────── */

#tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(15, 17, 21, 0.86);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: center;
    z-index: 20;
}

#tabbar .tab {
    flex: 1;
    max-width: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-3);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: color 0.15s;
}

#tabbar .tab svg {
    width: 24px;
    height: 24px;
}

#tabbar .tab.on {
    color: var(--text);
}

/* ─── Rest timer ─────────────────────────────────────────────────────────── */

#rest-timer {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 10px);
    z-index: 25;
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--surface-3);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-pill);
    padding: 4px 6px 4px 14px;
    box-shadow: var(--shadow);
    animation: rise 0.2s ease;
}

#rest-timer[hidden] {
    display: none;
}

@keyframes rise {
    from {
        transform: translateX(-50%) translateY(12px);
        opacity: 0;
    }

    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

#rest-timer .lbl {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-3);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-right: 6px;
}

#rest-timer .t {
    font-family: var(--font-display);
    font-size: 26px;
    font-weight: 700;
    min-width: 58px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

/* Rest is over: the pill turns red and the clock counts up until the next set */
#rest-timer.done {
    border-color: var(--danger);
}

#rest-timer.done .t,
#rest-timer.done .lbl {
    color: var(--danger);
}

#rest-timer button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--text-2);
    font-size: 18px;
    display: grid;
    place-items: center;
}

#rest-timer button:active {
    background: var(--surface-2);
}

/* ─── Sheets ─────────────────────────────────────────────────────────────── */

.overlay {
    position: fixed;
    /* The visible area (app.js tracks it): above the iOS keyboard when it's open */
    left: 0;
    right: 0;
    top: var(--vv-top, 0px);
    height: var(--vv-h, 100%);
    background: rgba(0, 0, 0, 0.55);
    z-index: 40;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fade 0.15s ease;
}

@keyframes fade {
    from {
        opacity: 0;
    }
}

.sheet {
    width: 100%;
    max-width: var(--maxw);
    max-height: 86%;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 20px 20px 0 0;
    padding: 8px var(--gutter) calc(16px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    animation: up 0.2s ease;
}

@keyframes up {
    from {
        transform: translateY(24px);
    }
}

.sheet .grab {
    width: 38px;
    height: 4px;
    border-radius: 2px;
    background: var(--line-strong);
    margin: 4px auto 12px;
    flex: none;
}

.sheet h2 {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 10px;
}

.sheet .sub {
    color: var(--text-3);
    font-size: 13px;
    margin: -6px 0 10px;
}

.sheet .body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

.menu .mi {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 50px;
    padding: 0 6px;
    text-align: left;
    font-weight: 600;
    font-size: 15px;
    border-top: 1px solid var(--line);
}

.menu .mi:first-child {
    border-top: 0;
}

.menu .mi svg {
    width: 20px;
    height: 20px;
    color: var(--text-3);
    flex: none;
}

.menu .mi.danger {
    color: var(--danger);
}

.menu .mi.danger svg {
    color: var(--danger);
}

.picker .opt {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 48px;
    padding: 6px 6px;
    text-align: left;
    border-top: 1px solid var(--line);
    font-size: 15px;
}

.picker .opt:first-child {
    border-top: 0;
}

.picker .opt .grow {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.picker .opt .tag {
    color: var(--text-3);
    font-size: 12px;
    flex: none;
}

.picker .opt.create {
    color: var(--done);
    font-weight: 600;
}

.picker .opt.create svg {
    width: 18px;
    height: 18px;
}

.picker .grp {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
    padding: 12px 6px 4px;
}

.check-line {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 4px 4px;
    color: var(--text-2);
    font-size: 14px;
}

.check-line input {
    width: 20px;
    height: 20px;
    accent-color: var(--done);
}

/* ─── Toast ──────────────────────────────────────────────────────────────── */

#toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 16px);
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: 10px 16px;
    border-radius: var(--r-pill);
    font-weight: 600;
    font-size: 14px;
    box-shadow: var(--shadow);
    z-index: 60;
    max-width: calc(100% - 32px);
    text-align: center;
    animation: rise 0.2s ease;
}

#toast[hidden] {
    display: none;
}

/* ─── Small screens ──────────────────────────────────────────────────────── */

@media (max-width: 360px) {
    h1.title {
        font-size: 34px;
    }

    .set {
        grid-template-columns: 18px 1fr 12px 1fr 42px;
        gap: 6px;
    }

    .cell .cpill {
        font-size: 9.5px;
        padding: 0 3px;
    }
}

@media (min-width: 600px) {
    #tabbar .tab {
        flex-direction: row;
        gap: 8px;
        font-size: 13px;
    }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}

/* ─── Recovery tab (health.js) ───────────────────────────────────────────── */

.h-source {
    color: var(--text-3);
    font-size: 13px;
    margin: -2px 0 4px;
}

.h-source.warn {
    color: var(--danger);
}

.sync-btn.spinning svg {
    animation: spin 0.9s linear infinite;
}

.h-tiles {
    margin-top: 12px;
}

.h-tiles .stat .v {
    font-size: 28px;
}

.h-sub {
    font-size: 12px;
    color: var(--text-2);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.h-filter {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0 8px;
}

.h-hint {
    color: var(--text-3);
    font-size: 12.5px;
}

.h-train-legend {
    margin: 0 0 10px;
    justify-content: flex-start;
}

.h-train-note {
    color: var(--text-3);
}

.h-charts {
    display: grid;
    gap: 10px;
    transition: opacity 0.2s;
}

.h-charts.refreshing {
    opacity: 0.55;
}

.h-chart-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 0 8px 2px;
}

.h-chart-head .chart-title {
    padding: 0;
}

.h-chart-val {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
}

.h-chart-val small {
    font-size: 11px;
    color: var(--text-3);
    font-weight: 600;
    margin-left: 2px;
}

.h-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    padding: 2px 8px 2px;
    font-size: 12px;
    color: var(--text-2);
}

.h-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.h-legend b {
    color: var(--text);
    font-weight: 600;
}

.k-line {
    width: 14px;
    height: 2px;
    border-radius: 1px;
    flex: none;
    display: inline-block;
}

.k-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: none;
    display: inline-block;
}

.k-rect {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex: none;
    display: inline-block;
}

.h-chart .chart {
    position: relative;
    touch-action: pan-y;
    outline: none;
    cursor: pointer;
}

.h-chart .chart:focus-visible {
    box-shadow: 0 0 0 2px var(--line-strong);
    border-radius: 8px;
}

.chart .band {
    fill: rgba(169, 176, 187, 0.14);
}

.chart .pt.soft {
    fill-opacity: 0.55;
}

.chart .xh {
    stroke: var(--text-2);
    stroke-width: 1;
    pointer-events: none;
}

.chart .tdot {
    stroke: var(--surface);
    stroke-width: 1.5;
}

.chart .sleep-shade {
    fill: rgba(124, 148, 244, 0.12);
}

.h-tip {
    position: absolute;
    top: 0;
    z-index: 3;
    min-width: 132px;
    max-width: 220px;
    background: var(--surface-3);
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    padding: 8px 10px;
    box-shadow: var(--shadow);
    pointer-events: none;
    font-size: 12px;
}

.h-tip[hidden] {
    display: none;
}

.h-tip-date {
    color: var(--text-3);
    font-weight: 600;
    margin-bottom: 4px;
}

.h-tip-row {
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.6;
    white-space: nowrap;
}

.h-tip-row b {
    color: var(--text);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.h-tip-row span:not([class]) {
    color: var(--text-2);
}

.h-sources .h-src {
    border-top: 1px solid var(--line);
}

.h-sources .h-src:first-child {
    border-top: 0;
}

.h-src summary {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 54px;
    padding: 10px 14px;
    cursor: pointer;
    list-style: none;
}

.h-src summary::-webkit-details-marker {
    display: none;
}

.h-src summary .grow {
    flex: 1;
    min-width: 0;
}

.h-src summary .row-sub {
    white-space: normal;
}

.h-src[open] summary .chev svg {
    transform: rotate(90deg);
}

.h-steps {
    padding: 0 16px 14px 34px;
    color: var(--text-2);
    font-size: 13.5px;
    line-height: 1.5;
    display: grid;
    gap: 6px;
}

.h-steps code {
    display: inline-block;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 12.5px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 1px 6px;
    margin: 2px 0 0 4px;
    color: var(--text);
    word-break: break-all;
}

.h-steps b {
    color: var(--text);
}

.h-sheet .h-day {
    max-height: none;
}

.h-cells {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.h-cell {
    background: var(--surface-2);
    border-radius: var(--r-sm);
    padding: 10px 12px;
    min-width: 0;
}

.h-cell .l {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-3);
}

.h-cell .v {
    font-size: 20px;
    font-weight: 700;
    margin-top: 2px;
    white-space: nowrap;
}

.h-cell .v small {
    font-size: 12px;
    color: var(--text-3);
    font-weight: 600;
    margin-left: 2px;
}

.h-cell .s {
    font-size: 12px;
    color: var(--text-2);
    margin-top: 1px;
}

.h-block {
    margin-top: 14px;
}

.h-block .chart-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-3);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.h-hr-wait {
    color: var(--text-3);
    font-size: 13px;
}

.stage-bar {
    display: flex;
    gap: 2px;
    height: 14px;
    border-radius: 4px;
    overflow: hidden;
}

.stage-legend {
    padding: 8px 0 0;
}

.h-tiles .stat .l {
    letter-spacing: 0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.h-days .row-sub {
    white-space: normal;
}

.h-legend-note {
    color: var(--text-3);
}

.h-factors {
    display: grid;
    gap: 8px;
}

.h-factor {
    display: grid;
    grid-template-columns: 104px 1fr 92px;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.h-factor .lbl {
    color: var(--text-2);
}

.h-factor .fb {
    color: var(--text);
    font-weight: 600;
    text-align: right;
}

.h-factor .meter {
    height: 6px;
    border-radius: 3px;
    background: rgba(43, 179, 192, 0.18);
    overflow: hidden;
}

.h-factor .meter span {
    display: block;
    height: 100%;
    border-radius: 3px;
    background: #2bb3c0;
}

.h-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.h-chips span {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-pill);
    padding: 3px 10px;
    font-size: 12px;
    color: var(--text-2);
}

.h-chips b {
    color: var(--text);
    font-weight: 600;
}

.h-mini-title {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    margin: 10px 0 2px;
}

.h-mini-title span {
    color: var(--text-3);
    font-weight: 500;
}

.h-act {
    background: var(--surface-2);
    border-radius: var(--r-sm);
    padding: 12px;
    margin-top: 8px;
}

.h-act-card {
    padding: 2px;
    margin-top: 8px;
}

.h-act-card .h-act {
    margin: 0;
    background: none;
}

.h-act-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    font-size: 15px;
}

.h-act-head span {
    color: var(--text-3);
    font-size: 12.5px;
}

.h-act-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 8px 12px;
    margin-top: 10px;
}

.h-act-grid .l {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-3);
}

.h-act-grid .v {
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
}

.h-act-grid .v small {
    font-size: 11px;
    color: var(--text-3);
    font-weight: 600;
    margin: 0 4px 0 2px;
}

.h-act-note {
    font-size: 12.5px;
    color: var(--text-2);
    margin-top: 8px;
}

.h-act-zones {
    margin-top: 12px;
}

.h-act-zones .chart-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.zone-bar {
    height: 10px;
}

.h-hypno-slot {
    margin-top: 12px;
}

/* Recovery — last 24 hours recap */
.h-sec-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.h-sec-note {
    color: var(--text-3);
    font-size: 12px;
}

.h-summary {
    color: var(--text-2);
    font-size: 15px;
    line-height: 1.5;
    margin: 0 2px 4px;
}

.h-recap-tiles {
    margin-top: 10px;
}

.h-card {
    margin-top: 10px;
    padding: 12px 14px 10px;
}

.h-card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.h-card-head .chart-title,
.h-card .chart-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-3);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.h-card-note {
    color: var(--text-2);
    font-size: 12.5px;
    text-align: right;
}

.h-card .h-mini-title:first-of-type {
    margin-top: 0;
}

.h-empty-note {
    color: var(--text-2);
    font-size: 13.5px;
    line-height: 1.45;
}

.h-card-list {
    margin-top: 10px;
}

.h-trends-label {
    margin-top: 30px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.h-filter {
    flex-wrap: wrap;
    row-gap: 6px;
}

/* Pickers keep a fixed height: a shrinking result list mustn't move the search box */
.sheet.picker-sheet {
    height: 86%;
}

.picker-sheet .body {
    flex: 1;
}

/* ─── Workout recap (recap.js) ───────────────────────────────────────────── */

.rc-tiles {
    margin-top: 12px;
}

.rc-tiles .h-sub {
    white-space: normal;
}

.rc-up {
    color: var(--done);
    font-weight: 600;
}

.rc-down {
    color: var(--text-2);
    font-weight: 600;
}

.rc-same {
    color: var(--text-3);
}

.rc-label-note {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 500;
    margin-left: 6px;
}

.rc-list {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    overflow: hidden;
}

.rc-ex {
    display: block;
    width: 100%;
    text-align: left;
    padding: 12px 14px;
    border-top: 1px solid var(--line);
}

.rc-ex:first-child {
    border-top: 0;
}

.rc-ex:active {
    background: var(--surface-2);
}

.rc-ex-head {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
}

.rc-ex-head b {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rc-badge {
    flex: none;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--done-ink);
    background: var(--done);
    border-radius: var(--r-pill);
    padding: 2px 8px;
}

.rc-badge.quiet {
    color: var(--text-2);
    background: var(--surface-3);
}

.rc-last {
    color: var(--text-3);
}

.rc-last b {
    color: var(--text-2) !important;
}

.rc-when {
    font-weight: 600;
    min-width: 72px;
}

.rc-changes {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 14px;
    margin-top: 6px;
    font-size: 12.5px;
    color: var(--text-3);
}

.rc-note {
    padding: 0 2px;
    margin-top: 8px;
}
