:root {
    color-scheme: dark light;
    --bg: #0e1014;
    --panel: #181b22;
    --panel-2: #22262f;
    --text: #f6f7f9;
    --muted: #a9b0bd;
    --line: #303642;
    --accent: #e6f45f;
    --accent-2: #61d394;
    --danger: #ff6b6b;
    --shadow: 0 18px 40px rgba(0, 0, 0, .28);
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f4f5f7;
        --panel: #ffffff;
        --panel-2: #eceff3;
        --text: #13161d;
        --muted: #606977;
        --line: #dce1e8;
        --shadow: 0 14px 34px rgba(35, 45, 60, .12);
    }
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
    margin: 0;
    color: var(--text);
    background: linear-gradient(180deg, rgba(97, 211, 148, .08), transparent 24rem), var(--bg);
}

body.modal-open {
    overflow: hidden;
    touch-action: none;
}

button,
input,
select {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

.app-shell {
    width: min(100%, 760px);
    min-height: 100svh;
    margin: 0 auto;
    padding: max(18px, env(safe-area-inset-top)) 16px calc(92px + env(safe-area-inset-bottom));
}

.app-shell--center {
    display: grid;
    place-items: center;
    padding-bottom: max(18px, env(safe-area-inset-bottom));
}

.screen,
.auth-panel,
.onboarding {
    width: 100%;
}

.auth-panel {
    max-width: 440px;
    padding: 28px 22px;
    background: rgba(24, 27, 34, .92);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    margin-bottom: 24px;
    border-radius: 8px;
    background: var(--accent);
    color: #111318;
    font-weight: 900;
}

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

h1 {
    margin-bottom: 22px;
    font-size: 2rem;
    line-height: 1.05;
}

h2 {
    margin-bottom: 0;
    font-size: 1.2rem;
}

.kicker {
    margin-bottom: 6px;
    color: var(--accent);
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.stack {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 8px;
}

label span,
.metrics-grid span,
.connections span {
    color: var(--muted);
    font-size: .92rem;
}

input,
select {
    width: 100%;
    min-height: 52px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 14px;
    background: var(--panel);
    color: var(--text);
}

.primary-button,
.secondary-button,
.start-button,
.icon-button,
.segmented button,
.user-button,
.text-button {
    min-height: 52px;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 900;
}

.primary-button,
.start-button {
    display: grid;
    place-items: center;
    width: 100%;
    background: var(--accent);
    color: #111318;
    text-transform: uppercase;
}

.secondary-button,
.segmented button,
.text-button {
    background: var(--panel-2);
    color: var(--text);
}

.auth-question {
    margin-bottom: 14px;
    color: var(--muted);
    font-weight: 800;
}

.user-select-grid {
    display: grid;
    gap: 14px;
}

.user-button {
    width: 100%;
    min-height: 72px;
    background: var(--accent);
    color: #111318;
    font-size: 1.2rem;
}

.switch-form {
    margin-top: 14px;
}

.text-button {
    width: 100%;
}

.icon-button {
    width: 48px;
    min-height: 48px;
    background: var(--panel-2);
    color: var(--text);
}

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    background: rgba(255, 107, 107, .14);
    color: var(--danger);
}

.alert.success {
    background: rgba(97, 211, 148, .16);
    color: var(--accent-2);
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.phase-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-height: 136px;
    padding: 20px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--panel), #252a30);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.phase-panel p {
    margin-bottom: 8px;
    color: var(--muted);
}

.ring {
    display: grid;
    place-items: center;
    flex: 0 0 70px;
    width: 70px;
    height: 70px;
    border: 8px solid var(--accent);
    border-radius: 50%;
    color: var(--accent);
    font-weight: 900;
}

.start-button {
    min-height: 68px;
    margin: 18px 0;
    font-size: 1.05rem;
}

.metrics-grid,
.tabs,
.connections {
    display: grid;
    gap: 12px;
}

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

.metrics-grid article,
.tabs section,
.connections article,
.settings-panel {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(24, 27, 34, .86);
}

.metrics-grid strong {
    display: block;
    margin-top: 10px;
    font-size: 1.35rem;
}

.bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 3px;
    max-width: 760px;
    margin: 0 auto;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    background: rgba(14, 16, 20, .92);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(16px);
}

.bottom-nav a {
    display: grid;
    gap: 3px;
    place-items: center;
    min-height: 58px;
    border-radius: 8px;
    color: var(--muted);
    font-size: .68rem;
    font-weight: 800;
}

.bottom-nav span {
    font-size: 1rem;
}

.bottom-nav a.active {
    background: var(--panel-2);
    color: var(--text);
}

.progress-line {
    height: 8px;
    overflow: hidden;
    margin-bottom: 18px;
    border-radius: 999px;
    background: var(--panel-2);
}

.progress-line span {
    display: block;
    height: 100%;
    background: var(--accent);
}

.picker-grid,
.choice-grid {
    display: grid;
    gap: 10px;
}

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

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

.choice-grid.five {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.choice input {
    position: absolute;
    opacity: 0;
}

.choice span {
    display: grid;
    align-items: center;
    min-height: 54px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    font-weight: 800;
}

.choice input:checked + span {
    border-color: var(--accent);
    background: rgba(230, 244, 95, .14);
}

.button-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 8px;
}

.button-row .primary-button:only-child {
    grid-column: 1 / -1;
}

.fieldset {
    margin: 0;
    padding: 0;
    border: 0;
}

.fieldset legend,
.connections h2 {
    margin-bottom: 10px;
    font-weight: 900;
}

.finish-note {
    padding: 18px;
    border-radius: 8px;
    background: var(--panel);
    color: var(--muted);
    line-height: 1.5;
}

.segmented {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.segmented button {
    min-height: 44px;
    font-size: .82rem;
}

.settings-panel {
    display: grid;
    gap: 14px;
    margin-bottom: 22px;
}

.settings-panel h2 {
    margin-bottom: 2px;
}

.connections article {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.connections article.connection-detail {
    display: grid;
    gap: 14px;
}

.connection-detail > div:first-child,
.connection-meta div,
.connection-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.connection-meta {
    display: grid;
    gap: 8px;
    margin: 0;
}

.connection-meta dt {
    color: var(--muted);
    font-size: .82rem;
    font-weight: 800;
}

.connection-meta dd {
    margin: 0;
    text-align: right;
    font-weight: 800;
}

.pairing-box {
    display: grid;
    gap: 7px;
    padding: 14px;
    border: 1px solid rgba(230, 244, 95, .32);
    border-radius: 8px;
    background: rgba(230, 244, 95, .1);
}

.pairing-box strong {
    font-size: 2.2rem;
    line-height: 1;
    letter-spacing: .12em;
}

.pairing-box small,
.pairing-box p,
.connection-counts span {
    color: var(--muted);
}

.pairing-box p {
    margin: 0;
}

.connection-counts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.connection-counts span {
    padding: 7px 9px;
    border-radius: 8px;
    background: var(--panel-2);
    font-size: .82rem;
    font-weight: 800;
}

.connection-actions {
    align-items: stretch;
}

.connection-actions form {
    flex: 1;
}

.strava-button {
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 52px;
    border: 0;
    border-radius: 8px;
    background: #fc4c02;
    color: #fff;
    cursor: pointer;
    font-weight: 900;
}

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

.segmented a {
    display: grid;
    place-items: center;
    min-height: 44px;
    border-radius: 8px;
    background: var(--panel-2);
    color: var(--muted);
    font-size: .82rem;
    font-weight: 800;
}

.segmented a.active {
    background: var(--accent);
    color: #111318;
}

.activity-list {
    display: grid;
    gap: 10px;
}

.activity-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.activity-row div:last-child {
    text-align: right;
}

.activity-row span {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: .86rem;
}

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

.mini-action {
    display: grid;
    place-items: center;
    min-height: 48px;
    padding: 0 14px;
    border-radius: 8px;
    background: var(--accent);
    color: #111318;
    font-weight: 900;
    white-space: nowrap;
}

.plan-secondary-link {
    display: grid;
    place-items: center;
    width: 100%;
    margin: -6px 0 18px;
}

.plan-screen {
    display: grid;
    gap: 16px;
}

.plan-phase,
.plan-workout-card,
.plan-exercise-card,
.plan-stat-grid article {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(24, 27, 34, .86);
}

.plan-phase {
    display: grid;
    gap: 12px;
    padding: 16px;
}

.plan-phase-header,
.plan-workout-card,
.plan-exercise-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.plan-phase-header > span,
.status-label,
.plan-exercise-head p {
    color: var(--muted);
    font-size: .82rem;
    font-weight: 800;
}

.habituation-steps,
.workout-chips,
.plan-prescription-grid,
.plan-stat-grid {
    display: grid;
    gap: 8px;
}

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

.plan-pill,
.workout-chips span {
    display: grid;
    place-items: center;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--muted);
    font-weight: 900;
}

.plan-pill.current,
.week-row.current {
    border-color: var(--accent);
    color: var(--text);
}

.plan-pill.completed,
.week-row.completed {
    border-color: rgba(97, 211, 148, .55);
}

.week-list,
.plan-workout-list,
.plan-exercise-list {
    display: grid;
    gap: 10px;
}

.week-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 10px;
    min-height: 58px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.week-title {
    font-weight: 900;
}

.workout-chips {
    grid-template-columns: repeat(3, 34px);
}

.workout-chips span {
    min-height: 34px;
}

.workout-chips span.completed {
    border-color: rgba(97, 211, 148, .55);
    color: var(--accent-2);
}

.workout-chips span.current {
    border-color: var(--accent);
    color: var(--text);
}

.workout-chips span.upcoming {
    border-color: var(--line);
    color: var(--muted);
}

.plan-week-hero {
    min-height: 110px;
}

.plan-workout-card {
    min-height: 74px;
    padding: 16px;
}

.plan-workout-card.current {
    border-color: var(--accent);
}

.plan-workout-card.completed {
    border-color: rgba(97, 211, 148, .55);
}

.plan-workout-card span:first-child,
.plan-stat-grid span {
    color: var(--muted);
    font-size: .88rem;
    font-weight: 800;
}

.plan-workout-card strong,
.plan-stat-grid strong {
    display: block;
    margin-top: 5px;
}

.plan-exercise-card {
    display: grid;
    gap: 12px;
    padding: 14px;
}

.plan-exercise-head {
    justify-content: flex-start;
}

.plan-exercise-head > span {
    display: grid;
    place-items: center;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: var(--panel-2);
    font-weight: 900;
}

.plan-exercise-head h2 {
    margin-bottom: 4px;
}

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

.plan-prescription-grid span {
    padding: 10px;
    border-radius: 8px;
    background: var(--panel-2);
    font-weight: 900;
}

.plan-stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 16px;
}

.plan-stat-grid article {
    padding: 14px;
}

.strength-list {
    display: grid;
    gap: 10px;
}

.strength-row {
    display: grid;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.strength-row h3,
.strength-row p {
    margin: 0;
}

.strength-row p {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.strength-row span {
    color: var(--muted);
    font-weight: 800;
}

.set-target,
.last-set-line {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 800;
}

.history-list {
    display: grid;
    gap: 10px;
    margin-top: 22px;
}

.history-row,
.history-detail {
    display: grid;
    gap: 8px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(24, 27, 34, .86);
}

.history-row {
    grid-template-columns: 1fr 1.3fr 1.2fr 1fr 1fr;
    align-items: center;
    font-size: .88rem;
}

.compact-workout {
    max-width: 620px;
    margin: 0 auto;
}

.workout-screen {
    padding-bottom: 120px;
}

.workout-header {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
}

.workout-header h1 {
    margin-bottom: 6px;
    font-size: clamp(2rem, 10vw, 4.5rem);
    line-height: .95;
    overflow-wrap: anywhere;
}

.workout-menu {
    position: relative;
}

.workout-menu summary {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 8px;
    background: var(--panel-2);
    cursor: pointer;
    list-style: none;
    font-size: 1.8rem;
    font-weight: 900;
}

.workout-menu summary::-webkit-details-marker {
    display: none;
}

.workout-menu > div {
    position: absolute;
    right: 0;
    z-index: 20;
    width: min(86vw, 340px);
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.today-card,
.calibration-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}

.today-card > div,
.calibration-row {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.today-card span,
.calibration-row span,
.save-state {
    display: block;
    color: var(--muted);
    font-size: .84rem;
}

.today-card strong,
.calibration-row strong {
    display: block;
    margin-top: 6px;
    font-size: 1.35rem;
}

.calibration-row {
    grid-template-columns: 1fr;
}

.set-list {
    display: grid;
    gap: 14px;
}

.set-card {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(24, 27, 34, .94);
}

.set-card.is-done {
    border-color: rgba(97, 211, 148, .55);
}

.set-title {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.picker-row {
    display: grid;
    grid-template-columns: 74px 1fr 74px;
    gap: 8px;
    margin-bottom: 10px;
}

.picker-row button,
.rir-row button {
    min-height: 54px;
    border: 0;
    border-radius: 8px;
    background: var(--panel-2);
    color: var(--text);
    font-weight: 900;
}

.wheel-value {
    height: 54px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    text-align: center;
    font-size: 1.35rem;
    font-weight: 900;
}

.rir-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

.rir-row button.active {
    background: var(--accent);
    color: #111318;
}

.rir-hint {
    margin-bottom: 10px;
    color: var(--accent);
    font-weight: 800;
}

.set-actions {
    display: grid;
    gap: 8px;
}

.set-actions .primary-button[disabled] {
    opacity: .5;
}

.inline-check {
    display: flex;
    align-items: center;
    gap: 10px;
}

.inline-check input {
    width: 22px;
    min-height: 22px;
}

.rest-overlay {
    position: fixed;
    right: 16px;
    bottom: calc(92px + env(safe-area-inset-bottom));
    left: 16px;
    z-index: 30;
    display: grid;
    gap: 12px;
    max-width: 520px;
    margin: 0 auto;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(14, 16, 20, .96);
    box-shadow: var(--shadow);
}

.rest-time {
    font-size: 4rem;
    line-height: 1;
    font-weight: 900;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.pause-form {
    margin-top: 16px;
}

.increment-form {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.increment-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.increment-grid .choice span {
    min-height: 44px;
    padding: 9px;
    text-align: center;
    font-size: .86rem;
}

.wheel-sheet[hidden] {
    display: none;
}

.wheel-sheet {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    align-items: end;
}

.wheel-backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(0, 0, 0, .46);
}

.wheel-panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    padding: 10px 16px calc(18px + env(safe-area-inset-bottom));
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    background: rgba(24, 27, 34, .98);
    box-shadow: var(--shadow);
}

.wheel-handle {
    width: 42px;
    height: 5px;
    margin: 0 auto 12px;
    border-radius: 999px;
    background: var(--line);
}

.wheel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 12px;
}

.wheel-title {
    font-size: 1.05rem;
}

.wheel-close {
    width: auto;
    min-height: 42px;
    padding: 0 14px;
}

.wheel-frame {
    position: relative;
    height: min(42svh, 320px);
    overflow: hidden;
}

.wheel-list {
    height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    scroll-snap-type: y mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.wheel-list::-webkit-scrollbar {
    display: none;
}

.wheel-spacer {
    height: calc((min(42svh, 320px) - 58px) / 2);
}

.wheel-item {
    display: grid;
    place-items: center;
    width: 100%;
    height: 58px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    scroll-snap-align: center;
    font-size: 1.5rem;
    font-weight: 800;
    opacity: .45;
    transform: scale(.92);
    transition: opacity .14s ease, transform .14s ease, color .14s ease, background .14s ease;
}

.wheel-item.near {
    opacity: .7;
}

.wheel-item.selected {
    background: rgba(230, 244, 95, .12);
    color: var(--text);
    opacity: 1;
    transform: scale(1.08);
}

.wheel-center-line {
    position: absolute;
    top: 50%;
    right: 0;
    left: 0;
    z-index: 1;
    height: 58px;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    transform: translateY(-50%);
    pointer-events: none;
}

@media (min-width: 680px) {
    .app-shell {
        padding-top: 32px;
    }

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

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

@media (max-width: 420px) {
    .picker-grid {
        grid-template-columns: 1fr;
    }

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

    .history-row {
        grid-template-columns: 1fr 1fr;
    }

    .today-card {
        grid-template-columns: 1fr;
    }
}
