:root {
    --bg: #f5f5f7;
    --surface: rgba(255,255,255,.88);
    --surface-solid: #ffffff;
    --text: #1d1d1f;
    --muted: #6e6e73;
    --line: rgba(0,0,0,.08);
    --accent: #0071e3;
    --accent-dark: #0058b0;
    --success: #248a3d;
    --danger: #d70015;
    --radius: 24px;
    --shadow: 0 12px 40px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }

html {
    background: var(--bg);
    color-scheme: light;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 50% -10%, rgba(0,113,227,.08), transparent 34rem),
        var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }

button { cursor: pointer; }

.hidden { display: none !important; }

.auth-shell,
.setup-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card,
.setup-card {
    width: min(100%, 420px);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 32px;
    box-shadow: var(--shadow);
    padding: 34px;
    backdrop-filter: blur(20px);
}

.brand-mark {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 15px;
    background: var(--text);
    color: white;
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 20px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(28px, 6vw, 40px); letter-spacing: -0.04em; margin-bottom: 6px; }
h2 { font-size: 26px; letter-spacing: -0.03em; margin-bottom: 0; }
h3 { letter-spacing: -0.02em; margin-bottom: 4px; }

.muted,
.goal-progress-text,
.settings-row .goal-title-wrap div > span,
.history-row small {
    color: var(--muted);
}

.stack {
    display: grid;
    gap: 16px;
    margin-top: 24px;
}

label {
    display: grid;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
}

input, select {
    width: 100%;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.96);
    color: var(--text);
    padding: 14px 15px;
    border-radius: 14px;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}

input:focus, select:focus {
    border-color: rgba(0,113,227,.5);
    box-shadow: 0 0 0 4px rgba(0,113,227,.1);
}

.primary-button,
.secondary-button,
.small-button,
.step-button {
    border: 0;
    border-radius: 14px;
    font-weight: 650;
    transition: transform .12s ease, opacity .12s ease, background .12s ease;
}

.primary-button:active,
.secondary-button:active,
.small-button:active,
.step-button:active {
    transform: scale(.97);
}

.primary-button {
    min-height: 48px;
    background: var(--accent);
    color: white;
    padding: 0 18px;
}

.primary-button:hover { background: var(--accent-dark); }

.secondary-button {
    min-height: 48px;
    background: #ececf0;
    color: var(--text);
    padding: 0 18px;
}

.form-error {
    min-height: 18px;
    color: var(--danger);
    font-size: 13px;
    margin: 0;
}

.topbar {
    width: min(100% - 32px, 760px);
    margin: 0 auto;
    padding: 26px 0 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.topbar h1 { font-size: 28px; margin: 0; }

.eyebrow {
    display: block;
    color: var(--muted);
    text-transform: uppercase;
    font-size: 11px;
    font-weight: 750;
    letter-spacing: .09em;
    margin-bottom: 4px;
}

.icon-button {
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--surface-solid);
    color: var(--muted);
}

.content {
    width: min(100% - 32px, 760px);
    margin: 0 auto;
    padding: 16px 0 110px;
}

.streak-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
    background: var(--text);
    color: white;
    border-radius: 22px;
    margin-bottom: 28px;
    box-shadow: var(--shadow);
}

.streak-card .eyebrow { color: rgba(255,255,255,.6); }
.streak-card strong { font-size: 20px; }
.streak-icon { font-size: 26px; }

.section-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.section-heading.compact { align-items: center; }

.complete-badge {
    color: var(--success);
    background: rgba(36,138,61,.1);
    padding: 8px 11px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.goal-list {
    display: grid;
    gap: 12px;
}

.goal-card {
    background: var(--surface-solid);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: 0 6px 24px rgba(0,0,0,.035);
}

.goal-card.done {
    border-color: rgba(36,138,61,.18);
}

.goal-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.goal-title-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.goal-icon {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: #f2f2f7;
    font-size: 22px;
}

.goal-title-wrap h3,
.goal-title-wrap strong {
    display: block;
    margin: 0 0 3px;
}

.goal-progress-text,
.settings-row .goal-title-wrap div > span {
    display: block;
    font-size: 13px;
}

.stepper {
    display: flex;
    gap: 7px;
}

.step-button {
    min-width: 54px;
    min-height: 42px;
    padding: 0 13px;
    background: #ededf1;
    color: var(--text);
}

.step-button.plus {
    background: var(--accent);
    color: white;
}

.progress-track {
    height: 7px;
    border-radius: 999px;
    background: #ededf1;
    overflow: hidden;
    margin-top: 16px;
}

.progress-fill {
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width .25s ease;
}

.goal-card.done .progress-fill { background: var(--success); }

.bottom-nav {
    position: fixed;
    left: 50%;
    bottom: max(14px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    width: min(calc(100% - 28px), 560px);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 7px;
    background: rgba(255,255,255,.86);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: 0 12px 38px rgba(0,0,0,.12);
    backdrop-filter: blur(22px);
    z-index: 10;
}

.nav-item {
    min-height: 46px;
    border: 0;
    border-radius: 16px;
    background: transparent;
    color: var(--muted);
    font-weight: 650;
}

.nav-item.active {
    background: var(--text);
    color: white;
}

.small-button {
    min-height: 38px;
    padding: 0 13px;
    background: var(--text);
    color: white;
}

.settings-list,
.history-list {
    display: grid;
    gap: 10px;
}

.settings-row,
.history-row {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--surface-solid);
    border-radius: 18px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    text-align: left;
}

.row-actions {
    display: flex;
    gap: 8px;
}

.text-button {
    padding: 8px;
    border: 0;
    background: transparent;
    color: var(--accent);
    font-size: 13px;
    font-weight: 650;
}

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

.form-card {
    margin-top: 16px;
    background: var(--surface-solid);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
}

.button-row {
    display: flex;
    gap: 10px;
}

.button-row > * { flex: 1; }

.empty-state,
.empty-row {
    text-align: center;
    color: var(--muted);
    padding: 36px 20px;
}

.empty-icon { font-size: 32px; margin-bottom: 12px; }

.history-row {
    cursor: pointer;
}

.history-row span:first-child {
    display: grid;
    gap: 3px;
}

.history-status {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #f2f2f7;
    color: var(--muted);
    font-weight: 800;
}

.history-status.success {
    background: rgba(36,138,61,.1);
    color: var(--success);
}

.notice {
    border-radius: 14px;
    padding: 12px 14px;
    font-size: 14px;
    margin-top: 18px;
}

.notice.success { background: rgba(36,138,61,.1); color: var(--success); }
.notice.error { background: rgba(215,0,21,.08); color: var(--danger); }

@media (max-width: 560px) {
    .goal-card-top {
        align-items: flex-start;
    }

    .goal-title-wrap {
        flex: 1;
    }

    .row-actions {
        flex-direction: column;
        align-items: end;
    }

    .auth-card,
    .setup-card {
        padding: 26px 22px;
        border-radius: 26px;
    }
}


/* v0.2: Verlauf als direkt erreichbares Overlay statt Detailkarte am Seitenende */
.history-overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    align-items: end;
    background: rgba(0,0,0,.28);
    padding: 18px;
    backdrop-filter: blur(8px);
    animation: fadeIn .16s ease;
}

.history-sheet {
    width: min(100%, 640px);
    max-height: min(78vh, 720px);
    overflow-y: auto;
    margin: 0 auto;
    background: var(--surface-solid);
    border: 1px solid var(--line);
    border-radius: 28px;
    padding: 20px;
    box-shadow: 0 24px 70px rgba(0,0,0,.22);
    animation: sheetUp .2s ease;
}

.history-sheet .goal-list {
    margin-top: 14px;
}

.backfill-note {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

.today-tag {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    margin-left: 8px;
    padding: 0 8px;
    border-radius: 999px;
    background: rgba(0,113,227,.09);
    color: var(--accent);
    font-size: 11px;
    font-weight: 750;
    vertical-align: middle;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes sheetUp {
    from { transform: translateY(18px); opacity: .7; }
    to { transform: translateY(0); opacity: 1; }
}

@media (min-width: 700px) {
    .history-overlay {
        align-items: center;
    }
}


/* v0.3 */
.streak-status {
    display: block;
    margin-top: 2px;
    color: rgba(255,255,255,.62);
    font-size: 12px;
    font-weight: 600;
}

.streak-status.complete {
    color: rgba(190,255,205,.92);
}

.goal-section-block + .goal-section-block {
    margin-top: 26px;
}

.goal-check {
    display: inline-grid;
    place-items: center;
    width: 20px;
    height: 20px;
    margin-left: 7px;
    border-radius: 50%;
    background: rgba(36,138,61,.1);
    color: var(--success);
    font-size: 12px;
    vertical-align: 2px;
}

.goal-card.just-updated {
    animation: goalPulse .28s ease;
}

.step-button.is-busy,
.primary-button.is-busy,
.secondary-button.is-busy,
.text-button.is-busy,
.icon-button.is-busy {
    opacity: .55;
    pointer-events: none;
}

.paused-card {
    background: #f7f7f9;
    opacity: .78;
}

@keyframes goalPulse {
    0% { transform: scale(1); }
    48% { transform: scale(1.012); }
    100% { transform: scale(1); }
}


/* v0.3.1 Benutzerverwaltung */
.admin-section {
    margin-top: 42px;
    padding-top: 30px;
    border-top: 1px solid var(--line);
}

.admin-heading {
    margin-bottom: 16px;
}

.user-info {
    min-width: 0;
}

.user-info > span {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
}

.user-name-line {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.user-badges {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.user-badge {
    display: inline-flex;
    align-items: center;
    min-height: 21px;
    padding: 0 7px;
    border-radius: 999px;
    background: #ededf1;
    color: var(--muted);
    font-size: 10px;
    font-weight: 750;
    line-height: 1;
}

.user-badge.admin {
    background: rgba(0,113,227,.09);
    color: var(--accent);
}

.user-badge.inactive {
    background: rgba(215,0,21,.07);
    color: var(--danger);
}

.user-inactive {
    opacity: .72;
}

@media (max-width: 560px) {
    .user-row {
        align-items: flex-start;
    }

    .user-row .row-actions {
        flex-shrink: 0;
    }
}


/* v0.3.2: iOS/Safari färbt Button-Text sonst standardmäßig blau */
.history-row {
    color: var(--text);
    -webkit-appearance: none;
    appearance: none;
}

/* v0.4 Mobile & Polish */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body.modal-open {
    overflow: hidden;
}

button {
    touch-action: manipulation;
}

.brand-mark {
    padding: 0;
    overflow: hidden;
    background: transparent;
}

.brand-mark img {
    display: block;
    width: 100%;
    height: 100%;
}

.icon-button {
    display: grid;
    place-items: center;
    padding: 0;
}

.logout-icon {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.goal-title-wrap > div,
.goal-copy {
    min-width: 0;
}

.goal-name-line {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    min-width: 0;
}

.goal-name-line h3 {
    min-width: 0;
    margin: 0 0 3px;
    overflow-wrap: anywhere;
}

.goal-name-line .goal-check {
    flex: 0 0 20px;
    margin: 1px 0 0;
}

.streak-card.streak-up {
    animation: streakCardGlow .82s ease;
}

.streak-card.streak-up .streak-icon {
    animation: streakFlamePop .7s cubic-bezier(.2,.9,.2,1);
}

.streak-card.streak-up strong {
    display: inline-block;
    animation: streakNumberPop .62s cubic-bezier(.2,.9,.2,1);
}

@keyframes streakCardGlow {
    0%, 100% { box-shadow: var(--shadow); }
    42% { box-shadow: 0 16px 46px rgba(36,138,61,.20), 0 0 0 2px rgba(190,255,205,.18); }
}

@keyframes streakFlamePop {
    0% { transform: scale(1) rotate(0); }
    38% { transform: scale(1.32) rotate(-6deg); }
    68% { transform: scale(.96) rotate(3deg); }
    100% { transform: scale(1) rotate(0); }
}

@keyframes streakNumberPop {
    0% { transform: translateY(0) scale(1); }
    42% { transform: translateY(-2px) scale(1.12); }
    100% { transform: translateY(0) scale(1); }
}

/* Verlauf: echte, zentrierte Modal-Fläche mit sicheren Rändern auf kleinen Displays. */
.history-overlay {
    place-items: center;
    padding:
        max(14px, env(safe-area-inset-top))
        max(12px, env(safe-area-inset-right))
        max(14px, env(safe-area-inset-bottom))
        max(12px, env(safe-area-inset-left));
    overflow: hidden;
}

.history-sheet {
    width: min(100%, 640px);
    max-width: 100%;
    max-height: min(82dvh, 720px);
    margin: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.history-sheet .section-heading.compact > div {
    min-width: 0;
}

.history-sheet .section-heading.compact h3 {
    overflow-wrap: anywhere;
}

.history-sheet #closeHistoryDetail {
    flex: 0 0 auto;
}

@media (max-width: 560px) {
    input,
    select,
    textarea {
        font-size: 16px;
    }

    .history-sheet {
        padding: 18px 16px;
        border-radius: 26px;
    }

    .history-sheet .goal-card {
        padding: 16px;
    }
}

@media (max-width: 430px) {
    .history-sheet .goal-card-top {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 14px;
    }

    .history-sheet .goal-title-wrap {
        width: 100%;
    }

    .history-sheet .stepper {
        width: 100%;
        justify-content: flex-end;
    }

    .history-sheet .step-button {
        min-width: 68px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .streak-card.streak-up,
    .streak-card.streak-up .streak-icon,
    .streak-card.streak-up strong {
        animation: none;
    }
}


/* v0.4.1: Ziel erstellen/bearbeiten als Modal statt als Karte am Seitenende */
.goal-form-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    padding:
        max(14px, env(safe-area-inset-top))
        max(12px, env(safe-area-inset-right))
        max(14px, env(safe-area-inset-bottom))
        max(12px, env(safe-area-inset-left));
    overflow: hidden;
    background: rgba(0,0,0,.28);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: fadeIn .16s ease;
}

.goal-form-sheet {
    width: min(100%, 560px);
    max-width: 100%;
    max-height: min(82dvh, 680px);
    margin: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 24px 70px rgba(0,0,0,.22);
    animation: sheetUp .2s ease;
}

.goal-form-heading {
    margin-bottom: 18px;
}

.goal-form-heading > div {
    min-width: 0;
}

.goal-form-heading h3 {
    margin: 3px 0 0;
}

.goal-form-heading #closeGoalFormButton {
    flex: 0 0 auto;
}

@media (max-width: 560px) {
    .goal-form-sheet {
        padding: 18px 16px;
        border-radius: 26px;
    }
}


/* v0.5 Profil & Einstellungen */
.profile-icon {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.settings-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding:
        max(14px, env(safe-area-inset-top))
        max(12px, env(safe-area-inset-right))
        max(14px, env(safe-area-inset-bottom))
        max(12px, env(safe-area-inset-left));
    background: rgba(0,0,0,.30);
    backdrop-filter: blur(9px);
    animation: fadeIn .16s ease;
}

.settings-sheet {
    width: min(100%, 680px);
    max-width: 100%;
    max-height: min(88dvh, 840px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--surface-solid);
    border: 1px solid var(--line);
    border-radius: 30px;
    box-shadow: 0 26px 80px rgba(0,0,0,.24);
    animation: sheetUp .2s ease;
}

.settings-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 20px 22px 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(18px);
    z-index: 2;
}

.settings-sheet-header h2 {
    margin: 3px 0 0;
    font-size: clamp(22px, 5vw, 28px);
    letter-spacing: -.035em;
}

.settings-content {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 20px 22px 24px;
}

.account-summary {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    margin-bottom: 28px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: #f8f8fa;
}

.account-avatar {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--text);
    color: white;
    font-size: 19px;
    font-weight: 800;
    text-transform: uppercase;
}

.account-summary-copy {
    min-width: 0;
}

.account-summary-copy strong,
.account-summary-copy span {
    display: block;
}

.account-summary-copy strong {
    overflow-wrap: anywhere;
    font-size: 17px;
}

.account-summary-copy span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
}

.settings-section + .settings-section,
.settings-section + .admin-section,
.admin-section + .settings-section {
    margin-top: 34px;
    padding-top: 30px;
    border-top: 1px solid var(--line);
}

.settings-section-heading {
    margin-bottom: 16px;
}

.settings-section-heading h3 {
    margin: 4px 0 5px;
    font-size: 19px;
}

.settings-section-heading p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.settings-form {
    max-width: 100%;
}

.settings-form .primary-button {
    width: 100%;
}

.form-message {
    min-height: 18px;
    margin: -2px 0 0;
    font-size: 13px;
    font-weight: 650;
}

.form-message.success { color: var(--success); }
.form-message.error { color: var(--danger); }

.settings-sheet .admin-section {
    margin-top: 34px;
    padding-top: 30px;
    border-top: 1px solid var(--line);
}

.settings-sheet .admin-heading {
    margin-bottom: 14px;
}

.settings-sheet #userFormCard {
    margin: 0 0 14px;
}

.settings-sheet #usersList {
    margin-top: 0;
}

.logout-settings-button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--danger);
}

.logout-settings-button svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

@media (max-width: 560px) {
    .settings-overlay {
        padding:
            max(10px, env(safe-area-inset-top))
            max(8px, env(safe-area-inset-right))
            max(10px, env(safe-area-inset-bottom))
            max(8px, env(safe-area-inset-left));
    }

    .settings-sheet {
        max-height: calc(100dvh - max(20px, env(safe-area-inset-top)) - max(20px, env(safe-area-inset-bottom)));
        border-radius: 26px;
    }

    .settings-sheet-header {
        padding: 18px 17px 14px;
    }

    .settings-content {
        padding: 17px 16px 22px;
    }

    .settings-sheet .admin-heading {
        align-items: flex-start;
    }

    .settings-sheet .admin-heading .small-button {
        flex: 0 0 auto;
    }
}


/* v0.5.1 – Branding: ausgewähltes Konzept 1 */
.topbar-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}

.topbar-brand-mark {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    display: block;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 4px 16px rgba(0,0,0,.05);
}

.auth-card .brand-mark {
    width: 56px;
    height: 56px;
    border-radius: 17px;
    box-shadow: 0 8px 24px rgba(0,0,0,.07);
}

.auth-card .brand-mark img {
    object-fit: cover;
}

@media (max-width: 420px) {
    .topbar-brand {
        gap: 9px;
    }

    .topbar-brand-mark {
        width: 34px;
        height: 34px;
        flex-basis: 34px;
        border-radius: 11px;
    }

    .topbar h1 {
        font-size: 27px;
    }
}

/* v0.6 – Streak-Statistik, Sortieren & Archiv */
.streak-card-button {
    width: 100%;
    border: 0;
    text-align: left;
    font: inherit;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    transition: transform .14s ease, box-shadow .18s ease;
}

.streak-card-button:active {
    transform: scale(.992);
}

.streak-card-copy {
    min-width: 0;
    flex: 1;
    display: grid;
}

.streak-card-copy strong {
    display: block;
}

.streak-card-accessory {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(255,255,255,.09);
    color: rgba(255,255,255,.72);
}

.streak-card-accessory svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.heading-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.small-button.subtle {
    background: #e9e9ee;
    color: var(--text);
}

.small-button:disabled,
.sort-move-button:disabled {
    opacity: .38;
    cursor: default;
    pointer-events: none;
}

.archive-section {
    padding-top: 4px;
}

.archive-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface-solid);
    color: var(--text);
    text-align: left;
    -webkit-appearance: none;
    appearance: none;
}

.archive-toggle > span {
    min-width: 0;
}

.archive-toggle .eyebrow {
    margin-bottom: 3px;
}

.archive-toggle strong {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 15px;
}

.archive-count {
    min-width: 22px;
    height: 22px;
    display: inline-grid;
    place-items: center;
    padding: 0 6px;
    border-radius: 999px;
    background: #ededf1;
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
}

.archive-toggle svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    fill: none;
    stroke: var(--muted);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform .18s ease;
}

.archive-toggle[aria-expanded="true"] svg {
    transform: rotate(180deg);
}

.archive-content {
    margin-top: 10px;
}

.archived-goal-row {
    background: rgba(255,255,255,.72);
}

.archived-goal-row .goal-icon {
    filter: grayscale(.18);
    opacity: .86;
}

.utility-overlay {
    position: fixed;
    inset: 0;
    z-index: 45;
    display: grid;
    place-items: center;
    padding:
        max(14px, env(safe-area-inset-top))
        max(12px, env(safe-area-inset-right))
        max(14px, env(safe-area-inset-bottom))
        max(12px, env(safe-area-inset-left));
    overflow: hidden;
    background: rgba(0,0,0,.29);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: fadeIn .16s ease;
}

.utility-sheet {
    width: min(100%, 580px);
    max-width: 100%;
    max-height: min(84dvh, 720px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    margin: 0;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 28px;
    background: var(--surface-solid);
    box-shadow: 0 24px 70px rgba(0,0,0,.22);
    animation: sheetUp .2s ease;
}

.utility-sheet-heading {
    margin-bottom: 16px;
}

.utility-sheet-heading h3 {
    margin: 3px 0 0;
}

.utility-sheet-heading > div {
    min-width: 0;
}

.streak-stats-content {
    min-height: 120px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.stat-card {
    min-width: 0;
    min-height: 112px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #f8f8fa;
}

.stat-card.primary-stat {
    background: var(--text);
    color: white;
    border-color: transparent;
}

.stat-card > span,
.stat-card small {
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
    line-height: 1.35;
}

.stat-card.primary-stat > span,
.stat-card.primary-stat small {
    color: rgba(255,255,255,.62);
}

.stat-card strong {
    display: block;
    margin-top: 6px;
    font-size: clamp(21px, 5vw, 28px);
    letter-spacing: -.035em;
    line-height: 1.08;
}

.stat-card small {
    margin-top: 7px;
}

.record-badge {
    align-self: flex-start;
    margin-top: 8px;
    padding: 5px 8px;
    border-radius: 999px;
    background: rgba(36,138,61,.1);
    color: var(--success);
    font-size: 10px;
    font-style: normal;
    font-weight: 750;
}

.stats-note {
    margin: 14px 2px 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.stats-loading,
.stats-error {
    padding: 30px 12px;
    color: var(--muted);
    text-align: center;
    font-size: 13px;
}

.stats-error {
    color: var(--danger);
}

.sort-help {
    margin: -4px 0 14px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.sort-list {
    display: grid;
    gap: 9px;
}

.sort-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 13px;
    border: 1px solid var(--line);
    border-radius: 17px;
    background: #fafafa;
}

.sort-goal-info {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 11px;
}

.sort-goal-info .goal-icon {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
    border-radius: 13px;
    font-size: 20px;
}

.sort-goal-info > div {
    min-width: 0;
}

.sort-goal-info strong,
.sort-state {
    display: block;
}

.sort-goal-info strong {
    overflow-wrap: anywhere;
}

.sort-state {
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 650;
}

.sort-controls {
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
}

.sort-move-button {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 13px;
    background: #ededf1;
    color: var(--text);
    font-size: 18px;
    font-weight: 750;
}

.sort-actions {
    margin-top: 16px;
}

@media (max-width: 560px) {
    #goalsPanel > .section-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
    }

    #goalsPanel > .section-heading .heading-actions {
        width: 100%;
        justify-content: stretch;
    }

    #goalsPanel > .section-heading .small-button {
        flex: 1;
    }

    .utility-sheet {
        padding: 18px 16px;
        border-radius: 26px;
    }
}

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

    .sort-row {
        align-items: flex-start;
    }

    .sort-controls {
        flex-direction: column;
    }
}

@media (prefers-reduced-motion: reduce) {
    .streak-card-button,
    .archive-toggle svg,
    .utility-overlay,
    .utility-sheet {
        transition: none;
        animation: none;
    }
}
