:root {
  --bg: #fdfaf6;
  --surface: #ffffff;
  --surface-alt: #f5efe6;
  --text: #2b2118;
  --text-muted: #6e5d4f;
  --primary: #c85a32;
  --primary-hover: #ad4822;
  --primary-soft: #fbece6;
  --accent: #2e6f40;
  --accent-soft: #e6f4ea;
  --border: #e8decb;
  --shadow-sm: 0 2px 8px rgba(43, 33, 24, 0.06);
  --shadow-md: 0 10px 28px rgba(43, 33, 24, 0.1);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
}

[data-theme="dark"] {
  --bg: #181411;
  --surface: #241e1a;
  --surface-alt: #302822;
  --text: #f5ede6;
  --text-muted: #b8a99a;
  --primary: #e06d44;
  --primary-hover: #f07e55;
  --primary-soft: #3d251c;
  --accent: #589e6f;
  --accent-soft: #1e3324;
  --border: #3a3028;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.hidden {
  display: none !important;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.9rem;
  padding-bottom: 0.9rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text);
}

.brand-icon {
  font-size: 2rem;
}

.brand-title {
  display: block;
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.2;
}

.brand-subtitle {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.sync-badge {
  font-size: 0.78rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-weight: 500;
}

.sync-badge.connected {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--primary);
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-icon {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  cursor: pointer;
  font-size: 1.05rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.meta-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}

.link-btn:hover {
  text-decoration: underline;
}

/* Hero Section */
.hero {
  padding: 2.5rem 0 1.25rem;
  background: radial-gradient(circle at top right, var(--primary-soft), transparent 60%);
}

.hero-content {
  max-width: 760px;
  margin: 0 auto;
  text-align: center;
}

.hero-badge {
  display: inline-block;
  padding: 0.3rem 0.85rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.hero h1 {
  font-family: 'Playfair Display', serif;
  font-size: clamp(1.85rem, 3.5vw, 2.65rem);
  margin-bottom: 0.6rem;
}

.hero p {
  color: var(--text-muted);
  font-size: 0.98rem;
  margin-bottom: 1.5rem;
}

.search-wrapper {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 1.75rem;
}

.search-input-group {
  flex: 1 1 360px;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 1rem;
  font-size: 1rem;
  pointer-events: none;
}

.search-input-group input {
  width: 100%;
  padding: 0.82rem 2.5rem 0.82rem 2.75rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
}

.search-input-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.clear-btn {
  position: absolute;
  right: 0.85rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
}

.filter-controls {
  display: flex;
  gap: 0.6rem;
}

.filter-controls select {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

/* Category Tabs */
.category-bar {
  display: flex;
  gap: 0.55rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  scrollbar-width: thin;
}

.category-chip {
  padding: 0.55rem 1.05rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.category-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.category-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Main Grid */
.main-section {
  padding-top: 1.25rem;
  padding-bottom: 3.5rem;
}

.section-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.15rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 1.5rem;
}

.recipe-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.22s ease, box-shadow 0.22s ease;
  cursor: pointer;
}

.recipe-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

.card-media {
  position: relative;
  height: 210px;
  background: var(--surface-alt);
  overflow: hidden;
}

.card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.35s ease;
}

.recipe-card:hover .card-media img {
  transform: scale(1.04);
}

.card-category-badge {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  background: rgba(24, 20, 17, 0.76);
  color: #fff;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  backdrop-filter: blur(4px);
}

.fav-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}

.fav-btn:hover {
  transform: scale(1.12);
}

.card-body {
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-meta {
  display: flex;
  gap: 0.85rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.card-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.22rem;
  margin-bottom: 0.45rem;
  color: var(--text);
}

.card-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-tags {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag-pill {
  font-size: 0.74rem;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--text-muted);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3.5rem 1.25rem;
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
}

.empty-state h3 {
  margin-bottom: 0.4rem;
}

.empty-state p {
  color: var(--text-muted);
  max-width: 520px;
  margin: 0 auto 1.25rem;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 12, 10, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  overflow-y: auto;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}

.detail-modal {
  max-width: 820px;
}

.form-modal {
  max-width: 700px;
  padding: 1.5rem;
}

.modal-close {
  position: sticky;
  top: 1rem;
  float: right;
  margin: 1rem 1rem 0 0;
  z-index: 10;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}

.detail-hero {
  height: 300px;
  width: 100%;
  object-fit: cover;
}

.detail-body {
  padding: 1.5rem 1.75rem 2rem;
}

.detail-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.detail-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.75rem;
}

.detail-stats {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.9rem 1.15rem;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  margin: 1rem 0 1.5rem;
  align-items: center;
  justify-content: space-between;
}

.servings-adjuster {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.servings-btn {
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.detail-columns {
  display: grid;
  grid-template-columns: 1fr 1.45fr;
  gap: 1.75rem;
}

@media (max-width: 720px) {
  .detail-columns {
    grid-template-columns: 1fr;
  }
}

.ingredients-list {
  list-style: none;
  margin-top: 0.75rem;
}

.ingredients-list li {
  padding: 0.5rem 0;
  border-bottom: 1px dashed var(--border);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.92rem;
}

.ingredients-list input[type="checkbox"]:checked + span {
  text-decoration: line-through;
  color: var(--text-muted);
}

.steps-list {
  list-style: none;
  margin-top: 0.75rem;
  counter-reset: step-counter;
}

.steps-list li {
  counter-increment: step-counter;
  position: relative;
  padding-left: 2.35rem;
  margin-bottom: 1rem;
  font-size: 0.94rem;
}

.steps-list li::before {
  content: counter(step-counter);
  position: absolute;
  left: 0;
  top: 0.1rem;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.recipe-note-box {
  margin-top: 1.5rem;
  padding: 1rem 1.15rem;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  border-left: 4px solid var(--primary);
  font-size: 0.88rem;
}

.recipe-note-box a {
  color: var(--primary);
  font-weight: 600;
}

.detail-actions {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
}

/* Upload & Password Box */
.upload-box,
.password-box {
  padding: 0.95rem 1.1rem;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.upload-controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.upload-controls input {
  flex: 1 1 220px;
}

.image-preview-container {
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.image-preview-container img {
  width: 96px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* Form Styles */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.modal-header .modal-close {
  position: static;
  margin: 0;
}

.recipe-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-row {
  display: flex;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1 1 160px;
}

.flex-2 {
  flex: 2 1 280px;
}

.flex-1 {
  flex: 1 1 160px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
}

.label-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 0.5rem;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 1.75rem 0;
  font-size: 0.86rem;
  color: var(--text-muted);
  text-align: center;
}

.site-footer a {
  color: var(--primary);
  font-weight: 600;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--text);
  color: var(--bg);
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  box-shadow: var(--shadow-md);
}

@media print {
  .site-header,
  .hero,
  .main-section,
  .site-footer,
  .modal-close,
  .detail-actions {
    display: none !important;
  }
  .modal-backdrop {
    position: static;
    background: none;
    padding: 0;
  }
  .modal-card {
    max-height: none;
    box-shadow: none;
    border: none;
  }
}
