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

:root {
    --bg: #f5f5f7;
    --surface: #fff;
    --nav-bg: rgba(28,28,30,0.94);
    --text: #1d1d1f;
    --text-secondary: #86868b;
    --border: #e5e5ea;
    --input-bg: #f2f2f7;
    --blue: #007AFF;
    --red: #FF3B30;
    --green: #34C759;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --radius: 10px;
    --radius-sm: 8px;
    --control-height: 36px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

/* ── Nav ── */

nav {
    position: sticky;
    top: 0;
    z-index: 100;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: rgba(28, 28, 30, 0.88);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.nav-start,
.nav-end {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-center {
    flex: 0 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2.5rem;
}

.nav-brand {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #fff;
    text-decoration: none;
}
.nav-brand:hover {
    color: rgba(255, 255, 255, 0.85);
}

.nav-user-link {
    color: rgba(255, 255, 255, 0.55);
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.2s;
}
.nav-user-link:hover {
    color: rgba(255, 255, 255, 0.85);
}

.nav-logout {
    color: rgba(255, 255, 255, 0.35);
    font-size: 12px;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.2s;
}
.nav-logout:hover {
    color: rgba(255, 255, 255, 0.7);
}

nav a {
    position: relative;
    color: rgba(255, 255, 255, 0.5);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.02em;
    padding: 8px 0;
    transition: color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

nav a:hover {
    color: rgba(255, 255, 255, 0.85);
}

nav a.active {
    color: #fff;
}

nav a.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--blue);
}

/* ── Nav toggle (hamburger) ── */

.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    gap: 4px;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.nav-toggle-bar {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 1px;
    background: rgba(255, 255, 255, 0.5);
    transition: transform 0.2s, opacity 0.2s;
    pointer-events: none;
}

/* ── Nav dropdown (mobile) ── */

.nav-dropdown {
    display: none;
    position: fixed;
    top: 52px;
    left: 0;
    right: 0;
    z-index: 99;
    flex-direction: column;
    background: rgba(28, 28, 30, 0.97);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding: 8px 0;
}
.nav-dropdown a {
    display: block;
    padding: 12px 1.5rem;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.nav-dropdown a:hover {
    color: #fff;
}
.nav-dropdown a.active {
    color: #fff;
}
.nav-dropdown hr {
    margin: 4px 1.5rem;
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.nav-dropdown a:last-child {
    color: rgba(255, 255, 255, 0.35);
}

/* ── Nav checkbox hack ── */

#nav-check:checked ~ .nav-dropdown {
    display: flex;
}

#nav-check:checked ~ nav .nav-toggle-bar:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}
#nav-check:checked ~ nav .nav-toggle-bar:nth-child(2) {
    opacity: 0;
}
#nav-check:checked ~ nav .nav-toggle-bar:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}


/* ── Main ── */

main {
    max-width: 780px;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 1rem;
}

/* ── Workout list ── */

.month-group { margin-bottom: 1.75rem; }
.month-group h2 {
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 4px;
    margin-bottom: 6px;
}

.workout-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
    transition: background 0.12s;
}
.workout-card:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.workout-card:last-child { border-radius: 0 0 var(--radius) var(--radius); border-bottom: none; }
.workout-card:only-child { border-radius: var(--radius); }
.workout-card:hover { background: #f8f8fa; }

.workout-date { font-weight: 600; font-size: 15px; }
.workout-meta { color: var(--text-secondary); font-size: 13px; }

/* ── Workout detail ── */

.workout-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.workout-header h1 { margin-bottom: 0; }

.workout-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.exercise-block {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}
.exercise-block h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.set-list { list-style: none; }

.set-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    min-height: 36px;
}
.set-row:last-child { border-bottom: none; }

.set-row.missed .set-value {
    color: #c7c7cc;
    text-decoration: line-through;
}
.set-row .set-value {
    flex: 1;
    font-size: 15px;
    font-variant-numeric: tabular-nums;
}

.set-notes {
    color: var(--red);
    font-size: 12px;
    font-weight: 600;
    background: rgba(255,59,48,0.08);
    padding: 2px 8px;
    border-radius: 4px;
}

.set-toggle input { display: none; }
.check-indicator {
    display: inline-flex;
    width: 28px;
    height: 28px;
    border: 2px solid #c7c7cc;
    border-radius: 50%;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}
.set-toggle:hover .check-indicator {
    border-color: var(--green);
}
.set-toggle input:checked + .check-indicator {
    background: var(--green);
    border-color: var(--green);
}
.set-toggle input:checked + .check-indicator::after {
    content: '✓';
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
}

.no-sets { color: #c7c7cc; font-style: italic; font-size: 13px; }

.inline-form { display: inline; }

/* ── Buttons ── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: var(--control-height);
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    color: var(--text);
    transition: all 0.15s;
    white-space: nowrap;
    gap: 6px;
}
.btn:hover { background: #f0f0f2; }
.btn:active { background: #e8e8ec; transform: scale(0.97); }

.btn-primary {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}
.btn-primary:hover { background: #0066d6; }
.btn-primary:active { background: #0055b3; transform: scale(0.97); }

.btn-danger {
    color: var(--red);
    border-color: var(--red);
}
.btn-danger:hover { background: rgba(255,59,48,0.08); }
.btn-danger:active { background: rgba(255,59,48,0.15); transform: scale(0.97); }

.btn-plain {
    border-color: transparent;
    background: transparent;
    color: var(--text-secondary);
}
.btn-plain:hover { background: transparent; color: var(--text); }

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--control-height);
    height: var(--control-height);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    transition: all 0.12s;
    flex-shrink: 0;
    line-height: 1;
}
.btn-icon:hover { background: #f0f0f2; }
.btn-icon:active { background: #e8e8ec; transform: scale(0.92); }
.btn-icon:disabled {
    opacity: 0.25;
    cursor: default;
    background: var(--surface);
}
.btn-icon.danger {
    color: var(--red);
    border-color: transparent;
}
.btn-icon.danger:hover { background: rgba(255,59,48,0.08); }
.btn-icon.danger:active { background: rgba(255,59,48,0.15); }

/* ── Forms ── */

.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

input[type="date"],
input[type="text"],
input[type="number"],
select {
    height: var(--control-height);
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.2);
}

.exercise-form-block {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}
.exercise-header {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.exercise-header select { flex: 1; min-width: 160px; }
.exercise-header .exercise-name-input { flex: 1; min-width: 160px; }

.sets-container { margin-bottom: 8px; }

.set-form-row {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 5px 0;
    flex-wrap: wrap;
}
.set-form-row input.set-value { width: 72px; font-size: 13px; }
.set-form-row select.set-unit { width: 68px; font-size: 13px; }
.set-form-row input.set-value2 { width: 72px; font-size: 13px; }
.set-form-row select.set-unit2 { width: 68px; font-size: 13px; }
.set-form-row .sep { color: #8e8e93; font-size: 14px; user-select: none; }
.set-form-row input.set-notes { flex: 1; min-width: 80px; font-size: 13px; }

.set-done-toggle input { display: none; }
.done-indicator {
    display: inline-flex;
    width: 28px;
    height: 28px;
    border: 2px solid #c7c7cc;
    border-radius: 50%;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}
.set-done-toggle:hover .done-indicator {
    border-color: var(--green);
}
.set-done-toggle input:checked + .done-indicator {
    background: var(--green);
    border-color: var(--green);
}
.set-done-toggle input:checked + .done-indicator::after {
    content: '✓';
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
}

/* ── Stats ── */

.stats-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-top: 1rem;
}
.stats-table th, .stats-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.stats-table th {
    background: #f8f8fa;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
}

#stats-chart {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.pb-badge {
    display: inline-block;
    background: #34C759;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
    line-height: 1.5;
}

/* ── Misc ── */

.hidden { display: none !important; }

.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;
}

.form-separator {
    margin: 1.25rem 0;
    border: none;
    border-top: 1px solid var(--border);
}

.form-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.form-header .form-group {
    flex: 1;
    margin-bottom: 0;
}

.form-footer {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.form-footer > .btn-primary {
    margin-left: auto;
}

.workout-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 1.25rem;
}

.stats-subheading {
    margin-top: 1.5rem;
}

.error {
    background: rgba(255,59,48,0.08);
    color: var(--red);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 14px;
    font-weight: 500;
}

/* ── Media Form ── */

.media-form-block {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 10px;
    box-shadow: var(--shadow);
}

.media-header {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 8px;
}

.media-type-badge {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    background: var(--input-bg);
    padding: 2px 8px;
    border-radius: 4px;
    margin-right: auto;
}

.media-body textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    padding: 8px 10px;
    resize: vertical;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.media-body textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.2);
}

.media-body input[type="file"] {
    font-size: 13px;
    margin-bottom: 4px;
}

.media-body input[type="url"] {
    width: 100%;
}

.media-label {
    width: 100% !important;
    margin-top: 4px;
    font-size: 13px;
}

.media-file-name {
    font-size: 12px;
    color: var(--text-secondary);
    display: block;
    margin-top: 2px;
}

/* ── Media Display ── */

.workout-media {
    margin-top: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.media-block {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
}

.media-block .media-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.media-note-content {
    font-size: 15px;
    line-height: 1.6;
    white-space: pre-wrap;
}

.media-image img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    display: block;
}

.video-wrapper {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
    border-radius: var(--radius-sm);
}

.video-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

hr { border: none; border-top: 1px solid var(--border); }

/* ── Profile ── */

.profile-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 340px;
    box-shadow: var(--shadow);
    margin: 0 auto;
}

.profile-card h1 {
    font-size: 22px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 1.25rem;
    letter-spacing: -0.02em;
}

.profile-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.profile-stat:last-of-type {
    border-bottom: none;
}

.profile-stat-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.profile-stat-value {
    color: var(--text);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.profile-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.25rem 0;
}

.profile-field {
    margin-bottom: 1rem;
}

.profile-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.profile-field input {
    width: 100%;
    height: var(--control-height);
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
}

.profile-field input:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.2);
}

.profile-email-display {
    display: block;
    padding: 8px 0;
    font-size: 15px;
    color: var(--text-secondary);
}

.profile-btn {
    width: 100%;
    height: 40px;
    font-size: 15px;
    font-weight: 600;
    margin-top: 4px;
}

.profile-success {
    font-size: 13px;
    color: var(--green);
    font-weight: 500;
    text-align: center;
    margin-bottom: 0.75rem;
    padding: 8px 12px;
    background: rgba(52,199,89,0.08);
    border-radius: var(--radius-sm);
}

/* ── Login / Register ── */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
    margin: 0;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 340px;
    box-shadow: var(--shadow);
}

.login-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.03em;
    text-align: center;
    margin-bottom: 4px;
    color: var(--text);
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-field {
    margin-bottom: 1rem;
}

.login-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.login-field input {
    width: 100%;
    height: var(--control-height);
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
}

.login-field input:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.2);
}

.login-btn {
    width: 100%;
    height: 40px;
    font-size: 15px;
    font-weight: 600;
    margin-top: 4px;
}

.login-error {
    font-size: 13px;
    color: var(--red);
    font-weight: 500;
    text-align: center;
    margin-bottom: 0.75rem;
    padding: 8px 12px;
    background: rgba(255,59,48,0.08);
    border-radius: var(--radius-sm);
}

.login-toggle {
    text-align: center;
    margin-top: 1rem;
    font-size: 13px;
    color: var(--text-secondary);
}

.login-link {
    background: none;
    border: none;
    color: var(--blue);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
    text-decoration: none;
}

.login-link:hover {
    text-decoration: underline;
}

/* ── Empty state ── */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 15px;
    margin-bottom: 1rem;
}

/* ── Responsive ── */

@media (max-width: 640px) {
    main { margin: 1rem auto; }

    .nav-center { display: none; }
    .nav-toggle { display: flex; }
    .nav-user-link { display: none; }
    .nav-logout { display: none; }

    .exercise-header { flex-direction: row; flex-wrap: wrap; }
    .exercise-header select { min-width: 120px; flex: 1 1 100%; order: 1; }
    .exercise-header .btn-icon { order: 0; }
    .exercise-header .exercise-name-input { order: 2; flex: 1 1 100%; }
    nav { padding: 0 1rem; }
    .nav-center { gap: 1rem; }
}

@media (max-width: 565px) {
    .set-form-row {
        display: grid;
        grid-template-columns: auto 1fr 1fr auto 1fr 1fr;
        gap: 4px;
        align-items: center;
    }
    .set-form-row input.set-value,
    .set-form-row input.set-value2,
    .set-form-row select.set-unit,
    .set-form-row select.set-unit2 { font-size: 16px; }
    .set-form-row input.set-notes { grid-column: 1 / 6; grid-row: 2; font-size: 16px; }
    .set-form-row .remove-set { grid-column: 6; grid-row: 2; justify-self: end; }
}
