/* Cupertino design tokens and components, modelled on iOS system colours and metrics. */
:root {
    --bg: #F2F2F7;
    --bg-elevated: #FFFFFF;
    --card: #FFFFFF;
    --card-2: #F2F2F7;
    --label: #000000;
    --label-2: rgba(60, 60, 67, .6);
    --label-3: rgba(60, 60, 67, .3);
    --separator: rgba(60, 60, 67, .18);
    --fill: rgba(120, 120, 128, .12);
    --fill-2: rgba(120, 120, 128, .2);
    --tint: #000000;
    --on-tint: #FFFFFF;
    --tint-soft: rgba(0, 0, 0, .06);
    --red: #FF3B30;
    --green: #34C759;
    --orange: #FF9500;
    --purple: #AF52DE;
    --bar: rgba(249, 249, 249, .78);
    --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);
    --radius: 12px;
    --radius-lg: 20px;
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI Variable Text", "Segoe UI", system-ui, "Helvetica Neue", sans-serif;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --tabbar-h: 50px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #000000;
        --bg-elevated: #1C1C1E;
        --card: #1C1C1E;
        --card-2: #2C2C2E;
        --label: #FFFFFF;
        --label-2: rgba(235, 235, 245, .6);
        --label-3: rgba(235, 235, 245, .3);
        --separator: rgba(84, 84, 88, .55);
        --fill: rgba(118, 118, 128, .24);
        --fill-2: rgba(118, 118, 128, .32);
        --tint: #FFFFFF;
        --on-tint: #000000;
        --tint-soft: rgba(255, 255, 255, .1);
        --red: #FF453A;
        --green: #30D158;
        --orange: #FF9F0A;
        --purple: #BF5AF2;
        --bar: rgba(22, 22, 24, .78);
        --shadow: none;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #000000; --bg-elevated: #1C1C1E; --card: #1C1C1E; --card-2: #2C2C2E; --label: #FFFFFF;
    --label-2: rgba(235, 235, 245, .6); --label-3: rgba(235, 235, 245, .3); --separator: rgba(84, 84, 88, .55);
    --fill: rgba(118, 118, 128, .24); --fill-2: rgba(118, 118, 128, .32); --tint: #FFFFFF; --on-tint: #000000; --tint-soft: rgba(255, 255, 255, .1);
    --red: #FF453A; --green: #30D158; --orange: #FF9F0A; --purple: #BF5AF2; --bar: rgba(22, 22, 24, .78); --shadow: none;
    color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
    background: var(--bg);
    color: var(--label);
    font-family: var(--font);
    font-size: 17px;
    line-height: 1.29;
    letter-spacing: -0.41px;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
a { color: var(--tint); text-decoration: none; font-weight: 500; }
.row, .tile, .tab-bar a { font-weight: inherit; }
img { display: block; max-width: 100%; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--tint); outline-offset: 2px; border-radius: 6px; }

/* ---------- App shell ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.page {
    flex: 1;
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    padding: 0 16px calc(var(--tabbar-h) + var(--safe-bottom) + 32px);
}
.page.no-tabs { padding-bottom: calc(var(--safe-bottom) + 32px); }

/* Navigation bar: translucent, compact title fades in once the large title scrolls away. */
.nav-bar {
    position: sticky; top: 0; z-index: 20;
    padding-top: var(--safe-top);
    background: transparent;
    transition: background-color .2s, border-color .2s;
    border-bottom: 0.5px solid transparent;
}
.nav-bar.scrolled {
    background: var(--bar);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-bottom-color: var(--separator);
}
.nav-row {
    max-width: 760px; margin: 0 auto;
    height: 44px; padding: 0 8px;
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
}
.nav-title { font-weight: 600; font-size: 17px; opacity: 0; transition: opacity .2s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 56vw; }
.nav-bar.scrolled .nav-title, .nav-bar.compact .nav-title { opacity: 1; }
.nav-leading { justify-self: start; display: flex; gap: 4px; }
.nav-trailing { justify-self: end; display: flex; gap: 4px; align-items: center; }
.page-head { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px; }
.large-title { font-size: 34px; font-weight: 700; letter-spacing: 0.37px; line-height: 1.2; padding: 2px 0 10px; }
.large-subtitle { color: var(--label-2); font-size: 15px; margin-top: -6px; padding-bottom: 14px; letter-spacing: -0.24px; }

.bar-btn {
    display: inline-flex; align-items: center; gap: 2px;
    min-height: 44px; min-width: 44px; padding: 0 8px; justify-content: center;
    background: none; border: 0; color: var(--tint); font-size: 17px; cursor: pointer;
}
.bar-btn:disabled { color: var(--label-3); cursor: default; }
.bar-btn.bold { font-weight: 600; }
.bar-btn svg { width: 22px; height: 22px; }
.bar-btn .chev { width: 13px; height: 21px; margin-right: 4px; }

/* Tab bar */
.tab-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding-bottom: var(--safe-bottom);
    background: var(--bar);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-top: 0.5px solid var(--separator);
}
.tab-bar nav { display: flex; max-width: 560px; margin: 0 auto; height: var(--tabbar-h); }
.tab-bar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--label-2); font-size: 10px; font-weight: 500; letter-spacing: 0.1px;
}
.tab-bar a svg { width: 26px; height: 26px; }
.tab-bar a.active { color: var(--tint); }

/* ---------- Grouped lists ---------- */
.section { margin: 0 0 28px; }
.section-header {
    font-size: 13px; color: var(--label-2); text-transform: uppercase; letter-spacing: -0.08px;
    padding: 0 16px 6px; display: flex; justify-content: space-between; align-items: baseline;
}
.section-header a, .section-header button { text-transform: none; font-size: 15px; background: none; border: 0; color: var(--tint); cursor: pointer; padding: 0; }
.section-footer { font-size: 13px; color: var(--label-2); padding: 6px 16px 0; letter-spacing: -0.08px; }
.group { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.row {
    position: relative; display: flex; align-items: center; gap: 12px;
    min-height: 44px; padding: 10px 16px;
    background: none; border: 0; width: 100%; text-align: left; color: var(--label);
}
.row + .row::before, .row + .row-wrap::before, .row-wrap + .row::before {
    content: ""; position: absolute; top: 0; right: 0; left: 16px; height: 0.5px; background: var(--separator);
}
.row.with-icon + .row::before, .row.with-icon + .row.with-icon::before { left: 56px; }
a.row, button.row { cursor: pointer; }
a.row:active, button.row:active { background: var(--fill); }
.row-body { flex: 1; min-width: 0; }
.row-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--label-2); margin-top: 2px; letter-spacing: -0.08px; }
.row-value { color: var(--label-2); white-space: nowrap; }
.row-chev { width: 8px; height: 14px; color: var(--label-3); flex: none; }
.row.destructive { color: var(--red); justify-content: center; }
.row.tinted { color: var(--tint); }
.row-icon {
    width: 29px; height: 29px; border-radius: 7px; flex: none;
    display: grid; place-items: center; color: var(--on-tint); background: var(--tint);
}
.row-icon svg { width: 18px; height: 18px; }
.row input[type=text], .row input[type=email], .row input[type=password], .row select, .row textarea {
    flex: 1; min-width: 0; border: 0; background: none; outline: none; padding: 0; text-align: right; color: var(--label-2);
}
.row.stacked input, .row.stacked textarea { text-align: left; color: var(--label); }
.row textarea { resize: none; min-height: 64px; text-align: left; color: var(--label); }
.row select { appearance: none; -webkit-appearance: none; text-align-last: right; cursor: pointer; }
.row label { flex: none; }

/* ---------- Controls ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 50px; padding: 0 20px; border-radius: 14px; border: 0; cursor: pointer;
    background: var(--tint); color: var(--on-tint); font-weight: 600; font-size: 17px;
    transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(.98); opacity: .85; }
.btn:disabled { opacity: .4; cursor: default; transform: none; }
.btn.block { width: 100%; }
.btn.gray { background: var(--fill); color: var(--tint); }
.btn.plain { background: none; color: var(--tint); }
.btn.small { height: 34px; padding: 0 14px; border-radius: 17px; font-size: 15px; }
.btn svg { width: 20px; height: 20px; }

.segmented {
    display: flex; padding: 2px; border-radius: 9px; background: var(--fill); position: relative;
}
.segmented button {
    flex: 1 1 0; min-width: 0; border: 0; background: none; padding: 6px 4px; border-radius: 7px; font-size: 13px; font-weight: 500;
    cursor: pointer; color: var(--label); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.08px;
    transition: background .2s, box-shadow .2s;
}
.segmented button.on { background: var(--bg-elevated); box-shadow: 0 3px 8px rgba(0,0,0,.12), 0 3px 1px rgba(0,0,0,.04); font-weight: 600; }
:root[data-theme="dark"] .segmented button.on { background: #636366; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .segmented button.on { background: #636366; } }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
    border: 0; border-radius: 16px; padding: 7px 14px; font-size: 15px; cursor: pointer; white-space: nowrap;
    background: var(--fill); color: var(--label); transition: background .15s, color .15s;
}
.chip.on { background: var(--tint); color: var(--on-tint); }

.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--fill-2); transition: background .2s; cursor: pointer; }
.switch span::after {
    content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
    background: #fff; box-shadow: 0 3px 8px rgba(0,0,0,.15), 0 3px 1px rgba(0,0,0,.06); transition: transform .2s;
}
.switch input:checked + span { background: var(--label); }
.switch input:checked + span::after { transform: translateX(20px); }

.stepper { display: inline-flex; background: var(--fill); border-radius: 8px; overflow: hidden; flex: none; }
.stepper button { border: 0; background: none; width: 46px; height: 32px; font-size: 20px; cursor: pointer; color: var(--label); }
.stepper button + button { border-left: 0.5px solid var(--separator); }
.stepper button:disabled { color: var(--label-3); }

input[type=range] { width: 100%; accent-color: var(--tint); }

.search {
    display: flex; align-items: center; gap: 6px; background: var(--fill); border-radius: 10px; height: 36px; padding: 0 8px;
    color: var(--label-2); margin-bottom: 12px;
}
.search input { flex: 1; border: 0; background: none; outline: none; color: var(--label); }
.search svg { width: 16px; height: 16px; }

/* ---------- Cards, tiles ---------- */
.card { background: var(--card); border-radius: var(--radius-lg); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(5, 1fr); } }
.tile { position: relative; display: block; color: var(--label); min-width: 0; }
.tile-img {
    aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; background: var(--card);
    display: grid; place-items: center; position: relative;
}
.tile-img img { width: 100%; height: 100%; object-fit: cover; }
.tile-img svg.garment { width: 66%; height: 66%; }
.tile-name { font-size: 12px; margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: 0; }
.tile-sub { font-size: 11px; color: var(--label-2); display: flex; align-items: center; gap: 4px; letter-spacing: 0; }
.badge {
    position: absolute; top: 6px; left: 6px; padding: 2px 7px; border-radius: 10px; font-size: 11px; font-weight: 600;
    background: var(--bar); color: var(--label); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); letter-spacing: 0;
    display: inline-flex; align-items: center; gap: 4px;
}
.badge.buy { background: var(--tint); color: var(--on-tint); }
.badge.warn { background: var(--label); color: var(--bg); }
.badge.bad { background: var(--red); color: #fff; }

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 0.5px rgba(0,0,0,.2); display: inline-block; }

.swatches { display: flex; border-radius: 10px; overflow: hidden; height: 28px; box-shadow: inset 0 0 0 0.5px var(--separator); }
.swatches span { flex: 1; }
.swatches.mini { height: 16px; width: 90px; border-radius: 5px; flex: none; }
.swatches.big { height: 112px; border-radius: 16px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 24px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px 10px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 22px; font-weight: 700; letter-spacing: 0.35px; }
.stat span { font-size: 11px; color: var(--label-2); letter-spacing: 0; }

.h-scroll { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 4px; }
.h-scroll::-webkit-scrollbar { display: none; }
.h-scroll > * { scroll-snap-align: start; flex: none; width: 104px; }

.outfit { background: var(--card); border-radius: var(--radius); padding: 10px; flex: none; width: 236px; box-shadow: var(--shadow); }
.outfit-label { font-size: 12px; font-weight: 600; color: var(--tint); margin-bottom: 8px; letter-spacing: 0; }
.outfit-pieces { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.outfit-pieces .tile-img { border-radius: 8px; background: var(--card-2); }

.banner {
    display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: var(--radius); margin-bottom: 16px;
    background: var(--tint-soft); color: var(--label); font-size: 15px; letter-spacing: -0.24px;
}
.banner.warn { background: var(--fill); }
.banner.error { background: rgba(255, 59, 48, .12); }
.spinner.on-tint { border-color: color-mix(in srgb, var(--on-tint) 30%, transparent); border-top-color: var(--on-tint); }
.banner svg { width: 20px; height: 20px; flex: none; color: var(--tint); }

.empty { text-align: center; padding: 56px 24px; color: var(--label-2); }
.empty > svg { width: 64px; height: 64px; color: var(--label-3); margin-bottom: 12px; }
.empty h3 { color: var(--label); font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.empty p { margin-bottom: 20px; font-size: 15px; }

.spinner {
    width: 18px; height: 18px; border-radius: 50%; flex: none;
    border: 2.5px solid var(--fill-2); border-top-color: var(--label-2);
    animation: spin .8s linear infinite;
}
.spinner.large { width: 32px; height: 32px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.center { display: grid; place-items: center; padding: 64px 0; }

/* ---------- Sheet (modal) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; animation: fade .2s; }
.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-width: 560px; margin: 0 auto;
    background: var(--bg); border-radius: 14px 14px 0 0; padding: 8px 16px calc(var(--safe-bottom) + 20px);
    animation: rise .32s cubic-bezier(.2, .9, .3, 1); max-height: 92dvh; overflow: auto;
}
.sheet-grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--fill-2); margin: 0 auto 8px; }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin: 0 -8px 12px; }
.sheet-head h3 { font-size: 17px; font-weight: 600; }
.sheet-head > :last-child { justify-self: end; }
@keyframes rise { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.toast {
    position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px); transform: translateX(-50%);
    background: rgba(30,30,30,.92); color: #fff; padding: 10px 18px; border-radius: 22px; z-index: 60; font-size: 15px;
    animation: fade .2s; -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); white-space: nowrap;
}

/* ---------- Auth ---------- */
.auth { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; max-width: 420px; margin: 0 auto; padding: calc(var(--safe-top) + 24px) 16px calc(var(--safe-bottom) + 24px); }
.app-icon {
    width: 88px; height: 88px; border-radius: 22px; margin: 0 auto 18px; display: grid; place-items: center;
    background: linear-gradient(160deg, #3A3A3C, #000000); box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
}
.app-icon svg { width: 52px; height: 52px; color: #fff; }
.auth h1 { text-align: center; font-size: 30px; font-weight: 700; letter-spacing: 0.35px; }
.auth .tagline { text-align: center; color: var(--label-2); margin: 6px 0 28px; font-size: 15px; }
.auth .segmented { margin-bottom: 20px; }
.form-error { color: var(--red); font-size: 13px; padding: 8px 16px 0; }

/* ---------- Quiz ---------- */
.progress { display: flex; gap: 4px; margin: 4px 0 20px; }
.progress span { flex: 1; height: 4px; border-radius: 2px; background: var(--fill-2); transition: background .3s; }
.progress span.done { background: var(--tint); }
.quiz-q { font-size: 28px; font-weight: 700; letter-spacing: 0.36px; }
.quiz-sub { color: var(--label-2); margin: 4px 0 20px; }
.options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.option {
    background: var(--card); border: 0; border-radius: var(--radius-lg); padding: 10px 10px 12px; cursor: pointer; text-align: center;
    box-shadow: var(--shadow); outline: 2.5px solid transparent; transition: outline-color .15s, transform .12s; color: var(--label);
}
.option:active { transform: scale(.97); }
.option.on { outline-color: var(--tint); }
.option-art { aspect-ratio: 1; border-radius: 14px; background: var(--card-2); display: grid; place-items: center; overflow: hidden; margin-bottom: 8px; }
.option-art img { width: 100%; height: 100%; object-fit: cover; }
.option-art svg { width: 92%; height: 92%; }
.option span { font-weight: 600; font-size: 15px; letter-spacing: -0.24px; }

.bar-chart { display: grid; gap: 10px; }
.bar-chart .bar-row { display: grid; grid-template-columns: 96px 1fr 36px; align-items: center; gap: 10px; font-size: 15px; }
.bar-chart .bar { height: 8px; border-radius: 4px; background: var(--fill); overflow: hidden; }
.bar-chart .bar i { display: block; height: 100%; border-radius: 4px; background: var(--tint); }
.bar-chart small { color: var(--label-2); text-align: right; }

/* ---------- Palette editor ---------- */
.palette-strip { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; height: 168px; border-radius: 20px; overflow: hidden; box-shadow: var(--shadow); }
.palette-cell { position: relative; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; padding: 8px 2px; gap: 4px; min-width: 0; }
.palette-cell input[type=color] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.palette-cell .pc-name { font-size: 11px; font-weight: 600; letter-spacing: 0; text-align: center; overflow: hidden; text-overflow: ellipsis; max-width: 100%; white-space: nowrap; }
.palette-cell .pc-role { font-size: 10px; opacity: .75; letter-spacing: 0; }
.palette-cell button { position: relative; z-index: 1; border: 0; background: rgba(0,0,0,.18); color: inherit; border-radius: 50%; width: 28px; height: 28px; display: grid; place-items: center; cursor: pointer; }
.palette-cell button svg { width: 15px; height: 15px; }
.palette-cell.light { color: #000; }
.palette-cell.dark { color: #fff; }
.palette-cell.light button { background: rgba(255,255,255,.5); }

.detail-hero { border-radius: var(--radius-lg); overflow: hidden; background: var(--card); aspect-ratio: 4 / 5; margin-bottom: 20px; max-height: 60dvh; display: grid; place-items: center; }
.detail-hero img { width: 100%; height: 100%; object-fit: contain; }

.color-input { width: 28px; height: 28px; border: 0; padding: 0; background: none; border-radius: 50%; overflow: hidden; cursor: pointer; flex: none; }
.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: 0.5px solid var(--separator); border-radius: 50%; }
.color-input::-moz-color-swatch { border: 0.5px solid var(--separator); border-radius: 50%; }

.muted { color: var(--label-2); }
.small { font-size: 13px; letter-spacing: -0.08px; }
.stack { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.spacer { height: 16px; }

#blazor-error-ui {
    display: none; position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); z-index: 100;
    background: var(--red); color: #fff; padding: 12px 16px; border-radius: 12px;
}
#blazor-error-ui a { color: #fff; font-weight: 600; margin-left: 8px; }
#blazor-error-ui .dismiss { float: right; cursor: pointer; }
