:root {
  color-scheme: light;
  --font-scale: 1;
  --dim-opacity: 0;
  --bright-opacity: 0;
  --bg: #f5efe5;
  --panel: #fffaf3;
  --panel-2: #ffffff;
  --input-bg: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5ded1;
  --brand: #111827;
  --brand-2: #8b5e34;
  --accent-soft: #fff7df;
  --danger: #b91c1c;
  --shadow: 0 22px 60px rgba(17, 24, 39, 0.10);
  --shadow-soft: 0 12px 30px rgba(17, 24, 39, 0.07);
  --radius: 24px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11100e;
  --panel: #191612;
  --panel-2: #211c17;
  --input-bg: #252019;
  --text: #f4efe8;
  --muted: #b8aea3;
  --line: #40372c;
  --brand: #f5efe6;
  --brand-2: #d6aa72;
  --accent-soft: #2b2118;
  --danger: #ff7a7a;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  --shadow-soft: 0 12px 32px rgba(0, 0, 0, 0.26);
}


* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-size: calc(16px * var(--font-scale));
  line-height: 1.5;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at top left, color-mix(in srgb, var(--accent-soft) 88%, transparent) 0, transparent 30rem),
    radial-gradient(circle at bottom right, color-mix(in srgb, var(--brand-2) 10%, transparent) 0, transparent 28rem),
    var(--bg);
  color: var(--text);
  transition: background .25s ease, color .25s ease;
}
body::before, body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99999;
}
body::before { background: rgba(0, 0, 0, var(--dim-opacity)); }
body::after { background: rgba(255, 255, 255, var(--bright-opacity)); mix-blend-mode: screen; }
button, input, select, textarea { font: inherit; }
button {
  border: 0;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  padding: 0.7rem 1rem;
  cursor: pointer;
  font-weight: 700;
  transition: transform .15s ease, opacity .15s ease, box-shadow .15s ease;
}
button:hover { transform: translateY(-1px); box-shadow: 0 10px 20px rgba(17, 24, 39, 0.12); }
button:active { transform: translateY(0); }
button.ghost {
  background: color-mix(in srgb, var(--panel-2) 88%, transparent);
  color: var(--brand);
  border: 1px solid var(--line);
}
button.danger { background: var(--danger); }
button.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.5rem;
  background: color-mix(in srgb, var(--panel-2) 86%, var(--line));
  color: var(--text);
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--input-bg);
  border-radius: 14px;
  padding: .75rem .85rem;
  color: var(--text);
  outline: none;
}
textarea { resize: vertical; line-height: 1.65; }
input:focus, select:focus, textarea:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 4px rgba(139, 94, 52, .12);
}
label { display: grid; gap: .45rem; color: var(--muted); font-size: .9rem; font-weight: 700; }

.app-shell { width: min(1440px, 100%); margin: 0 auto; padding: 20px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 18px 22px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid rgba(229, 222, 209, .9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 14px;
  z-index: 10;
}
.topbar h1 { margin: .2rem 0 0; font-size: clamp(1.4rem, 2vw, 2rem); }
.eyebrow { margin: 0; color: var(--brand-2); font-size: .78rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.top-actions { display: flex; gap: .6rem; flex-wrap: wrap; justify-content: flex-end; align-items: center; }

.subtitle { margin: .35rem 0 0; color: var(--muted); font-size: .9rem; }
.display-settings { position: relative; }
.display-settings summary {
  list-style: none;
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel-2) 88%, transparent);
  color: var(--brand);
  border: 1px solid var(--line);
  padding: .7rem 1rem;
  cursor: pointer;
  font-weight: 800;
  user-select: none;
}
.display-settings summary::-webkit-details-marker { display: none; }
.display-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(330px, calc(100vw - 32px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  z-index: 40;
  display: grid;
  gap: .85rem;
}
.display-field { font-size: .82rem; color: var(--muted); }
.display-field select, .display-field input[type="range"] { margin-top: .4rem; }
.display-reset { justify-self: start; padding: .55rem .9rem; }


.setup-card {
  margin: 18px 0;
  padding: 18px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
}
.setup-card h2 { margin: 0 0 .4rem; }
.setup-card p { margin: 0; color: var(--muted); }
.auth-box { min-width: min(480px, 100%); }
.inline-form { display: flex; gap: .6rem; margin-top: .5rem; }
.inline-form input { min-width: 180px; }
.hint { font-size: .85rem; margin-top: .5rem !important; }

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 18px;
  align-items: start;
}
.sidebar, .content, .detail-card, .empty-state {
  background: rgba(255, 250, 243, .92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.sidebar { padding: 18px; position: sticky; top: 118px; max-height: calc(100vh - 138px); overflow: auto; }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; gap: .8rem; margin-bottom: 1rem; }
.sidebar h2 { margin: 0; }
.search { margin-bottom: .8rem; }
.filter-row { display: grid; grid-template-columns: 1fr auto; gap: .6rem; margin-bottom: 1rem; }
.recipe-list { display: grid; gap: .8rem; }
.recipe-item {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: .9rem;
  background: #fff;
  cursor: pointer;
}
.recipe-item.active { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(17, 24, 39, .06); }
.recipe-item h3 { margin: 0 0 .35rem; font-size: 1rem; }
.recipe-meta { display: flex; flex-wrap: wrap; gap: .4rem; color: var(--muted); font-size: .82rem; }
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #f3eee5;
  color: #6f4e2f;
  padding: .2rem .55rem;
  font-weight: 800;
  font-size: .78rem;
}
.badge.status-draft { background: #f1f5f9; color: #475569; }
.badge.status-structured { background: #ecfeff; color: #0e7490; }
.badge.status-tested { background: #eff6ff; color: #1d4ed8; }
.badge.status-stable { background: #ecfdf5; color: #047857; }

.content { min-height: 620px; padding: 0; background: transparent; border: 0; box-shadow: none; }
.empty-state { padding: 48px; text-align: center; }
.empty-state h2 { margin-top: 0; font-size: 1.8rem; }
.empty-state p { color: var(--muted); max-width: 560px; margin: 0 auto 1.2rem; line-height: 1.7; }
.detail-card { padding: 24px; }
.detail-header { display: flex; justify-content: space-between; gap: 1rem; align-items: start; border-bottom: 1px solid var(--line); padding-bottom: 18px; margin-bottom: 18px; }
.detail-header h2 { font-size: clamp(1.6rem, 3vw, 2.6rem); margin: .2rem 0 .6rem; }
.detail-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.detail-grid { display: grid; grid-template-columns: 1fr 360px; gap: 18px; align-items: start; }
.section-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 18px;
}
.section-card h3 { margin: 0 0 .9rem; }
.prose { line-height: 1.75; white-space: pre-wrap; }
.control-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem; }
.control-grid label { color: var(--text); }
.table { width: 100%; border-collapse: collapse; overflow: hidden; border-radius: 16px; }
.table th, .table td { text-align: left; border-bottom: 1px solid #eee7dc; padding: .75rem .55rem; vertical-align: top; }
.table th { font-size: .82rem; color: var(--muted); }
.table tr:last-child td { border-bottom: 0; }
.step-list { counter-reset: step; list-style: none; padding: 0; margin: 0; display: grid; gap: .8rem; }
.step-list li {
  background: #fffaf3;
  border: 1px solid #f0e7d8;
  border-radius: 16px;
  padding: .9rem .9rem .9rem 3.1rem;
  position: relative;
  line-height: 1.65;
}
.step-list li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: .85rem;
  top: .85rem;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: .78rem;
}
.chip-row { display: flex; flex-wrap: wrap; gap: .4rem; }
.copy-box {
  background: #111827;
  color: #f9fafb;
  border-radius: 18px;
  padding: 1rem;
  white-space: pre-wrap;
  line-height: 1.7;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: .92rem;
}
.json-box { max-height: 420px; overflow: auto; }

.dialog {
  width: min(980px, calc(100vw - 28px));
  border: 0;
  border-radius: 28px;
  padding: 0;
  box-shadow: 0 30px 80px rgba(17, 24, 39, .28);
  background: var(--panel);
}
.dialog::backdrop { background: rgba(17, 24, 39, .45); backdrop-filter: blur(6px); }
.dialog form { padding: 22px; }
.dialog-header { display: flex; justify-content: space-between; align-items: start; gap: 1rem; margin-bottom: 1rem; }
.dialog-header h2 { margin: .15rem 0 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; margin-bottom: .9rem; }
.full { margin-bottom: .9rem; }
.form-toolbar { display: flex; gap: .6rem; flex-wrap: wrap; margin: .4rem 0 .9rem; }
.dialog-actions { display: flex; align-items: center; gap: .6rem; margin-top: 1rem; }
.spacer { flex: 1; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  border-radius: 999px;
  padding: .75rem 1.1rem;
  box-shadow: var(--shadow);
  z-index: 100;
}

html[data-theme="dark"] .sidebar,
html[data-theme="dark"] .content,
html[data-theme="dark"] .detail-card,
html[data-theme="dark"] .empty-state,
html[data-theme="dark"] .setup-card,
html[data-theme="dark"] .section-card,
html[data-theme="dark"] .dialog form {
  background: color-mix(in srgb, var(--panel) 94%, transparent);
}
html[data-theme="dark"] .badge { background: #2b251f; color: #e8dcca; }
html[data-theme="dark"] .copy-box { background: #11100e; }
html[data-theme="dark"] .table th { background: #211c17; }
html[data-theme="dark"] .toast { background: #f4efe8; color: #11100e; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  .detail-grid { grid-template-columns: 1fr; }
  .setup-card { flex-direction: column; align-items: stretch; }
}
@media (max-width: 640px) {
  .app-shell { padding: 12px; }
  .topbar { position: static; flex-direction: column; align-items: stretch; }
  .top-actions { justify-content: stretch; }
  .top-actions button, .top-actions .display-settings { flex: 1; }
  .display-settings summary { text-align: center; }
  .display-panel { position: static; width: 100%; margin-top: .6rem; }
  .inline-form, .filter-row { grid-template-columns: 1fr; display: grid; }
  .form-grid, .control-grid { grid-template-columns: 1fr; }
  .detail-header { flex-direction: column; }
  .detail-actions { justify-content: flex-start; }
  .empty-state { padding: 28px 18px; }
}

.public-settings {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 20px;
  padding: 16px;
  margin: 0 0 1rem;
}
.public-settings h3 { margin: 0 0 .9rem; }
.public-summary { color: var(--muted); line-height: 1.7; max-width: 720px; }
.badge.visibility-private { background: #f8fafc; color: #475569; }
.badge.visibility-unlisted { background: #fff7ed; color: #c2410c; }
.badge.visibility-public { background: #ecfdf5; color: #047857; }
body.public-mode .setup-card { background: var(--panel-2); }
body.public-mode .topbar { position: static; }
body.public-mode .detail-card { background: var(--panel); }
body.family-mode { font-size: calc(18px * var(--font-scale)); }
body.family-mode .app-shell { width: min(980px, 100%); }
body.family-mode .layout { grid-template-columns: 1fr; }
body.family-mode .sidebar { display: none; }
body.family-mode .detail-grid { grid-template-columns: 1fr; }
body.family-mode .detail-actions button:not(#printCurrentBtn) { display: none; }
body.family-mode .step-list li { font-size: 1.08rem; padding: 1.1rem 1.1rem 1.1rem 3.4rem; }
body.family-mode .section-card h3 { font-size: 1.35rem; }
body.family-mode .table th, body.family-mode .table td { padding: .9rem .65rem; }
@media print {
  .topbar, .setup-card, .sidebar, .detail-actions, .toast { display: none !important; }
  .app-shell { padding: 0; width: 100%; }
  .layout, .detail-grid { display: block; }
  .detail-card, .section-card { box-shadow: none; border-color: #ddd; }
}

/* v0.5.3 Meal Planner */
button.small-btn {
  padding: .42rem .7rem;
  font-size: .78rem;
  font-weight: 800;
}
.recipe-item-actions {
  margin-top: .65rem;
  display: flex;
  justify-content: flex-end;
}
.planner-layout {
  display: grid;
  grid-template-columns: minmax(320px, .95fr) minmax(360px, 1.15fr);
  gap: 18px;
  align-items: start;
}
.planner-selector { grid-row: span 3; }
.planner-recipe-list { display: grid; gap: .9rem; }
.planner-recipe-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: color-mix(in srgb, var(--panel-2) 94%, transparent);
  padding: .95rem;
}
.planner-recipe-card.selected {
  border-color: color-mix(in srgb, var(--brand-2) 70%, var(--line));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand-2) 12%, transparent);
}
.planner-check {
  display: flex;
  grid-template-columns: none;
  align-items: start;
  gap: .65rem;
  color: var(--text);
  font-size: .95rem;
  cursor: pointer;
}
.planner-check input {
  width: auto;
  margin-top: .2rem;
  accent-color: var(--brand-2);
}
.planner-check small {
  display: block;
  color: var(--muted);
  font-weight: 700;
  margin-top: .15rem;
}
.planner-control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .7rem;
  margin-top: .85rem;
  padding-top: .85rem;
  border-top: 1px dashed var(--line);
}
.planner-control-grid label { color: var(--muted); font-size: .82rem; }
.planner-output .ghost { margin-top: .9rem; }
.shopping-group {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: .9rem;
  margin-bottom: .8rem;
  background: color-mix(in srgb, var(--panel) 72%, transparent);
}
.shopping-group h4 {
  margin: 0 0 .5rem;
  color: var(--brand-2);
}
.shopping-group ul { margin: 0; padding-left: 1.2rem; }
.shopping-group li { margin: .35rem 0; line-height: 1.55; }
.timeline-tips {
  border: 1px solid color-mix(in srgb, var(--brand-2) 32%, var(--line));
  background: color-mix(in srgb, var(--accent-soft) 72%, transparent);
  border-radius: 16px;
  padding: .85rem 1rem;
  margin-bottom: .9rem;
}
.timeline-tips p { margin: .25rem 0; }
.timeline-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: .65rem;
}
.timeline-list li {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: .8rem .9rem;
  background: var(--panel-2);
}
.timeline-badge {
  display: inline-flex;
  border-radius: 999px;
  padding: .16rem .55rem;
  margin-right: .45rem;
  font-size: .76rem;
  font-weight: 900;
  background: #f1f5f9;
  color: #475569;
}
.timeline-badge.passive { background: #ecfdf5; color: #047857; }
.timeline-badge.semi-active { background: #fff7ed; color: #c2410c; }
.timeline-badge.active { background: #eff6ff; color: #1d4ed8; }
button:disabled {
  opacity: .45;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

@media (max-width: 980px) {
  .planner-layout { grid-template-columns: 1fr; }
  .planner-selector { grid-row: auto; }
}
@media (max-width: 640px) {
  .planner-control-grid { grid-template-columns: 1fr; }
  .recipe-item-actions { justify-content: flex-start; }
}
