:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --text: #2a2420;
  --muted: #7a7168;
  --border: #e5ddd2;
  --accent: #b5652f;
  --accent-hover: #9a5326;
  --danger: #b3342a;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --surface: #26221e;
    --text: #ece6de;
    --muted: #a89f93;
    --border: #3a3530;
    --accent: #d98a4f;
    --accent-hover: #e69c60;
    --danger: #e0685a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; font-size: 1.2rem; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { text-decoration: none; color: var(--text); }
.topbar-user { display: flex; gap: 12px; align-items: center; color: var(--muted); font-size: 0.9rem; }

.page { max-width: 900px; margin: 0 auto; padding: 24px; }

.breadcrumb { color: var(--muted); font-size: 0.9rem; margin-bottom: 6px; }
.breadcrumb a { color: var(--muted); }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-actions { display: flex; gap: 8px; }

h1 { margin: 0; }

.flashes { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; }
.flash-error { background: rgba(179, 52, 42, 0.12); color: var(--danger); }
.flash-message, .flash-info { background: rgba(0,0,0,0.05); }

.btn-primary, .btn-secondary, .btn-danger {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
  font-size: 0.95rem;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: transparent; color: var(--text); border-color: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 0.85rem; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.filter-chip {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  font-size: 0.85rem;
}
.filter-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
}
.card-photo { width: 100%; height: 140px; object-fit: cover; display: block; }
.card-body { padding: 12px 14px; }
.card-body h2 { margin: 0 0 6px; font-size: 1.05rem; }

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { background: rgba(181, 101, 47, 0.12); color: var(--accent); border-radius: 999px; padding: 2px 10px; font-size: 0.8rem; }

.badge { display: inline-block; font-size: 0.8rem; color: var(--muted); background: rgba(0,0,0,0.05); border-radius: 999px; padding: 2px 10px; }

.empty-state { color: var(--muted); }

.form { display: flex; flex-direction: column; gap: 6px; max-width: 640px; }
.form label { font-weight: 600; margin-top: 10px; font-size: 0.9rem; }
.form label .hint, .hint { font-weight: 400; color: var(--muted); }
.form input, .form textarea, .form select, .share-form select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}
.form-row { display: flex; gap: 16px; }
.form-row > div { flex: 1; display: flex; flex-direction: column; }
.form-actions { margin-top: 16px; display: flex; gap: 10px; }
.form-photo-preview { max-width: 200px; border-radius: 8px; margin: 6px 0; }

.detail-photo { max-width: 100%; border-radius: 12px; margin-bottom: 16px; }
.meta-row { display: flex; gap: 18px; color: var(--muted); font-size: 0.9rem; margin: 10px 0; flex-wrap: wrap; }
.description { color: var(--muted); }
.detail-columns { display: grid; grid-template-columns: 1fr 1.4fr; gap: 32px; margin-top: 20px; }
.ingredient-list, .step-list { padding-left: 20px; }
.ingredient-list li, .step-list li { margin-bottom: 8px; }

.note-list { display: flex; flex-direction: column; gap: 12px; }
.note-row {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  text-decoration: none;
  color: var(--text);
}
.note-row h2 { margin: 0 0 4px; font-size: 1.05rem; }
.note-row p { margin: 6px 0 0; color: var(--muted); }
.note-body { line-height: 1.6; }
.note-body :first-child { margin-top: 0; }
.note-body :last-child { margin-bottom: 0; }
.note-body ul, .note-body ol { padding-left: 22px; }
.note-body li { margin-bottom: 4px; }
.note-body li input[type="checkbox"] { margin-right: 6px; }
.note-body pre {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
}
.note-body code { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 0.9em; }
.note-body blockquote {
  margin: 0;
  padding-left: 14px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}
.note-body table { border-collapse: collapse; width: 100%; }
.note-body th, .note-body td { border: 1px solid var(--border); padding: 6px 10px; }
.note-body ul.checklist { list-style: none; padding-left: 0; }

.link-card {
  display: flex;
  gap: 14px;
  align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  margin: 10px 0;
}
.link-card:hover { border-color: var(--accent); }
.link-card img { width: 140px; object-fit: cover; flex-shrink: 0; }
.link-card-body { display: flex; flex-direction: column; gap: 4px; padding: 12px 16px 12px 0; justify-content: center; overflow: hidden; }
.link-card-body strong { font-size: 0.98rem; }
.link-card-desc { color: var(--muted); font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.link-card-url { color: var(--muted); font-size: 0.78rem; }

.children-panel { margin-top: 28px; }
.note-children-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.note-children-list li { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.note-children-list a { text-decoration: none; color: var(--text); }

.share-panel { margin-top: 32px; border-top: 1px solid var(--border); padding-top: 16px; }
.share-list { list-style: none; padding: 0; }
.share-list li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.share-form { display: flex; gap: 8px; margin-top: 12px; }

.auth-screen { display: flex; justify-content: center; align-items: center; min-height: 80vh; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; width: 100%; max-width: 360px; }
.auth-sub { color: var(--muted); margin-top: 0; }
.auth-form { display: flex; flex-direction: column; gap: 6px; }
.auth-form label { font-weight: 600; font-size: 0.9rem; margin-top: 8px; }
.auth-form input {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.auth-form button { margin-top: 16px; }
.auth-hint { color: var(--muted); font-size: 0.85rem; margin-top: 16px; }

@media (max-width: 640px) {
  .detail-columns { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }
}
