/* Bake Lab: brown butter, cocoa, and a warm kitchen */

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

:root {
  --butter: #f6e6bd;
  --butter-deep: #edd49a;
  --cream: #fff8e6;
  --cocoa: #38200f;
  --cocoa-soft: #6d4a33;
  --crust: #b25a1c;
  --jam: #a3312b;
  --pistachio: #5f7d3c;
  --line: rgba(56, 32, 15, 0.22);

  --display: 'Fraunces', Georgia, serif;
  --text: 'DM Sans', system-ui, sans-serif;
  --arabic: 'Noto Naskh Arabic', 'Geeza Pro', serif;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--text);
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--cocoa);
  background: var(--butter);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, .recipe-card:focus-visible, .ingredient-item:focus-visible {
  outline: 3px solid var(--crust); outline-offset: 3px;
}

/* Header */
header { max-width: 1040px; margin: 0 auto; padding: 1.25rem 1.5rem 0; }
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 2.5rem; }
.home { color: var(--cocoa-soft); text-decoration: none; font-size: 0.95rem; }
.home:hover { color: var(--crust); text-decoration: underline; }

header h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(3rem, 11vw, 5.5rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
}
header p#headerSub { margin-top: 0.75rem; font-size: 1.15rem; color: var(--cocoa-soft); }

.lang-toggle {
  background: transparent;
  border: 1.5px solid var(--cocoa);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  font-weight: 500;
  font-size: 0.95rem;
  min-height: 44px;
}
.lang-toggle:hover { background: var(--cocoa); color: var(--cream); }

/* Tabs */
.nav-tabs { max-width: 1040px; margin: 0 auto; padding: 1.75rem 1.5rem 0; display: flex; gap: 0.5rem; }
.nav-tab {
  border: 1.5px solid transparent;
  background: transparent;
  border-radius: 999px;
  padding: 0.45rem 1.1rem;
  font-weight: 500;
  color: var(--cocoa-soft);
  min-height: 44px;
}
.nav-tab:hover { border-color: var(--line); }
.nav-tab.active { background: var(--cocoa); color: var(--cream); }

.container { max-width: 1040px; margin: 0 auto; padding: 1.5rem; }
.page { display: none; }
.page.active { display: block; }

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

.recipe-card {
  background: var(--cream);
  border: 1.5px solid var(--cocoa);
  border-radius: 20px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.recipe-card:hover { transform: translate(-2px, -2px); box-shadow: 5px 5px 0 var(--cocoa); }
.recipe-card:active { transform: none; box-shadow: none; }

.recipe-card-img {
  aspect-ratio: 11 / 6;
  display: flex; align-items: center; justify-content: center;
  background-color: var(--butter-deep);
  background-size: cover; background-position: center;
  border-bottom: 1.5px solid var(--cocoa);
}
.recipe-card-body { padding: 1.1rem 1.25rem 1.25rem; }
.recipe-card-body h3 { font-family: var(--display); font-weight: 600; font-size: 1.45rem; line-height: 1.15; margin-bottom: 0.4rem; }
.recipe-card-body p { font-size: 0.98rem; color: var(--cocoa-soft); line-height: 1.45; }

.recipe-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 1rem; margin-top: 0.9rem; font-size: 0.9rem; color: var(--cocoa-soft); }
.difficulty-badge { display: inline-block; padding: 0.1rem 0.65rem; border-radius: 999px; font-size: 0.85rem; font-weight: 500; border: 1.5px solid currentColor; }
.difficulty-easy { color: var(--pistachio); }
.difficulty-medium { color: var(--crust); }
.difficulty-hard { color: var(--jam); }

/* Baking view */
.back-btn { background: none; border: none; color: var(--cocoa-soft); padding: 0.5rem 0; margin-bottom: 0.5rem; min-height: 44px; }
.back-btn:hover { color: var(--crust); text-decoration: underline; }

.baking-header { margin-bottom: 1.25rem; }
.baking-header h2 { font-family: var(--display); font-weight: 600; font-size: clamp(2rem, 6vw, 3rem); line-height: 1.05; letter-spacing: -0.02em; }

.preheat-banner {
  display: flex; align-items: center; gap: 0.8rem;
  background: var(--jam); color: var(--cream);
  border-radius: 16px; padding: 0.9rem 1.1rem; margin-bottom: 1rem;
}
.preheat-banner .icon { font-size: 1.4rem; }
.preheat-banner .text h4 { font-weight: 700; font-size: 1.05rem; line-height: 1.3; }
.preheat-banner .text p { font-size: 0.92rem; opacity: 0.92; }
.preheat-banner.ready { background: var(--pistachio); }

.progress-container { background: var(--butter-deep); border-radius: 999px; height: 8px; margin: 1rem 0 0.5rem; overflow: hidden; }
.progress-bar { height: 100%; background: var(--crust); border-radius: 999px; transition: width 0.4s ease; }
.step-counter { font-size: 0.95rem; color: var(--cocoa-soft); margin-bottom: 1rem; }

.baking-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.5rem; align-items: start; }
.baking-sidebar { position: sticky; top: 1rem; }

.step-card { background: var(--cream); border: 1.5px solid var(--cocoa); border-radius: 20px; padding: 1.5rem 1.75rem 1.75rem; }
.step-card .step-number { font-family: var(--display); font-weight: 600; font-size: 3.5rem; line-height: 1; color: var(--crust); margin-bottom: 0.5rem; }
.step-card h3 { font-family: var(--display); font-weight: 600; font-size: 1.6rem; line-height: 1.2; margin-bottom: 0.6rem; }
.step-card p { font-size: 1.15rem; line-height: 1.6; max-width: 38rem; }

.step-tip { margin-top: 1.1rem; padding: 0.8rem 1rem; border: 1.5px dashed var(--crust); border-radius: 14px; font-size: 1rem; line-height: 1.5; color: var(--cocoa-soft); max-width: 38rem; }
.step-tip::before { content: 'Tip. '; font-weight: 700; color: var(--crust); }
[dir="rtl"] .step-tip::before { content: 'نصيحة. '; }

.step-nav { display: flex; gap: 0.75rem; margin-top: 1rem; }
.step-btn { flex: 1; min-height: 56px; padding: 0.8rem 1.2rem; border-radius: 16px; border: 1.5px solid var(--cocoa); font-weight: 700; font-size: 1.05rem; transition: transform 0.12s ease, box-shadow 0.12s ease; }
.step-btn-prev { background: transparent; }
.step-btn-prev:hover { background: var(--butter-deep); }
.step-btn-next { background: var(--cocoa); color: var(--cream); }
.step-btn-finish { background: var(--pistachio); border-color: var(--pistachio); color: var(--cream); }
.step-btn-next:hover, .step-btn-finish:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--crust); }
.step-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }

.collapse-toggle { display: none; width: 100%; min-height: 48px; background: var(--cream); border: 1.5px solid var(--cocoa); border-radius: 14px; font-weight: 700; margin-bottom: 0.75rem; }

.ingredients-panel, .timer-section { background: var(--cream); border: 1.5px solid var(--cocoa); border-radius: 20px; padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.ingredients-panel h3, .timer-section h3 { font-family: var(--display); font-weight: 600; font-size: 1.3rem; margin-bottom: 0.5rem; }

.ingredient-item { display: flex; align-items: flex-start; gap: 0.7rem; padding: 0.55rem 0; border-top: 1px solid var(--line); font-size: 1rem; line-height: 1.4; cursor: pointer; }
.ingredient-item:first-of-type { border-top: none; }
.ingredient-check { flex: none; width: 22px; height: 22px; margin-top: 0.05rem; border: 1.5px solid var(--cocoa); border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; }
.ingredient-item.checked { color: var(--cocoa-soft); text-decoration: line-through; }
.ingredient-item.checked .ingredient-check { background: var(--pistachio); border-color: var(--pistachio); color: var(--cream); }

.timer-card { padding: 0.75rem 0; border-top: 1px solid var(--line); }
.timer-card:first-of-type { border-top: none; }
.timer-info h4 { font-weight: 700; font-size: 1rem; }
.timer-info p { font-size: 0.9rem; color: var(--cocoa-soft); }
.timer-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.4rem; }
.timer-display { font-family: var(--display); font-weight: 600; font-size: 2rem; line-height: 1; font-variant-numeric: tabular-nums; margin-inline-end: auto; }
.timer-display.running { color: var(--jam); }
.timer-display.done { color: var(--pistachio); font-size: 1.3rem; }
.timer-btn { min-height: 40px; padding: 0.35rem 0.95rem; border-radius: 999px; border: 1.5px solid var(--cocoa); font-weight: 700; font-size: 0.92rem; background: transparent; }
.timer-btn-start { background: var(--cocoa); color: var(--cream); }
.timer-btn-stop { background: var(--jam); border-color: var(--jam); color: var(--cream); }
.timer-btn-reset:hover { background: var(--butter-deep); }

/* Finish */
.completion { padding: 3rem 0; max-width: 34rem; }
.completion .emoji { font-size: 3rem; margin-bottom: 0.75rem; }
.completion h2 { font-family: var(--display); font-weight: 600; font-size: clamp(2.2rem, 7vw, 3.4rem); line-height: 1.05; margin-bottom: 0.75rem; }
.completion p { font-size: 1.15rem; color: var(--cocoa-soft); margin-bottom: 1.5rem; }
.completion .step-btn { margin: 0 !important; }

/* Timer alarm */
.alarm-overlay { display: none; position: fixed; inset: 0; background: rgba(56, 32, 15, 0.7); z-index: 1000; align-items: center; justify-content: center; padding: 1.25rem; }
.alarm-overlay.active { display: flex; }
.alarm-box { background: var(--cream); border: 1.5px solid var(--cocoa); border-radius: 24px; padding: 2rem; max-width: 360px; width: 100%; text-align: center; box-shadow: 8px 8px 0 var(--jam); }
.alarm-box .emoji { font-size: 2.5rem; margin-bottom: 0.5rem; }
.alarm-box h3 { font-family: var(--display); font-weight: 600; font-size: 1.6rem; line-height: 1.2; margin-bottom: 0.4rem; }
.alarm-box p { color: var(--cocoa-soft); margin-bottom: 1.25rem; }
.alarm-dismiss { min-height: 52px; width: 100%; background: var(--cocoa); color: var(--cream); border: none; border-radius: 16px; font-weight: 700; font-size: 1.05rem; }

.copyright { margin-top: 3rem; padding: 1.25rem 0 0.5rem; border-top: 1px solid var(--line); font-size: 0.9rem; color: var(--cocoa-soft); }
.copyright a { color: var(--cocoa); }

/* Arabic */
[dir="rtl"] body { font-family: var(--arabic); font-size: 1.15rem; }
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3, [dir="rtl"] h4, [dir="rtl"] .timer-display.done { font-family: var(--arabic); letter-spacing: 0; }
[dir="rtl"] header h1 { line-height: 1.3; font-weight: 700; }
[dir="rtl"] .recipe-card:hover { transform: translate(2px, -2px); box-shadow: -5px 5px 0 var(--cocoa); }

@media (max-width: 820px) {
  .baking-layout { grid-template-columns: minmax(0, 1fr); }
  .baking-sidebar { position: static; }
  .collapse-toggle { display: block; }
  .baking-sidebar.collapsed .ingredients-panel,
  .baking-sidebar.collapsed .timer-section { display: none; }
}

@media (max-width: 520px) {
  header { padding: 1rem 1.1rem 0; }
  .head-row { margin-bottom: 1.75rem; }
  .nav-tabs { padding: 1.25rem 1.1rem 0; }
  .container { padding: 1.1rem; }
  .recipe-grid { grid-template-columns: minmax(0, 1fr); gap: 1.1rem; }
  .step-card { padding: 1.2rem 1.25rem 1.4rem; }
  .step-card .step-number { font-size: 2.8rem; }
}

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