:root {
  --accent: #e87b4a;
  --accent-dark: #c75e30;
  --accent-soft: #fce8dc;
  --bg: #fefaf6;
  --card: #ffffff;
  --text: #2a1f1a;
  --muted: #7a6e66;
  --border: #ede5dd;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 4px 12px rgba(232, 123, 74, 0.06);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  height: 100vh;
  height: 100dvh;
  padding-top: 0;
  padding-bottom: 0;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* Topbar */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 0.75rem) 1rem 0.75rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}
#topbar h1 { font-size: 1.1rem; font-weight: 600; flex: 1; text-align: center; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; color: var(--text);
}
.icon-btn:active { background: var(--accent-soft); }

/* Main view */
#view { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 1.5rem; }

/* List + grid */
.list, .planning, .courses, .form-recette, .import-screen { padding: 1rem; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.875rem;
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.card:active { transform: scale(0.97); }
.card-photo {
  aspect-ratio: 1 / 1;
  background: var(--accent-soft) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem;
}
.card-body { padding: 0.625rem 0.75rem 0.875rem; }
.card-title {
  font-size: 0.95rem; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }

/* Empty states */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
}
.empty-emoji { font-size: 3.5rem; margin-bottom: 1rem; }
.empty-state h2 { font-size: 1.2rem; margin-bottom: 0.5rem; }
.empty-state p { color: var(--muted); margin-bottom: 1.5rem; max-width: 320px; margin-inline: auto; }

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.95rem;
}
.btn-primary:active { background: var(--accent-dark); }
.btn-ghost {
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 0.5rem 0.875rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
}
.btn-link { color: var(--muted); padding: 0.5rem 1rem; }
.btn-link.danger { color: #c44; }

/* Detail */
.detail .hero {
  aspect-ratio: 4 / 3;
  background: var(--accent-soft) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  font-size: 4rem;
}
.detail-body { padding: 1rem 1.25rem 2rem; }
.meta { color: var(--muted); font-size: 0.85rem; display: flex; gap: 0.75rem; margin-bottom: 0.5rem; }
.detail-body h2 { font-size: 1.4rem; line-height: 1.3; margin-bottom: 1rem; }
.actions { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.detail-body h3 { font-size: 1rem; margin: 1.5rem 0 0.75rem; color: var(--accent-dark); }
.ingredients { list-style: none; }
.ingredients li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}
.etapes { padding-left: 1.25rem; }
.etapes li { padding: 0.5rem 0; line-height: 1.6; }
.footer-actions { display: flex; justify-content: space-between; margin-top: 2rem; }

/* Form */
.form-recette { display: flex; flex-direction: column; gap: 0.875rem; }
.form-recette label {
  display: flex; flex-direction: column; gap: 0.375rem;
  font-size: 0.85rem; color: var(--muted); font-weight: 500;
}
.form-recette input, .form-recette textarea {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.875rem;
  font-size: 1rem;
  color: var(--text);
  font-family: inherit;
}
.form-recette input:focus, .form-recette textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}
.form-recette textarea { resize: vertical; min-height: 80px; }
.paste-zone {
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex; flex-direction: column; gap: 0.625rem;
  margin-bottom: 0.5rem;
}
.paste-zone-text { display: flex; flex-direction: column; gap: 0.125rem; }
.paste-zone-text strong { font-size: 0.95rem; color: var(--accent-dark); }
.paste-zone-text span { font-size: 0.8rem; color: var(--muted); line-height: 1.45; }
.paste-zone textarea {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.625rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  min-height: 70px;
}
.paste-zone textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.paste-buttons { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.paste-action { padding: 0.5rem 1.125rem; font-size: 0.9rem; }
.paste-action.parsing { opacity: 0.6; pointer-events: none; }
.media-pick {
  display: inline-flex; align-items: center; gap: 0.375rem;
  padding: 0.5rem 0.875rem; font-size: 0.85rem;
  cursor: pointer;
}
.paste-hint { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }

.form-recette .row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.875rem; }
.form-recette .row label { margin: 0; }
.form-recette .btn-primary { margin-top: 0.5rem; }

/* Bottom nav */
#bottom-nav {
  display: flex;
  align-items: stretch;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  flex: 0 0 auto;
  min-height: 58px;
}
#bottom-nav button {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 0.7rem;
  color: var(--muted);
  gap: 2px;
  padding: 0.5rem 0;
}
#bottom-nav button.active { color: var(--accent); }
#bottom-nav button .icon { font-size: 1.3rem; }
#bottom-nav .add-btn {
  background: var(--accent);
  color: white;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  margin: 5px 0.5rem;
  align-self: center;
  flex: 0 0 auto;
  font-size: 1.5rem;
}
#bottom-nav .add-btn .icon { font-size: 1.6rem; line-height: 1; }
#bottom-nav .add-btn .label { display: none; }

/* Import screen */
.import-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
  margin-top: 2rem;
}
.import-card h2 { margin-bottom: 0.5rem; }
.import-card p { color: var(--muted); }

/* Planning */
.planning-grid { display: flex; flex-direction: column; gap: 0.75rem; }
.planning-day {
  background: var(--card);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  box-shadow: var(--shadow);
}
.planning-day h3 { font-size: 0.85rem; color: var(--accent); margin-bottom: 0.5rem; text-transform: uppercase; letter-spacing: 0.05em; }
.planning-day .meal { font-size: 0.95rem; padding: 0.25rem 0; color: var(--muted); }

/* Settings */
.settings { padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.settings-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem 1.25rem 1.25rem;
  box-shadow: var(--shadow);
}
.settings-card h2 { font-size: 1rem; margin-bottom: 0.5rem; color: var(--accent-dark); }
.settings-card.danger h2 { color: #c44; }
.settings-desc { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.875rem; line-height: 1.5; }
.settings-card label { display: flex; flex-direction: column; gap: 0.375rem; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.875rem; }
.settings-card input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.625rem 0.75rem;
  font-size: 0.95rem;
  color: var(--text);
  font-family: inherit;
}
.settings-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.settings-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.settings-hint { font-size: 0.75rem; color: var(--muted); margin-top: 0.625rem; }
.settings-hint a { color: var(--accent); text-decoration: none; }

/* Guide */
.guide { padding: 1rem 1.25rem 2rem; }
.guide h2 { font-size: 1.2rem; margin-bottom: 1rem; }
.guide-steps { padding-left: 1.5rem; display: flex; flex-direction: column; gap: 0.75rem; }
.guide-steps li { line-height: 1.5; font-size: 0.95rem; }
.guide-steps code {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 0.125rem 0.375rem;
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 0.85rem;
  word-break: break-all;
}
.guide-tip { background: var(--accent-soft); padding: 0.875rem 1rem; border-radius: 10px; margin-top: 1.5rem; font-size: 0.9rem; line-height: 1.5; }

/* Courses */
.courses-list { list-style: none; }
.courses-list li {
  background: var(--card);
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-bottom: 0.5rem;
  display: flex; align-items: center; gap: 0.75rem;
  box-shadow: var(--shadow);
}
.courses-list li.checked { opacity: 0.5; text-decoration: line-through; }
.courses-list input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
