:root {
    /* Palette lifted from silkycolor.com — white, near-black ink, caramel gold accent */
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f8f6f3;
    --line: #e6e1da;
    --ink: #212529;
    --muted: #6c757d;
    --accent: #c3935b;
    --accent-hover: #ac7a3f;
    --accent-ink: #ffffff;
    --danger: #dc3545;
    --ok: #28a745;
    --radius: 14px;
    --shadow: 0 8px 28px rgba(33, 37, 41, .07);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: radial-gradient(1200px 600px at 80% -10%, #f6f1ea 0%, var(--bg) 55%);
    color: var(--ink);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, .85);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 5;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 650;
    letter-spacing: .2px;
}

.brand .dot {
    width: 26px; height: 26px; border-radius: 50%;
    background: conic-gradient(from 200deg, #c3935b, #ac7a3f, #8f5f2e, #d8b98d, #c3935b);
    box-shadow: inset 0 0 0 2px rgba(255,255,255,.35);
}

.brand small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }

.topbar .who { color: var(--muted); font-size: 14px; display: flex; gap: 14px; align-items: center; }

/* ── Language selector (topbar / floating on login) ─────────────────────── */
.lang-seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.lang-seg button {
    background: transparent; color: var(--muted); border-radius: 0;
    font-size: 12px; font-weight: 600; letter-spacing: .6px; padding: 5px 11px;
    border-right: 1px solid var(--line);
}
.lang-seg button:last-child { border-right: none; }
.lang-seg button:hover { color: var(--ink); }
.lang-seg button.on { background: var(--accent); color: var(--accent-ink); }
.lang-seg select {
    display: none;              /* phones only — swapped in at 640px */
    width: auto;
    background: transparent;
    border: none;
    border-radius: 999px;
    color: var(--ink);
    font-size: 16px;            /* ≥16px so iOS doesn't zoom on focus */
    font-weight: 600;
    letter-spacing: .6px;
    padding: 5px 6px;
}
.lang-float { position: fixed; top: 18px; right: 20px; z-index: 5; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 28px 24px 64px; }

.grid { display: grid; grid-template-columns: 1.05fr .95fr; gap: 24px; align-items: start; }
@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
}

.card h2 { margin: 0 0 4px; font-size: 18px; }
.card .sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }

input, select {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--ink);
    border-radius: 10px;
    padding: 11px 12px;
    font-size: 15px;
    outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row > div { min-width: 0; }

.range-wrap { display: flex; align-items: center; gap: 12px; }
.range-wrap output {
    min-width: 34px; text-align: center; font-variant-numeric: tabular-nums;
    background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px;
}
input[type=range] { accent-color: var(--accent); padding: 0; }

button {
    cursor: pointer;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    padding: 12px 16px;
    transition: transform .04s ease, filter .15s ease;
}
button:active { transform: translateY(1px); }

.btn-primary { background: var(--accent); color: var(--accent-ink); width: 100%; margin-top: 22px; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }

.err { color: var(--danger); font-size: 14px; min-height: 18px; margin-top: 10px; }

/* ── Preview ─────────────────────────────────────────────────────────────── */
.preview { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.swatch {
    position: relative;
    aspect-ratio: 3 / 4;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    background-image:
        repeating-linear-gradient(115deg, rgba(255,255,255,.06) 0 2px, transparent 2px 7px);
    background-color: #6b4f38;
}
.swatch .tint { position: absolute; inset: 0; mix-blend-mode: color; }
.swatch .gloss {
    position: absolute; inset: 0;
    background: linear-gradient(105deg, rgba(255,255,255,.18), transparent 40%, rgba(0,0,0,.35));
    mix-blend-mode: soft-light;
}
.swatch span {
    position: absolute; left: 10px; bottom: 8px; font-size: 12px; color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,.7);
}

/* ── Recipe (web component) ──────────────────────────────────────────────── */
.recipe-empty { color: var(--muted); font-size: 14px; padding: 30px 0; text-align: center; }

.stat-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 4px 0 18px; }
.stat {
    background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
    padding: 10px 12px; flex: 1 1 120px;
}
.stat b { display: block; font-size: 18px; }
.stat small { color: var(--muted); font-size: 12px; }

.step {
    display: grid; grid-template-columns: 30px 1fr auto; gap: 12px; align-items: center;
    padding: 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px;
    background: var(--surface-2);
}
.step .num {
    width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
    background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 13px;
}
.step .what { font-size: 14px; min-width: 0; overflow-wrap: break-word; }
.step .what small { display: block; color: var(--muted); }
.step .grams { font-weight: 700; font-variant-numeric: tabular-nums; }
.step .grams small { display: block; color: var(--muted); font-weight: 400; text-align: right; }

.notes { margin: 16px 0 0; padding: 0; list-style: none; }
.notes li { color: var(--muted); font-size: 13px; padding: 6px 0 6px 18px; position: relative; }
.notes li::before { content: "•"; position: absolute; left: 4px; color: var(--accent); }

/* ── Wizard controls ─────────────────────────────────────────────────────── */
.wrap.wide { max-width: 1280px; }
.stepnum {
    display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
    background: var(--accent); color: var(--accent-ink); font-size: 13px; margin-right: 6px;
}
.hint { color: var(--muted); font-weight: 400; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button {
    flex: 1; min-width: 0; background: var(--surface-2); color: var(--muted); border-radius: 0;
    padding: 9px 6px; font-size: 13px; font-weight: 500; border-right: 1px solid var(--line);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 650; }

/* strand tiles */
.tile {
    background: #fff; border: 2px solid var(--line); border-radius: 10px; padding: 4px 4px 0;
    display: inline-flex; flex-direction: column; align-items: center; gap: 0;
}
.tile img { width: 44px; height: 62px; object-fit: contain; display: block; }
.tile span {
    font-size: 11px; font-weight: 650; color: #2b2320; padding: 1px 0 3px;
    font-variant-numeric: tabular-nums;
}
.tile.sel { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(195, 147, 91, .35); }
.tile:hover { border-color: var(--accent); }

/* all 10 levels must stay on one row: tiles shrink instead of wrapping */
.level-strip { display: flex; gap: 6px; flex-wrap: nowrap; }
.level-strip .tile { flex: 1 1 0; min-width: 0; padding: 4px 2px 0; }
.level-strip .tile img { width: 100%; max-width: 44px; }

.fam-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
    background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
    border-radius: 999px; padding: 5px 12px; font-size: 12px; font-weight: 500;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.swatch-grid { display: flex; gap: 6px; flex-wrap: wrap; max-height: 460px; overflow-y: auto; padding: 2px; }
.fam-head {
    flex-basis: 100%; font-size: 12px; color: var(--muted); text-transform: uppercase;
    letter-spacing: .8px; margin: 10px 0 2px;
}

/* target header */
.target-head { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; }
.target-head img { width: 56px; height: 80px; object-fit: contain; background: #fff; border-radius: 8px; padding: 3px; }
.target-head b { font-size: 20px; }
.target-head .btn-primary { width: auto; margin: 0; }

/* ── Plan rendering ──────────────────────────────────────────────────────── */
.ba { display: grid; grid-template-columns: 1fr auto 1fr 1fr; gap: 12px; align-items: start; margin: 8px 0 18px; }
.ba figure { margin: 0; text-align: center; }
.ba img, .ba .expected {
    width: 100%; max-width: 96px; height: 120px; object-fit: contain;
    background: #fff; border-radius: 10px; padding: 4px; border: 1px solid var(--line);
}
.ba .expected { box-sizing: border-box; }
.ba figcaption { font-size: 12px; margin-top: 6px; }
.ba figcaption small { color: var(--muted); }
.ba .arrow { align-self: center; color: var(--accent); font-size: 22px; }

.banner {
    background: rgba(220, 53, 69, .07); border: 1px solid var(--danger); color: var(--danger);
    border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px;
}
.warnings { margin: 0 0 14px; padding: 0; list-style: none; }
.warnings li {
    color: var(--danger); font-size: 13px; padding: 6px 0 6px 20px; position: relative;
}
.warnings li::before { content: "⚠"; position: absolute; left: 0; }

.phase {
    border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px;
    background: rgba(33, 37, 41, .015);
}
.phase header { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; flex-wrap: wrap; }
.phase header b { font-size: 15px; }
.phase .zone {
    font-size: 10px; letter-spacing: .8px; border: 1px solid var(--line); color: var(--muted);
    border-radius: 999px; padding: 2px 8px;
}
.phase .time { margin-left: auto; font-size: 13px; color: var(--accent); white-space: nowrap; }
.phase .purpose { color: var(--muted); font-size: 13px; margin: 2px 0 12px; }
.phase .apply { color: var(--ink); font-size: 13px; margin: 10px 0 0; opacity: .85; }
.phase-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.phase-meta span {
    font-size: 12px; background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 8px; padding: 4px 9px; color: var(--muted);
}

.step { grid-template-columns: 44px 1fr auto; }
.mini {
    width: 40px; height: 54px; object-fit: contain; background: #fff; border-radius: 7px; padding: 2px;
}
.mini.contain { object-fit: contain; }
.mini.emoji { display: grid; place-items: center; font-size: 22px; background: var(--surface); }

.notes-h { font-size: 13px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 18px 0 4px; }

@media (max-width: 640px) {
    body { overflow-x: hidden; }

    .topbar { padding: 12px 14px; gap: 10px; }
    .brand small { display: none; }
    .topbar .who { font-size: 13px; gap: 8px; }
    /* pills → compact native dropdown, and keep long usernames from pushing it off-screen */
    .lang-seg button { display: none; }
    .lang-seg select { display: block; }
    #who { max-width: 11ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .topbar .btn-ghost { padding: 8px 10px; font-size: 13px; white-space: nowrap; }
}
/* very narrow phones: the sign-out button matters more than the username */
@media (max-width: 400px) {
    #who { display: none; }

    .wrap { padding: 16px 12px 48px; }
    .grid { gap: 16px; }
    .card { padding: 16px 14px; }

    /* diagnosis fields stack instead of squeezing into two columns */
    .row { grid-template-columns: 1fr; gap: 0; }

    /* natural base level: two rows of five so the strand photos stay legible */
    .level-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
    .level-strip .tile { padding: 4px 3px 0; }
    .level-strip .tile img { max-width: 56px; }

    .seg button { padding: 9px 4px; font-size: 12px; }

    .swatch-grid { max-height: 380px; }

    .target-head { grid-template-columns: auto 1fr; }
    .target-head .btn-primary { grid-column: 1 / -1; width: 100%; }

    .stat { flex: 1 1 40%; }
    .stat b { font-size: 16px; }

    .phase { padding: 12px 10px; }
    .step { grid-template-columns: 38px 1fr auto; gap: 8px; padding: 10px 8px; }
    .mini { width: 34px; height: 46px; }

    .ba { grid-template-columns: 1fr 1fr; }
    .ba .arrow { display: none; }
}
@media print {
    .topbar, .fam-chips, .swatch-grid, .btn-ghost, .btn-primary, .level-strip, .seg, form, .lang-seg { display: none !important; }
    body { background: #fff; color: #000; }
    .card { box-shadow: none; border-color: #ccc; background: #fff; }
}

/* ── Login ───────────────────────────────────────────────────────────────── */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card { width: 100%; max-width: 380px; }

.pro-tag {
    display: inline-flex; gap: 6px; align-items: center; font-size: 11px; color: var(--accent);
    border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; margin-left: 8px;
}
