* {
    box-sizing: border-box;
}

:root {
    --bg: #f7f4ef;
    --surface: #fffdfa;
    --surface-soft: #f4eee5;
    --surface-muted: #edf2ec;
    --text: #27302f;
    --text-muted: #5d6864;
    --primary: #315c54;
    --primary-text: #fffdfa;
    --accent: #9d4f35;
    --border: #e1d8cc;
    --border-strong: #cfc4b5;
    --shadow: rgba(39, 48, 47, 0.08);
    --notice-bg: #fff3e4;
    --notice-border: #e5c6a9;
    --notice-text: #6d3f20;
    --danger-bg: #fff0f0;
    --danger-border: #e1a4a4;
    --danger-text: #872929;
}

body[data-theme="food"] {
    --bg: #f8f1e7;
    --surface: #fffaf3;
    --surface-soft: #f3e2cf;
    --surface-muted: #e8f0df;
    --text: #26322d;
    --text-muted: #5f6a5e;
    --primary: #2f6b4f;
    --primary-text: #fffaf3;
    --accent: #c15b2d;
    --border: #e5d3bd;
    --border-strong: #d0b897;
    --shadow: rgba(87, 55, 24, 0.12);
}

body[data-theme="pastel"] {
    --bg: #fbf7ff;
    --surface: #ffffff;
    --surface-soft: #f3e9fb;
    --surface-muted: #e9f7fb;
    --text: #342d3d;
    --text-muted: #6c6175;
    --primary: #7f6bb2;
    --primary-text: #ffffff;
    --accent: #d46f9f;
    --border: #eadff2;
    --border-strong: #d8c7e6;
    --shadow: rgba(83, 62, 112, 0.11);
}

body[data-theme="soft"] {
    --bg: #fff6f8;
    --surface: #ffffff;
    --surface-soft: #ffe6ec;
    --surface-muted: #f7edf6;
    --text: #392c32;
    --text-muted: #735f68;
    --primary: #b85d7b;
    --primary-text: #ffffff;
    --accent: #da8a58;
    --border: #f0d7df;
    --border-strong: #dfbac7;
    --shadow: rgba(142, 76, 101, 0.13);
}

body[data-theme="warm"] {
    --bg: #f9f2e8;
    --surface: #fffaf2;
    --surface-soft: #efdec8;
    --surface-muted: #f1eadf;
    --text: #332f29;
    --text-muted: #6a5d4e;
    --primary: #8b5a34;
    --primary-text: #fffaf2;
    --accent: #b66a3c;
    --border: #e5d4bd;
    --border-strong: #cdb28d;
    --shadow: rgba(84, 55, 30, 0.12);
}

body[data-theme="neutral"] {
    --bg: #f5f5f2;
    --surface: #ffffff;
    --surface-soft: #ece9e2;
    --surface-muted: #edf0ec;
    --text: #2f3331;
    --text-muted: #616864;
    --primary: #4b625c;
    --primary-text: #ffffff;
    --accent: #7b6b54;
    --border: #dedbd2;
    --border-strong: #c7c1b5;
    --shadow: rgba(42, 48, 45, 0.09);
}

body[data-theme="dark"] {
    --bg: #171918;
    --surface: #222624;
    --surface-soft: #2b312e;
    --surface-muted: #303835;
    --text: #f1f3ef;
    --text-muted: #bbc4bd;
    --primary: #80bfa2;
    --primary-text: #12211a;
    --accent: #e5a36b;
    --border: #38413d;
    --border-strong: #52615b;
    --shadow: rgba(0, 0, 0, 0.32);
    --notice-bg: #30281f;
    --notice-border: #60472d;
    --notice-text: #ffd9a8;
    --danger-bg: #351f25;
    --danger-border: #70414b;
    --danger-text: #ffccd3;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Arial, sans-serif;
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    display: block;
    max-width: 100%;
}

input,
select,
textarea,
button {
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    padding: 0.78rem 0.9rem;
}

textarea {
    resize: vertical;
}

label {
    display: grid;
    gap: 0.45rem;
    font-weight: 700;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 72px;
    padding: 0 4vw;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(14px);
}

.brand,
.primary-nav,
.button-row,
.meta-row,
.section-heading {
    display: flex;
    align-items: center;
}

.brand {
    gap: 0.65rem;
    font-weight: 800;
}

.brand-mark {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 8px;
    background: var(--primary);
    color: var(--primary-text);
}

.primary-nav {
    gap: 0.2rem;
}

.primary-nav a {
    border-radius: 8px;
    padding: 0.62rem 0.8rem;
    color: var(--text-muted);
    font-weight: 700;
}

.primary-nav a:hover {
    background: var(--surface-soft);
}

.nav-toggle {
    display: none;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    padding: 0.6rem 0.8rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.theme-picker {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 800;
}

.theme-picker select {
    width: auto;
    min-width: 118px;
    padding: 0.48rem 0.65rem;
}

.page-shell {
    width: min(1180px, 92vw);
    margin: 0 auto;
    padding: 2.5rem 0 4rem;
}

.hero,
.auth-layout,
.recipe-detail,
.two-column,
.editor-grid {
    display: grid;
    gap: 1.5rem;
}

.hero {
    grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
    align-items: stretch;
    min-height: 520px;
}

.hero-copy {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.hero h1,
.page-heading h1,
.recipe-title-block h1 {
    margin: 0;
    max-width: 820px;
    font-size: clamp(2.2rem, 6vw, 4.8rem);
    line-height: 1.02;
    letter-spacing: 0;
}

.lede {
    max-width: 680px;
    color: var(--text-muted);
    font-size: 1.14rem;
}

.eyebrow {
    margin: 0 0 0.7rem;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.hero-panel,
.panel,
.recipe-card,
.stat-card,
.planner-day,
.empty-state {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 18px 38px var(--shadow);
}

.hero-panel {
    display: grid;
    gap: 1rem;
    align-items: center;
    padding: 1.2rem;
}

.recipe-preview-card {
    display: grid;
    gap: 0.65rem;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--surface-soft), var(--surface-muted));
    padding: 1rem;
}

.plate-visual {
    position: relative;
    display: grid;
    width: min(230px, 100%);
    aspect-ratio: 1;
    place-items: center;
    margin: 0 auto;
    border: 12px solid var(--surface);
    border-radius: 50%;
    background: var(--surface);
    box-shadow: inset 0 0 0 2px var(--border), 0 18px 28px var(--shadow);
}

.plate-visual span {
    position: absolute;
    border-radius: 999px;
}

.plate-visual span:nth-child(1) {
    width: 42%;
    height: 34%;
    background: var(--primary);
    transform: translate(-18%, 0) rotate(-18deg);
}

.plate-visual span:nth-child(2) {
    width: 36%;
    height: 28%;
    background: var(--accent);
    transform: translate(28%, -16%) rotate(20deg);
}

.plate-visual span:nth-child(3) {
    width: 28%;
    height: 22%;
    background: var(--surface-soft);
    border: 2px solid var(--border-strong);
    transform: translate(22%, 32%) rotate(-8deg);
}

.cook-flow {
    display: grid;
    gap: 1rem;
    width: 100%;
}

.cook-flow div,
.flow-step {
    border-left: 4px solid var(--primary);
    border-radius: 8px;
    background: var(--surface-soft);
    padding: 1rem;
}

.cook-flow span,
.flow-step > span,
.meal-chip span {
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.cook-flow strong {
    display: block;
    font-size: 1.4rem;
}

.button-row {
    flex-wrap: wrap;
    gap: 0.7rem;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0.7rem 1rem;
    font-weight: 800;
    cursor: pointer;
}

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

.button-secondary {
    border-color: var(--border-strong);
    background: var(--surface);
    color: var(--primary);
}

.feature-grid,
.stat-grid,
.recipe-grid,
.planner-grid,
.shopping-groups {
    display: grid;
    gap: 1rem;
}

.feature-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 2rem;
}

.feature-grid article {
    padding: 1.1rem 0;
}

.page-heading,
.section-heading {
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.4rem;
}

.section-heading {
    margin-top: 2rem;
}

.stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat-card,
.panel,
.empty-state,
.planner-day {
    padding: 1.2rem;
}

.stat-card span {
    display: block;
    color: var(--primary);
    font-size: 2.3rem;
    font-weight: 900;
}

.recipe-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.recipe-card {
    overflow: hidden;
}

.recipe-card-media {
    display: grid;
    aspect-ratio: 4 / 3;
    place-items: center;
    background: var(--surface-soft);
    color: var(--text-muted);
    font-weight: 800;
}

.recipe-card-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.recipe-card-body {
    padding: 1rem;
}

.recipe-card h2,
.panel h2,
.planner-day h2 {
    margin: 0 0 0.6rem;
}

.meta-row {
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 0.9rem;
}

.meta-row span {
    border-radius: 8px;
    background: var(--surface-muted);
    color: var(--primary);
    padding: 0.36rem 0.55rem;
    font-size: 0.88rem;
    font-weight: 800;
}

.toolbar {
    display: grid;
    grid-template-columns: 1fr 190px 170px;
    gap: 0.8rem;
    margin-bottom: 1.2rem;
}

.auth-layout {
    grid-template-columns: minmax(0, 1fr) 420px;
    align-items: start;
}

.narrow-page {
    max-width: 680px;
    margin: 0 auto;
}

.form-stack {
    display: grid;
    gap: 1rem;
}

.form-row,
.list-builder-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.8rem;
}

.editor-grid {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
    align-items: start;
}

.editor-wide {
    grid-column: 1 / -1;
}

.step-editor {
    display: grid;
    gap: 0.7rem;
    margin-bottom: 0.8rem;
}

.upload-panel {
    display: grid;
    gap: 1rem;
}

.drop-zone {
    min-height: 230px;
    place-items: center;
    border: 2px dashed var(--border-strong);
    background: var(--surface-soft);
    text-align: center;
    cursor: pointer;
}

.drop-zone input {
    display: none;
}

.drop-zone.is-dragging {
    border-color: var(--primary);
    background: var(--surface-muted);
}

.recipe-detail {
    grid-template-columns: minmax(0, 1fr) 280px;
    align-items: end;
    margin-bottom: 1.4rem;
}

.serving-panel {
    display: grid;
    gap: 0.8rem;
}

.segmented-control {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    overflow: hidden;
}

.segmented-control button {
    border: 0;
    background: var(--surface);
    color: var(--text);
    padding: 0.7rem 0.4rem;
    cursor: pointer;
}

.segmented-control button.active {
    background: var(--primary);
    color: var(--primary-text);
}

.two-column {
    grid-template-columns: 360px minmax(0, 1fr);
    align-items: start;
}

.check-list {
    display: grid;
    gap: 0.7rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.check-list label {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    font-weight: 600;
}

.check-list input {
    width: 20px;
    height: 20px;
    margin-top: 0.15rem;
}

.check-list small {
    display: block;
    margin-left: 1.8rem;
    color: var(--text-muted);
}

.flow-list {
    display: grid;
    gap: 1rem;
}

.flow-step {
    display: grid;
    grid-template-columns: 48px 1fr;
    gap: 1rem;
    background: var(--surface);
}

.flow-step > span {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 8px;
    background: var(--accent);
    color: var(--primary-text);
    font-size: 1rem;
}

.planner-grid {
    grid-template-columns: repeat(7, minmax(145px, 1fr));
    overflow-x: auto;
    padding-bottom: 0.5rem;
}

.planner-day {
    min-height: 220px;
}

.meal-chip {
    display: grid;
    gap: 0.25rem;
    border-radius: 8px;
    background: var(--surface-muted);
    padding: 0.75rem;
}

.add-meal {
    width: 100%;
    min-height: 88px;
    border: 1px dashed var(--border-strong);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-muted);
    cursor: pointer;
}

.shopping-groups {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.empty-state {
    padding: 2rem;
    text-align: center;
}

.empty-state.compact {
    padding: 1.2rem;
}

.notice {
    margin: 0 0 1.2rem;
    border: 1px solid var(--notice-border);
    border-radius: 8px;
    background: var(--notice-bg);
    color: var(--notice-text);
    padding: 0.85rem 1rem;
    font-weight: 700;
}

.form-error {
    border: 1px solid var(--danger-border);
    border-radius: 8px;
    background: var(--danger-bg);
    color: var(--danger-text);
    padding: 0.75rem 0.9rem;
    font-weight: 800;
}

.qr-code {
    width: 220px;
    height: 220px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    padding: 0.5rem;
}

@media (max-width: 900px) {
    .nav-toggle {
        display: inline-flex;
    }

    .primary-nav {
        position: absolute;
        top: 72px;
        right: 4vw;
        display: none;
        width: min(320px, 92vw);
        flex-direction: column;
        align-items: stretch;
        border: 1px solid #e1d8cc;
        border-radius: 8px;
        background: #fffdfa;
        padding: 0.5rem;
        box-shadow: 0 18px 38px rgba(39, 48, 47, 0.16);
    }

    .primary-nav.is-open {
        display: flex;
    }

    .hero,
    .auth-layout,
    .recipe-detail,
    .two-column,
    .editor-grid,
    .feature-grid,
    .stat-grid,
    .recipe-grid,
    .shopping-groups {
        grid-template-columns: 1fr;
    }

    .toolbar,
    .form-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .site-header {
        padding: 0 1rem;
    }

    .page-shell {
        width: min(100% - 2rem, 1180px);
        padding-top: 1.5rem;
    }

    .page-heading,
    .section-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .hero {
        min-height: auto;
    }

    .list-builder-row {
        grid-template-columns: 1fr;
    }
}
