:root {
  --bg: #0f0d0a;
  --bg-soft: #1a1612;
  --bg-card: #1f1b16;
  --gold: #d4a853;
  --gold-light: #e8c97a;
  --gold-soft: rgba(212, 168, 83, 0.12);
  --gold-glow: 0 0 30px rgba(212, 168, 83, 0.25);
  --cream: #f5efe6;
  --cream-muted: #c4b8a8;
  --line: rgba(245, 239, 230, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --container: 800px;
  --font-display: "Playfair Display", Georgia, serif;
  --font-body: "DM Sans", Arial, sans-serif;
}

:root[data-theme="light"] {
  --bg: #faf6ef;
  --bg-soft: #f2ebdd;
  --bg-card: #ffffff;
  --gold: #b8863a;
  --gold-light: #9c6f2c;
  --gold-soft: rgba(184, 134, 58, 0.1);
  --gold-glow: 0 0 30px rgba(184, 134, 58, 0.15);
  --cream: #2a2318;
  --cream-muted: #6b5f4d;
  --line: rgba(42, 35, 24, 0.1);
}

.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.03);
  color: var(--cream-muted);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 200ms ease;
}

.theme-toggle:hover {
  border-color: rgba(212, 168, 83, 0.4);
  color: var(--gold-light);
}

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

html {
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  color: var(--cream);
  font-family: var(--font-body);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(212, 168, 83, 0.06), transparent 50%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
  overflow-x: hidden;
  line-height: 1.6;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 256px 256px;
}

.container {
  width: min(100% - 32px, var(--container));
  margin: 0 auto;
}

.lang-select {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 10;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--cream-muted);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
}

/* =========================
   Hero
========================= */
.hero {
  min-height: 100vh;
  display: flex;
  align-items: center;
  padding: 40px 0;
  position: relative;
}

.hero::before {
  content: "";
  position: absolute;
  top: -30%;
  right: -20%;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(212, 168, 83, 0.08), transparent 60%);
  pointer-events: none;
}

.hero-content {
  text-align: center;
  margin-bottom: 48px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid rgba(212, 168, 83, 0.3);
  border-radius: 999px;
  background: rgba(212, 168, 83, 0.08);
  color: var(--gold-light);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  margin-bottom: 24px;
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(4rem, 14vw, 7rem);
  font-weight: 900;
  line-height: 0.88;
  letter-spacing: -0.03em;
  color: var(--cream);
}

h1 span {
  display: block;
  font-style: italic;
  font-weight: 400;
  color: var(--gold);
  text-shadow: var(--gold-glow);
}

.subtitle {
  margin-top: 20px;
  font-size: clamp(1rem, 2.5vw, 1.15rem);
  color: var(--cream-muted);
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.7;
}

.accent {
  color: var(--gold-light);
  font-weight: 500;
}

/* =========================
   Form
========================= */
.chef-form {
  max-width: 560px;
  margin: 0 auto;
  display: grid;
  gap: 28px;
}

.input-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--cream-muted);
  margin-bottom: 10px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 250ms ease, box-shadow 250ms ease;
}

.input-wrapper:focus-within {
  border-color: rgba(212, 168, 83, 0.5);
  box-shadow: 0 0 0 3px rgba(212, 168, 83, 0.08), var(--gold-glow);
}

.input-wrapper.is-dragover {
  border-color: var(--gold);
  background: rgba(212, 168, 83, 0.08);
  box-shadow: 0 0 0 3px rgba(212, 168, 83, 0.15), var(--gold-glow);
}

.input-wrapper.is-dragover .drop-hint {
  opacity: 1;
}

.drop-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  color: var(--gold);
  font-weight: 600;
  letter-spacing: 0.04em;
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms ease;
  background: rgba(15, 13, 10, 0.85);
  border-radius: var(--radius);
}

.input-icon {
  flex: 0 0 auto;
  padding: 0 0 0 18px;
  font-size: 1.3rem;
}

.input-wrapper input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 18px 18px 18px 14px;
  outline: none;
  font-weight: 500;
}

.input-wrapper input::placeholder {
  color: rgba(245, 239, 230, 0.25);
}

.servings-wrapper input {
  max-width: 100px;
}

.photo-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-right: 6px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--cream-muted);
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 200ms ease;
  position: relative;
}

.photo-btn:hover {
  background: rgba(212, 168, 83, 0.1);
  color: var(--gold-light);
}

.photo-btn:focus-visible,
.photo-preview-clear:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.photo-btn:active {
  transform: scale(0.92);
}

.photo-btn.is-loading .photo-icon {
  display: none;
}

.photo-btn.is-loading .photo-loader {
  display: block;
}

.photo-loader {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(212, 168, 83, 0.25);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.photo-preview {
  position: relative;
  display: none;
  margin-top: 12px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
}

.photo-preview.is-visible {
  display: block;
  animation: fadeInUp 0.3s ease;
}

.photo-preview img {
  display: block;
  width: 100%;
  max-height: 200px;
  object-fit: cover;
}

.photo-preview-clear {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: var(--cream);
  font-size: 0.9rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 200ms ease;
}

.photo-preview-clear:hover {
  background: rgba(255, 80, 80, 0.7);
}

.photo-error {
  display: none;
  margin-top: 8px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 100, 100, 0.3);
  border-radius: var(--radius-sm);
  background: rgba(255, 100, 100, 0.06);
  color: #ff8a8a;
  font-size: 0.85rem;
  font-weight: 500;
}

.hint {
  font-size: 0.8rem;
  color: rgba(196, 184, 168, 0.5);
  margin-top: 8px;
  font-style: italic;
}

/* =========================
   API Key section
========================= */
#api-key-section {
  max-width: 560px;
  margin: 0 auto;
}

.api-key-form {
  display: grid;
  gap: 24px;
}

/* =========================
   Vibe selector
========================= */
.vibe-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.vibe-btn {
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 14px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: all 250ms ease;
  font: inherit;
  color: var(--cream-muted);
}

.vibe-btn:hover {
  border-color: rgba(212, 168, 83, 0.3);
  background: rgba(212, 168, 83, 0.04);
}

.vibe-btn.is-active {
  border-color: var(--gold);
  background: rgba(212, 168, 83, 0.1);
  color: var(--gold-light);
  box-shadow: 0 0 0 1px rgba(212, 168, 83, 0.3), var(--gold-glow);
}

.vibe-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.vibe-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* =========================
   History
========================= */
.history {
  max-width: 560px;
  margin: 24px auto 0;
}

.history-title {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--cream-muted);
  margin-bottom: 10px;
}

.history-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--cream-muted);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 8px 16px;
  cursor: pointer;
  transition: all 200ms ease;
}

.history-item:hover {
  border-color: rgba(212, 168, 83, 0.4);
  color: var(--gold-light);
  background: rgba(212, 168, 83, 0.06);
}

.history-list li,
.favorites-list li {
  display: flex;
  align-items: center;
  gap: 4px;
}

.history-delete,
.favorite-delete {
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.02);
  color: var(--cream-muted);
  width: 26px;
  height: 26px;
  line-height: 1;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 200ms ease;
}

.history-delete:hover,
.favorite-delete:hover {
  border-color: rgba(220, 90, 90, 0.5);
  color: #dc5a5a;
  background: rgba(220, 90, 90, 0.08);
}

/* =========================
   Diet selector
========================= */
.diet-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.diet-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--cream-muted);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 8px 14px;
  cursor: pointer;
  transition: all 200ms ease;
}

.diet-btn:hover {
  border-color: rgba(212, 168, 83, 0.3);
  background: rgba(212, 168, 83, 0.04);
}

.diet-btn.is-active {
  border-color: var(--gold);
  background: rgba(212, 168, 83, 0.1);
  color: var(--gold-light);
  box-shadow: 0 0 0 1px rgba(212, 168, 83, 0.3);
}

/* =========================
   Submit
========================= */
.submit-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 0 32px;
  border: 0;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--gold), #c4953a);
  color: #0f0d0a;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 250ms ease;
  gap: 10px;
  overflow: hidden;
}

.submit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(212, 168, 83, 0.3);
}

.submit-btn:active {
  transform: translateY(0);
}

.submit-btn.is-loading .btn-text {
  opacity: 0;
}

.submit-btn.is-loading .btn-loader {
  display: block;
}

.btn-loader {
  display: none;
  position: absolute;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(15, 13, 10, 0.3);
  border-top-color: #0f0d0a;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.clear-key-btn {
  justify-self: center;
  border: 0;
  background: transparent;
  color: rgba(196, 184, 168, 0.5);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 200ms ease;
  padding: 4px 8px;
}

.clear-key-btn:hover {
  color: var(--gold-light);
}

.loading-message {
  text-align: center;
  margin-top: -8px;
  font-size: 0.82rem;
  color: rgba(196, 184, 168, 0.6);
  font-style: italic;
  min-height: 1.2em;
}

/* =========================
   Recipe Section
========================= */
.recipe-section {
  padding: 0 0 80px;
  display: none;
}

.recipe-section.is-visible {
  display: block;
  animation: fadeInUp 0.6s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.recipe-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(145deg, var(--bg-card), var(--bg-soft));
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.streaming-preview {
  max-width: 100%;
  max-height: 300px;
  overflow-y: auto;
  padding: 20px 24px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.2);
  color: var(--cream-muted);
  font-family: monospace;
  font-size: 0.78rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.cancel-btn {
  display: block;
  margin: 0 auto 16px;
  border: 1px solid rgba(220, 90, 90, 0.3);
  border-radius: 999px;
  background: rgba(220, 90, 90, 0.06);
  color: #dc5a5a;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 18px;
  cursor: pointer;
  transition: all 200ms ease;
}

.cancel-btn:hover {
  border-color: rgba(220, 90, 90, 0.6);
  background: rgba(220, 90, 90, 0.12);
}

.recipe-card:focus {
  outline: 2px solid rgba(212, 168, 83, 0.5);
  outline-offset: 2px;
}

.recipe-header {
  padding: 32px 32px 24px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(ellipse at 0% 100%, rgba(212, 168, 83, 0.04), transparent 50%);
}

.recipe-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.recipe-badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(212, 168, 83, 0.1);
  border: 1px solid rgba(212, 168, 83, 0.25);
  color: var(--gold-light);
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.favorite-btn {
  border: 0;
  background: transparent;
  color: var(--cream-muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  margin-bottom: 16px;
  transition: color 200ms ease, transform 150ms ease;
}

.favorite-btn:hover {
  color: var(--gold-light);
  transform: scale(1.1);
}

.favorite-btn.is-favorite {
  color: var(--gold);
}

/* =========================
   Favorites
========================= */
.favorites {
  max-width: 560px;
  margin: 24px auto 0;
}

.favorites-title {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--cream-muted);
  margin-bottom: 10px;
}

.favorites-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.favorite-item {
  border: 1px solid rgba(212, 168, 83, 0.25);
  border-radius: 999px;
  background: rgba(212, 168, 83, 0.06);
  color: var(--gold-light);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 8px 16px;
  cursor: pointer;
  transition: all 200ms ease;
}

.favorite-item:hover {
  border-color: var(--gold);
  background: rgba(212, 168, 83, 0.12);
}

.recipe-header h2 {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 700;
  color: var(--cream);
  line-height: 1.2;
  margin-bottom: 12px;
}

.recipe-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.meta-item {
  font-size: 0.85rem;
  color: var(--cream-muted);
  font-weight: 500;
}

/* =========================
   Recipe Body
========================= */
.recipe-body {
  display: grid;
  gap: 0;
}

@media (min-width: 700px) {
  .recipe-body {
    grid-template-columns: 1fr 1.5fr;
  }
}

.recipe-ingredients {
  padding: 28px 32px;
  border-right: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.12);
}

.recipe-steps {
  padding: 28px 32px;
}

.recipe-ingredients h3,
.recipe-steps h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--gold-light);
  margin-bottom: 18px;
  font-weight: 700;
}

.recipe-ingredients ul {
  list-style: none;
  display: grid;
  gap: 10px;
}

.recipe-ingredients li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  font-size: 0.92rem;
  color: var(--cream-muted);
}

.recipe-ingredients li::before {
  content: "•";
  color: var(--gold);
  font-weight: 700;
}

.recipe-steps ol {
  list-style: none;
  counter-reset: step;
  display: grid;
  gap: 16px;
}

.recipe-steps li {
  counter-increment: step;
  display: flex;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  font-size: 0.92rem;
  color: var(--cream-muted);
  line-height: 1.65;
}

.recipe-steps li::before {
  content: counter(step);
  flex: 0 0 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(212, 168, 83, 0.12);
  color: var(--gold);
  font-weight: 700;
  font-size: 0.82rem;
}

/* =========================
   Tips
========================= */
.recipe-tips {
  padding: 24px 32px;
  border-top: 1px solid var(--line);
  background: rgba(212, 168, 83, 0.03);
}

.recipe-tips h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--gold-light);
  margin-bottom: 8px;
}

.recipe-tips p {
  color: var(--cream-muted);
  font-size: 0.92rem;
  line-height: 1.7;
  font-style: italic;
}

/* =========================
   Actions
========================= */
.recipe-actions {
  padding: 20px 32px;
  border-top: 1px solid var(--line);
  text-align: center;
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.new-recipe-btn,
.copy-recipe-btn,
.pdf-btn,
.variant-btn,
.share-btn {
  border: 0;
  background: transparent;
  color: var(--cream-muted);
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 200ms ease;
  padding: 8px 16px;
  position: relative;
}

.new-recipe-btn:hover,
.copy-recipe-btn:hover,
.pdf-btn:hover,
.variant-btn:hover,
.share-btn:hover {
  color: var(--gold-light);
}

.variant-btn.is-loading .btn-text {
  opacity: 0;
}

.variant-btn.is-loading .btn-loader {
  display: block;
  border-top-color: var(--gold);
}

.variant-btn .btn-loader {
  border-color: rgba(196, 184, 168, 0.25);
}

/* =========================
   Footer
========================= */
.footer {
  padding: 40px 0;
  border-top: 1px solid var(--line);
  text-align: center;
}

.footer p {
  font-size: 0.85rem;
  color: rgba(196, 184, 168, 0.4);
}

.footer a {
  color: var(--gold);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* =========================
   Error
========================= */
.error-message {
  padding: 14px 18px;
  border: 1px solid rgba(255, 100, 100, 0.3);
  border-radius: var(--radius-sm);
  background: rgba(255, 100, 100, 0.06);
  color: #ff8a8a;
  font-size: 0.88rem;
  font-weight: 500;
  text-align: center;
}

/* =========================
   Responsive
========================= */
@media (max-width: 600px) {
  .vibe-selector {
    grid-template-columns: repeat(2, 1fr);
  }

  .recipe-header {
    padding: 24px 20px;
  }

  .recipe-ingredients,
  .recipe-steps {
    padding: 24px 20px;
  }

  .recipe-ingredients {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .recipe-tips,
  .recipe-actions {
    padding: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* =========================
   Print (export PDF)
========================= */
@media print {
  .grain,
  .hero,
  .footer,
  .recipe-actions {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  .recipe-section {
    display: block !important;
    padding: 0;
  }

  .recipe-card {
    border: 0;
    box-shadow: none;
    background: none;
  }

  .recipe-header h2,
  .recipe-ingredients h3,
  .recipe-steps h3,
  .recipe-tips h3 {
    color: #000;
  }

  .meta-item,
  .recipe-ingredients li,
  .recipe-steps li,
  .recipe-tips p {
    color: #222;
  }
}
