:root {
    color-scheme: light;
    --bg: #f4f5f2;
    --surface: #ffffff;
    --surface-soft: #ecefea;
    --ink: #17231d;
    --muted: #68746d;
    --line: #dce2dc;
    --accent: #246b45;
    --accent-dark: #194d32;
    --accent-soft: #e1eee6;
    --danger: #a33a3a;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); line-height: 1.45; padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
a { color: inherit; }
button, input, textarea, select { font: inherit; }
button, .button, summary { min-height: 44px; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: wait; }
h1 { font-size: clamp(1.8rem, 6vw, 2.6rem); line-height: 1.08; letter-spacing: -.04em; margin: .2rem 0 .7rem; }
h2 { font-size: 1.15rem; line-height: 1.25; letter-spacing: -.015em; margin: .5rem 0; }
h3 { margin-bottom: .4rem; }
p { margin: .45rem 0; }

.app-header { display: grid; grid-template-columns: 1fr auto; align-items: center; padding: calc(.65rem + env(safe-area-inset-top)) 1rem 0; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: .55rem; min-height: 44px; font-size: .82rem; font-weight: 900; letter-spacing: .14em; text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: var(--accent); color: white; font-size: 1rem; letter-spacing: 0; }
.app-header nav { grid-column: 1 / -1; grid-row: 2; display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; }
.app-header nav a { position: relative; display: grid; place-items: center; min-height: 46px; padding: 0 .65rem; text-decoration: none; color: var(--muted); font-size: .88rem; font-weight: 650; white-space: nowrap; }
.app-header nav a:focus-visible, .app-header nav a:active { color: var(--accent); }
.logout-form { margin: 0; }
.logout-form button { padding: 0 .2rem; border: 0; background: transparent; color: var(--muted); font-size: .85rem; }
.page { width: min(100%, 900px); margin: 0 auto; padding: 1.25rem 1rem 2rem; }
.narrow-page { max-width: 560px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 1rem; margin: .85rem 0; }
.eyebrow { color: var(--accent); font-size: .72rem; font-weight: 850; letter-spacing: .13em; margin: 0 0 .35rem; }
.muted, .optional { color: var(--muted); }
.note { display: block; white-space: pre-wrap; color: var(--muted); }
.warning { color: #805d13; }
.error { color: var(--danger); }
.success { color: var(--accent); }
.message { padding: .75rem .9rem; margin: 1rem 0; border-radius: 10px; background: #f8eaea; border: 1px solid #ebcccc; }
.success.message { background: var(--accent-soft); border-color: #c6ddcf; }
.intro { margin: -.25rem 0 1.25rem; }
.global-feedback:empty { display: none; }
.global-feedback { padding: .65rem 1rem; background: #fff0c7; color: #57440f; text-align: center; }
.back-link { display: inline-flex; align-items: center; min-height: 44px; margin-bottom: .5rem; color: var(--muted); text-decoration: none; font-size: .9rem; }
.text-link { color: var(--accent); font-size: .88rem; font-weight: 750; }
.standalone-link { display: inline-block; margin: 1rem 0; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 46px; border: 1px solid transparent; border-radius: 11px; padding: .68rem 1rem; font-weight: 750; text-decoration: none; text-align: center; }
.button.primary { background: var(--accent); color: white; }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.button.danger { background: transparent; color: var(--danger); border-color: #dbbcbc; }
.button.full { width: 100%; margin-top: .65rem; }
.button-row { display: flex; flex-wrap: wrap; gap: .6rem; }
.button-row .button { flex: 1 1 150px; }
.icon-button { border: 0; background: transparent; }

fieldset { border: 0; padding: 0; margin: 1rem 0; }
legend { font-size: 1.1rem; font-weight: 750; margin-bottom: .55rem; }
label { display: block; font-size: .88rem; font-weight: 650; }
input, textarea, select { width: 100%; min-height: 48px; margin-top: .4rem; padding: .7rem .8rem; border: 1px solid #cfd7d0; border-radius: 10px; background: var(--surface); color: var(--ink); font-size: 16px; }
input::placeholder, textarea::placeholder { color: #8b958f; }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid #92bfa4; outline-offset: 2px; }
.stacked-form > label { margin: 1rem 0; }
.search { display: flex; gap: .5rem; align-items: end; margin: 1rem 0; }
.search label { flex: 1; }
.search input { margin: 0; }
.page-title, .session-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin: .4rem 0 1.25rem; }
.page-title h1, .session-heading h1 { margin-bottom: .25rem; }
.page-title .button, .session-heading .button { flex-shrink: 0; }
.session-heading { align-items: flex-start; }
.session-heading .muted { font-size: .9rem; }

.login-body { display: grid; place-items: center; padding: 1rem; background: var(--surface); }
.login-shell { width: min(100%, 410px); }
.login-brand { display: flex; align-items: center; justify-content: center; gap: .6rem; margin-bottom: 2rem; font-size: .85rem; font-weight: 900; letter-spacing: .14em; }
.login-card h1 { font-size: 2.4rem; }
.login-card > .muted { margin-bottom: 1.5rem; }
.social-button { background: var(--surface); color: var(--ink); border-color: var(--line); }
.auth-divider { display: flex; align-items: center; gap: .75rem; margin: 1.25rem 0 .25rem; color: var(--muted); font-size: .78rem; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.forgot-link { display: block; margin: -.35rem 0 .75rem; color: var(--accent); font-size: .85rem; text-align: right; }
.auth-switch { margin: 1.5rem 0 .25rem; color: var(--muted); text-align: center; font-size: .9rem; }
.auth-switch a { color: var(--accent); font-weight: 750; }

.resume-card { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.2rem; margin-bottom: 2rem; border-radius: 16px; background: var(--accent); color: white; }
.resume-card .eyebrow, .resume-card .muted { color: #d6e8dc; }
.resume-card h1 { font-size: 1.55rem; }
.resume-card .button { background: white; color: var(--accent-dark); flex-shrink: 0; }
.routine-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem; }
.routine-card { padding: 1.15rem; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
.routine-name { display: inline-block; font-size: 1.2rem; font-weight: 780; text-decoration: none; letter-spacing: -.02em; }
.routine-link { display: flex; flex-direction: column; gap: .4rem; text-decoration: none; }
.routine-link .text-link { margin-top: .65rem; }
.empty-state { padding: 2rem 1rem; text-align: center; }
.empty-state .button { margin-top: .75rem; }

.routine-title-form { display: flex; align-items: end; gap: .6rem; margin: .4rem 0 .8rem; }
.routine-title-form label { flex: 1; }
.routine-title-input { margin: 0; padding: .2rem 0; min-height: 52px; border: 0; border-radius: 0; background: transparent; font-size: clamp(1.65rem, 5vw, 2.3rem); font-weight: 800; letter-spacing: -.04em; }
.routine-title-input:focus { outline-offset: 4px; }
.routine-builder { overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
.routine-exercise-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: .5rem; padding: .55rem .65rem; border-bottom: 1px solid var(--line); }
.routine-exercise-row:last-child { border-bottom: 0; }
.routine-exercise-row select { margin: 0; border-color: transparent; background: transparent; font-weight: 700; }
.exercise-number { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-soft); color: var(--muted); font-size: .78rem; }
.remove-button { padding: 0 .4rem; color: var(--muted); font-size: .78rem; }
.empty-inline { padding: 1rem; }
.add-exercise-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: .6rem; margin-top: 1rem; }
.add-exercise-form select { margin: 0; }
.routine-footer { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }

.expanded-plan { display: grid; gap: 1rem; }
.exercise-block { padding: .8rem; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.exercise-heading { display: flex; align-items: center; gap: .65rem; margin-bottom: .65rem; }
.exercise-heading h2 { flex: 1; margin: 0; }
.session-replace-form { flex: 1; min-width: 0; }
.session-replace-form select { margin: 0; padding: .3rem 1.8rem .3rem 0; min-height: 44px; border-color: transparent; background: transparent; font-size: 1.15rem; font-weight: 800; letter-spacing: -.02em; }
.set-count { flex-shrink: 0; color: var(--muted); font-size: .78rem; }
.last-time { display: flex; flex-wrap: wrap; gap: .3rem .75rem; padding: .55rem .65rem; margin-bottom: .65rem; border-radius: 9px; background: var(--surface-soft); color: var(--muted); font-size: .78rem; }
.last-time strong { color: var(--ink); }
.set-table-labels, .set-row { display: grid; grid-template-columns: 30px minmax(0, 1fr) minmax(0, 1fr) 44px; gap: .45rem; align-items: center; }
.set-table-labels { padding: 0 .1rem .25rem; color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; }
.set-table-labels span:nth-child(2), .set-table-labels span:nth-child(3) { padding-left: .55rem; }
.set-row { position: relative; padding: .35rem 0; border-top: 1px solid var(--line); }
.set-row label { min-width: 0; }
.set-row input { min-height: 46px; margin: 0; padding: .55rem; border-color: transparent; border-radius: 8px; background: var(--surface-soft); font-size: 1.05rem; font-weight: 700; text-align: center; }
.set-row input:focus { border-color: var(--accent); background: var(--surface); }
.set-number { color: var(--muted); font-size: .85rem; text-align: center; }
.new-set-number { color: var(--accent); font-size: 1.3rem; }
.set-menu { position: relative; }
.set-menu summary { display: grid; place-items: center; width: 44px; border-radius: 8px; color: var(--muted); cursor: pointer; font-size: 1.5rem; font-weight: 800; list-style: none; }
.set-menu summary::-webkit-details-marker { display: none; }
.set-menu[open] summary { background: var(--surface-soft); color: var(--ink); }
.menu-popover { position: absolute; z-index: 20; top: 48px; right: 0; width: min(250px, calc(100vw - 3rem)); padding: .75rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: 0 12px 35px #17231d24; }
.menu-popover label { margin-bottom: .65rem; }
.menu-popover input { text-align: left; font-size: .95rem; font-weight: 500; background: var(--surface); border-color: var(--line); }
.menu-action { width: 100%; padding: .5rem; border: 0; background: transparent; text-align: left; }
.danger-text { color: var(--danger); }
.new-set-row { margin-top: .15rem; }
.add-set-button { grid-column: 2 / -1; min-height: 38px; margin: .1rem 0 .25rem; border: 0; background: transparent; color: var(--accent); font-size: .85rem; font-weight: 800; text-align: left; }
.duplicate-prompt { grid-column: 1 / -1; padding: .75rem; margin: .35rem 0; border-radius: 10px; background: #fff4d9; font-size: .85rem; }
.duplicate-prompt > span { display: block; margin: .2rem 0 .6rem; }
.exercise-note { margin-top: .45rem; padding-top: .45rem; border-top: 1px solid var(--line); }
.exercise-note textarea { min-height: 40px; margin: 0; padding: .55rem; border-color: transparent; background: transparent; font-size: .85rem; resize: none; }
.inline-set-form.htmx-request { opacity: .6; }
.session-summary { position: fixed; z-index: 10; bottom: 0; left: 0; right: 0; min-height: 72px; padding: .55rem max(1rem, calc((100vw - 860px) / 2)) calc(.55rem + env(safe-area-inset-bottom)); display: grid; grid-template-columns: .7fr .7fr 1.6fr; background: #17231df2; color: white; backdrop-filter: blur(10px); }
.session-summary div { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.session-summary strong { font-size: 1.08rem; }
.session-summary span { color: #c1cbc4; font-size: .72rem; }

.review-exercise { padding: .9rem 0; border-bottom: 1px solid var(--line); }
.set-readback { padding-left: 1.5rem; }
.set-readback li { padding: .35rem 0; }
.history-card { display: block; padding: 1rem 0; border-bottom: 1px solid var(--line); text-decoration: none; }
.history-card > div { display: flex; justify-content: space-between; gap: 1rem; }
.exercise-list { border-top: 1px solid var(--line); }
.exercise-link { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 58px; padding: .6rem 0; border-bottom: 1px solid var(--line); text-decoration: none; }
.offline-status { border-color: #ddc27b; }
.queued-set { padding: .65rem 0; border-top: 1px solid var(--line); }
.queued-set small { display: block; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (min-width: 760px) {
    .app-header { grid-template-columns: auto 1fr auto; gap: 1rem; padding: .4rem max(1rem, calc((100vw - 900px) / 2)); }
    .app-header nav { grid-column: 2; grid-row: 1; justify-content: center; }
    .logout-form { grid-column: 3; }
    .page { padding-top: 2rem; }
    .exercise-block { padding: 1rem 1.2rem; }
    .set-row input { font-size: 1.1rem; }
}

@media (max-width: 480px) {
    .page { padding-left: .75rem; padding-right: .75rem; }
    .page-title .button.secondary { padding: .55rem .7rem; font-size: .82rem; }
    .session-heading { gap: .5rem; }
    .session-heading .muted { max-width: 230px; }
    .resume-card { padding: 1rem; }
    .add-exercise-form { grid-template-columns: 1fr; }
    .routine-title-form { align-items: center; }
    .routine-title-form .button { padding: .5rem .65rem; font-size: .78rem; }
}
