:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #eef1f4;
    --text: #172033;
    --muted: #667085;
    --line: #dfe3e8;
    --accent: #111827;
    --accent-contrast: #ffffff;
    --danger: #b42318;
    --success: #16803c;
    --warning: #b54708;
    --shadow: 0 12px 35px rgba(15, 23, 42, .08);
    --radius: 18px;
    --radius-sm: 12px;
    --max: 1120px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color-scheme: light;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
code, textarea[readonly] { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.topbar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 30;
    height: 68px;
    padding: 0 max(24px, calc((100vw - var(--max)) / 2));
    align-items: center;
    justify-content: space-between;
    background: rgba(255,255,255,.88);
    backdrop-filter: blur(18px);
    border-bottom: 1px solid rgba(223, 227, 232, .8);
}

.brand, .auth-logo {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: var(--accent);
    color: var(--accent-contrast);
    font-weight: 800;
    letter-spacing: -.04em;
}
.auth-logo { width: 52px; height: 52px; margin-bottom: 20px; }
.desktop-nav { display: flex; gap: 8px; }
.desktop-nav a { padding: 10px 14px; border-radius: 10px; color: var(--muted); font-weight: 650; }
.desktop-nav a:hover { background: var(--surface-2); color: var(--text); }

.app-shell {
    width: min(100%, var(--max));
    margin: 0 auto;
    padding: 22px 16px calc(96px + env(safe-area-inset-bottom));
}
.app-shell--centered { min-height: 100vh; display: grid; place-items: center; padding-bottom: 22px; }

.bottom-nav {
    position: fixed;
    z-index: 40;
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 7px;
    border: 1px solid rgba(223,227,232,.9);
    border-radius: 20px;
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow);
}
.bottom-nav a { display: grid; place-items: center; gap: 2px; min-height: 54px; border-radius: 14px; color: var(--muted); }
.bottom-nav span { font-size: 20px; line-height: 1; }
.bottom-nav small { font-size: 11px; font-weight: 700; }
.bottom-nav a:active { background: var(--surface-2); }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(30px, 8vw, 46px); line-height: 1.05; letter-spacing: -.045em; }
h2 { margin-bottom: 8px; letter-spacing: -.02em; }
h3 { margin-bottom: 6px; }
.eyebrow { margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
.muted { color: var(--muted); }
.page-heading { margin-bottom: 20px; }
.page-heading--actions { display: flex; gap: 14px; align-items: end; justify-content: space-between; }
.page-heading--actions .button { flex: 0 0 auto; }
.page-heading--compact { margin-bottom: 12px; }
.page-heading--compact h1 { margin-bottom: 0; font-size: clamp(24px, 6vw, 34px); }

.service-grid { display: grid; gap: 14px; }
.service-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 14px;
    align-items: center;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 6px 22px rgba(15,23,42,.04);
}
.service-card h2 { margin-bottom: 4px; font-size: 20px; }
.service-card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.service-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 15px; background: var(--surface-2); font-size: 22px; }
.service-arrow { font-size: 24px; color: var(--muted); }

.button {
    appearance: none;
    border: 0;
    min-height: 44px;
    padding: 11px 16px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 750;
    transition: transform .12s ease, opacity .12s ease, background .12s ease;
}
.button:active { transform: scale(.985); }
.button:disabled { opacity: .55; cursor: not-allowed; }
.button--primary { background: var(--accent); color: var(--accent-contrast); }
.button--secondary { background: var(--surface-2); color: var(--text); }
.button--ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.button--danger { background: #fee4e2; color: var(--danger); }
.button--icon { min-width: 46px; min-height: 46px; padding: 0; font-size: 24px; line-height: 1; }

.panel {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}
.panel--danger { border-color: #fecdca; }
.settings-grid { display: grid; gap: 14px; }
.code-line { display: block; padding: 12px; margin: 12px 0; border-radius: 10px; background: var(--surface-2); overflow-wrap: anywhere; font-size: 12px; }

.auth-card, .setup-card {
    width: min(100%, 520px);
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: var(--shadow);
}
.stack-form { display: grid; gap: 14px; margin-top: 22px; }
.stack-form label, .field { display: grid; gap: 7px; }
.stack-form label > span, .field > span { font-size: 13px; font-weight: 750; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    padding: 12px 13px;
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #98a2b3; box-shadow: 0 0 0 3px rgba(152,162,179,.15); }
textarea { resize: vertical; }
.form-error { margin: 8px 0 0; color: var(--danger); font-weight: 650; }

.requirements-list { display: grid; gap: 8px; margin: 20px 0; }
.requirement { display: flex; gap: 10px; align-items: center; padding: 11px; border-radius: 12px; background: var(--surface-2); }
.requirement > span { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; color: #fff; font-weight: 800; }
.requirement--ok > span { background: var(--success); }
.requirement--bad > span { background: var(--danger); }
.requirement div { display: grid; }
.requirement small { color: var(--muted); overflow-wrap: anywhere; }
.notice { padding: 12px 14px; margin: 14px 0; border-radius: 12px; }
.notice--success { background: #dcfae6; color: #067647; }
.notice--danger { background: #fee4e2; color: #b42318; }

.filters-bar { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 16px; }
.filters-bar--compact { grid-template-columns: minmax(0, 1fr) 112px; align-items: center; }
.filters-bar--compact input, .filters-bar--compact select { min-height: 44px; }
.card-list, .timeline-list, .feed-list { display: grid; gap: 12px; }
.recipe-card, .watch-card, .feed-card {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}
.recipe-card { display: grid; grid-template-columns: 96px 1fr; min-height: 118px; }
.recipe-card__image { width: 96px; min-height: 118px; object-fit: cover; background: var(--surface-2); }
.recipe-card__placeholder { display: grid; place-items: center; width: 96px; min-height: 118px; background: var(--surface-2); font-size: 28px; }
.recipe-card__body { padding: 14px; }
.recipe-card h2, .watch-card h2 { margin: 0 0 6px; font-size: 18px; }
.meta-row { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; color: var(--muted); font-size: 12px; }
.chip { display: inline-flex; align-items: center; min-height: 25px; padding: 4px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 750; }
.chip--important { background: #fff1eb; color: #b54708; }
.chip--critical { background: #fee4e2; color: #b42318; }
.skeleton-card { height: 118px; border-radius: var(--radius); background: linear-gradient(90deg, #e9edf1 25%, #f3f5f7 40%, #e9edf1 60%); background-size: 300% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

.segmented-control { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; margin-bottom: 14px; border-radius: 14px; background: var(--surface-2); }
.segmented-control button { border: 0; padding: 10px; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 750; }
.segmented-control button.is-active { background: var(--surface); color: var(--text); box-shadow: 0 3px 10px rgba(15,23,42,.06); }

.watch-card { padding: 16px; }
.watch-card--compact { display: grid; gap: 12px; padding: 14px; }
.watch-card__header { min-width: 0; }
.watch-card__header h2 { margin: 7px 0 0; font-size: 19px; line-height: 1.2; }
.watch-date-line {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 10px;
    width: 100%;
    padding: 11px 13px;
    border-radius: 14px;
    background: var(--surface-2);
}
.watch-date-line__prefix {
    color: var(--muted);
    font-size: 11px;
    line-height: 1;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
}
.watch-date-line__label {
    color: var(--text);
    font-size: 17px;
    line-height: 1.25;
    font-weight: 800;
}
.watch-date-line__note {
    width: 100%;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.25;
    font-weight: 650;
}
.watch-date-line--exact .watch-date-line__label { font-size: 19px; }
.watch-date-line--estimate { align-items: center; }
.feed-card { padding: 15px; }
.feed-card__head { display: flex; gap: 10px; justify-content: space-between; align-items: start; }
.feed-card p:last-child { margin-bottom: 0; }
.timeline-month { margin: 12px 2px 2px; font-size: 12px; font-weight: 850; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

.detail-page { display: grid; gap: 14px; }
.detail-hero { overflow: hidden; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); }
.detail-hero__image { width: 100%; aspect-ratio: 16/8; object-fit: cover; background: var(--surface-2); }
.detail-hero__body { padding: 20px; }
.detail-hero__actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.detail-section { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.ingredient-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 9px; }
.ingredient-list li { display: grid; grid-template-columns: minmax(80px, auto) 1fr; gap: 12px; padding-bottom: 9px; border-bottom: 1px solid var(--line); }
.ingredient-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.step-list { counter-reset: steps; display: grid; gap: 14px; }
.step-card { position: relative; padding-left: 48px; }
.step-card::before { counter-increment: steps; content: counter(steps); position: absolute; left: 0; top: 0; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 800; }
.update-list { display: grid; gap: 12px; }
.update-card { position: relative; padding: 14px; border-left: 3px solid var(--line); background: var(--surface-2); border-radius: 0 12px 12px 0; }
.update-card--important { border-left-color: #f79009; }
.update-card--critical { border-left-color: var(--danger); }
.source-link { color: #175cd3; text-decoration: underline; text-underline-offset: 2px; }

.editor-form { display: grid; gap: 14px; }
.form-section h2 { font-size: 18px; }
.form-grid { display: grid; gap: 12px; }
.form-grid--2 { grid-template-columns: 1fr; }
.section-heading { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-heading h2 { margin: 0; }
.repeat-list { display: grid; gap: 10px; }
.repeat-row { position: relative; display: grid; gap: 9px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); }
.repeat-row__top { display: grid; grid-template-columns: 1.2fr .7fr .6fr auto; gap: 8px; }
.repeat-row__remove { width: 42px; min-height: 42px; border: 0; border-radius: 10px; background: #fee4e2; color: var(--danger); font-weight: 900; }
.sticky-actions { position: sticky; bottom: calc(82px + env(safe-area-inset-bottom)); z-index: 10; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px; margin: 0 -4px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.92); backdrop-filter: blur(16px); }

.empty-state { min-height: 50vh; display: grid; place-items: center; align-content: center; text-align: center; padding: 24px; }
.empty-icon { display: grid; place-items: center; min-width: 64px; height: 64px; padding: 0 14px; margin-bottom: 14px; border-radius: 18px; background: var(--surface-2); font-weight: 900; }
.detail-loading { padding: 40px 20px; text-align: center; color: var(--muted); }

.dialog { width: min(92vw, 560px); border: 0; border-radius: 20px; padding: 20px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(15,23,42,.48); backdrop-filter: blur(3px); }
.dialog textarea { margin: 12px 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 11px 15px; border-radius: 999px; background: #101828; color: #fff; box-shadow: var(--shadow); font-size: 13px; font-weight: 700; }

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b0f17;
        --surface: #111827;
        --surface-2: #1d2636;
        --text: #f6f7f9;
        --muted: #a7b0c0;
        --line: #293448;
        --accent: #f7f8fa;
        --accent-contrast: #111827;
        --shadow: 0 16px 40px rgba(0,0,0,.28);
        color-scheme: dark;
    }
    .topbar, .bottom-nav, .sticky-actions { background: rgba(17,24,39,.9); }
    .button--danger { background: #3b1717; }
    .notice--success { background: #13351f; color: #86efac; }
    .notice--danger { background: #3b1717; color: #fda29b; }
    .chip--important { background: #3d2c13; color: #fec84b; }
    .chip--critical { background: #3b1717; color: #fda29b; }
    .skeleton-card { background: linear-gradient(90deg, #182131 25%, #222d40 40%, #182131 60%); background-size: 300% 100%; }
}

@media (min-width: 720px) {
    .app-shell { padding: 34px 24px 60px; }
    .topbar { display: flex; }
    .bottom-nav { display: none; }
    .service-grid { grid-template-columns: 1fr 1fr; }
    .service-card { min-height: 160px; }
    .filters-bar { grid-template-columns: minmax(260px, 1fr) 240px; }
    .filters-bar--compact { grid-template-columns: minmax(260px, 1fr) 180px; }
    .settings-grid { grid-template-columns: 1fr 1fr; }
    .form-grid--2 { grid-template-columns: 1fr 1fr; }
    .field--wide { grid-column: 1 / -1; }
    .sticky-actions { position: static; display: flex; justify-content: flex-end; padding: 0; margin: 0; border: 0; background: transparent; backdrop-filter: none; }
    .recipe-card { grid-template-columns: 160px 1fr; }
    .recipe-card__image, .recipe-card__placeholder { width: 160px; min-height: 140px; }
    .detail-hero { display: grid; grid-template-columns: minmax(280px, 40%) 1fr; }
    .detail-hero__image { height: 100%; aspect-ratio: auto; }
    .watch-card--compact { grid-template-columns: minmax(0, 1fr) minmax(230px, 330px); align-items: center; gap: 18px; }
    .watch-date-line { height: 100%; align-content: center; }
    .toast { bottom: 28px; }
}

@media (max-width: 520px) {
    .repeat-row__top { grid-template-columns: 1fr 1fr; }
    .repeat-row__remove { width: 100%; }
    .page-heading--actions { align-items: center; }
    .watch-card--compact { padding: 14px; }
}
