:root {
    color-scheme: dark;
    --bg: #07090d;
    --bg-soft: #10141c;
    --panel: #10151d;
    --panel-2: #171d27;
    --text: #f4f7fb;
    --muted: #8f9aaa;
    --line: rgba(255, 255, 255, .1);
    --surface-glass: rgba(255, 255, 255, .055);
    --field-bg: rgba(4, 8, 14, .86);
    --page-gradient: radial-gradient(circle at top left, rgba(24, 168, 255, .2), transparent 34rem), linear-gradient(145deg, #05070a 0%, #10141c 46%, #07090d 100%);
    --login-gradient: radial-gradient(circle at 50% -10%, rgba(24, 168, 255, .28), transparent 24rem), linear-gradient(145deg, #05070a 0%, #121721 54%, #05070a 100%);
    --blue: #18a8ff;
    --green: #45f0b7;
    --danger: #ff5570;
    --shadow: rgba(0, 0, 0, .44);
}

:root[data-theme="light"] {
    color-scheme: light;
    --bg: #eef3f8;
    --bg-soft: #f8fbff;
    --panel: #ffffff;
    --panel-2: #f4f8fc;
    --text: #101722;
    --muted: #627083;
    --line: rgba(17, 24, 39, .12);
    --surface-glass: rgba(255, 255, 255, .78);
    --field-bg: rgba(255, 255, 255, .92);
    --page-gradient: radial-gradient(circle at top left, rgba(24, 168, 255, .18), transparent 32rem), linear-gradient(145deg, #f8fbff 0%, #eef4fa 52%, #e6edf5 100%);
    --login-gradient: radial-gradient(circle at 50% -10%, rgba(24, 168, 255, .24), transparent 23rem), linear-gradient(145deg, #f8fbff 0%, #edf4fb 54%, #e5edf6 100%);
    --blue: #0878d8;
    --green: #0d9f73;
    --danger: #d9314f;
    --shadow: rgba(31, 45, 61, .16);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    background: var(--page-gradient);
    color: var(--text);
}

button,
input,
select,
textarea {
    font: inherit;
}

.app-shell {
    width: min(1120px, 100%);
    margin: 0 auto;
    padding: 20px clamp(14px, 4vw, 32px) 48px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 0 14px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-chip {
    max-width: 132px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-glass);
    color: var(--muted);
    font-size: 13px;
}

.theme-toggle {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    z-index: 40;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: var(--panel);
    color: var(--text);
    box-shadow: 0 14px 34px var(--shadow);
    cursor: pointer;
    backdrop-filter: blur(12px);
}

.theme-toggle span {
    font-size: 20px;
    line-height: 1;
}

.eyebrow {
    display: inline-flex;
    color: var(--green);
    font-size: 12px;
    font-weight: 800;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    margin-top: 4px;
    font-size: clamp(32px, 9vw, 64px);
    line-height: .95;
}

.topbar p,
.gym-note,
.folder-note,
.exercise-row span,
.metrics span {
    color: var(--muted);
}

.icon-button {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 46px;
    height: 46px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-glass);
    color: var(--text);
    font-size: 26px;
    cursor: pointer;
}

.icon-button.primary {
    background: linear-gradient(145deg, var(--blue), #256dff);
    border: 0;
    box-shadow: 0 16px 34px rgba(24, 168, 255, .24);
}

.logout-button {
    text-decoration: none;
    color: var(--danger);
    font-size: 20px;
}

.alert {
    margin: 10px 0 16px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--surface-glass);
}

.alert.success {
    border-color: rgba(69, 240, 183, .35);
}

.alert.danger {
    border-color: rgba(255, 85, 112, .45);
}

.quick-actions,
.day-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 0;
    scrollbar-width: none;
}

.quick-actions::-webkit-scrollbar,
.day-tabs::-webkit-scrollbar {
    display: none;
}

.action-button,
.day-tab,
.folder-actions button {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 14px;
    background: var(--surface-glass);
    color: var(--text);
    white-space: nowrap;
    cursor: pointer;
}

.action-button.active,
.day-tab.active {
    background: var(--text);
    color: var(--bg);
}

.action-button.ghost {
    color: var(--green);
}

.metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 14px 0 18px;
}

.metrics div {
    min-width: 0;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface-glass);
}

.metrics strong {
    display: block;
    font-size: 24px;
}

.folder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
}

.workout-folder {
    position: relative;
    min-height: 320px;
    padding: 18px;
    border: 1px solid var(--line);
    border-top: 4px solid var(--accent);
    border-radius: 18px;
    background: var(--panel);
    box-shadow: 0 20px 48px var(--shadow);
}

.workout-folder::before {
    content: "";
    position: absolute;
    top: -13px;
    left: 18px;
    width: 96px;
    height: 16px;
    border-radius: 10px 10px 0 0;
    background: var(--accent);
}

.folder-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 12px;
}

.folder-label {
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.folder-head h2 {
    margin-top: 4px;
    font-size: 23px;
    line-height: 1.08;
}

.status-pill {
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--surface-glass);
    color: var(--muted);
    font-size: 12px;
}

.folder-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 14px 0;
}

.folder-meta span {
    padding: 7px 10px;
    border-radius: 999px;
    background: rgba(24, 168, 255, .12);
    color: var(--blue);
    font-size: 13px;
}

.gym-note,
.folder-note {
    margin: 10px 0;
    font-size: 14px;
    line-height: 1.45;
}

.exercise-list {
    display: grid;
    gap: 8px;
    margin-top: 14px;
}

.exercise-row {
    display: grid;
    grid-template-columns: 62px minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel-2);
}

.exercise-thumb-button {
    width: 62px;
    height: 62px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--field-bg);
    cursor: zoom-in;
    overflow: hidden;
}

.exercise-thumb {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.exercise-thumb.placeholder {
    display: grid;
    place-items: center;
    width: 62px;
    height: 62px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--field-bg);
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
}

.gif-viewer {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px 0;
    background: rgba(0, 0, 0, .78);
    z-index: 60;
}

.gif-viewer.open {
    display: flex;
}

.gif-viewer-panel {
    width: 100%;
    max-width: 760px;
    max-height: 92vh;
    overflow: auto;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
}

.gif-viewer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
}

.gif-viewer-head h2 {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 18px;
}

.gif-viewer-panel img {
    display: block;
    width: 100%;
    height: auto;
    max-height: calc(92vh - 72px);
    object-fit: contain;
    background: #fff;
}

.exercise-row strong,
.exercise-row span,
.sets b,
.sets small {
    display: block;
}

.exercise-row span,
.sets small {
    margin-top: 3px;
    font-size: 12px;
}

.sets {
    min-width: 58px;
    text-align: right;
}

.sets b {
    font-size: 18px;
    color: var(--green);
}

.folder-actions {
    margin-top: 14px;
}

.folder-actions button {
    color: var(--danger);
}

.empty-state {
    padding: 22px;
    border: 1px dashed var(--line);
    border-radius: 18px;
    background: var(--surface-glass);
}

.empty-state span {
    display: block;
    margin-top: 6px;
    color: var(--muted);
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: end;
    justify-content: center;
    padding: 12px;
    background: rgba(0, 0, 0, .72);
    z-index: 20;
}

.modal.open {
    display: flex;
}

.modal-panel {
    width: min(760px, 100%);
    max-height: min(92vh, 860px);
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: var(--panel);
    padding: 18px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, .54);
}

.modal-panel.compact {
    width: min(520px, 100%);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.modal-head h2 {
    font-size: 24px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.form-grid label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
}

.form-grid .full {
    grid-column: 1 / -1;
}

input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 11px 12px;
    background: var(--field-bg);
    color: var(--text);
    outline: 0;
}

textarea {
    resize: vertical;
}

.submit-button {
    min-height: 48px;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(145deg, var(--blue), #2a6cff);
    color: white;
    font-weight: 800;
    cursor: pointer;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 76px 16px 28px;
    background: var(--login-gradient);
}

.login-shell {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
}

.login-card {
    width: 100%;
    padding: 26px 22px 22px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: var(--panel);
    box-shadow: 0 26px 70px var(--shadow);
    overflow: hidden;
    position: relative;
}

.login-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 5px;
    background: linear-gradient(90deg, var(--blue), var(--green));
}

:root[data-theme="light"] .login-card {
    background: #ffffff;
}

.login-brand {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 14px;
    align-items: center;
    margin-bottom: 24px;
}

.login-mark {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: linear-gradient(145deg, var(--blue), #256dff);
    color: #fff;
    font-weight: 900;
    box-shadow: 0 16px 34px rgba(24, 168, 255, .22);
}

.login-brand h1 {
    margin-top: 5px;
    font-size: 34px;
    line-height: 1;
}

.login-brand p {
    margin-top: 8px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.login-form {
    display: grid;
    gap: 15px;
}

.login-form label,
.recovery-form label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.login-form input,
.recovery-form input {
    min-height: 52px;
    border-radius: 15px;
    background: var(--field-bg);
    font-size: 16px;
}

.remember-row {
    display: flex !important;
    grid-template-columns: none;
    align-items: center;
    gap: 10px !important;
    min-height: 28px;
    color: var(--text) !important;
    font-weight: 600 !important;
}

.remember-row input {
    width: 18px;
    min-height: 18px;
    height: 18px;
    accent-color: var(--blue);
}

.login-form .submit-button {
    margin-top: 4px;
    min-height: 54px;
    border-radius: 15px;
    font-size: 16px;
}

.submit-button.secondary {
    margin-top: 4px;
    min-height: 48px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
}

.forgot-button {
    width: 100%;
    min-height: 42px;
    margin-top: 14px;
    border: 0;
    background: transparent;
    color: var(--blue);
    font-weight: 800;
    cursor: pointer;
}

.recovery-form {
    display: grid;
    gap: 12px;
    margin-top: 10px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface-glass);
}

.recovery-form[hidden] {
    display: none;
}

.login-hint {
    margin-top: 18px;
    padding: 12px;
    border: 1px solid rgba(69, 240, 183, .28);
    border-radius: 14px;
    background: rgba(69, 240, 183, .09);
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

.is-hidden {
    display: none;
}

@media (max-width: 680px) {
    .app-shell {
        padding-bottom: 92px;
    }

    .topbar {
        align-items: end;
    }

    .topbar-actions {
        align-self: flex-start;
    }

    .user-chip {
        display: none;
    }

    .metrics {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .metrics div {
        padding: 12px 10px;
    }

    .metrics strong {
        font-size: 20px;
    }

    .metrics span {
        font-size: 12px;
    }

    .folder-grid {
        grid-template-columns: 1fr;
    }

    .exercise-row {
        grid-template-columns: 76px minmax(0, 1fr) auto;
    }

    .exercise-thumb-button,
    .exercise-thumb.placeholder {
        width: 76px;
        height: 76px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .modal {
        align-items: end;
        padding: 0;
    }

    .modal-panel {
        border-radius: 22px 22px 0 0;
    }

    .login-shell {
        max-width: 100%;
    }

    .login-card {
        padding: 24px 18px 20px;
        border-radius: 22px;
    }

    .login-brand {
        grid-template-columns: 52px minmax(0, 1fr);
        gap: 12px;
    }

    .login-mark {
        width: 52px;
        height: 52px;
        border-radius: 16px;
    }

    .login-brand h1 {
        font-size: 30px;
    }
}
