/* Mässiv – klassischer iOS-Stil (iOS 16–18), ohne Blur und Transparenz-Ebenen. */

:root {
    color-scheme: light dark;

    --bg: #F2F2F7;
    --cell: #FFFFFF;
    --cell-pressed: #D1D1D6;
    --text: #000000;
    --text-secondary: rgba(60, 60, 67, 0.6);
    --text-tertiary: rgba(60, 60, 67, 0.3);
    --separator: rgba(60, 60, 67, 0.29);
    --accent: #D35400;
    --on-accent: #FFFFFF;       /* Schrift auf Akzentflächen */
    --success: #34C759;
    --success-fill: #E9F9EE;
    --on-success: #000000;      /* Schrift auf grünen Flächen: Weiss auf #34C759 wäre zu schwach */
    --destructive: #FF3B30;
    --pending: var(--text-secondary); /* «Nicht synchronisiert»: grau mit Uhr, nicht orange */
    --tabbar: #F9F9F9;
    --inactive: #999999;

    /* Muskel-Schema: Grundfarbe, Haupt-/Nebenmuskel, Stufen 1–4 (deckend, ohne Transparenz) */
    --map-body: #D1D1D6;
    --map-primary: var(--accent);
    --map-secondary: #EDBB99;
    --map-1: #F3CFB8;
    --map-2: #E9AA80;
    --map-3: #DE7F40;
    --map-4: var(--accent);

    /* Uhr-Symbol als Maske, eingefärbt über background */
    --clock-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9.5'/%3E%3Cpath d='M12 6.5V12l3.5 2.5'/%3E%3C/svg%3E");

    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
    --radius: 10px;
    --gutter: 16px;
    --hairline: 0.5px solid var(--separator);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;
        --cell: #1C1C1E;
        --cell-pressed: #3A3A3C;
        --text: #FFFFFF;
        --text-secondary: rgba(235, 235, 245, 0.6);
        --text-tertiary: rgba(235, 235, 245, 0.3);
        --separator: rgba(84, 84, 88, 0.65);
        --accent: #FF8A1F;
        --on-accent: #000000;   /* Weiss auf diesem Orange wäre zu schwach */
        --success: #30D158;
        --success-fill: #0F2A17;
        --destructive: #FF453A;
        --tabbar: #121212;
        --inactive: #8E8E93;

        --map-body: #3A3A3C;
        --map-primary: var(--accent);
        --map-secondary: #B0641F;
        --map-1: #69411E;
        --map-2: #99581F;
        --map-3: #CD721F;
        --map-4: var(--accent);
    }
}

*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 17px;
    line-height: 1.3;
    letter-spacing: -0.41px;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; letter-spacing: inherit; color: inherit; }
/* Kein Doppeltipp-Zoom auf Bedienelementen; Pinch-Zoom bleibt für die Barrierefreiheit erhalten.
   Eingabefelder haben mindestens 16px Schrift, sonst zoomt iOS beim Antippen. */
a, button, input, label, select, summary, textarea, .stepper, .set-row { touch-action: manipulation; }
code { font-size: 15px; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Navigationsleiste mit Large Title */

.navbar {
    padding-top: env(safe-area-inset-top);
    background: var(--bg);
}

.navbar-row {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 8px;
}

.navbar-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 44px;
    min-width: 44px;
    padding: 0 8px 0 0;
    font-size: 17px;
}

.chevron-left {
    width: 12px;
    height: 12px;
    border-left: 3px solid currentColor;
    border-bottom: 3px solid currentColor;
    border-radius: 1px;
    transform: rotate(45deg);
    margin: 0 2px 0 6px;
}

.large-title {
    margin: 0;
    padding: 2px var(--gutter) 8px;
    font-size: 34px;
    font-weight: 700;
    line-height: 41px;
    letter-spacing: 0.37px;
}

/* Inhalt */

.content {
    padding: 8px var(--gutter) calc(32px + env(safe-area-inset-bottom));
    max-width: 680px;
    margin: 0 auto;
}

.has-tabs .content {
    padding-bottom: calc(49px + 32px + env(safe-area-inset-bottom));
}

.message {
    margin: 16px 4px;
    color: var(--text-secondary);
    font-size: 15px;
}

/* Inset-Grouped-Listen */

.list {
    list-style: none;
    margin: 0 0 8px;
    padding: 0;
    background: var(--cell);
    border-radius: var(--radius);
    overflow: hidden;
}

.list-spacer { margin-top: 35px; }
.list + .list { margin-top: 35px; }

.cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 44px;
    padding: 11px var(--gutter);
    color: var(--text);
    background: var(--cell);
}

/* Haarlinie zwischen Zeilen, links eingerückt wie bei iOS */
.list > li { position: relative; }
.list > li + li::before {
    content: "";
    position: absolute;
    z-index: 1;
    top: 0;
    left: var(--gutter);
    right: 0;
    border-top: var(--hairline);
}

.cell-link { padding-right: 34px; }
.cell-link::after {
    content: "";
    position: absolute;
    right: 18px;
    top: 50%;
    width: 8px;
    height: 8px;
    margin-top: -4px;
    border-top: 2px solid var(--text-tertiary);
    border-right: 2px solid var(--text-tertiary);
    transform: rotate(45deg);
}

a.cell:active, button.cell:active, label.cell:active { background: var(--cell-pressed); }

.cell-value {
    color: var(--text-secondary);
    text-align: right;
}

/* Beim Beenden ausgelassene Übung */
.cell-skipped { color: var(--text-secondary); }

.cell-button {
    width: 100%;
    border: 0;
    margin: 0;
    text-align: left;
    cursor: pointer;
    justify-content: flex-start;
}

/* Trainingstag auf der Startseite: grüner Chip «▶ Start» statt Chevron */
.cell-start { justify-content: space-between; }
.start-chip {
    flex: 0 0 auto;
    padding: 6px 12px;
    border-radius: 14px;
    background: var(--success);
    color: var(--on-success);
    font-size: 15px;
    font-weight: 600;
    line-height: 18px;
    white-space: nowrap;
}

.cell-accent { color: var(--accent); }
.cell-destructive { color: var(--destructive); }
.text-secondary { color: var(--text-secondary); }
.nowrap { white-space: nowrap; } /* Zahl und Einheit nie trennen */

.cell-wrap { word-break: break-all; }
.link-text { font-size: 15px; color: var(--text-secondary); }

.cell-input label {
    flex: 0 0 auto;
    min-width: 90px;
}

.cell-input input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    margin: -11px 0;
    border: 0;
    background: transparent;
    text-align: right;
    outline: none;
}

.cell-input input::placeholder { color: var(--text-tertiary); }

.cell-choice { cursor: pointer; }
.cell-choice input { position: absolute; opacity: 0; pointer-events: none; }
.cell-choice .checkmark {
    width: 8px;
    height: 15px;
    margin-right: 6px;
    border-right: 2.5px solid var(--accent);
    border-bottom: 2.5px solid var(--accent);
    transform: rotate(45deg) translate(-2px, -2px);
    visibility: hidden;
}
.cell-choice input:checked ~ .checkmark { visibility: visible; }
.cell-choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }

.steps { counter-reset: step; }
.steps .cell { justify-content: flex-start; }
.steps .cell::after {
    counter-increment: step;
    content: counter(step);
    order: -1;
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border-radius: 12px;
    background: var(--accent);
    color: var(--on-accent);
    font-size: 15px;
    font-weight: 600;
    line-height: 24px;
    text-align: center;
}

/* Abschnittstitel über einer Box (iOS «prominent header»); Hinweise darunter: .section-footer */
.section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin: 30px var(--gutter) 8px;
    font-size: 17px;
    font-weight: 600;
    line-height: 22px;
    letter-spacing: -0.43px;
    color: var(--text);
}
.section-header-title { min-width: 0; overflow-wrap: anywhere; }
.section-header-detail {
    flex: 0 1 auto;
    max-width: 50%;
    font-size: 13px;
    font-weight: 400;
    line-height: 18px;
    letter-spacing: -0.08px;
    color: var(--text-secondary);
    text-align: right;
}
.section-header-detail > span { white-space: nowrap; }

.content > .section-header:first-child,
.content > form:first-child > .section-header:first-child,
.content > form:first-child > input[type="hidden"]:first-child + .section-header { margin-top: 16px; }

.section-footer {
    margin: 0 var(--gutter) 0;
    padding-top: 0;
    font-size: 13px;
    line-height: 18px;
    letter-spacing: -0.08px;
    color: var(--text-secondary);
}

/* Hinweise */

.banner {
    margin: 0 0 16px;
    padding: 12px var(--gutter);
    border-radius: var(--radius);
    background: var(--cell);
    font-size: 15px;
}
.banner-error { color: var(--destructive); }
.banner-success { color: var(--success); }
.banner-pending { display: flex; align-items: center; gap: 10px; color: var(--pending); }
.banner-pending::before { flex: 0 0 auto; width: 20px; height: 20px; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
}

/* Buttons */

.button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 50px;
    margin-top: 24px;
    padding: 0 var(--gutter);
    border: 0;
    border-radius: 12px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
}

.button-primary { background: var(--accent); color: var(--on-accent); }
.button-primary:active { opacity: 0.7; }
.button:disabled { opacity: 0.4; }

/* PIN */

.pin-input {
    text-align: center !important;
    font-size: 28px;
    letter-spacing: 8px;
}

.pin-input::placeholder {
    font-size: 17px;
    letter-spacing: -0.41px;
}

/* Navigationsleiste: Aktion rechts */

.navbar-action {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    min-width: 44px;
    padding: 0 8px;
    justify-content: flex-end;
}
.navbar-action.is-bold { font-weight: 600; }

/* Zellen mit zwei Zeilen */

.cell-stack {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 2px;
}

.cell-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
}

.align-left { text-align: left !important; }

.cell-textarea textarea {
    width: 100%;
    min-height: 66px;
    border: 0;
    padding: 0;
    background: transparent;
    font: inherit;
    resize: vertical;
    outline: none;
}
.cell-textarea textarea::placeholder { color: var(--text-tertiary); }

.is-disabled { opacity: 0.45; cursor: default; }
.is-disabled:active { background: var(--cell) !important; }

/* Suchfeld */

.search { margin: 0 0 12px; }
.search input {
    width: 100%;
    height: 36px;
    padding: 0 10px 0 32px;
    border: 0;
    border-radius: 10px;
    background: rgba(118, 118, 128, 0.12) no-repeat 10px center / 15px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='6.5' cy='6.5' r='5' fill='none' stroke='%238E8E93' stroke-width='1.8'/%3E%3Cpath d='M10.3 10.3l4.2 4.2' stroke='%238E8E93' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
    font-size: 17px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
.search input::placeholder { color: var(--text-secondary); }
@media (prefers-color-scheme: dark) {
    .search input { background-color: rgba(118, 118, 128, 0.24); }
}

/* Schalter (iOS-Switch) */

.cell-switch { cursor: pointer; }
.cell-switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
    position: relative;
    flex: 0 0 auto;
    width: 51px;
    height: 31px;
    border-radius: 16px;
    background: rgba(120, 120, 128, 0.16);
    transition: background 0.2s;
}
.switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 27px;
    height: 27px;
    border-radius: 50%;
    background: #FFFFFF;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.16);
    transition: transform 0.2s;
}
.cell-switch input:checked + .switch { background: var(--success); }
.cell-switch input:checked + .switch::after { transform: translateX(20px); }
.cell-switch:has(input:focus-visible) .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-color-scheme: dark) {
    .switch { background: rgba(120, 120, 128, 0.32); }
}

/* Segmented Control */

/* Muskel-Zeile: der Control bleibt immer rechts, ein langer Name bricht links um.
   Ist die Zeile schmal (kleines iPhone mit Zoom, Safari-Seitenzoom), wird der Control kompakter. */
.cell-muscle { flex-wrap: nowrap; container-type: inline-size; }
.cell-muscle > span:first-child {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: break-word;
    -webkit-hyphens: auto;
    hyphens: auto;
}
@container (max-width: 270px) {
    .cell-muscle .segmented span { min-width: 34px; padding: 0 5px; font-size: 12px; }
}

.segmented {
    display: flex;
    flex: 0 0 auto;
    padding: 2px;
    border-radius: 9px;
    background: rgba(118, 118, 128, 0.12);
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 58px;
    min-height: 32px;
    padding: 0 8px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}
.segmented input:checked + span,
.segmented [aria-current] > span {
    background: var(--cell);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);
    font-weight: 600;
}
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
@media (prefers-color-scheme: dark) {
    .segmented { background: rgba(118, 118, 128, 0.24); }
    .segmented input:checked + span,
    .segmented [aria-current] > span { background: #636366; }
}

/* Segmented Control über die ganze Breite (Statistik, Bestenliste); Links oder Radio-Knöpfe */
.segmented-full > a,
.segmented-full > label { flex: 1 1 0; min-width: 0; color: var(--text); text-decoration: none; }
.segmented-full span { min-width: 0; min-height: 32px; text-align: center; }
.stats-switch { margin: 0 0 8px; }

/* Stepper: grosse Plus/Minus-Knöpfe */

.cell-stepper { padding-top: 6px; padding-bottom: 6px; }
.set-label { flex: 0 0 auto; min-width: 56px; }

.stepper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.stepper input {
    width: 72px;
    height: 44px;
    border: 0;
    border-radius: 8px;
    background: var(--bg);
    font-size: 22px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: center;
    outline: none;
}
.stepper input:focus { box-shadow: inset 0 0 0 2px var(--accent); }

.stepper-button {
    width: 48px;
    height: 44px;
    border: 0;
    border-radius: 8px;
    background: var(--bg);
    color: var(--accent);
    font-size: 26px;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
}
.stepper-button:active { background: var(--cell-pressed); }

.remove-button,
.reorder button {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 22px;
    cursor: pointer;
}
.remove-button { color: var(--destructive); margin-right: -10px; }
.remove-button:disabled { visibility: hidden; }

.reorder { display: flex; gap: 4px; margin: -6px -8px -6px 0; }
.reorder button { color: var(--accent); background: var(--bg); }
.reorder button:disabled { color: var(--text-tertiary); }

.inline-button {
    min-height: 44px;
    min-width: 44px;
    margin: -11px -8px -11px 8px;
    padding: 0 8px;
    border: 0;
    background: transparent;
    cursor: pointer;
}

.cell form { display: flex; align-items: center; }

/* Training */

.workout-meta {
    margin: -4px 4px 0;
    font-size: 15px;
    color: var(--text-secondary);
}

.last-sets { display: flex; flex-wrap: wrap; gap: 6px; }
.last-set {
    padding: 4px 8px;
    border-radius: 6px;
    background: var(--bg);
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.set-row {
    padding: 10px var(--gutter) 12px;
    background: var(--cell);
}
.set-row.is-saved { background: var(--success-fill); }

.set-head {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
}
.set-title { font-weight: 600; }
.set-hint {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    color: var(--text-secondary);
}
.set-status { font-size: 13px; color: var(--text-secondary); text-align: right; }
.set-status.is-error { color: var(--destructive); }

.save-button {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border: 2px solid var(--separator);
    border-radius: 50%;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 22px;
    font-weight: 700;
    cursor: pointer;
}
.set-row.is-dirty .save-button,
.set-row:not(.is-saved) .save-button { border-color: var(--accent); color: var(--accent); }
.set-row.is-saved .save-button {
    border-color: var(--success);
    background: var(--success);
    color: #FFFFFF;
}
.set-row.is-saving .save-button { opacity: 0.5; }
/* Lokal gespeichert, wartet auf Empfang: grau mit Uhr statt Häkchen */
.set-row.is-pending .save-button {
    border-color: var(--pending);
    color: transparent;
    position: relative;
}
.set-row.is-pending .save-button::before,
.banner-pending::before {
    content: "";
    background: var(--pending);
    -webkit-mask: var(--clock-icon) center / contain no-repeat;
    mask: var(--clock-icon) center / contain no-repeat;
}
.set-row.is-pending .save-button::before { position: absolute; inset: 9px; }
.set-row.is-pending .set-status { color: var(--pending); font-weight: 600; }

.set-inputs {
    display: grid;
    /* kg breiter als Wdh (ca. 40/60), damit z.B. «102.5» ganz sichtbar ist; Wdh behält Platz für zwei Ziffern */
    grid-template-columns: minmax(136px, 2fr) 3fr;
    gap: 12px;
    margin-top: 4px;
}
.set-field { min-width: 0; }
.set-field-label {
    display: block;
    margin: 0 0 4px 2px;
    font-size: 13px;
    color: var(--text-secondary);
}

.stepper-compact { gap: 4px; margin-left: 0; }
.stepper-compact input { width: 100%; min-width: 0; flex: 1; padding: 0 4px; }
.stepper-compact input::placeholder { color: var(--text-tertiary); }
.stepper-compact .stepper-button { flex: 0 0 44px; width: 44px; }
.set-row.is-saved .stepper input,
.set-row.is-saved .stepper-button { background: var(--cell); }

/* Bestwerte im Block «Letztes Mal»: antippen zeigt Datum und Notiz; «M» = manuell erfasst */

.best-detail summary { list-style: none; cursor: pointer; }
.best-detail summary::-webkit-details-marker { display: none; }
.best-detail summary:active { background: var(--cell-pressed); }
.best-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: -4px 0 0;
    padding: 0 var(--gutter) 11px;
    font-size: 13px;
    line-height: 18px;
    color: var(--text-secondary);
    text-align: right;
}
.best-note { white-space: normal; overflow-wrap: anywhere; }
.manual-chip {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--cell-pressed);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    line-height: 16px;
    vertical-align: 1px;
}

/* «Meine Einstellungen» (SPEC 2.9): in der Übungsansicht aufklappbar, gespeichert per fetch */

.icon-wrench { flex: 0 0 auto; color: var(--accent); }
.my-settings { display: block; margin: 12px 0 0; }
.my-settings summary { list-style: none; cursor: pointer; }
.my-settings summary::-webkit-details-marker { display: none; }
.my-settings-summary { justify-content: flex-start; }
.my-settings-summary:active { background: var(--cell-pressed); }
.my-settings-text { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; white-space: pre-line; }
.my-settings-text.is-empty { color: var(--text-secondary); }
.my-settings[open] .my-settings-summary { display: none; }
.my-settings-form { padding: 8px var(--gutter) 0; }
.my-settings-form textarea {
    width: 100%;
    min-height: 66px;
    border: 0;
    padding: 4px 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    resize: vertical;
    outline: none;
}
.my-settings-form textarea::placeholder { color: var(--text-tertiary); }
.my-settings-error { margin: 4px 0 0; font-size: 15px; color: var(--destructive); }
.my-settings-actions { display: flex; justify-content: flex-end; gap: 8px; border-top: var(--hairline); margin: 4px calc(-1 * var(--gutter)) 0; padding: 0 var(--gutter); }
.my-settings-actions .inline-button { margin: 0; color: var(--accent); font-size: 17px; }
.my-settings-actions .is-bold { font-weight: 600; }
.my-settings-title { display: inline-flex; align-items: center; gap: 6px; }
.other-settings { display: block; margin-top: 8px; }
.other-settings summary { list-style: none; cursor: pointer; }
.other-settings summary::-webkit-details-marker { display: none; }
.other-settings[open] summary::after { transform: rotate(135deg); margin-top: -6px; }

/* Status in der Übungsliste */

.cell-status { justify-content: flex-start; }
.status-icon {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--text-tertiary);
}
.status-current { border-color: var(--accent); position: relative; }
.status-current::after {
    content: "";
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    background: var(--accent);
}
.status-done {
    border-color: var(--success);
    background: var(--success);
    position: relative;
}
.status-done::after {
    content: "";
    position: absolute;
    left: 7px;
    top: 3px;
    width: 6px;
    height: 11px;
    border-right: 2.5px solid #FFFFFF;
    border-bottom: 2.5px solid #FFFFFF;
    transform: rotate(45deg);
}

/* Feste Leiste unten (Pausen-Timer) */

.has-toolbar .content {
    padding-bottom: calc(56px + 32px + env(safe-area-inset-bottom));
}

.toolbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 56px;
    padding: 0 calc(var(--gutter) + env(safe-area-inset-right)) env(safe-area-inset-bottom) calc(var(--gutter) + env(safe-area-inset-left));
    background: var(--tabbar);
    border-top: var(--hairline);
}
.toolbar-label { color: var(--text-secondary); font-size: 15px; }
.timer {
    font-size: 22px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.toolbar-link {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
}

.stale-footer { margin-top: 8px; }

/* Rekorde in der Übersicht */

.section-header-record { color: var(--success); font-weight: 600; }
.cell-record { justify-content: flex-start; background: var(--success-fill); }
.record-badge {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--success);
    color: #FFFFFF;
    font-size: 15px;
    line-height: 28px;
    text-align: center;
}
.record-text { font-size: 15px; color: var(--success); font-weight: 600; }
.record-tag {
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--success);
    color: #FFFFFF;
    font-size: 12px;
    font-weight: 600;
    vertical-align: 2px;
}

/* Kalorien als Essens-Vergleich: pro Einheit ein Emoji, der Rest nur teilweise farbig */

.food { padding: 16px var(--gutter) 14px; text-align: center; }
.food p { margin: 0; }
.food-emojis {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    font-size: min(64px, 14vw);
    line-height: 1.15;
}
.food-emoji { position: relative; display: inline-block; }
.food-emoji-faded { filter: grayscale(1); opacity: .25; }
.food-emoji-fill { position: absolute; inset: 0; }
.food-text { margin-top: 10px !important; font-size: 17px; font-weight: 600; }
.food-note { margin-top: 2px !important; font-size: 13px; color: var(--text-secondary); }
@media (prefers-color-scheme: dark) {
    .food-emoji-faded { opacity: .35; }
}

/* Bestenliste (SPEC 5.4): pro Übung Absolut/Relativ, ohne JavaScript umgeschaltet */

.lb-mode { margin: 0 0 8px; }
.lb-list + .lb-list { margin-top: 0; } /* nur eine der beiden Listen ist sichtbar */
.lb-rel { display: none; }
.lb-box:has(.lb-mode input[value="rel"]:checked) .lb-rel { display: block; }
.lb-box:has(.lb-mode input[value="rel"]:checked) .lb-abs { display: none; }
.lb-row { justify-content: flex-start; }
.lb-rank {
    flex: 0 0 28px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
}
.lb-medal .lb-rank { font-size: 20px; }
.lb-first .lb-name > span:first-child { font-weight: 600; }
.lb-name { flex: 1 1 auto; }
.lb-row .cell-value { flex: 0 0 auto; }

/* Tab-Bar: solid, Haarlinie oben */

.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-around;
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: var(--tabbar);
    border-top: var(--hairline);
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 49px;
    padding-top: 2px;
    color: var(--inactive);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.1px;
}

.tab svg { width: 28px; height: 28px; fill: currentColor; }
.tab.is-active { color: var(--accent); }

/* Statistik: Monatskalender */

.calendar { padding-bottom: 8px; }
.calendar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
}
.calendar-title {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
}
.calendar-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    color: var(--accent);
}
.chevron-right {
    width: 12px;
    height: 12px;
    border-right: 3px solid currentColor;
    border-top: 3px solid currentColor;
    border-radius: 1px;
    transform: rotate(45deg);
    margin-right: 4px;
}
.calendar-nav .chevron-left { margin: 0 0 0 4px; }
.calendar-grid {
    list-style: none;
    margin: 0;
    padding: 0 8px;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
}
.calendar-weekday {
    padding: 4px 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}
.calendar-day {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin: 2px auto;
    border-radius: 50%;
    font-size: 17px;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}
.calendar-day.is-today { color: var(--accent); font-weight: 600; }
.calendar-day.has-workout {
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
}
a.calendar-day.has-workout:active { opacity: 0.6; }

/* Übungsfilter: Suchfeld mit Filter-Knopf, Chips, Sheet */

.search-with-filter { display: flex; align-items: center; gap: 8px; }
.search-with-filter input { flex: 1; min-width: 0; }
.filter-button {
    flex: 0 0 auto;
    min-width: 44px;
    min-height: 44px;
    padding: 0 4px;
    border: 0;
    background: none;
    color: var(--accent);
    font: inherit;
    font-size: 17px;
    cursor: pointer;
}
.filter-button.is-active { font-weight: 600; }

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    column-gap: 8px;
    margin: -8px 0 8px;
}
.chip {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    cursor: pointer;
}
.chip span {
    padding: 6px 12px;
    border-radius: 16px;
    background: var(--cell);
    color: var(--accent);
    font-size: 15px;
}
.chip:active span { background: var(--cell-pressed); }
.chip-reset span { background: none; padding-left: 4px; padding-right: 4px; }

.sheet {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    max-width: 680px;
    max-height: 90vh;
    margin: 0 auto;
    padding: 0;
    border: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--bg);
    color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.4); }
.sheet-content {
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 var(--gutter) calc(24px + env(safe-area-inset-bottom));
}
.sheet-header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    min-height: 56px;
    margin: 0 calc(-1 * var(--gutter));
    padding: 0 8px;
    background: var(--bg);
    border-bottom: var(--hairline);
}
.sheet-title { margin: 0; font-size: 17px; font-weight: 600; }
.sheet-action {
    min-height: 44px;
    padding: 0 8px;
    border: 0;
    background: none;
    color: var(--accent);
    font: inherit;
    font-size: 17px;
    cursor: pointer;
    justify-self: start;
}
.sheet-action.is-bold { font-weight: 600; justify-self: end; }

/* Action Sheet (iOS), deckend statt Blur. Tipp auf den Hintergrund schliesst. */
.action-sheet {
    position: fixed;
    inset: auto 0 0 0;
    width: auto;
    max-width: 680px;
    margin: 0 auto;
    padding: 0 8px calc(8px + env(safe-area-inset-bottom));
    border: 0;
    background: none;
    overflow: visible;
}
.action-sheet::backdrop { background: rgba(0, 0, 0, 0.4); }
.action-sheet:focus { outline: none; } /* Fokus liegt beim Öffnen auf dem Sheet, nicht auf dem ersten Knopf */
.action-sheet-group {
    overflow: hidden;
    border-radius: 14px;
    background: var(--cell);
}
.action-sheet-group + .action-sheet-group { margin-top: 8px; }
.action-sheet-title {
    margin: 0;
    padding: 14px var(--gutter);
    font-size: 13px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    color: var(--text-secondary);
}
.action-sheet-button {
    display: block;
    width: 100%;
    min-height: 57px;
    padding: 0 var(--gutter);
    border: 0;
    border-top: var(--hairline);
    background: var(--cell);
    color: var(--accent);
    font: inherit;
    font-size: 20px;
    text-align: center;
    cursor: pointer;
}
.action-sheet-button[hidden] { display: none; }
.action-sheet-button:first-child { border-top: 0; }
.action-sheet-button:active { background: var(--cell-pressed); }
.action-sheet-button:disabled { opacity: 0.4; }
.action-sheet-button.is-destructive { color: var(--destructive); }
.action-sheet-button.is-cancel { font-weight: 600; }

/* Foto und Muskel-Schema einer Übung (SPEC 2.7, 2.8) */

.exercise-visual {
    display: flex;
    align-items: center;
    margin: 12px 0 8px;
    background: var(--cell);
    border-radius: var(--radius);
    overflow: hidden;
}
.exercise-visual > * { flex: 1 1 0; min-width: 0; }
.exercise-photo {
    display: block;
    align-self: stretch;
    aspect-ratio: 1;
    background: var(--map-body);
}
.exercise-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.exercise-photo:active { opacity: 0.7; }

.body-map {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin: 0;
    padding: 12px 8px 8px;
}
.exercise-photo + .body-map { border-left: var(--hairline); }
.body-map-view {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    max-width: 96px;
}
.body-map svg { display: block; width: 100%; height: auto; }
.body-map polygon { fill: var(--map-body); }
.body-map-caption { margin-top: 4px; font-size: 11px; color: var(--text-secondary); }

.body-map .bm-primary, .legend-swatch.bm-primary { fill: var(--map-primary); background: var(--map-primary); }
.body-map .bm-secondary, .legend-swatch.bm-secondary { fill: var(--map-secondary); background: var(--map-secondary); }
.body-map .bm-1, .legend-swatch.bm-1 { fill: var(--map-1); background: var(--map-1); }
.body-map .bm-2, .legend-swatch.bm-2 { fill: var(--map-2); background: var(--map-2); }
.body-map .bm-3, .legend-swatch.bm-3 { fill: var(--map-3); background: var(--map-3); }
.body-map .bm-4, .legend-swatch.bm-4 { fill: var(--map-4); background: var(--map-4); }

.legend-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin: 0 4px 0 8px;
    border-radius: 3px;
    vertical-align: -1px;
}
.body-map-legend { margin-bottom: 16px; }
.body-map-legend .legend-swatch:first-child { margin-left: 0; }
.body-map-legend .legend-swatch + .legend-swatch { margin-left: 0; }

/* Foto gross: schwarzer Hintergrund wie in der Fotos-App, ohne Blur */
.photo-viewer {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: #000000;
}
.photo-viewer::backdrop { background: #000000; }
.photo-viewer img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.photo-viewer-close {
    position: absolute;
    top: calc(env(safe-area-inset-top) + 4px);
    right: calc(env(safe-area-inset-right) + 8px);
    min-width: 44px;
    min-height: 44px;
    padding: 0 8px;
    border: 0;
    background: none;
    color: #FFFFFF;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
}

/* Admin-Testseite Muskel-Schema */

.bm-debug-maps {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--cell);
    border-radius: var(--radius);
}
.bm-debug-view { flex: 1 1 0; min-width: 0; margin: 0; text-align: center; }
.bm-debug-view svg { display: block; width: 100%; height: auto; }
.bm-debug-view polygon {
    fill: var(--map-body);
    stroke: var(--cell);
    stroke-width: 0.3;
    cursor: pointer;
}
.bm-debug-view polygon.is-selected { fill: var(--map-primary); }
.bm-debug-cutoff { stroke: var(--text-secondary); stroke-width: 0.3; stroke-dasharray: 1.5 1; }
.bm-debug-status { margin: 12px 4px 4px; font-size: 15px; min-height: 22px; }
.bm-debug-name { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 15px; }
.bm-debug-area.is-selected .bm-debug-name { color: var(--accent); font-weight: 600; }

/* Filter-Sheet der Übungslisten: alles scrollt als Ganzes, nur die Knöpfe unten sind fixiert.
   Das Sheet reicht bis knapp unter die Statusleiste, damit von der Seite dahinter nichts hervorschaut. */

.filter-sheet {
    height: calc(100vh - 12px);
    height: calc(100dvh - env(safe-area-inset-top) - 12px);
    max-height: none;
}
.filter-sheet::backdrop { background: rgba(0, 0, 0, 0.5); }
.filter-sheet .sheet-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: none;
    overflow: hidden;
    padding: 0;
}
.sheet-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 0 var(--gutter) 24px;   /* die Leiste liegt ausserhalb, darunter verschwindet nichts */
}
.filter-sheet .sheet-header { position: static; margin: 0 calc(-1 * var(--gutter)); }
.filter-sheet .sheet-header .sheet-action:last-child { justify-self: end; }
.filter-figures {
    position: relative;
    padding: 8px 0 0;
}
.body-map-picker { padding: 0; gap: 4px; }
.body-map-picker .body-map-view { max-width: none; }
.body-map-picker svg {
    width: auto;
    height: min(36vh, 300px);
    height: min(36dvh, 300px);
    max-width: 100%;
}
.body-map-picker polygon { stroke: var(--bg); stroke-width: 0.5; }
.body-map-picker polygon.bm-pick { cursor: pointer; }
.body-map-picker polygon.is-selected { fill: var(--map-primary); }
.sheet-footer {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
    border-top: var(--hairline);
    background: var(--bg);
}
.sheet-footer .sheet-action { flex: 0 0 auto; padding-left: 0; }
.filter-show { flex: 1; width: auto; margin-top: 0; }

.filter-chip-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: 8px;
    min-height: 44px;
    margin-bottom: 8px;
}
.filter-chip-empty { font-size: 15px; color: var(--text-secondary); }
.chip-toggle.is-selected span { background: var(--accent); color: var(--on-accent); }
.chip-toggle.is-selected span::before { content: "✓ "; }
.chip-toggle:not(.is-selected) span { color: var(--text); }

/* Muskeln als Liste: aufklappbare Gruppe */
.filter-muscle-list { display: block; margin-top: 24px; }
.filter-muscle-list summary { list-style: none; cursor: pointer; }
.filter-muscle-list summary::-webkit-details-marker { display: none; }
.filter-muscle-list[open] summary::after { transform: rotate(135deg); margin-top: -6px; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain > li { position: relative; }
.list-plain > li::before {
    content: "";
    position: absolute;
    z-index: 1;
    top: 0;
    left: var(--gutter);
    right: 0;
    border-top: var(--hairline);
}

/* Auswahlmenü für Flächen mit mehreren Muskeln (wie iOS-Kontextmenü, deckend) */
.area-menu {
    position: absolute;
    z-index: 5;
    min-width: 200px;
    border-radius: 12px;
    background: var(--cell);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}
.area-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
    min-height: 44px;
    padding: 0 16px;
    border: 0;
    background: none;
    color: var(--text);
    font: inherit;
    font-size: 17px;
    text-align: left;
    cursor: pointer;
}
.area-menu-item + .area-menu-item { border-top: var(--hairline); }
.area-menu-item:active { background: var(--cell-pressed); }
.area-menu-check { color: var(--accent); visibility: hidden; }
.area-menu-item[aria-checked="true"] .area-menu-check { visibility: visible; }
