:root {
    --bg: #ffffff;
    --surface: #f5f5f5;
    --text: #0c0d0e;
    --text-muted: #6b7280;
    --accent: #D6FB00;
    --accent-text: #000000;
    --border: #e5e7eb;
    --danger: #ef4444;
    --radius: 12px;
    --radius-sm: 8px;
}

[data-theme="dark"] {
    --bg: #0f0f0f;
    --surface: #1a1a1a;
    --text: #f0f0f0;
    --text-muted: #9ca3af;
    --accent: #D6FB00;
    --accent-text: #000000;
    --border: #2d2d2d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

/* ---- Layout ---- */
.screen { display: none; min-height: 100dvh; flex-direction: column; }
.screen.active { display: flex; }

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-title { font-size: 17px; font-weight: 600; }
.header-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.content { flex: 1; padding: 20px; overflow-y: auto; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 24px;
    border-radius: var(--radius);
    border: none;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
    width: 100%;
    gap: 8px;
}
.btn:active { opacity: 0.75; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 8px 16px; font-size: 14px; font-weight: 500; width: auto; }
.btn-icon { width: 40px; height: 40px; padding: 0; border-radius: 50%; background: var(--surface); border: 1px solid var(--border); font-size: 18px; }

/* ---- Card ---- */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

/* ---- Header logo ---- */
.header-logo { font-size: 22px; font-weight: 800; letter-spacing: -1px; }
.header-logo span { color: var(--accent); }

/* ---- Start screen ---- */
.start-date {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: capitalize;
    margin-bottom: 4px;
}
.start-workout-name {
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 6px;
    line-height: 1.2;
}
.start-meta {
    display: flex;
    gap: 6px;
    align-items: center;
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 20px;
}
.start-meta-dot { opacity: 0.4; }

.start-ex-list {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 4px 0;
    margin-bottom: 24px;
    max-height: 220px;
    overflow-y: auto;
}
.start-ex-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
}
.start-ex-item:last-child { border-bottom: none; }
.start-ex-num {
    width: 20px;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    flex-shrink: 0;
}
.start-ex-name { flex: 1; font-size: 15px; font-weight: 500; }
.start-ex-muscle { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }

.start-field-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* ---- Energy row (start screen) ---- */
.energy-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}
.energy-row .energy-btn { flex: 1; height: 48px; }
.energy-desc {
    font-size: 13px;
    color: var(--text-muted);
    min-height: 18px;
    margin-bottom: 4px;
}

.section-label {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* ---- Energy selector ---- */
.energy-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
}
.energy-btn {
    flex: 1;
    height: 44px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
    background: var(--surface);
    font-size: 18px;
    cursor: pointer;
    transition: all 0.15s;
}
.energy-btn.active {
    border-color: var(--accent);
    background: var(--accent);
}
.energy-btn:active { opacity: 0.75; }

/* ---- Workout screen ---- */
.exercise-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}
.exercise-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}
.exercise-name { font-size: 18px; font-weight: 700; }
.exercise-muscle { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.exercise-history { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.exercise-history strong { color: var(--text); }
.exercise-actions { display: flex; gap: 8px; margin-bottom: 12px; }

/* ---- Sets list ---- */
.sets-list { margin-bottom: 12px; }
.set-row {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.set-row:last-child { border-bottom: none; }
.set-main-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.set-num {
    width: 24px;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
    flex-shrink: 0;
}
/* ---- RPE selector ---- */
.rpe-selector {
    display: flex;
    gap: 6px;
    margin: 8px 0;
    align-items: center;
}
.rpe-label { font-size: 12px; color: var(--text-muted); margin-right: 4px; }
.rpe-btn {
    flex: 1;
    height: 36px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}
.rpe-btn.active {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-text);
}
.rpe-tooltip {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
}
.rpe-tooltip.visible { opacity: 1; }

/* ---- Failure toggle ---- */
.failure-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 10px 0 0;
    padding-left: 32px;
}
.failure-label { font-size: 14px; color: var(--text-muted); }
.toggle {
    width: 44px;
    height: 24px;
    background: var(--border);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
    border: none;
}
.toggle.on { background: var(--accent); }
.toggle::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: left 0.2s;
}
.toggle.on::after { left: 22px; }

/* ---- Timer ---- */
.timer-bar {
    display: none;
    position: sticky;
    bottom: 0;
    background: var(--text);
    color: var(--bg);
    padding: 12px 20px;
    display: none;
    align-items: center;
    justify-content: space-between;
    z-index: 20;
}
.timer-bar.active { display: flex; }
.timer-time { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer-label { font-size: 13px; opacity: 0.7; }
.timer-skip { background: rgba(255,255,255,0.15); border: none; color: white; padding: 8px 16px; border-radius: var(--radius-sm); font-size: 14px; cursor: pointer; }

/* ---- Finish screen ---- */
.finish-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.finish-stat:last-child { border-bottom: none; }
.finish-stat-label { color: var(--text-muted); font-size: 14px; }
.finish-stat-value { font-size: 16px; font-weight: 700; }

/* ---- History ---- */
.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.history-item:active { opacity: 0.7; }
.history-date { font-size: 15px; font-weight: 600; }
.history-meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.history-arrow { color: var(--text-muted); }

/* ---- No workout screen ---- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    padding: 40px 20px;
}
.empty-icon { font-size: 64px; margin-bottom: 16px; }
.empty-title { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.empty-sub { font-size: 15px; color: var(--text-muted); margin-bottom: 32px; }

/* ---- Theme toggle ---- */
.theme-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---- Progress bar ---- */
.progress-bar {
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin: 8px 0 0;
}
.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s;
}

/* ---- Icon helpers ---- */
.btn-ic {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.btn-ic svg, .btn-icon svg, .theme-btn svg {
    width: 100%;
    height: 100%;
    display: block;
}
.btn-icon { color: var(--text); }
.btn-icon svg { width: 18px; height: 18px; }
.btn-save {
    width: 44px;
    height: 44px;
    background: var(--accent);
    color: var(--accent-text);
    border: none;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-save svg { width: 20px; height: 20px; }
.empty-icon-svg {
    width: 72px;
    height: 72px;
    color: var(--text-muted);
    margin-bottom: 16px;
}
.empty-icon-svg svg { width: 100%; height: 100%; }

/* ---- Utils ---- */
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.fw-700 { font-weight: 700; }
.text-muted { color: var(--text-muted); font-size: 13px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ---- Loading ---- */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Overlay for replacing ---- */
.replace-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.replace-overlay.active { display: flex; }
.replace-modal {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 24px;
    margin: 20px;
    text-align: center;
    width: 100%;
    max-width: 340px;
}
.replace-modal h3 { margin-bottom: 8px; }
.replace-modal p { color: var(--text-muted); font-size: 14px; margin-bottom: 20px; }

/* ---- Start section (top of workout screen) ---- */
.start-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}
.ws-row { display: flex; gap: 12px; margin-bottom: 12px; }
.ws-field { flex: 1; }
.ws-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.ws-input-wrap { display: flex; align-items: center; gap: 6px; }
.ws-input {
    flex: 1; min-width: 0;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 20px;
    font-weight: 700;
}
.ws-input:focus { outline: none; border-color: var(--accent); }
.ws-unit { font-size: 14px; color: var(--text-muted); }
.ws-input-large { font-size: 28px; font-weight: 800; padding: 12px 16px; }

/* ---- Stepper ---- */
.stepper {
    display: flex;
    align-items: center;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg);
}
.stepper-btn {
    width: 40px; height: 44px;
    border: none;
    background: var(--surface);
    color: var(--text);
    font-size: 22px;
    font-weight: 400;
    cursor: pointer;
    flex-shrink: 0;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.stepper-btn:active { background: var(--accent); color: var(--accent-text); }
.stepper-val {
    flex: 1; min-width: 0;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    padding: 0 4px;
    height: 44px;
}
.stepper-val:focus { outline: none; }
.stepper-val-static {
    flex: 1;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    line-height: 44px;
}
.set-inputs { display: flex; gap: 8px; flex: 1; }
.set-field { flex: 1; }
.set-field-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }

/* ---- Set actions (save + delete) ---- */
.set-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
.btn-del-set {
    width: 36px; height: 36px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.btn-del-set svg { width: 14px; height: 14px; }
.btn-del-set:active { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ---- Saved set state ---- */
.set-saved { opacity: 0.6; }
.btn-save.saved { background: var(--surface); color: var(--text-muted); }

/* ---- RPE row (in set) ---- */
.set-extra { margin: 10px 0 0; padding-left: 32px; }
.set-extra-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.rpe-row { display: flex; gap: 4px; }
.rpe-btn {
    flex: 1; height: 40px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 1px;
    font-size: 11px;
}
.rpe-icon { font-size: 15px; line-height: 1; }
.rpe-label-text { font-size: 9px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.rpe-btn.active .rpe-label-text { color: var(--accent-text); }
