:root {
    color-scheme: light;
    --page: #f5f7f3;
    --paper: #ffffff;
    --tint: #f0f4ee;
    --text: #17261d;
    --muted: #526459;
    --line: #d8e2d9;
    --accent: #205b3c;
    --accent-hover: #16492e;
    --accent-text: #ffffff;
    --soft-accent: #dfeee3;
    --success: #227147;
    --partial: #80520e;
    --partial-bg: #fcf0d9;
    --danger: #a0302a;
    --danger-bg: #fff0ee;
    --user-color: #397953;
    --shadow: 0 14px 46px #152a1b24;
    --radius: 18px;
    --max: 740px;
    --nav-height: 66px;
    font: 16px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #151a17;
    --paper: #202923;
    --tint: #1a211c;
    --text: #e9f3eb;
    --muted: #b3c5b7;
    --line: #394c40;
    --accent: #9ed9ad;
    --accent-hover: #bceac7;
    --accent-text: #14271a;
    --soft-accent: #2d4935;
    --success: #9ed9ad;
    --partial: #ffd188;
    --partial-bg: #46361b;
    --danger: #ffaea8;
    --danger-bg: #4c2524;
    --shadow: 0 14px 46px #0007;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--text); }
button, input, textarea, select { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button, input, textarea, select {
    min-width: 0;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper);
}
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 13px;
    font-weight: 650;
    line-height: 1.2;
    touch-action: manipulation;
}
button:hover:not(:disabled) { background: var(--tint); }
button:disabled { opacity: .5; cursor: wait; }
button svg, summary svg { flex: 0 0 auto; }
button.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.quiet, button.danger-text { border-color: transparent; background: transparent; color: var(--accent); }
button.danger-text { color: var(--danger); }
button.danger-button { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); }
button.small { font-size: .875rem; padding-inline: 9px; }
button.selected { background: var(--soft-accent); border-color: var(--accent); color: var(--accent); }
input:not([type="checkbox"]), select, textarea { padding: 8px 11px; width: 100%; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .85; }
input[type="checkbox"] { width: 19px; height: 19px; min-height: 0; flex: 0 0 auto; accent-color: var(--accent); }
textarea { display: block; resize: vertical; min-height: 64px; }
select {
    appearance: none;
    padding-inline-end: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='%23526459' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: 16px;
    background-position: right 8px center;
}
:root[data-theme="dark"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='%23b3c5b7' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }
p, h1, h2, h3 { margin: 0; }
h1, h2, h3, strong { overflow-wrap: anywhere; }
h1 { font-size: clamp(1.38rem, 5vw, 2.02rem); line-height: 1.15; letter-spacing: -.035em; }
h2 { font-size: 1.1rem; line-height: 1.25; letter-spacing: -.015em; }
h3 { font-size: 1rem; }
label { display: grid; min-width: 0; gap: 5px; font-size: .9rem; font-weight: 620; }
label > input, label > textarea, label > select { font-size: 1rem; font-weight: 500; }
fieldset { display: grid; gap: 11px; border: 1px solid var(--line); border-radius: 12px; margin: 0; padding: 12px; min-width: 0; }
legend { padding-inline: 5px; font-weight: 650; font-size: .88rem; }
progress {
    display: block;
    appearance: none;
    width: 100%;
    height: 8px;
    accent-color: var(--accent);
    border: none;
    border-radius: 10px;
    overflow: hidden;
    background: var(--tint);
    color: var(--accent);
}
progress::-webkit-progress-bar { background: var(--tint); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 10px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 10px; }
summary { cursor: pointer; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.shell { max-width: var(--max); margin-inline: auto; width: 100%; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.row { display: flex; gap: 6px; align-items: center; }
.stack { display: grid; gap: 12px; }
.icon-button { width: 44px; height: 44px; flex: 0 0 44px; padding: 0; color: var(--muted); }
.notice, .loading { color: var(--muted); padding: 12px; overflow-wrap: anywhere; }
.notice.danger, .form-error { color: var(--danger); }
.form-error:empty { display: none; }
.form-error { font-size: .9rem; }
.app-header { background: var(--paper); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.topbar {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    min-height: 69px;
    padding: 9px max(16px, env(safe-area-inset-right)) 9px max(16px, env(safe-area-inset-left));
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 750; letter-spacing: -.028em; min-width: 0; }
.brand img { display: block; border-radius: 10px; flex: 0 0 auto; }
.brand span { overflow-wrap: anywhere; }
.user-picker { position: relative; min-width: 100px; max-width: min(49%, 260px); flex: 0 1 auto; }
.user-picker select { background-color: var(--tint); padding-inline-start: 30px; font-weight: 650; }
.user-dot { position: absolute; inset-inline-start: 11px; top: 17px; width: 10px; height: 10px; border-radius: 50%; background: var(--user-color); pointer-events: none; }

.main {
    padding: 24px max(16px, env(safe-area-inset-right)) calc(var(--nav-height) + env(safe-area-inset-bottom) + 30px) max(16px, env(safe-area-inset-left));
}
body:has(.timer:not([hidden])) .main { padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 166px); }
.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-block-end: 17px; }
.page-heading button { flex-shrink: 0; font-size: .9rem; }
.bottom-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 4;
    background: var(--paper);
    border-top: 1px solid var(--line);
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.nav-inner { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 3px; min-height: var(--nav-height); padding: 6px 10px; }
.nav-inner button { border: none; background: transparent; color: var(--muted); flex-direction: column; gap: 3px; font-size: .8rem; padding: 5px 3px; }
.nav-inner button[aria-current="page"] { background: var(--soft-accent); color: var(--accent); }
.nav-inner svg { width: 21px; height: 21px; }

.date-top { display: flex; justify-content: space-between; align-items: end; gap: 8px; margin-bottom: 14px; }
.date-top > div:first-child { min-width: 0; }
.kicker { color: var(--muted); font-size: .8rem; font-weight: 700; margin-bottom: 3px; }
.date-actions { display: flex; gap: 5px; }
.week-strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.day {
    display: flex;
    flex-direction: column;
    border-radius: 11px;
    gap: 4px;
    min-height: 65px;
    padding: 6px 0;
    background: var(--paper);
    font-variant-numeric: tabular-nums;
    font-size: 1rem;
}
.day.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.day.selected:hover { background: var(--accent-hover); }
.weekday { font-size: .75rem; font-weight: 650; color: var(--muted); }
.day.selected .weekday { color: currentColor; }
.day-marker, .legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; border: 1px solid var(--muted); }
.planned .day-marker, .legend .planned { border-radius: 2px; border-color: var(--muted); background: var(--muted); }
.partial .day-marker, .legend .partial { border-radius: 1px; border-color: var(--partial); background: var(--partial); transform: rotate(45deg) scale(.82); }
.complete .day-marker, .legend .complete { border-radius: 0; border: 0; border-inline-end: 2px solid var(--success); border-bottom: 2px solid var(--success); transform: rotate(42deg); width: 6px; height: 9px; }
.day.selected .day-marker { border-color: currentColor; }
.day.selected.planned .day-marker, .day.selected.partial .day-marker { background: currentColor; }
.calendar-foot { display: flex; justify-content: space-between; align-items: center; gap: 4px; min-height: 43px; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--muted); font-size: .73rem; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.month-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.month-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); text-align: center; gap: 4px; }
.month-days .day { min-height: 44px; gap: 3px; }
.month-days .day.outside { opacity: .56; }
.month-days .notice { grid-column: 1 / -1; }
.jump-date { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; margin-top: 14px; }

.summary { padding: 14px; }
.summary-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.summary-top .muted { display: block; margin-top: 3px; font-size: .85rem; }
.daily-notes, .exercise-notes { margin-top: 11px; border-top: 1px solid var(--line); }
.daily-notes summary, .exercise-notes summary { display: flex; gap: 6px; align-items: center; min-height: 42px; color: var(--muted); font-size: .86rem; font-weight: 650; list-style: none; }
.daily-notes summary::after, .exercise-notes summary::after { content: '+'; margin-left: auto; font-size: 1.1rem; }
.daily-notes[open] summary::after, .exercise-notes[open] summary::after { content: '−'; }
.daily-notes svg, .exercise-notes svg { width: 16px; height: 16px; }
.save-region { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; min-height: 34px; font-size: .79rem; color: var(--muted); }
#save-status[data-status="error"] { color: var(--danger); overflow-wrap: anywhere; }
#save-status[data-status="saving"] { color: var(--accent); }
.exercise-list { display: grid; gap: 12px; }
.exercise-card { padding: 12px; position: relative; }
.exercise-head { display: flex; align-items: center; gap: 5px; }
.drag-handle { touch-action: none; cursor: grab; background: var(--tint); }
.exercise-title { flex: 1 1 auto; min-width: 0; padding-inline: 3px; }
.exercise-title .targets { font-size: .84rem; margin-top: 3px; overflow-wrap: anywhere; }
.exercise-status { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); border-radius: 10px; padding: 4px 7px; font-size: .72rem; line-height: 1.25; font-weight: 680; white-space: nowrap; }
.exercise-status svg { width: 13px; height: 13px; }
.exercise-status.complete { color: var(--success); background: var(--soft-accent); }
.exercise-status.partial { color: var(--partial); background: var(--partial-bg); }
.exercise-status.planned { background: var(--tint); }
.sets { margin-top: 9px; }
.set-labels, .set-row {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr) minmax(0, 1fr) 44px;
    align-items: center;
    gap: 6px;
}
.set-labels { padding-block: 4px; color: var(--muted); font-size: .78rem; font-weight: 650; }
.set-labels select { min-height: 38px; font-size: .82rem; padding: 3px 23px 3px 6px; background-position: right 4px center; }
.set-rows { display: grid; gap: 5px; }
.set-index { font-size: .9rem; font-weight: 650; text-align: center; color: var(--muted); }
.set-index small { margin-inline-start: 2px; }
.set-row input { font-variant-numeric: tabular-nums; background: var(--tint); }
.set-row.logged input[name="value"] { background: var(--soft-accent); color: var(--text); }
.set-row .icon-button { border-color: transparent; }
.set-row .icon-button svg { width: 16px; height: 16px; }
.exercise-foot { display: flex; justify-content: space-between; align-items: center; gap: 5px; margin-top: 6px; }
.exercise-total { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; font-size: .82rem; }
.exercise-total strong { font-size: .9rem; }
.add-set { white-space: nowrap; font-size: .88rem; }
.add-exercise { width: 100%; margin-top: 13px; min-height: 49px; }
.dragging { opacity: .65; }
.drop-before::before, .drop-after::after { position: absolute; inset-inline: 0; height: 4px; border-radius: 5px; background: var(--accent); content: ''; }
.drop-before::before { top: -9px; }
.drop-after::after { bottom: -9px; }

.empty.panel { padding: 23px 16px; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 47px; height: 47px; border-radius: 14px; background: var(--soft-accent); color: var(--accent); margin: 0 auto 11px; }
.empty-icon svg { width: 24px; height: 24px; }
.empty p { color: var(--muted); margin: 6px auto 0; max-width: 38ch; font-size: .9rem; }
.empty button, .empty a { margin-top: 13px; }
.list-panel { padding: 3px 12px; }
.list-action { width: 100%; padding: 10px 7px; justify-content: flex-start; min-height: 51px; text-align: left; border: 0; }
.list-action span { flex: 1 1 auto; overflow-wrap: anywhere; }
.list-action svg { color: var(--muted); }
.list-action svg:last-child { width: 16px; height: 16px; }
.list-panel > * + *, .menu-list > * + * { border-top: 1px solid var(--line); }
.management-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; gap: 10px; }
.row-text { display: grid; min-width: 0; }
.row-text span { font-size: .85rem; overflow-wrap: anywhere; }
.search-label { margin-bottom: 13px; }

dialog {
    color: var(--text);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0;
    width: min(92vw, 500px);
    max-width: calc(100vw - 18px);
    max-height: min(86dvh, 850px);
    box-shadow: var(--shadow);
    overscroll-behavior: contain;
}
dialog::backdrop { background: #10221892; }
.dialog-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; background: var(--paper); border-bottom: 1px solid var(--line); }
.dialog-body { padding: 14px; }
.dialog-body > .menu-list { margin-block: -5px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; align-items: end; }
.form-actions, .preset-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.preset-row { justify-content: flex-start; }
.preset-row button { flex: 1 1 auto; }
.check { display: flex; align-items: center; min-height: 44px; gap: 8px; }
.color-field { display: flex; align-items: center; justify-content: space-between; }
.color-field input { width: 65px; }
.user-tools { border-top: 1px solid var(--line); margin-top: 13px; padding-top: 10px; }
.exercise-picker { position: relative; min-width: 0; }
.suggestions {
    position: relative;
    z-index: 1;
    overflow: auto;
    max-height: 190px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper);
    margin-top: 3px;
}
.suggestions button { display: flex; justify-content: space-between; width: 100%; text-align: left; border: 0; }
.suggestions button span { overflow-wrap: anywhere; }
.suggestions button small { color: var(--muted); flex-shrink: 0; }
.suggestions button[aria-selected="true"] { background: var(--soft-accent); }
.plan-tools { display: flex; justify-content: flex-end; gap: 5px; }
.weekday-choices { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.weekday-choices label { display: grid; place-items: center; font-size: .72rem; }
.weekday-choices input { margin: 0; }
.weekday-choices span { text-align: center; overflow-wrap: anywhere; }
.plan-preview { margin: 0; list-style: none; padding: 0; }
.plan-preview li { display: flex; justify-content: space-between; padding: 6px 0; gap: 8px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.plan-preview li span { color: var(--muted); text-align: right; flex: 0 0 auto; }

.progress-controls, .stat-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat { display: grid; justify-content: stretch; gap: 6px; text-align: left; padding: 12px; min-height: 72px; }
.stat span { font-size: .8rem; color: var(--muted); }
.stat strong { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.progress-panel { padding: 14px; margin-bottom: 12px; }
.history-search, .exercise-chart { margin-top: 11px; }
.chart { display: block; width: 100%; height: auto; margin-top: 8px; overflow: visible; }
.chart text { fill: var(--muted); font-size: 17px; font-family: inherit; }
.grid-line { stroke: var(--line); }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linejoin: round; }
.chart-bar, .chart-dot { fill: var(--accent); }
.chart-data { font-size: .86rem; color: var(--muted); }
.chart-data summary { min-height: 44px; display: flex; align-items: center; font-weight: 650; }
.chart-data table { width: 100%; border-collapse: collapse; text-align: left; }
.chart-data th, .chart-data td { border-bottom: 1px solid var(--line); padding: 5px; }
.history-list { display: grid; gap: 11px; }
.history-entry { border-top: 1px solid var(--line); padding-block-start: 10px; }
.history-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.set-history { list-style: none; padding: 0; margin: 6px 0 0; font-size: .86rem; }
.set-history li { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px 0; }
.set-history li > :last-child { text-align: right; }
.history-notes { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .86rem; color: var(--muted); }

.timer {
    position: fixed;
    inset: auto 0 calc(var(--nav-height) + env(safe-area-inset-bottom) + 8px);
    z-index: 5;
    padding-inline: max(9px, env(safe-area-inset-left)) max(9px, env(safe-area-inset-right));
    pointer-events: none;
}
.timer-inner { width: min(100%, 365px); margin-left: auto; padding: 8px; border: 1px solid var(--line); border-radius: 15px; background: var(--paper); box-shadow: var(--shadow); pointer-events: auto; }
.timer-top { display: grid; grid-template-columns: 28px 1fr auto 44px; align-items: center; gap: 5px; }
.timer-top > svg { color: var(--accent); margin-inline-start: 4px; }
.timer-label { font-size: .75rem; }
.timer-time { font-weight: 750; font-size: 1.3rem; line-height: 1.15; font-variant-numeric: tabular-nums; }
.timer-controls { display: grid; grid-template-columns: 1.2fr 1fr .8fr .8fr; gap: 4px; margin-top: 5px; }
.timer-controls button { font-size: .79rem; padding: 4px; }
.toast { position: fixed; z-index: 10; inset: 10px 12px auto; padding: 12px; width: fit-content; max-width: calc(100vw - 24px); margin-inline: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--text); box-shadow: var(--shadow); overflow-wrap: anywhere; }
.toast.error { color: var(--danger); background: var(--danger-bg); }
.gate { display: grid; place-items: center; min-height: 100dvh; padding: 15px; }
.gate .panel { width: min(100%, 390px); padding: 23px; display: grid; gap: 15px; }

@media (min-width: 600px) {
    .main { padding-top: 31px; }
    .topbar { min-height: 74px; }
    .summary, .exercise-card { padding: 16px; }
    .date-actions, .week-strip { gap: 8px; }
    .stat-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 360px) {
    .topbar, .main { padding-inline: 11px; }
    .date-actions { gap: 3px; }
    .date-actions button { flex-basis: 40px; width: 40px; }
    .exercise-card { padding-inline: 9px; }
    .exercise-head { gap: 3px; }
    .exercise-status { padding-inline: 4px; }
    .legend { gap: 6px; }
    .page-heading { align-items: start; }
    .page-heading button { max-width: 47%; }
}

@media (max-width: 500px) {
    .chart text { font-size: 22px; }
}

@media (prefers-reduced-motion: no-preference) {
    progress::-webkit-progress-value { transition: width .16s ease-out; }
}
