:root {
  --paper: #ece3d1;
  --card: #fbf7ee;
  --ink: #2c261c;
  --ink-soft: #6b6153;
  --herb: #4a5d3a;
  --herb-dark: #37452b;
  --rust: #b0432e;
  --gold: #b9924a;
  --line: #d9cdb3;
  --shadow: rgba(44, 38, 28, 0.16);

  --font-display: 'Noto Serif TC', serif;
  --font-body: 'Zen Kaku Gothic New', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-hand: 'Caveat', cursive;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(44,38,28,0.05) 1px, transparent 0);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--font-body);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ---- topbar ---- */
.topbar {
  background: var(--herb);
  border-bottom: 4px solid var(--herb-dark);
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.brand {
  font-family: var(--font-display);
  color: #fbf7ee;
  font-size: 28px;
  font-weight: 700;
  margin: 0;
}
.brand-sub {
  font-family: var(--font-hand);
  font-size: 18px;
  color: #d8dfc9;
  margin-left: 10px;
}
.btn-add {
  font-family: var(--font-body);
  font-weight: 700;
  background: var(--rust);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: 0 2px 0 #7c2c1c;
  transition: transform .1s ease;
}
.btn-add:hover { transform: translateY(-1px); }
.btn-add:active { transform: translateY(1px); box-shadow: none; }

/* ---- layout ---- */
.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin-bottom: 26px;
}
.search-input {
  font-family: var(--font-body);
  font-size: 15px;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: 4px;
  background: var(--card);
  color: var(--ink);
  min-width: 220px;
  flex: 0 1 260px;
}
.search-input:focus { outline: 2px solid var(--herb); border-color: var(--herb); }

.tag-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
}
.tag-chip {
  font-family: var(--font-hand);
  font-size: 16px;
  padding: 3px 12px 5px;
  border: 1.5px dashed var(--gold);
  border-radius: 14px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transform: rotate(-1deg);
}
.tag-chip:nth-child(even) { transform: rotate(1deg); }
.tag-chip.active {
  background: var(--gold);
  color: #fff;
  border-style: solid;
}

/* ---- empty state ---- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-soft); }
.empty-hand { font-family: var(--font-hand); font-size: 34px; color: var(--rust); margin: 0; }
.empty-sub { margin-top: 6px; }

/* ---- grid & card ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 22px;
}

.recipe-card {
  background: var(--card);
  border-radius: 3px;
  padding: 18px 16px 16px;
  position: relative;
  box-shadow: 0 3px 8px var(--shadow);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
  border-top: 3px solid var(--gold);
}
.recipe-card:hover {
  transform: translateY(-3px) rotate(-0.3deg);
  box-shadow: 0 8px 16px var(--shadow);
}
.recipe-card::before, .recipe-card::after {
  content: "";
  position: absolute;
  top: 9px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.3);
}
.recipe-card::before { left: 14px; }
.recipe-card::after { right: 14px; }

.card-photo {
  width: 100%;
  height: 130px;
  object-fit: cover;
  border-radius: 2px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
}
.card-photo-placeholder {
  width: 100%;
  height: 130px;
  border-radius: 2px;
  margin-bottom: 10px;
  border: 1px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  font-family: var(--font-hand);
  font-size: 20px;
  background: repeating-linear-gradient(135deg, transparent, transparent 8px, rgba(44,38,28,0.03) 8px, rgba(44,38,28,0.03) 16px);
}

.card-title {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  margin: 0 0 4px;
}
.card-servings {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
}
.card-tags {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.mini-tag {
  font-family: var(--font-hand);
  font-size: 14px;
  color: var(--herb-dark);
  background: #eef0e2;
  padding: 1px 9px 3px;
  border-radius: 10px;
}

/* ---- modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 25, 18, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}
.modal {
  background: var(--card);
  max-width: 620px;
  width: 100%;
  border-radius: 4px;
  padding: 30px 30px 26px;
  position: relative;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  border-top: 5px solid var(--rust);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 26px;
  background: none;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--rust); }

.form-title {
  font-family: var(--font-display);
  margin-top: 0;
}

.field-label {
  display: block;
  font-family: var(--font-hand);
  font-size: 18px;
  color: var(--herb-dark);
  margin: 16px 0 6px;
}
.text-input, textarea {
  width: 100%;
  font-family: var(--font-body);
  font-size: 15px;
  padding: 9px 12px;
  border: 1.5px solid var(--line);
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
}
.text-input:focus, textarea:focus { outline: none; border-color: var(--herb); }

.field-row { display: flex; gap: 16px; }
.field-col { flex: 1; }

.photo-drop {
  border: 2px dashed var(--line);
  border-radius: 4px;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: #fff;
  overflow: hidden;
}
.photo-preview { width: 100%; max-height: 220px; object-fit: cover; }
.photo-placeholder { color: var(--ink-soft); font-family: var(--font-hand); font-size: 18px; }

.link-btn {
  background: none;
  border: none;
  color: var(--rust);
  font-family: var(--font-hand);
  font-size: 17px;
  cursor: pointer;
  padding: 4px 0;
}
.link-btn:hover { text-decoration: underline; }

.dyn-rows { display: flex; flex-direction: column; gap: 8px; }
.ing-row { display: flex; gap: 8px; }
.ing-row input:first-child { flex: 2; }
.ing-row input:last-child { flex: 1; font-family: var(--font-mono); }
.step-row { display: flex; gap: 8px; align-items: flex-start; }
.step-num {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--gold);
  padding-top: 9px;
  min-width: 20px;
}
.row-del {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}
.row-del:hover { color: var(--rust); }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 26px;
}
.btn-primary, .btn-secondary {
  font-family: var(--font-body);
  font-weight: 700;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
  border: none;
}
.btn-primary { background: var(--herb); color: #fff; }
.btn-primary:hover { background: var(--herb-dark); }
.btn-secondary { background: transparent; color: var(--ink-soft); border: 1.5px solid var(--line); }

/* ---- detail modal ---- */
.detail-photo {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: 3px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
}
.detail-title {
  font-family: var(--font-display);
  font-size: 26px;
  margin: 0 0 6px;
}
.detail-meta {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.detail-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.detail-section-title {
  font-family: var(--font-hand);
  font-size: 20px;
  color: var(--herb-dark);
  border-bottom: 1.5px dashed var(--gold);
  padding-bottom: 4px;
  margin: 20px 0 10px;
}
.ing-list { list-style: none; padding: 0; margin: 0; }
.ing-list li {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px dotted var(--line);
  font-size: 15px;
}
.ing-list li span:last-child { font-family: var(--font-mono); color: var(--ink-soft); }
.step-list { padding-left: 0; list-style: none; counter-reset: step; margin: 0; }
.step-list li {
  counter-increment: step;
  padding: 6px 0 6px 34px;
  position: relative;
  font-size: 15px;
  line-height: 1.55;
}
.step-list li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 6px;
  font-family: var(--font-mono);
  font-weight: 700;
  color: #fff;
  background: var(--herb);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.detail-source { margin-top: 18px; font-size: 14px; }
.detail-source a { color: var(--rust); }
.detail-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

/* ---- toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fbf7ee;
  padding: 10px 20px;
  border-radius: 4px;
  font-size: 14px;
  z-index: 200;
}

/* ---- responsive ---- */
@media (max-width: 480px) {
  .field-row { flex-direction: column; gap: 0; }
  .brand { font-size: 22px; }
  .modal { padding: 24px 18px 20px; }
}
