:root {
    color-scheme: light dark;
    --bg: #f4f4f2;
    --surface: #fff;
    --text: #1a1a18;
    --muted: #5c5c56;
    --border: #d8d8d0;
    --accent: #2d6a4f;
    --accent-text: #fff;
    --danger: #b42318;
    --done: #1b7f4a;
    --done-muted: rgba(27, 127, 74, 0.12);
    --radius: 12px;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.4;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121211;
        --surface: #1e1e1c;
        --text: #f2f2ee;
        --muted: #a3a39a;
        --border: #33332e;
        --accent: #40916c;
        --accent-text: #0d0d0c;
        --done: #52b788;
        --done-muted: rgba(82, 183, 136, 0.18);
        --shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
    }
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}

#app {
    max-width: 520px;
    margin: 0 auto;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.35rem;
    padding: max(0.75rem, env(safe-area-inset-top)) 1rem 0.5rem;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 5;
}

.topbar__back {
    justify-self: start;
    min-width: 4.5rem;
}

.topbar__title {
    grid-column: 2;
    font-size: 1.15rem;
    font-weight: 650;
    margin: 0;
    text-align: center;
}

.topbar__logout {
    grid-column: 3;
    justify-self: end;
    text-decoration: none;
    white-space: nowrap;
}

.login-wrap {
    max-width: 420px;
    margin: 0 auto;
}

.login-main {
    padding-top: 2rem;
}

.login-title {
    margin: 0 0 0.25rem;
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
}

.login-sub {
    text-align: center;
    margin: 0 0 1.25rem;
}

.login-error {
    background: rgba(180, 35, 24, 0.1);
    color: var(--danger);
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius);
    margin: 0 0 1rem;
    font-size: 0.92rem;
}

.login-form {
    margin-top: 0.5rem;
}

.main {
    flex: 1;
    padding: 0 1rem 1.5rem;
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
}

.view {
    display: none;
}

.view--active {
    display: block;
}

.next-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin: 0 0 0.35rem;
}

.next-session {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

.next-session__name {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
}

.next-session__hint {
    margin: 0.35rem 0 0;
    font-size: 0.9rem;
}

.next-session__media {
    margin: 0 0 0.75rem;
}

.next-session__zoom {
    display: block;
    width: 100%;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 10px;
    overflow: hidden;
    cursor: zoom-in;
    background: var(--border);
}

.next-session__img {
    display: block;
    width: 100%;
    min-height: 36vh;
    max-height: 48vh;
    object-fit: cover;
}

.muted {
    color: var(--muted);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.stack--footer {
    margin-top: 1.25rem;
}

.start-picker__divider {
    margin: 1rem 0 0.5rem;
    font-size: 0.78rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.start-picker-list {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.start-picker__session {
    width: 100%;
    text-align: left;
    justify-content: flex-start;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.65rem 1rem;
    font-size: 1rem;
    font-weight: 600;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    min-height: 48px;
}

.btn--large {
    min-height: 52px;
    font-size: 1.05rem;
    width: 100%;
}

.btn--primary {
    background: var(--accent);
    color: var(--accent-text);
    border-color: transparent;
}

.btn--ghost {
    background: transparent;
    border-color: transparent;
    color: var(--accent);
    padding-inline: 0.5rem;
}

.row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.row .btn {
    flex: 1;
}

.session-head {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.session-head__media {
    display: block;
    width: 100%;
    padding: 0;
    margin: 0;
    border: 0;
    background: var(--border);
    cursor: zoom-in;
}

.session-head__media--empty {
    cursor: default;
}

.session-head__img {
    width: 100%;
    min-height: 44vh;
    max-height: 58vh;
    object-fit: cover;
    display: block;
    background: var(--border);
}

.session-head__img--placeholder {
    min-height: 120px;
    max-height: 24vh;
    background: var(--border);
}

.session-head__meta {
    padding: 0.85rem 1rem;
}

.session-head__name {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
}

.session-head__progress {
    margin: 0.4rem 0 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--done);
}

.cards {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.card {
    display: flex;
    gap: 0.85rem;
    align-items: stretch;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.65rem;
    text-align: left;
    width: 100%;
    color: inherit;
    font: inherit;
    box-shadow: var(--shadow);
    min-height: 96px;
}

.card--done {
    border-color: var(--done);
    background: linear-gradient(135deg, var(--surface) 0%, var(--done-muted) 100%);
    box-shadow: var(--shadow), 0 0 0 1px var(--done);
}

.card__thumb {
    flex-shrink: 0;
    width: 108px;
    min-height: 108px;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 10px;
    overflow: hidden;
    background: var(--border);
    cursor: zoom-in;
    align-self: center;
}

.card__thumb:disabled {
    cursor: default;
    opacity: 0.85;
}

.card__img {
    width: 100%;
    height: 100%;
    min-height: 108px;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

.card__thumb .card__img--placeholder {
    min-height: 108px;
    height: 108px;
}

.card__main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    padding: 0.15rem 0;
    margin: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.card__body {
    flex: 1;
    min-width: 0;
}

.card__name {
    font-weight: 650;
    margin: 0 0 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.card__tick {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--done);
    color: var(--accent-text);
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1;
}

.card__last {
    margin: 0;
    font-size: 0.88rem;
    color: var(--muted);
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.panel__title {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    font-weight: 650;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.field__label {
    font-size: 0.85rem;
    color: var(--muted);
}

input[type="text"],
input[type="number"],
input[type="file"],
select {
    font: inherit;
    padding: 0.65rem 0.75rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    min-height: 48px;
}

.preview {
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.preview img {
    display: block;
    width: 100%;
    max-height: 160px;
    object-fit: cover;
}

.manage-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.manage-session {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.65rem 0.75rem;
}

.manage-session__head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
}

.manage-session__title {
    font-weight: 650;
    margin: 0;
    flex: 1;
    min-width: 0;
}

.manage-session__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.manage-ex-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem 0.6rem;
    margin-top: 0.45rem;
    padding: 0.45rem 0.5rem;
    border-radius: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
}

.manage-ex-row__meta {
    font-size: 0.92rem;
    color: var(--muted);
    flex: 1;
    min-width: 0;
}

.manage-ex-row__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.btn--sm {
    min-height: 40px;
    padding: 0.4rem 0.65rem;
    font-size: 0.9rem;
    width: auto;
}

.btn--danger {
    border-color: rgba(180, 35, 24, 0.45);
    color: var(--danger);
}

.field--row {
    flex-direction: row;
    align-items: center;
    gap: 0.55rem;
}

.field--row input[type="checkbox"] {
    width: auto;
    min-height: auto;
    margin: 0;
}

.field__label--inline {
    margin: 0;
}

.move-exercise__hint {
    margin: 0 0 0.5rem;
}

.edit-session-exercises-block {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.edit-session-exercises-block__title {
    margin: 0 0 0.65rem;
    font-size: 0.95rem;
    font-weight: 650;
}

.edit-session-exercises-block__hint {
    margin: 0.75rem 0 0.5rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.edit-session-exercises-list {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.edit-session-ex-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.92rem;
}

.edit-session-ex-line__meta {
    flex: 1;
    min-width: 0;
    color: var(--muted);
}

.edit-session-ex-line__name {
    font-weight: 600;
    color: var(--text);
}

.monthly-browser {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
    box-shadow: var(--shadow);
    min-height: min(62vh, 520px);
    max-height: min(72vh, 640px);
}

.monthly-col {
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.monthly-col:last-child {
    border-right: 0;
}

.monthly-col--narrow {
    flex: 0 0 3.5rem;
    max-width: 4rem;
    min-width: 3.25rem;
}

.monthly-col--narrow .monthly-col__label {
    padding-left: 0.4rem;
    padding-right: 0.4rem;
}

.monthly-col--narrow .monthly-pick {
    padding-left: 0.45rem;
    padding-right: 0.45rem;
    font-size: 0.86rem;
}

.monthly-col--wide {
    flex: 1 1 0;
    min-width: 0;
}

.monthly-col__label {
    margin: 0;
    padding: 0.4rem 0.55rem;
    font-size: 0.7rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.monthly-col__scroll {
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.monthly-pick {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0.55rem 0.65rem;
    border: 0;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.92rem;
    text-align: left;
    cursor: pointer;
    min-height: 44px;
}

.monthly-pick:last-child {
    border-bottom: 0;
}

.monthly-pick.is-selected {
    background: var(--done-muted);
    font-weight: 700;
}

.monthly-pick--muted {
    color: var(--muted);
}

.monthly-session-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.65rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
}

.monthly-session-row:last-child {
    border-bottom: 0;
}

.monthly-session-row__main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.monthly-session-row__date {
    font-size: 0.78rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.monthly-session-row__title {
    font-weight: 650;
    word-break: break-word;
}

.monthly-session-row__progress {
    font-size: 0.82rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--done);
}

.monthly-session-row__del {
    flex-shrink: 0;
    min-height: 40px;
    padding: 0.35rem 0.55rem;
    font-size: 0.82rem;
    width: auto;
}

.monthly-empty {
    padding: 1rem 0.75rem;
    margin: 0;
    color: var(--muted);
    font-size: 0.92rem;
}

@media (max-width: 520px) {
    .monthly-browser {
        flex-direction: column;
        max-height: none;
        min-height: auto;
    }

    .monthly-col {
        border-right: 0;
        border-bottom: 1px solid var(--border);
        max-height: 36vh;
    }

    .monthly-col:last-child {
        border-bottom: 0;
        max-height: 46vh;
    }
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.lightbox[hidden] {
    display: none;
}

.lightbox__backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    padding: 0;
    margin: 0;
    background: rgba(0, 0, 0, 0.92);
    cursor: pointer;
}

.lightbox__img {
    position: relative;
    z-index: 1;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    pointer-events: none;
}

.lightbox__close {
    position: absolute;
    z-index: 2;
    top: max(0.75rem, env(safe-area-inset-top));
    right: max(0.75rem, env(safe-area-inset-right));
    min-height: 48px;
    padding: 0 1rem;
    width: auto;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal[hidden] {
    display: none;
}

.modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.modal__sheet {
    position: relative;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow: auto;
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 1rem 1rem max(1rem, env(safe-area-inset-bottom));
    border: 1px solid var(--border);
    border-bottom: none;
    box-shadow: var(--shadow);
}

.modal__title {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
}

.field[hidden],
#field-weight-wrap[hidden] {
    display: none !important;
}
