:root {
    color-scheme: dark;
    --background: #111315;
    --surface: #181b1e;
    --surface-raised: #202428;
    --border: #343a40;
    --border-strong: #4a525a;
    --text: #f2f4f5;
    --muted: #a5adb5;
    --accent: #d9e2e8;
    --accent-text: #111315;
    --danger: #ff9b9b;
    --danger-surface: #351d20;
    --focus: #9ec7e0;
    --radius: 10px;
}

* {
    box-sizing: border-box;
}

html {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--background);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
}

body {
    margin: 0;
    min-width: 320px;
    background: var(--background);
}

a {
    color: inherit;
}

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

button,
a {
    -webkit-tap-highlight-color: transparent;
}

.site-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.65rem;
    min-height: 60px;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.brand-group {
    display: flex;
    align-items: baseline;
    gap: 0.65rem;
}

.site-header form {
    margin: 0;
}

.header-action {
    min-height: 40px;
    padding: 0.4rem 0.6rem;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.brand {
    font-weight: 750;
    text-decoration: none;
}

.brand-note {
    color: var(--muted);
    font-size: 0.8rem;
}

.container {
    width: min(100%, 780px);
    margin: 0 auto;
    padding: 1.25rem 1rem 4rem;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(1.75rem, 8vw, 2.35rem);
    line-height: 1.15;
    letter-spacing: -0.025em;
}

h2 {
    font-size: 1.25rem;
    line-height: 1.25;
}

h3 {
    font-size: 1rem;
}

.eyebrow,
.back-link {
    color: var(--muted);
    font-size: 0.9rem;
}

.eyebrow {
    margin-bottom: 0.25rem;
}

.back-link {
    display: inline-block;
    min-height: 44px;
    margin-bottom: 0.35rem;
    padding-top: 0.7rem;
    text-decoration: none;
}

.page-heading,
.detail-heading {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.heading-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.6rem;
}

.form-heading {
    margin-bottom: 1.5rem;
}

.button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-height: 48px;
    padding: 0.7rem 1rem;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface-raised);
    color: var(--text);
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.button:hover {
    border-color: #69737c;
}

.button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.button-add {
    background: transparent;
    border-style: dashed;
    color: var(--accent);
}

.button-danger {
    border-color: #6f393f;
    background: var(--danger-surface);
    color: var(--danger);
}

.button-full {
    width: 100%;
}

.workout-list,
.progress-list {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.workout-row,
.progress-row {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-height: 72px;
    padding: 1rem;
    background: var(--surface);
    text-decoration: none;
}

.workout-row + .workout-row,
.progress-row + .progress-row {
    border-top: 1px solid var(--border);
}

.workout-row:hover,
.progress-row:hover {
    background: var(--surface-raised);
}

.workout-row span,
.progress-row span {
    color: var(--muted);
    font-size: 0.92rem;
}

.empty-state,
.workout-note,
.notice,
.error-box {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.empty-state p,
.workout-note p {
    color: var(--muted);
}

.empty-state .button {
    margin-top: 0.5rem;
}

.notice {
    margin-bottom: 1rem;
    border-color: #41584d;
    background: #19271f;
}

.error-box {
    margin-bottom: 1rem;
    border-color: #6f393f;
    background: var(--danger-surface);
    color: #ffd7d7;
}

.error-box ul {
    margin: 0.5rem 0 0;
    padding-left: 1.25rem;
}

.error-box p:last-child {
    margin-bottom: 0;
}

.login-panel {
    width: min(100%, 430px);
    margin: 8vh auto 0;
    padding: 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.login-panel h1 {
    margin-bottom: 1.5rem;
}

.login-form {
    display: grid;
    gap: 1rem;
}

.workout-note {
    margin-bottom: 1rem;
}

.workout-note h2 {
    margin-bottom: 0.35rem;
    font-size: 0.95rem;
}

.workout-note p {
    margin-bottom: 0;
}

.exercise-details {
    border-top: 1px solid var(--border);
}

.exercise-detail {
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border);
}

.exercise-detail header h2 {
    margin-bottom: 0.2rem;
}

.weight {
    margin-bottom: 1rem;
    color: var(--muted);
    font-weight: 650;
}

.set-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.set-list li {
    padding: 0.8rem 0;
}

.set-list li + li {
    border-top: 1px solid #292e32;
}

.set-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.25rem;
}

.set-note,
.exercise-note p {
    margin-bottom: 0;
    color: var(--muted);
}

.exercise-note {
    margin-top: 1rem;
    padding: 0.85rem 1rem;
    border-left: 3px solid var(--border-strong);
    background: var(--surface);
}

.exercise-note strong {
    display: block;
    margin-bottom: 0.15rem;
    font-size: 0.88rem;
}

.danger-zone {
    margin-top: 2rem;
}

.workout-form {
    display: grid;
    gap: 1rem;
}

.form-section,
.exercise-card {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.workout-fields,
.exercise-card {
    display: grid;
    gap: 1rem;
}

.exercise-form-list {
    display: grid;
    gap: 1rem;
}

.card-heading,
.set-card-heading,
.sets-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.card-heading h2,
.sets-heading h3 {
    margin-bottom: 0;
}

.text-button {
    min-height: 44px;
    padding: 0.5rem;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.danger-text {
    color: var(--danger);
}

label {
    display: grid;
    gap: 0.4rem;
    font-weight: 650;
}

label > span {
    font-size: 0.92rem;
}

small {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 450;
}

input,
select,
textarea {
    width: 100%;
    min-height: 48px;
    padding: 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    outline: none;
    background: #101214;
    color: var(--text);
}

select {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) 20px, calc(100% - 13px) 20px;
    background-repeat: no-repeat;
    background-size: 5px 5px, 5px 5px;
    padding-right: 2.5rem;
}

textarea {
    min-height: 84px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
.button:focus-visible,
.text-button:focus-visible,
.header-action:focus-visible,
a:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--focus) 45%, transparent);
    outline-offset: 2px;
    border-color: var(--focus);
}

[hidden] {
    display: none !important;
}

.number-with-unit {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.number-with-unit input {
    flex: 1;
}

.number-with-unit > span {
    color: var(--muted);
    font-weight: 500;
}

.sets-list {
    display: grid;
    gap: 0.75rem;
}

.set-card {
    display: grid;
    gap: 0.85rem;
    padding: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #141719;
}

.set-numbers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.form-actions {
    position: sticky;
    bottom: 0;
    padding: 0.75rem 0 calc(0.75rem + env(safe-area-inset-bottom));
    background: linear-gradient(to bottom, transparent, var(--background) 25%);
}

.progress-section {
    margin-top: 1.5rem;
}

.progress-section > h2 {
    margin-bottom: 0.75rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px;
    overflow: hidden;
    margin: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--border);
}

.stats-grid div {
    min-width: 0;
    padding: 0.85rem;
    background: var(--surface);
}

.stats-grid dt {
    margin-bottom: 0.2rem;
    color: var(--muted);
    font-size: 0.78rem;
}

.stats-grid dd {
    margin: 0;
    font-size: 1rem;
    font-weight: 750;
    overflow-wrap: anywhere;
}

.chart-grid,
.session-list {
    display: grid;
    gap: 0.85rem;
}

.chart-card,
.session-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.chart-card {
    padding: 0.85rem;
}

.chart-card h3 {
    margin-bottom: 0.4rem;
}

.chart-wrap {
    position: relative;
    height: 210px;
}

.session-card {
    overflow: hidden;
}

.session-card summary {
    display: grid;
    gap: 0.2rem;
    min-height: 72px;
    padding: 1rem 2.5rem 1rem 1rem;
    cursor: pointer;
    list-style-position: outside;
}

.session-card summary span {
    color: var(--muted);
    font-size: 0.88rem;
}

.session-card[open] summary {
    border-bottom: 1px solid var(--border);
}

.history-sets,
.session-card .exercise-note,
.history-link {
    margin-right: 1rem;
    margin-left: 1rem;
}

.history-sets {
    padding-top: 0.4rem;
}

.history-link {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
    color: var(--muted);
    font-size: 0.9rem;
}

@media (min-width: 640px) {
    .site-header {
        padding-inline: 1.5rem;
    }

    .container {
        padding-top: 2rem;
    }

    .page-heading,
    .detail-heading {
        flex-direction: row;
        align-items: flex-end;
        justify-content: space-between;
    }

    .heading-actions {
        display: flex;
    }

    .page-heading .button,
    .detail-heading .button {
        flex: 0 0 auto;
    }

    .workout-row,
    .progress-row {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    .form-section,
    .exercise-card {
        padding: 1.25rem;
    }

    .workout-fields {
        grid-template-columns: minmax(180px, 0.55fr) 1fr;
        align-items: start;
    }


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

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