:root {
  color-scheme: light;
  --bg: #f7f4ee;
  --surface: #fffdf8;
  --surface-2: #f0ebe2;
  --ink: #24201d;
  --muted: #716a60;
  --line: #ddd4c7;
  --accent: #28685c;
  --accent-2: #a64d3e;
  --accent-3: #315f8c;
  --gold: #b9862c;
  --soft: #e6f0eb;
  --soft-blue: #e9eef6;
  --soft-red: #f6e8e4;
  --warn: #9a6718;
  --shadow: 0 16px 38px rgba(47, 39, 30, 0.11);
  --shadow-soft: 0 8px 20px rgba(47, 39, 30, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

button:hover,
select:hover {
  border-color: #b9ad9e;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.card:focus-visible {
  outline: 3px solid rgba(49, 95, 140, 0.25);
  outline-offset: 2px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 46px);
  line-height: 0.98;
  font-weight: 860;
}

h2 {
  font-size: 15px;
  line-height: 1.25;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 24px;
  align-items: end;
  padding: 28px 32px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.88);
  position: sticky;
  top: 0;
  z-index: 4;
  backdrop-filter: blur(14px);
}

.brand-block {
  min-width: 0;
}

.brand-block .eyebrow {
  color: var(--accent-2);
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(74px, 1fr));
  gap: 8px;
  align-items: end;
}

.stat {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 9px 10px;
  min-width: 0;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.stat strong {
  display: block;
  font-size: 20px;
  line-height: 1;
  font-weight: 850;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
}

.shell {
  display: grid;
  grid-template-columns: 306px minmax(0, 1fr);
  gap: 28px;
  padding: 26px 32px 46px;
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 124px;
  display: grid;
  gap: 22px;
  min-width: 0;
}

.sidebar section h2,
.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  margin: 0 0 10px;
  text-transform: uppercase;
}

.field {
  display: grid;
  gap: 8px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  min-height: 44px;
  padding: 0 13px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset;
}

textarea {
  min-height: 120px;
  padding: 12px 13px;
  resize: vertical;
  line-height: 1.45;
}

input::placeholder {
  color: #958d81;
}

.segmented,
.topic-list,
.tag-filter-list {
  display: grid;
  gap: 7px;
}

.tag-filter-list {
  max-height: 288px;
  overflow: auto;
  padding-right: 4px;
}

.tag-filter-list::-webkit-scrollbar,
.detail-body::-webkit-scrollbar {
  width: 10px;
}

.tag-filter-list::-webkit-scrollbar-thumb,
.detail-body::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: #c9bfb1;
  background-clip: padding-box;
}

.filter-button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.64);
  color: var(--ink);
  cursor: pointer;
  padding: 8px 10px;
  text-align: left;
}

.filter-button span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.filter-button:hover {
  background: var(--surface);
  border-color: var(--line);
  box-shadow: var(--shadow-soft);
}

.filter-button[aria-pressed="true"] {
  border-color: rgba(40, 104, 92, 0.28);
  background: var(--soft);
  color: #163f36;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.82) inset;
}

.tag-filter[aria-pressed="true"] {
  border-color: rgba(49, 95, 140, 0.28);
  background: var(--soft-blue);
  color: #213f62;
}

.count {
  color: var(--muted);
  font-size: 12px;
  flex: 0 0 auto;
  font-weight: 750;
}

.content {
  min-width: 0;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.9fr);
  gap: 14px 18px;
  align-items: end;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.toolbar-title {
  min-width: 0;
}

.toolbar h2 {
  font-size: 22px;
  font-weight: 850;
}

.toolbar-controls {
  display: grid;
  grid-template-columns: minmax(210px, 1fr) 178px;
  gap: 10px;
  align-items: end;
  min-width: 0;
}

.quick-filters {
  grid-column: 1 / -1;
  min-width: 0;
}

.quick-filters .eyebrow {
  margin-bottom: 8px;
}

.quick-tag-list {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 3px;
}

.quick-tag-list .filter-button {
  flex: 0 0 auto;
  min-height: 34px;
  white-space: nowrap;
  background: rgba(255, 253, 248, 0.82);
  border-color: var(--line);
}

.quick-tag-list::-webkit-scrollbar {
  height: 8px;
}

.quick-tag-list::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: #c9bfb1;
  background-clip: padding-box;
}

.edit-export-bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  padding: 12px;
}

.edit-export-copy {
  min-width: 0;
}

.edit-export-copy strong {
  display: block;
  font-size: 16px;
  line-height: 1.2;
}

.edit-export-copy span,
.export-note,
.export-list span {
  color: var(--muted);
  font-size: 13px;
}

.edit-export-actions {
  flex: 0 0 auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(254px, 1fr));
  gap: 18px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  display: grid;
  grid-template-rows: 186px auto;
  min-height: 430px;
  position: relative;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: #cfc3b4;
}

.thumb {
  background: #e1dfd8;
  position: relative;
  overflow: hidden;
}

.thumb::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 48%;
  background: linear-gradient(to top, rgba(24, 22, 19, 0.56), rgba(24, 22, 19, 0));
  pointer-events: none;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 260ms ease;
}

.card:hover .thumb img {
  transform: scale(1.035);
}

.fallback {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 16px;
  color: #345149;
  background: linear-gradient(135deg, #e9efe9, #f1e4db);
  font-weight: 850;
  text-align: center;
}

.badge {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 1;
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.94);
  color: var(--ink);
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 850;
  box-shadow: 0 4px 16px rgba(20, 18, 16, 0.18);
}

.card-body {
  display: grid;
  gap: 10px;
  padding: 14px;
  align-content: start;
}

.card-source {
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.18;
  font-weight: 850;
}

.meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.pill {
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 4px 8px;
  background: #fbfaf7;
}

.edited-pill {
  border-color: rgba(40, 104, 92, 0.3);
  background: var(--soft);
  color: #173d33;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--soft-blue);
  color: #28486d;
  font-size: 12px;
  font-weight: 800;
}

.tag-chip:nth-child(3n + 2) {
  background: var(--soft);
  color: #214e43;
}

.tag-chip:nth-child(3n) {
  background: var(--soft-red);
  color: #793a30;
}

.card-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.card-facts span {
  display: grid;
  gap: 1px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  padding: 7px 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.1;
}

.card-facts strong {
  color: var(--ink);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-list {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 32px;
  color: var(--muted);
  background: rgba(255, 253, 248, 0.58);
}

dialog {
  width: min(1080px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.32);
}

dialog::backdrop {
  background: rgba(24, 22, 19, 0.58);
}

.detail {
  display: grid;
  grid-template-columns: minmax(300px, 42%) minmax(0, 1fr);
  min-height: 620px;
  position: relative;
}

.detail-media {
  background: #e5e0d6;
  min-height: 620px;
  position: sticky;
  top: 0;
}

.detail-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-link {
  display: block;
  width: 100%;
  height: 100%;
  color: inherit;
}

.detail-media .fallback {
  width: 100%;
  height: 100%;
}

.detail-body {
  padding: 32px;
  overflow: auto;
  max-height: 88vh;
}

.detail-body h2 {
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.02;
  margin-bottom: 14px;
  font-weight: 880;
}

.detail-section {
  margin-top: 24px;
}

.fact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(116px, 1fr));
  gap: 9px;
  margin-top: 18px;
}

.fact {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  padding: 10px 11px;
  min-width: 0;
}

.fact span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0;
}

.fact strong {
  display: block;
  margin-top: 4px;
  font-size: 15px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.notice {
  border-left: 4px solid var(--warn);
  background: #fff5e4;
  border-radius: 8px;
  color: #69430f;
  margin-top: 16px;
  padding: 11px 12px;
  font-size: 14px;
  line-height: 1.35;
}

.success-notice {
  border-left-color: var(--accent);
  background: var(--soft);
  color: #173d33;
}

.scale-panel {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  padding: 12px;
  margin-top: 18px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.scale-readout {
  min-width: 0;
}

.scale-readout strong {
  display: inline-block;
  font-size: 22px;
  line-height: 1;
  margin-right: 8px;
}

.scale-readout span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.scale-actions {
  display: grid;
  grid-template-columns: 38px 52px 38px;
  gap: 6px;
  flex: 0 0 auto;
}

.scale-button,
.scale-reset,
.unit-switch button,
.secondary-button {
  min-width: 0;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 850;
  text-decoration: none;
}

.scale-button {
  font-size: 21px;
  line-height: 1;
}

.scale-reset {
  font-size: 13px;
}

.unit-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(62px, 1fr));
  gap: 6px;
  min-width: 144px;
}

.unit-switch button {
  padding: 0 10px;
  font-size: 13px;
}

.unit-switch button[aria-pressed="true"] {
  border-color: rgba(40, 104, 92, 0.42);
  background: var(--soft);
  color: #173d33;
  box-shadow: inset 0 0 0 1px rgba(40, 104, 92, 0.06);
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  font-size: 13px;
  background: #fbfaf7;
}

.secondary-button:disabled {
  cursor: default;
  opacity: 0.55;
}

.primary-action {
  border-color: rgba(40, 104, 92, 0.38);
  background: var(--soft);
  color: #153d33;
}

.danger-action {
  border-color: rgba(159, 63, 48, 0.28);
  background: var(--soft-red);
  color: #793a30;
}

.scale-button:disabled,
.scale-reset:disabled {
  cursor: default;
  opacity: 0.45;
}

.detail-section h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
  color: var(--muted);
  margin: 0 0 12px;
}

.detail-section li {
  margin: 0 0 9px;
  line-height: 1.48;
}

.recipe-parts {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 26px;
  align-items: start;
}

.part-section {
  border-left: 4px solid var(--line);
  padding-left: 13px;
  margin-bottom: 18px;
}

.part-section h4 {
  margin: 0 0 9px;
  font-size: 15px;
  line-height: 1.25;
}

.part-section ul,
.part-section ol {
  margin: 0;
  padding-left: 21px;
}

.source-link {
  color: var(--accent);
  font-weight: 850;
}

.edit-form {
  display: grid;
  gap: 18px;
}

.edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.edit-field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.edit-field.wide {
  grid-column: 1 / -1;
}

.edit-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.edit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.export-panel {
  position: relative;
  padding: 30px;
  max-height: 88vh;
  overflow: auto;
}

.export-panel h2 {
  font-size: clamp(28px, 4vw, 38px);
  line-height: 1.04;
  margin-bottom: 16px;
  font-weight: 880;
}

.export-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin: 16px 0;
}

.export-list {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
}

.export-list li {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  padding: 10px 11px;
}

.export-list strong,
.export-list span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.export-preview {
  min-height: 220px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.94);
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

.close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  font-size: 25px;
  line-height: 1;
}

@media (max-width: 1040px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
  }

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

@media (max-width: 860px) {
  .topbar,
  .toolbar {
    align-items: stretch;
  }

  .topbar {
    padding: 22px 18px 18px;
  }

  .stats {
    grid-template-columns: repeat(5, minmax(104px, 1fr));
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .stats .stat:last-child {
    grid-column: auto;
  }

  .shell {
    grid-template-columns: 1fr;
    padding: 18px;
  }

  .content {
    order: 1;
  }

  .sidebar {
    order: 2;
    position: static;
  }

  .topic-list,
  .tag-filter-list,
  .segmented {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .tag-filter-list {
    max-height: none;
  }

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

  .toolbar-controls {
    grid-template-columns: 1fr;
  }

  .detail {
    grid-template-columns: 1fr;
    min-height: 0;
    max-height: 92vh;
    overflow: auto;
  }

  .detail-body {
    max-height: none;
    overflow: visible;
    padding: 24px 20px;
  }

  .recipe-parts {
    grid-template-columns: 1fr;
  }

  .edit-grid {
    grid-template-columns: 1fr;
  }

  .scale-panel {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .scale-actions {
    grid-template-columns: 44px 1fr 44px;
  }

  .unit-switch {
    grid-template-columns: 1fr 1fr;
    min-width: 0;
  }

  .detail-media {
    height: clamp(220px, 34vh, 320px);
    min-height: 0;
    position: relative;
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 34px;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .card {
    min-height: 0;
  }

  .card-facts {
    grid-template-columns: 1fr 1fr;
  }

  .fact-grid {
    grid-template-columns: 1fr 1fr;
  }

  .edit-export-bar,
  .export-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .edit-export-actions,
  .edit-export-actions .secondary-button,
  .export-actions .secondary-button {
    width: 100%;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .topbar,
  .shell > .sidebar,
  .toolbar,
  .export-panel,
  .detail-media,
  .close,
  .detail-actions {
    display: none !important;
  }

  dialog {
    display: block;
    width: auto;
    box-shadow: none;
  }

  .detail {
    display: block;
    min-height: 0;
  }

  .detail-body {
    max-height: none;
    padding: 0;
  }

  .recipe-parts {
    grid-template-columns: 1fr 1fr;
  }
}
