:root {
    --frame-width: 393px;
    --frame-height: 852px;
    --page-padding-x: 24px;
    --page-padding-top: max(16px, env(safe-area-inset-top));
    --page-padding-bottom: 24px;
    --section-gap: 16px;
    --single-bg: #c20707;
    --multi-bg: #1c1010;
    --text: #ffffff;
    --border: #ffffff;
    --muted: rgba(255, 255, 255, 0.72);
    --dimmed: rgba(255, 255, 255, 0.46);
    --font-family: "JetBrains Mono", monospace;
    --header-size: 20px;
    --mode-size: 12px;
    --single-label-size: 15px;
    --single-value-size: clamp(36px, 13vw, 54px);
    --single-value-line: 0.96;
    --single-field-gap: clamp(18px, 4vh, 30px);
    --single-control-height: 48px;
    --single-footer-gap: 18px;
    --single-circle-size: clamp(84px, 25vw, 102px);
    --single-reset-height: 22px;
    --multi-content-width: 345px;
    --multi-panel-height: 574px;
    --multi-chart-width: 172.5px;
    --multi-handle-height: 12px;
    --multi-rule: rgba(255, 255, 255, 0.92);
    --mp-header-h: 48px;
    --mp-total-h: 48px;
    --mp-footer-h: 112px;
    --mp-gap: 16px;
    --mp-panel-h: calc(
        100dvh
        - var(--mp-header-h)
        - var(--mp-total-h)
        - var(--mp-footer-h)
        - (var(--mp-gap) * 3)
    );
}

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

html,
body {
    min-height: 100%;
}

body {
    background: var(--single-bg);
    color: var(--text);
    font-family: var(--font-family);
    font-feature-settings: "tnum" 1;
    font-variant-numeric: tabular-nums slashed-zero;
    transition: background-color 160ms ease;
}

body.is-multi-pace {
    background: var(--multi-bg);
}

button,
input {
    font: inherit;
}

button {
    border: 0;
    background: none;
    color: inherit;
}

[hidden] {
    display: none !important;
}

.ctds-app {
    position: relative;
    width: min(100vw, var(--frame-width));
    min-height: min(100dvh, var(--frame-height));
    margin: 0 auto;
    padding: var(--page-padding-top) var(--page-padding-x) var(--page-padding-bottom);
    display: flex;
    flex-direction: column;
    gap: var(--section-gap);
}

.ctds-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 26px;
}

.ctds-header-title {
    font-size: var(--header-size);
    font-weight: 500;
    line-height: 1.25;
    white-space: nowrap;
}

.ctds-mode-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.ctds-mode-label {
    font-size: var(--mode-size);
    line-height: 1;
}

.ctds-mode-switch-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: 1px solid var(--border);
    padding: 0;
    overflow: hidden;
}

.ctds-mode-btn {
    min-width: 50px;
    height: 24px;
    padding: 0 4px;
    border: 0;
    font-size: var(--mode-size);
    line-height: 1;
    cursor: pointer;
}

.ctds-mode-btn + .ctds-mode-btn {
    margin-left: 0;
}

body .ctds-mode-btn.is-active {
    background: var(--text);
    color: var(--single-bg);
    font-weight: 500;
}

body.is-multi-pace .ctds-mode-btn.is-active {
    background: var(--text);
    color: var(--multi-bg);
    font-weight: 500;
}

.ctds-mode-btn:focus-visible,
.ctds-toggle:focus-visible,
.ctds-circle:focus-visible,
.ctds-action-btn:focus-visible,
.ctds-reset-btn:focus-visible,
.ctds-multi-zone:focus-visible,
.mp-sheet-input:focus-visible,
.mp-sheet-confirm:focus-visible,
.ctds-multi-divider:focus-visible {
    outline: 1px solid rgba(255, 255, 255, 0.96);
    outline-offset: 2px;
}

.ctds-single-shell,
.ctds-multi-shell {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.ctds-multi-shell {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
}

.ctds-main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: var(--single-field-gap);
    min-height: 0;
    padding: 10px 0 12px;
}

.ctds-field {
    display: grid;
    grid-template-columns: minmax(66px, auto) minmax(0, 1fr);
    align-items: end;
    column-gap: 12px;
    width: 100%;
}

.ctds-label {
    justify-self: start;
    align-self: end;
    font-size: var(--single-label-size);
    line-height: 1.15;
    color: var(--muted);
    padding-bottom: 8px;
    white-space: nowrap;
}

.ctds-value {
    width: 100%;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    text-align: right;
    font-size: var(--single-value-size);
    line-height: var(--single-value-line);
    letter-spacing: -0.07em;
    caret-color: var(--text);
}

.ctds-field--time .ctds-value {
    max-width: 8.4ch;
    justify-self: end;
}

.ctds-field--distance .ctds-value,
.ctds-field--speed .ctds-value {
    max-width: 5.65ch;
    justify-self: end;
}

.ctds-field--pace .ctds-value {
    max-width: 5.1ch;
    justify-self: end;
}

.ctds-value::placeholder {
    color: currentColor;
    opacity: 1;
}

.ctds-value:disabled {
    cursor: not-allowed;
    -webkit-text-fill-color: currentColor;
    opacity: 1;
}

.ctds-field.is-target .ctds-label,
.ctds-field.is-target .ctds-value {
    color: var(--dimmed);
}

.ctds-field.is-nontarget .ctds-label,
.ctds-field.is-nontarget .ctds-value {
    color: var(--text);
}

.ctds-controls {
    display: flex;
    flex-direction: column;
    gap: var(--single-footer-gap);
}

.ctds-toggle-row {
    display: flex;
}

.ctds-toggle {
    flex: 1 1 50%;
    height: var(--single-control-height);
    border: 1px solid var(--border);
    font-size: 16px;
    line-height: 1;
    text-transform: uppercase;
    cursor: pointer;
}

.ctds-toggle + .ctds-toggle {
    margin-left: -1px;
}

.ctds-toggle.is-active {
    background: var(--text);
    color: var(--single-bg);
}

.ctds-circles {
    display: flex;
    justify-content: space-between;
    gap: 14px;
}

.ctds-circle {
    flex: 1 1 0;
    min-width: 0;
    aspect-ratio: 1 / 1;
    max-width: var(--single-circle-size);
    border: 1px solid var(--border);
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    text-transform: uppercase;
    text-align: center;
    font-size: 15px;
    line-height: 1.15;
    cursor: pointer;
}

.ctds-circle.is-active {
    background: var(--text);
    color: var(--single-bg);
}

.ctds-reset,
.ctds-reset--multi {
    display: flex;
    align-items: center;
    min-height: var(--single-reset-height);
}

.ctds-reset-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 22px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}

.ctds-reset-icon {
    font-size: 22px;
    line-height: 1;
}

.ctds-announcer {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.ctds-multi-main {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.ctds-multi-status {
    min-height: 0;
    padding-top: 2px;
}

.ctds-multi-message {
    font-size: 12px;
    line-height: 1.35;
}

.ctds-multi-message + .ctds-multi-message {
    margin-top: 6px;
}

.ctds-multi-message--error {
    color: #ffb7b7;
}

.ctds-multi-message--warning {
    color: rgba(255, 255, 255, 0.82);
}

.ctds-multi-empty {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    width: var(--multi-content-width);
    margin: 0 auto;
    text-align: center;
}

.ctds-multi-hint {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 12px;
    line-height: 1.4;
    color: var(--muted);
}

.ctds-action-btn {
    height: 48px;
    border: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 12px;
    color: var(--text);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
}

.ctds-action-btn--full {
    width: 100%;
}

.ctds-action-btn--active,
.ctds-action-btn.is-active {
    background: var(--text);
    color: var(--multi-bg);
}

.ctds-action-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ctds-multi-loaded {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ctds-multi-panel {
    width: var(--multi-content-width);
    height: var(--mp-panel-h);
    max-height: var(--mp-panel-h);
    overflow: hidden;
    flex-shrink: 0;
    display: grid;
    grid-template-columns: var(--multi-chart-width) var(--multi-chart-width);
    margin: 0 auto;
    border-top: 1px solid var(--multi-rule);
    border-bottom: 1px solid var(--multi-rule);
}

.ctds-multi-chart-region {
    height: 100%;
    overflow: hidden;
    position: relative;
    border-right: 1px solid var(--multi-rule);
}

.ctds-multi-zones {
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.ctds-multi-chart-bars {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow: hidden;
}

.ctds-multi-bar {
    flex: 1 1 0;
    min-height: 1px;
    border-left: none;
    background: var(--text);
}

.ctds-multi-boundary {
    position: absolute;
    left: 0;
    width: 200%;
    height: 1px;
    background: rgba(255, 255, 255, 0.6);
    pointer-events: none;
    z-index: 10;
}

.ctds-multi-zones {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: transparent;
}
.ctds-multi-zone {
    position: relative;
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--multi-rule);
    padding: 10px 8px;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    min-height: 0;
}

.ctds-multi-zone:first-child {
    border-top: 0;
}

.ctds-multi-zone.is-selected {
    background: transparent;
}

.ctds-multi-zone-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: end;
    width: 100%;
}

.ctds-multi-zone-copy {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.ctds-multi-zone-title-row {
    display: flex;
    justify-content: flex-start;
    gap: 4px;
    font-size: 12px;
    line-height: 1.25;
}

.ctds-multi-zone-title {
    font-weight: 500;
    white-space: nowrap;
}

.ctds-multi-zone-distance {
    color: var(--muted);
    white-space: nowrap;
}

.ctds-multi-zone-duration {
    font-size: 14px;
    line-height: 1.2;
}

.ctds-multi-zone-value {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    min-width: 70px;
}

.ctds-multi-zone-pace {
    font-size: 22px;
    line-height: 1;
}

.ctds-multi-zone-speed {
    font-size: 12px;
    line-height: 1.2;
    color: var(--muted);
}

.ctds-multi-divider {
    position: relative;
    display: block;
    width: 100%;
    height: 44px;
    margin: -16px 0;
    border: 0;
    cursor: row-resize;
    touch-action: none;
    z-index: 1;
}

.ctds-multi-divider::before,
.ctds-multi-divider::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px solid var(--multi-rule);
}

.ctds-multi-divider::before {
    top: calc(50% - (var(--multi-handle-height) / 2));
}

.ctds-multi-divider::after {
    top: calc(50% + (var(--multi-handle-height) / 2));
}

.ctds-multi-divider-handle {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 1px;
    background: var(--text);
    transform: translate(-50%, -50%);
}

.ctds-multi-total {
    width: var(--multi-content-width);
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
    padding: 8px 0;
}

.ctds-multi-total-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ctds-multi-total-label {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ctds-multi-total-value {
    font-size: 22px;
    line-height: 1;
}

.mp-chart-tooltip {
    position: absolute;
    left: 105%;
    background: var(--text);
    color: var(--multi-bg);
    font-size: 11px;
    font-family: var(--font-family);
    padding: 2px 5px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 20;
    transform: translateY(-50%);
}

.ctds-multi-footer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.ctds-multi-actions {
    width: var(--multi-content-width);
    display: flex;
    margin: 0 auto;
}

.ctds-multi-actions .ctds-action-btn {
    flex: 1 1 50%;
}

.ctds-multi-actions .ctds-action-btn + .ctds-action-btn {
    margin-left: -1px;
}

.ctds-reset--multi {
    width: var(--multi-content-width);
    min-height: 22px;
    margin: 0 auto;
}

.mp-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
}

.mp-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #1C1010;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    z-index: 101;
    padding: 24px 24px env(safe-area-inset-bottom, 16px);
    transform: translateY(100%);
    transition: transform 200ms ease;
}

.mp-sheet.is-open {
    transform: translateY(0);
}

.mp-sheet-inner {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mp-sheet-label {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.6);
    white-space: nowrap;
    flex-shrink: 0;
}

.mp-sheet-input {
    flex: 1;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: #ffffff;
    font-family: var(--font-family);
    font-size: 32px;
    font-weight: 700;
    text-align: center;
    padding: 8px;
    min-width: 0;
}

.mp-sheet-input:focus {
    outline: none;
    border-color: #ffffff;
}

.mp-sheet-confirm {
    height: 48px;
    padding: 0 20px;
    background: #ffffff;
    color: #1C1010;
    border: none;
    font-family: var(--font-family);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
}

@media (max-width: 420px) {
    :root {
        --single-value-size: clamp(34px, 12.4vw, 50px);
        --single-label-size: 14px;
        --single-field-gap: clamp(17px, 3.8vh, 26px);
    }

    .ctds-field {
        grid-template-columns: minmax(58px, auto) minmax(0, 1fr);
        column-gap: 10px;
    }

    .ctds-circles {
        gap: 12px;
    }

    .ctds-circle {
        font-size: 14px;
    }
}

@supports not (height: 100dvh) {
    .ctds-app {
        min-height: min(100vh, var(--frame-height));
    }
}
