/* ── Variables ── */
:root {
  --cream:      #FDF6EC;
  --terracotta: #C1440E;
  --saffron:    #E8A020;
  --dark:       #2C1810;
  --mid:        #6B4C3B;
  --border:     #E8D5BC;
  --card-bg:    #FFF8F0;
  --radius:     12px;
  --shadow:     0 2px 12px rgba(44,24,16,0.08);
}

/* ── Dark mode ── */
[data-theme="dark"] {
  --cream:   #1C1410;
  --card-bg: #2A1E16;
  --dark:    #F0E4D0;
  --mid:     #C4956A;
  --border:  #4A3428;
  --shadow:  0 2px 12px rgba(0,0,0,0.4);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base ── */
body {
  background: var(--cream);
  color: var(--dark);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  padding: 0 16px 48px;
}

h1, h2, h3 {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 600;
  line-height: 1.2;
}

/* ── Theme toggle ── */
.theme-toggle {
  position: fixed;
  top: 14px;
  left: 16px;
  font-size: 0.75rem;
  color: var(--mid);
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
  z-index: 100;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.2s, color 0.2s;
}
.theme-toggle:hover { color: var(--terracotta); border-color: var(--terracotta); }

/* ── Credits badge ── */
.credits-badge {
  position: fixed;
  top: 14px;
  right: 16px;
  font-size: 0.75rem;
  color: var(--mid);
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
  z-index: 100;
  transition: border-color 0.2s, color 0.2s;
}
.credits-badge.low {
  color: #C17A00;
  border-color: #E8A020;
}
.credits-badge.critical {
  color: var(--terracotta);
  border-color: var(--terracotta);
  font-weight: 600;
}

/* ── App Shell ── */
#app {
  max-width: 640px;
  margin: 0 auto;
}

/* ── Screens ── */
.screen { display: none; padding-top: 40px; }
.screen.active { display: block; }

/* ── Screen 1: Picker ── */
.family-title {
  font-size: 2rem;
  color: var(--terracotta);
  text-align: center;
  margin-bottom: 8px;
}

.subtitle {
  text-align: center;
  color: var(--mid);
  margin-bottom: 12px;
  font-size: 1rem;
}

.story {
  font-family: 'Playfair Display', Georgia, serif;
  text-align: center;
  color: var(--mid);
  font-size: 1rem;
  line-height: 1.75;
  margin-bottom: 12px;
  font-style: italic;
}

.explainer {
  text-align: center;
  color: var(--dark);
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 8px;
}

.disclaimer {
  text-align: center;
  color: var(--mid);
  font-size: 0.78rem;
  font-style: italic;
  margin-bottom: 32px;
  opacity: 0.75;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.member-card:last-child:nth-child(odd) {
  grid-column: 1 / -1;
  width: calc(50% - 8px);
  margin: 0 auto;
}

.member-card {
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  box-shadow: var(--shadow);
}

.member-card:hover {
  border-color: var(--terracotta);
  box-shadow: 0 4px 20px rgba(193,68,14,0.15);
  transform: translateY(-2px);
}

.member-card:active { transform: translateY(0); }

.card-name {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.15rem;
  color: var(--dark);
  margin-bottom: 4px;
}

.card-location {
  font-size: 0.8rem;
  color: var(--mid);
  margin-bottom: 8px;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.card-tag {
  font-size: 0.72rem;
  color: var(--terracotta);
  background: rgba(193,68,14,0.07);
  border: 1px solid rgba(193,68,14,0.2);
  border-radius: 20px;
  padding: 2px 8px;
}

/* ── Input hint + example ── */
.input-hint {
  color: var(--mid);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.input-prompts {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.input-prompts li {
  font-size: 0.82rem;
  color: var(--mid);
  padding-left: 14px;
  position: relative;
}
.input-prompts li::before {
  content: '·';
  position: absolute;
  left: 4px;
  color: var(--saffron);
}

.input-example {
  font-size: 0.85rem;
  color: var(--mid);
  margin-bottom: 16px;
}

.example-text {
  color: var(--terracotta);
  font-style: italic;
  cursor: pointer;
  border-bottom: 1px dashed var(--terracotta);
}
.example-text:hover { opacity: 0.75; }

/* ── Screen 2: Input ── */
.back-btn {
  background: none;
  border: none;
  color: var(--mid);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
  margin-bottom: 24px;
  display: block;
}
.back-btn:hover { color: var(--terracotta); }

.kitchen-title {
  font-size: 1.6rem;
  color: var(--terracotta);
  margin-bottom: 24px;
}

.input-form { display: flex; flex-direction: column; gap: 12px; }

textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--dark);
  resize: vertical;
  transition: border-color 0.15s;
}
textarea:focus { outline: none; border-color: var(--saffron); }
textarea::placeholder { color: #B09080; }

.optional-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="text"] {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--dark);
}
input[type="text"]:focus { outline: none; border-color: var(--saffron); }
input[type="text"]::placeholder { color: #B09080; }

/* ── Buttons ── */
.primary-btn {
  background: var(--terracotta);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 14px 24px;
  font-size: 1rem;
  font-family: 'Playfair Display', Georgia, serif;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
}
.primary-btn:hover { background: #A33A0C; }
.primary-btn:disabled { background: var(--border); cursor: not-allowed; }

/* ── Screen 3: Result ── */
.result-header { margin-bottom: 24px; }

/* ── Markdown inside recipe box ── */
.recipe-content h1,
.recipe-content h2,
.recipe-content h3 {
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--terracotta);
  margin: 16px 0 8px;
  font-size: 1rem;
}
.recipe-content h1 { font-size: 1.15rem; }
.recipe-content ul,
.recipe-content ol {
  padding-left: 20px;
  margin: 8px 0;
}
.recipe-content li { margin: 4px 0; }
.recipe-content strong { color: var(--dark); }
.recipe-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}
.recipe-content p { margin: 8px 0; }

.recipe-content {
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  white-space: pre-wrap;
  font-size: 0.95rem;
  line-height: 1.8;
  min-height: 100px;
}

.loading {
  color: var(--mid);
  font-style: italic;
  padding: 24px 0;
  text-align: center;
  font-size: 1rem;
  animation: loading-fade 1.8s ease-in-out infinite;
}
.loading.hidden { display: none; }

@keyframes loading-fade {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

.result-actions {
  margin-top: 24px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.result-actions.hidden { display: none; }

.action-btn {
  background: var(--saffron);
  color: var(--dark);
  border: none;
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s;
}
.action-btn:hover { background: #D4920A; }

.secondary-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--mid);
  transition: border-color 0.15s;
}
.secondary-btn:hover { border-color: var(--terracotta); color: var(--terracotta); }

/* ── Saffron accent line ── */
.accent-line {
  height: 3px;
  background: linear-gradient(90deg, var(--terracotta), var(--saffron));
  border-radius: 2px;
  margin: 12px 0 32px;
}

/* ── Follow-up chat ── */
.followup-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1.5px solid var(--border);
}
.followup-section.hidden { display: none; }

.followup-hint {
  font-size: 0.85rem;
  color: var(--mid);
  margin-bottom: 10px;
  font-style: italic;
}

.followup-row {
  display: flex;
  gap: 8px;
}

.followup-row input[type="text"] {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--dark);
}
.followup-row input[type="text"]:focus { outline: none; border-color: var(--saffron); }

.followup-btn {
  background: var(--terracotta);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.followup-btn:hover { background: #A33A0C; }
.followup-btn:disabled { background: var(--border); cursor: not-allowed; }

.followup-question {
  margin-top: 20px;
  padding: 10px 14px;
  background: #F0E8D8;
  border-left: 3px solid var(--saffron);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.9rem;
  color: var(--dark);
  font-style: italic;
}

.followup-response {
  margin-top: 12px;
  padding-top: 4px;
}

/* ── Quota error ── */
.quota-error {
  text-align: center;
  padding: 16px 0;
}
.quota-img {
  width: min(90%, 360px);
  border-radius: var(--radius);
  margin-bottom: 20px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}
.quota-text {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.1rem;
  color: var(--dark);
  margin-bottom: 6px;
}
.quota-sub {
  font-size: 0.9rem;
  color: var(--mid);
  margin-bottom: 16px;
}
.quota-link {
  display: inline-block;
  background: var(--terracotta);
  color: #fff;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 0.9rem;
  text-decoration: none;
  transition: background 0.15s;
}
.quota-link:hover { background: #A33A0C; }

/* ── Footer ── */
.site-footer {
  text-align: center;
  color: var(--mid);
  font-size: 0.78rem;
  padding: 32px 0 16px;
  opacity: 0.7;
}
.site-footer a {
  color: var(--terracotta);
  text-decoration: none;
}
.site-footer a:hover { text-decoration: underline; }

/* ── Cookbook ── */
.cookbook-nav-btn {
  display: block;
  margin: 28px auto 0;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 6px 18px;
  font-size: 0.85rem;
  color: var(--mid);
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s;
}
.cookbook-nav-btn:hover { border-color: var(--terracotta); color: var(--terracotta); }

.cookbook-entry {
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
}

.cookbook-entry-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.cookbook-member {
  font-size: 0.8rem;
  color: var(--terracotta);
  font-weight: 600;
}

.cookbook-date {
  font-size: 0.75rem;
  color: var(--mid);
  opacity: 0.7;
}

.cookbook-dish {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.05rem;
  color: var(--dark);
  margin-bottom: 12px;
}

.cookbook-actions {
  display: flex;
  gap: 8px;
}

.cookbook-actions .action-btn,
.cookbook-actions .secondary-btn {
  padding: 8px 16px;
  font-size: 0.85rem;
}

.cookbook-empty {
  color: var(--mid);
  font-style: italic;
  text-align: center;
  padding: 32px 0;
  font-size: 0.9rem;
}

.action-btn.saved {
  background: var(--border);
  color: var(--mid);
  cursor: default;
}

/* ── Print stylesheet ── */
@media print {
  body { background: #fff; padding: 0; font-size: 12pt; }
  .screen { display: none !important; }
  #screen-result { display: block !important; padding: 0; }
  .back-btn,
  .result-actions,
  .loading { display: none !important; }
  .kitchen-title { color: #000; font-size: 18pt; margin-bottom: 16pt; }
  .recipe-content {
    border: none;
    background: #fff;
    padding: 0;
    font-size: 11pt;
    line-height: 1.7;
  }
  .accent-line { background: #000; }
}

/* ── Responsive ── */
@media (max-width: 400px) {
  .cards-grid { grid-template-columns: 1fr; }
  .optional-fields { grid-template-columns: 1fr; }
  .family-title { font-size: 1.6rem; }
}
