:root {
    color-scheme: dark;
    font-family: system-ui, sans-serif;
    background: var(--canvas);
    color: var(--ink);
    --canvas: #0d0d10;
    --ink: #f1eef0;
    --muted: #b9afb6;
    --accent: #ff8296;
    --brand: #bd102c;
    --border: #3b3037;
    --surface: #19171b;
    --input: #121115;
    --accent-soft: #301b24;
    --green: #9be5b7;
    --green-soft: #163025;
    --green-border: #41684f;
    --amber: #ffdc89;
    --amber-soft: #392d17;
    --red: #ffadb8;
    --red-soft: #3a2028;
    --inactive: #242127;
}

:root[data-theme="light"] {
    color-scheme: light;
    --canvas: #f8f8f8;
    --ink: #282426;
    --muted: #686166;
    --accent: #bd102c;
    --border: #e5dfe1;
    --surface: #fff;
    --input: #fff;
    --accent-soft: #fff0f2;
    --green: #16724b;
    --green-soft: #eaf7ef;
    --green-border: #a9d7bd;
    --amber: #745005;
    --amber-soft: #fff1cb;
    --red: #b42335;
    --red-soft: #fff0f2;
    --inactive: #f4f1f2;
}
* { box-sizing: border-box; }
body { margin: 0; padding-inline: env(safe-area-inset-left) env(safe-area-inset-right); }
.frame { width: min(100% - 32px, 760px); margin-inline: auto; }
.top { padding-top: env(safe-area-inset-top); border-bottom: 1px solid var(--border); background: var(--surface); }
.top-inner, .brand { display: flex; align-items: center; }
.top-inner { justify-content: space-between; min-height: 66px; gap: 10px; }
.brand { gap: 8px; color: inherit; text-decoration: none; font-weight: 800; }
.brand span { background: var(--brand); color: #fff; border-radius: 8px; padding: 4px 8px; }
main { padding-block: 30px 54px; }
body:not(.has-app-tabs) { padding-bottom: env(safe-area-inset-bottom, 0px); }
h1 { font-size: clamp(2rem, 6vw, 3rem); margin: 0 0 12px; line-height: 1.08; letter-spacing: -.045em; }
h2 { font-size: 1.25rem; margin: 28px 0 12px; }
h3 { font-size: 1rem; margin: 0 0 4px; overflow-wrap: anywhere; }
p { line-height: 1.5; }
a { color: var(--accent); }
.card, .hero { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: clamp(14px, 4vw, 24px); }
.hero { background: linear-gradient(130deg, var(--accent-soft), var(--surface) 70%); padding: clamp(10px, 3vw, 18px); }
.streak-summary { margin-top: 14px; color: var(--muted); font-size: .875rem; }
.streak-summary p { margin: 0 0 4px; }
.streak-summary strong { margin-inline-start: 4px; color: var(--accent); }
.muted { color: var(--muted); }
.auth { max-width: 460px; margin-inline: auto; }
.stack { display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-size: .88rem; font-weight: 650; }
input, button { font: inherit; min-height: 44px; border-radius: 9px; }
input { width: 100%; min-width: 0; border: 1px solid var(--border); background: var(--input); color: inherit; padding: 8px 10px; font-size: 1rem; }
button { border: 1px solid transparent; background: var(--brand); color: #fff; padding: 8px 12px; font-weight: 750; cursor: pointer; }
button.secondary { background: transparent; color: inherit; border-color: var(--border); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.setup-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(112px, 140px); gap: 10px; }
.habit-title, .habit-form, .task-row { display: flex; align-items: center; gap: 8px; }
.habit-title, .task-row { justify-content: space-between; }
.habit-form { flex-wrap: wrap; margin-top: 10px; }
.habit-form input { flex: 1 1 165px; }
.habit-form button { flex: 1 0 auto; }
.habit.done { border-color: var(--green-border); }
.pill { color: var(--green); white-space: nowrap; font-size: .8rem; }
.task-row { border-top: 1px solid var(--border); padding-top: 10px; }
.task-row span { overflow-wrap: anywhere; }
.task-done { text-decoration: line-through; color: var(--muted); }
.calendar { margin-top: 16px; }
.calendar-head { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; gap: 4px; margin-bottom: 12px; }
.calendar-head h2 { grid-column: 2; margin: 0; text-align: center; }
.calendar-head a:last-child { grid-column: 3; }
.calendar-head a { display: grid; place-items: center; min-width: 44px; min-height: 44px; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: clamp(3px, 1vw, 8px); text-align: center; }
.weekday { font-size: .75rem; color: var(--muted); }
.day { display: grid; place-content: center; min-height: clamp(43px, 11vw, 60px); border-radius: 9px; font-weight: 750; }
.day small { font-size: .65rem; }
.day[aria-current] { box-shadow: inset 0 0 0 2px var(--accent); }
.full { background: var(--green-soft); color: var(--green); }
.partial { background: var(--amber-soft); color: var(--amber); }
.missed { background: var(--red-soft); color: var(--red); }
.inactive { background: var(--inactive); color: var(--muted); }
.legend { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.legend span { padding: 5px 7px; border-radius: 6px; font-size: .75rem; }
.errors { background: var(--red-soft); color: var(--red); border-radius: 10px; padding: 1px 12px; margin-bottom: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.phone-field { display: grid; gap: 6px; }

.hero-overview { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hero-copy { min-width: 0; }
.hero-copy p { margin: 0; color: var(--muted); font-size: .8rem; }
.hero-copy .date { color: var(--accent); font-weight: 700; }
.hero-copy h1 { margin: 5px 0; font-size: clamp(1.35rem, 5vw, 1.85rem); overflow-wrap: anywhere; }

@property --daily-fill {
    syntax: '<percentage>';
    inherits: false;
    initial-value: 0%;
}
.daily-ring {
    --daily-fill: var(--daily-target);
    --ring-color: var(--accent);
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    --ring-size: clamp(56px, 16vw, 68px);
    width: var(--ring-size);
    height: var(--ring-size);
    padding: 5px;
    border-radius: 50%;
    background: conic-gradient(var(--ring-color) var(--daily-fill), var(--border) 0);
    transition: --daily-fill 350ms ease-out;
}
.daily-ring-complete { --ring-color: var(--green); }
.daily-ring > span {
    display: grid;
    grid-auto-flow: column;
    place-content: center;
    align-items: baseline;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--surface);
    color: var(--ink);
    font-size: 1.25rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}
.daily-ring small { color: var(--muted); font-size: .75rem; }

.hero-streak {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0 12px;
    margin-top: 8px;
    padding-top: 3px;
    border-top: 1px solid var(--border);
}
.streak-stat { display: flex; align-items: center; gap: 8px; }
.streak-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--accent-soft); }
.streak-icon:not(.streak-lit) > span { filter: grayscale(1); opacity: .55; }
.streak-lit {
    background: #682437;
    box-shadow: 0 0 12px #e2555050;
}
.streak-lit > span { transform-origin: center bottom; animation: streak-flicker 900ms ease-in-out 3; }
.streak-stat p { margin: 0; color: var(--muted); font-size: .72rem; }
.streak-stat strong { font-size: 1.15rem; line-height: 1.05; }
.progress-link { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font-size: .8rem; font-weight: 750; }
@keyframes streak-flicker {
    30% { transform: rotate(-8deg) scale(1.1); filter: brightness(1.18); }
    70% { transform: rotate(7deg) scale(.95); }
}
@media (prefers-reduced-motion: reduce) {
    .daily-ring { transition: none; }
    .streak-lit > span { animation: none; }
}
.calendar { border-top: 3px solid var(--accent); }
.day-meter { display: flex; justify-content: center; gap: 1px; margin-top: 3px; }
.day-meter i { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: .23; }
.day-meter .filled { opacity: 1; }
.legend .legend-today { box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent); }


.habit-form button[aria-disabled="true"] { cursor: wait; }
.checkin-error { margin: 8px 0 0; color: var(--red); font-size: .85rem; }
.streak-celebration {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    pointer-events: none;
    color: white;
}
.celebration-shade { position: absolute; inset: 0; background: radial-gradient(circle at center, #361521e8, #08060bf5 65%); }
.celebration-flame { position: relative; font-size: clamp(4rem, 16vw, 6rem); line-height: 1; text-shadow: 0 0 34px #f95b30; }
.streak-celebration strong { position: absolute; top: calc(50% + 3.7rem); text-align: center; font-size: clamp(1.15rem, 5vw, 1.6rem); }

.edit-link {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface);
    color: var(--accent);
    cursor: pointer;
    font-size: 1.25rem;
    text-decoration: none;
    list-style: none;
}
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 22px 0 10px; }
.section-heading h1, .section-heading h2 { margin: 0; }
.section-heading h2 { font-size: clamp(1.15rem, 4.7vw, 1.5rem); }
.edit-link { flex: 0 0 44px; }
.editor-heading h1 { font-size: clamp(1.65rem, 6vw, 2.5rem); }
.back-link { display: inline-flex; align-items: center; min-height: 44px; }
.habit-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(104px, 132px); gap: 12px; }
.habit-editor > button, .habit-editor > span { grid-column: 1 / -1; }
.habit-editor > button { justify-self: start; }
.save-indicator { margin: 10px 0 0; color: var(--accent); font-size: .85rem; }
[data-task-list][hidden] { display: none; }
[data-task-list] .checkin-error { width: 100%; margin: 0; }
.task-row { flex-wrap: wrap; }
.task-row > span { flex: 1 1 100px; }

.group-heading, .group-tile-heading, .group-tile-body {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.group-heading { margin-bottom: 16px; }
.group-heading h1, .group-tile h2 { margin: 0; overflow-wrap: anywhere; min-width: 0; }
.group-home-link, .group-history-link {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    margin-top: 12px;
    min-height: 48px;
    padding: 12px 14px;
    text-decoration: none;
    font-weight: 750;
}
.group-home-link > :last-child, .group-history-link > :last-child, .group-arrow { margin-inline-start: auto; color: var(--accent); }
.group-tile { display: grid; gap: 14px; color: var(--ink); text-decoration: none; }
.group-tile:hover, .group-history-link:hover, .group-home-link:hover { border-color: var(--accent); }
.group-tile-body { justify-content: flex-start; color: var(--muted); font-size: .9rem; }
.group-days { color: var(--accent); font-size: .9rem; font-weight: 750; white-space: nowrap; }
.group-avatars { display: flex; padding-inline-start: 3px; }
.group-avatars .group-avatar { margin-inline-start: -3px; }
.group-avatar {
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: .82rem;
    font-weight: 800;
}
.group-avatar.is-ready { background: var(--green-soft); color: var(--green); }
.group-empty { display: flex; align-items: center; gap: 12px; }
.group-empty > span { font-size: 1.55rem; }
.group-empty p { margin: 0; }
.group-actions { display: grid; gap: 10px; margin-top: 14px; }
.group-action { padding: 0; }
.group-action > summary, .group-leave > summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 50px;
    padding: 8px 12px;
    color: var(--accent);
    cursor: pointer;
    list-style: none;
    font-weight: 750;
}
.group-action > summary::-webkit-details-marker, .group-leave > summary::-webkit-details-marker { display: none; }
.group-action-primary:not([open]) { background: var(--brand); border-color: var(--brand); }
.group-action-primary:not([open]) > summary { color: white; }
.group-action > form, .group-action > p, .group-action > .group-code { margin: 0 14px 14px; }
.group-action > form > button { justify-self: start; }
.group-streak-hero {
    display: grid;
    place-items: center;
    padding: 18px;
    border-color: #6d3544;
    background: radial-gradient(ellipse at 50% 0%, #752938, #23151d 75%);
    color: #fff5f6;
}
.group-streak-hero p { color: #ffc0ce; margin: 3px 0 0; font-size: .85rem; font-weight: 700; }
.group-streak-hero strong { font-size: clamp(2rem, 7vw, 3.35rem); line-height: 1.13; letter-spacing: -.04em; }
.group-flame { font-size: 1.8rem; filter: grayscale(1); opacity: .65; }
.group-flame-lit { filter: drop-shadow(0 0 14px #ff7945); opacity: 1; }
.group-section { margin-top: 18px; }
.group-section > h2, .group-section > p { margin: 0 0 8px; }
.group-segments { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.group-segments > span { flex: 1 0 6px; height: 9px; border-radius: 9px; background: var(--border); }
.group-segments > .is-ready { background: var(--green); }
.group-team, .group-inbox { margin: 0; padding: 0 12px; list-style: none; }
.group-team li {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) auto;
    align-items: center;
    gap: 5px 8px;
    min-height: 52px;
    padding-block: 8px;
}
.group-team li + li, .group-inbox li + li { border-top: 1px solid var(--border); }
.group-team strong { overflow-wrap: anywhere; }
.member-status { color: var(--muted); font-size: .78rem; }
.member-ready { color: var(--green); font-weight: 750; }
.member-cheered, .group-team form { grid-column: 2 / -1; justify-self: end; }
.member-cheered { color: var(--muted); font-size: .75rem; }
.group-team button { font-size: .8rem; }
.group-notice { padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--ink); }
.group-inbox-link { font-size: .85rem; white-space: nowrap; }
.group-inbox li { padding-block: 10px; }
.group-invite { margin-top: 10px; }
.group-code { display: flex; align-items: end; gap: 8px; }
.group-code label { flex: 1 1 auto; min-width: 0; }
.group-code input { font-family: ui-monospace, monospace; }
.group-leave { margin-top: 10px; }
.group-leave > summary { justify-content: flex-start; color: var(--muted); font-size: .85rem; }
.group-leave > form { padding: 0 12px; }
.group-celebration {
    width: min(100% - 32px, 390px);
    border: 1px solid #6d3544;
    border-radius: 24px;
    padding: clamp(22px, 7vw, 38px);
    background: radial-gradient(ellipse at top, #5b251e, #17131a 70%);
    color: #fff5f6;
    text-align: center;
}
.group-celebration::backdrop { background: #08060cdb; }
.group-celebration h2 { margin: 10px 0 4px; font-size: clamp(1.75rem, 7vw, 2.4rem); }
.group-celebration p { margin: 0 0 18px; color: #ffc0ce; }
.group-celebration button { width: 100%; }
.group-celebration-flame { font-size: clamp(3.6rem, 16vw, 5rem); filter: drop-shadow(0 0 22px #e64b24); }
@media (prefers-reduced-motion: no-preference) {
    .group-celebration[open] .group-celebration-flame { animation: group-ignite 850ms ease-out; }
    @keyframes group-ignite {
        from { transform: scale(.65); opacity: .3; }
        65% { transform: scale(1.15); }
    }
}

.has-app-tabs {
    --tab-space: calc(68px + env(safe-area-inset-bottom));
    padding-bottom: var(--tab-space);
}
html:has(.has-app-tabs) { scroll-padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
.app-tabs {
    position: fixed;
    z-index: 20;
    inset: auto 0 0;
    padding: 5px env(safe-area-inset-right) max(5px, env(safe-area-inset-bottom)) env(safe-area-inset-left);
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.app-tabs-inner {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
}
.app-tabs a {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 3px;
    min-height: 48px;
    border-radius: 10px;
    color: var(--muted);
    text-decoration: none;
    font-size: .75rem;
    font-weight: 650;
}
.app-tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.app-tabs a:hover { color: var(--accent); }
.app-tabs svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.settings-row p { margin: 4px 0 0; font-size: .875rem; }
button.theme-switch {
    flex: 0 0 auto;
    min-width: 52px;
    padding: 0 5px;
    border: 1px solid var(--border);
    background: var(--inactive);
    border-radius: 24px;
}
.theme-switch span { display: block; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); }
.theme-switch[aria-checked="true"] { background: var(--brand); border-color: var(--brand); }
.theme-switch[aria-checked="true"] span { background: white; margin-inline-start: auto; }
.account-details { margin: 0; padding-block: 0; }
.account-details > div { padding: 12px 0; }
.account-details > div + div { border-top: 1px solid var(--border); }
.account-details dt { color: var(--muted); font-size: .82rem; }
.account-details dd { margin: 4px 0 0; overflow-wrap: anywhere; font-weight: 650; }
.settings-logout { margin-top: 16px; }
.settings-logout button { color: var(--red); }
