:root {
  color-scheme: light;
  --bg: #f4f4f5;
  --card: #ffffff;
  --text: #18181b;
  --muted: #71717a;
  --accent: #c8102e;
  --accent-soft: rgba(200, 16, 46, 0.12);
  --ok: #15803d;
  --ok-soft: rgba(21, 128, 61, 0.1);
  --danger: #dc2626;
  --line: #e4e4e7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(24, 24, 27, 0.04), 0 8px 24px rgba(24, 24, 27, 0.06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#app {
  max-width: 920px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.brand-copy .eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11px;
  color: var(--muted);
}

.brand-copy h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.muted { color: var(--muted); font-size: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 14px;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 56px;
  padding: 8px 4px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.tab svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab:hover { color: var(--text); background: #f4f4f5; }
.tab.active {
  color: var(--accent);
  background: var(--accent-soft);
}

button, .ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
}

button[type="submit"],
#regenPlanBtn,
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

button[type="submit"]:hover,
#regenPlanBtn:hover,
.btn-primary:hover {
  filter: brightness(0.95);
}

button:disabled { opacity: 0.55; cursor: not-allowed; }

.ghost {
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
  font-weight: 500;
}

.ghost:hover { color: var(--text); }

.btn-compact {
  padding: 7px 12px;
  font-size: 13px;
  width: fit-content;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

input, select, textarea {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 9px 11px;
  font: inherit;
  font-size: 14px;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}

.stack { display: grid; gap: 10px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.check { flex-direction: row; align-items: center; gap: 8px; }

h2, h3 { margin: 0 0 10px; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

.list { list-style: none; padding: 0; margin: 0 0 12px; }
.list li {
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
}

.price-hits {
  list-style: none;
  padding-left: 0;
  margin: 12px 0 0;
}
.price-hits li { padding: 0; border-bottom: 1px solid var(--line); }
.price-hit {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}
.price-hit-main {
  flex: 1;
  display: grid;
  grid-template-columns: 4.6rem 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 1px;
  text-align: left;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  padding: 4px 6px;
  cursor: pointer;
  font: inherit;
}
.price-hit-main:hover,
.price-hit-main:focus-visible {
  background: var(--accent-soft);
}
.price-hit .price {
  grid-row: 1 / span 2;
  align-self: center;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.price-hit .retailer {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}
.price-hit .name {
  grid-column: 2;
  font-size: 14px;
  line-height: 1.35;
  color: var(--text);
}
.price-hit .actions {
  display: flex;
  flex-direction: row;
  gap: 6px;
  flex-shrink: 0;
}
.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.icon-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn.open-btn {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.icon-btn.list-btn:hover {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
  color: var(--accent);
}

.plan-days { display: grid; gap: 10px; }
.plan-day {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fafafa;
}
.plan-day h4 { margin: 0 0 6px; }
.plan-day p { margin: 2px 0; font-size: 13px; color: var(--muted); }

.error { color: var(--danger); font-size: 14px; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--ok-soft);
  border: 1px solid color-mix(in srgb, var(--ok) 25%, transparent);
  color: var(--ok);
  padding: 6px 12px;
  border-radius: 999px;
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
}

.banner {
  border-color: var(--line);
  color: var(--muted);
  font-size: 13px;
}
.banner strong { color: var(--text); }
.banner p { margin: 4px 0 0; }

.user-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.panel-hint {
  margin: -2px 0 12px;
  font-size: 13px;
}

.search-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.search-row input { flex: 1; }
.search-row button { flex-shrink: 0; }

.book-toolbar {
  display: grid;
  grid-template-columns: minmax(140px, 200px) 1fr auto;
  gap: 8px;
  margin-bottom: 12px;
}
.book-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 600;
}
.book-root { display: grid; gap: 10px; }
.book-chapter, .book-recipe-row {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fafafa;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}
.book-recipe-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.book-recipe-row .thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  background: #ececec;
  flex-shrink: 0;
}
.book-recipe-row .thumb-empty {
  display: inline-block;
  background: linear-gradient(135deg, #f4f4f5 0%, #e4e4e7 100%);
  box-shadow: inset 0 0 0 1px var(--line);
}
.book-recipe-row .row-copy { flex: 1; min-width: 0; }
.book-hero {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 12px;
  background: #ececec;
  aspect-ratio: 16 / 10;
}
.book-hero-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.book-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.book-hero .zoom {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background: rgba(255,255,255,0.92);
  border: 0;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
}
.book-kicker { margin: 0; font-size: 13px; color: var(--muted); }
.book-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}
.book-actions button,
.book-actions a {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px 8px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: center;
}
.btn-yt { background: #fff0f0; border-color: #fecaca; color: #b91c1c; }
.btn-cook, .btn-gen { background: #fff7ed; border-color: #fed7aa; color: #c2410c; }
.macro-badge {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  background: #ececec;
  border-radius: 8px;
  padding: 6px 12px;
  min-width: 58px;
}
.macro-badge small {
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
}
.macro-badge strong { font-size: 15px; }
.ns-panel {
  background: #f4f4f5;
  border-radius: 12px;
  padding: 12px;
  margin: 8px 0 4px;
}
.ns-panel .book-kicker { margin-bottom: 4px; }
.book-ol { margin: 6px 0 0; padding-left: 18px; }
.accordion summary::after {
  content: "›";
  float: right;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}
.accordion[open] summary::after { content: "⌄"; }
#saveGenerated { width: 100%; margin-top: 8px; }
.hero-full {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: grid;
  place-items: center;
  z-index: 80;
  padding: 24px;
}
.hero-full img {
  max-width: 100%;
  max-height: 88vh;
  object-fit: contain;
  border-radius: 12px;
}
.hero-full button {
  position: absolute;
  top: 16px;
  right: 16px;
  background: #fff;
}
.ns-scale {
  display: flex;
  gap: 4px;
  margin: 8px 0 4px;
}
.ns-scale span {
  flex: 1;
  text-align: center;
  padding: 6px 0;
  border-radius: 8px;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
  opacity: 0.35;
}
.ns-scale span.on { opacity: 1; transform: scale(1.05); }
.accordion {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}
.accordion summary {
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}
.accordion summary::-webkit-details-marker { display: none; }
.book-footer-actions { display: grid; gap: 8px; margin-top: 12px; }
.book-footer-actions button {
  justify-content: flex-start;
  background: transparent;
  border: 0;
  color: var(--accent);
  padding: 8px 0;
}
.visual-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  background: linear-gradient(180deg, #fff 0%, #fafafa 100%);
}
.visual-card h3 { margin: 0 0 4px; }
.visual-card ul, .visual-card ol { margin: 8px 0 12px; padding-left: 18px; }
.cook-step {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin: 8px 0;
  background: #fafafa;
}
.cook-step.on { border-color: var(--accent); background: var(--accent-soft); }
.book-chapter:hover, .book-recipe-row:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.book-chapter .meta, .book-recipe-row .meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
.book-section-title {
  margin: 8px 0 4px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.book-detail h3 { margin: 0 0 6px; }
.book-macros {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 12px;
}
.ns-badge {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  border-radius: 8px;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
}
.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  background: #f4f4f5;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.book-steps {
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
}

@media (max-width: 640px) {
  .row-fields { grid-template-columns: 1fr 1fr; }
  .tab span { font-size: 10px; }
  .search-row { flex-direction: column; }
  .search-row button { width: 100%; }
  .tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .book-toolbar { grid-template-columns: 1fr auto; }
  .book-toolbar input { grid-column: 1 / -1; }
}
