:root {
  --bg-primary: #f5ebd9;
  --bg-surface: #fbf6ec;
  --bg-desk: #462e1e;
  --text-primary: #2d1b10;
  --text-secondary: #5c3f2b;
  --accent-primary: #9e1b24;
  --accent-pine: #1e5932;
  --accent-ginger: #b96d2c;
  --border-page: #d8c2a1;
  --font-book: 'Cambria', 'Book Antiqua', serif;
  --font-clean: 'Tahoma', 'Arial', sans-serif;
  --font-code: 'Lucida Sans Typewriter', monospace;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background-color: var(--bg-desk);
  background-image:
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.025) 0 40px,
      rgba(0, 0, 0, 0.06) 40px 80px
    ),
    radial-gradient(circle at 50% 0%, #5c3d28 0%, #3a2417 100%);
  color: var(--text-primary);
  font-family: var(--font-clean);
  line-height: 1.55;
  overflow-x: clip;
}

.skip-book {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent-primary);
  color: #fbf6ec;
  padding: 0.6rem 1rem;
  font-weight: 700;
  z-index: 200;
}

.skip-book:focus {
  left: 1rem;
  top: 1rem;
}

button {
  font-family: inherit;
  cursor: pointer;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent-primary);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

/* Barra superior con marcadores de libro */
.book-desk-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(45, 27, 16, 0.96);
  border-bottom: 3px solid var(--accent-ginger);
  color: #fbf6ec;
}

.desk-bar-inner {
  width: min(1240px, 95vw);
  margin: 0 auto;
  padding: 0.7rem 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.book-crest {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.crest-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent-primary);
  display: grid;
  place-items: center;
  font-size: 1.3rem;
}

.book-title-mini {
  display: block;
  font-family: var(--font-book);
  font-size: 1.1rem;
}

.book-sub-mini {
  display: block;
  font-size: 0.76rem;
  color: #e6d4bc;
}

.bookmark-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.bookmark-btn {
  background: #63422c;
  color: #fbf6ec;
  border: 1px solid #966d4b;
  border-radius: 8px 8px 0 0;
  padding: 0.45rem 0.78rem;
  font-size: 0.82rem;
  font-weight: 700;
  transition: background-color 0.2s, transform 0.15s;
}

.bookmark-btn.is-current {
  background: var(--bg-primary);
  color: var(--text-primary);
  border-color: var(--bg-primary);
  transform: translateY(2px);
}

.book-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.baker-score-pill {
  font-size: 0.84rem;
  background: #362013;
  border: 1px solid var(--accent-ginger);
  padding: 0.34rem 0.7rem;
  border-radius: 999px;
}

/* Botones de cocina */
.book-btn-cherry,
.book-btn-pine,
.book-btn-paper,
.page-turn-btn,
.recipe-tab,
.tag-paper,
.pantry-btn {
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.54rem 1rem;
  transition: transform 0.14s, background-color 0.18s, border-color 0.18s;
}

.book-btn-cherry {
  background: var(--accent-primary);
  color: #fbf6ec;
  border: 2px solid #7c131b;
}

.book-btn-cherry:hover { transform: translateY(-1px); }

.book-btn-pine {
  background: var(--accent-pine);
  color: #fbf6ec;
  border: 2px solid #154024;
}

.book-btn-pine:hover { transform: translateY(-1px); }

.book-btn-paper {
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 2px solid var(--accent-ginger);
}

.page-turn-btn {
  background: var(--bg-desk);
  color: #fbf6ec;
  border: 2px solid var(--accent-ginger);
}

.page-turn-btn.is-next {
  background: var(--accent-primary);
  border-color: #7c131b;
}

/* Contenedor de libro abierto */
.cookbook-desk {
  width: min(1220px, 95vw);
  margin: 1.5rem auto 2.5rem;
}

.cookbook-binding {
  background: var(--bg-primary);
  border: 6px solid #7a4b2a;
  border-radius: 18px;
  padding: 1.3rem;
  box-shadow:
    0 24px 54px rgba(15, 8, 3, 0.58),
    inset 0 0 0 2px #e5d2b3;
}

.book-page-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding-bottom: 1rem;
  margin-bottom: 1.2rem;
  border-bottom: 2px dashed var(--border-page);
}

.folio-indicator {
  font-family: var(--font-book);
  font-weight: 700;
  color: var(--accent-primary);
  font-size: 0.98rem;
}

/* Doble hoja abierta con lomo sombreado */
.book-spread {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.8rem;
  position: relative;
  animation: pageFadeIn 0.28s ease;
}

.book-spread[hidden] {
  display: none;
}

.book-spread.single-wide-spread {
  grid-template-columns: 1fr;
}

@keyframes pageFadeIn {
  from { opacity: 0.35; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.left-leaf,
.right-leaf,
.wide-leaf {
  background: var(--bg-surface);
  border: 1px solid var(--border-page);
  border-radius: 12px;
  padding: 1.5rem 1.5rem 2.4rem;
  position: relative;
  box-shadow: inset 0 0 24px rgba(185, 109, 44, 0.08);
}

.left-leaf {
  box-shadow: inset -14px 0 22px -12px rgba(70, 46, 30, 0.22);
}

.right-leaf {
  box-shadow: inset 14px 0 22px -12px rgba(70, 46, 30, 0.22);
}

.folio-num {
  position: absolute;
  bottom: 0.75rem;
  right: 1.15rem;
  font-family: var(--font-code);
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.chapter-stamp {
  display: inline-block;
  font-family: var(--font-code);
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  color: var(--accent-pine);
  background: #e6f0e8;
  border: 1px solid #b8d3be;
  padding: 0.24rem 0.6rem;
  border-radius: 6px;
  margin-bottom: 0.55rem;
}

h1, h2, h3, h4 {
  font-family: var(--font-book);
  margin: 0 0 0.65rem;
  line-height: 1.2;
}

h1 { font-size: clamp(1.85rem, 3.2vw, 2.65rem); }
h2 { font-size: clamp(1.38rem, 2.3vw, 1.92rem); }

.book-lead {
  color: var(--text-secondary);
  margin-bottom: 1.1rem;
  font-size: 0.96rem;
}

.utensil-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.2rem;
}

.utensil-strip span {
  background: var(--bg-primary);
  border: 1px dashed var(--accent-ginger);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.84rem;
  font-weight: 700;
}

.book-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.center-btns {
  justify-content: center;
}

/* Polaroids de recetario */
.recipe-polaroid {
  margin: 0 0 1rem;
  background: #ffffff;
  border: 1px solid var(--border-page);
  padding: 0.55rem 0.55rem 0.75rem;
  border-radius: 8px;
  box-shadow: 0 8px 16px rgba(70, 46, 30, 0.12);
}

.recipe-polaroid.is-tilted {
  margin-bottom: 0;
}

.recipe-polaroid img,
.inline-leaf-photo img {
  width: 100%;
  height: 185px;
  object-fit: cover;
  display: block;
  border-radius: 5px;
}

.recipe-polaroid figcaption,
.inline-leaf-photo figcaption {
  margin-top: 0.45rem;
  font-family: var(--font-book);
  font-style: italic;
  font-size: 0.86rem;
  color: var(--text-secondary);
  text-align: center;
}

.inline-leaf-photo {
  margin: 0 0 1rem;
}

/* Lista de pasos */
.recipe-step-list {
  padding-left: 1.25rem;
  margin: 0 0 1rem;
  display: grid;
  gap: 0.65rem;
  font-size: 0.91rem;
}

.recipe-step-list li {
  background: var(--bg-primary);
  border-left: 4px solid var(--accent-primary);
  border-radius: 0 8px 8px 0;
  padding: 0.55rem 0.75rem;
}

.baker-tip-box {
  background: #edf5ef;
  border: 1px dashed var(--accent-pine);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.88rem;
}

.baker-tip-box p { margin: 0.25rem 0 0; }

/* Pestañas de los 4 juegos */
.games-book-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1.15rem;
}

.recipe-tab-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.recipe-tab {
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 2px solid var(--border-page);
}

.recipe-tab.is-active {
  background: var(--accent-primary);
  color: #fbf6ec;
  border-color: #7c131b;
}

.recipe-tab.is-done {
  border-color: var(--accent-pine);
}

.game-leaf-panel {
  background: var(--bg-primary);
  border: 1px solid var(--border-page);
  border-radius: 12px;
  padding: 1.25rem;
}

.leaf-split {
  display: grid;
  grid-template-columns: 0.95fr 1.05fr;
  gap: 1.4rem;
  align-items: start;
}

.tray-canvas-box {
  background: #ffffff;
  border: 2px solid var(--border-page);
  border-radius: 12px;
  padding: 0.75rem;
  text-align: center;
}

#cookieCanvas,
#houseCanvas {
  width: 100%;
  max-width: 380px;
  height: auto;
  display: block;
  margin: 0 auto;
  border-radius: 8px;
  background: #f9f2e4;
}

.tray-note {
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.recipe-opt {
  margin-bottom: 0.9rem;
}

.opt-label {
  display: block;
  font-family: var(--font-code);
  font-size: 0.76rem;
  color: var(--accent-primary);
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.tag-paper {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-page);
  padding: 0.45rem 0.8rem;
}

.tag-paper.is-selected {
  background: var(--accent-pine);
  color: #fbf6ec;
  border-color: var(--accent-pine);
}

.leaf-feedback {
  margin: 0.85rem 0 0;
  padding: 0.6rem 0.85rem;
  background: var(--bg-surface);
  border-left: 4px solid var(--accent-ginger);
  border-radius: 8px;
  font-size: 0.9rem;
}

/* Juego 2: Tazón */
.bowl-visual-card {
  background: var(--bg-surface);
  border: 2px solid var(--border-page);
  border-radius: 12px;
  padding: 1rem;
}

.bowl-meter-wrap {
  height: 18px;
  border-radius: 999px;
  background: #e8d8be;
  overflow: hidden;
  margin: 0.7rem 0;
}

.bowl-fill-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #b96d2c, #1e5932);
  transition: width 0.25s ease;
}

.bowl-added-list {
  padding-left: 1.25rem;
  margin: 0.5rem 0 0;
  font-size: 0.88rem;
}

.pantry-grid,
.house-parts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.55rem;
  margin-bottom: 0.9rem;
}

.pantry-btn {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 2px solid var(--border-page);
  text-align: left;
}

.pantry-btn.is-used {
  background: #e1f0e5;
  border-color: var(--accent-pine);
  color: #164226;
}

/* Juego 3: Horno mágico */
.oven-window-card {
  background: #2f1d13;
  color: #fbf6ec;
  border: 3px solid var(--accent-ginger);
  border-radius: 14px;
  padding: 1.1rem;
}

.oven-door {
  min-height: 145px;
  border-radius: 10px;
  background: #472c1c;
  border: 2px solid #8c5c38;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  margin-bottom: 0.9rem;
  transition: background-color 0.2s;
}

.oven-cookie-preview {
  font-size: 3rem;
}

.oven-bar-track {
  position: relative;
  height: 24px;
  border-radius: 999px;
  background: linear-gradient(90deg, #d9c2a3 0%, #d48c32 62%, #3a1a0d 100%);
  overflow: hidden;
}

.oven-perfect-band {
  position: absolute;
  left: 55%;
  width: 22%;
  top: 0;
  bottom: 0;
  background: rgba(30, 89, 50, 0.48);
  border-left: 2px solid #fbf6ec;
  border-right: 2px solid #fbf6ec;
}

.oven-progress-needle {
  position: absolute;
  top: 1px;
  left: 2%;
  width: 14px;
  height: 22px;
  border-radius: 4px;
  background: #fbf6ec;
  border: 2px solid #2d1b10;
}

.oven-legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  margin-top: 0.45rem;
  color: #f0dec4;
}

.oven-score-line {
  font-size: 0.98rem;
  margin: 0.65rem 0 0.9rem;
}

/* Cámara real */
.baker-cam-frame {
  position: relative;
  border: 3px solid var(--accent-ginger);
  border-radius: 12px;
  overflow: hidden;
  background: #2d1b10;
}

#bakerCanvas {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: 4 / 3;
}

.baker-cam-cover {
  position: absolute;
  inset: 0;
  background: rgba(45, 27, 16, 0.85);
  color: #fbf6ec;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.4rem;
}

.baker-cam-cover[hidden] {
  display: none;
}

/* Sello final */
.award-center {
  text-align: center;
}

.baker-ribbon-seal {
  width: 62px;
  height: 62px;
  margin: 0 auto 0.6rem;
  border-radius: 50%;
  background: var(--accent-primary);
  border: 3px solid var(--accent-ginger);
  display: grid;
  place-items: center;
  font-size: 1.8rem;
}

.award-checklist {
  list-style: none;
  padding: 0;
  margin: 1.1rem auto;
  max-width: 560px;
  text-align: left;
  display: grid;
  gap: 0.45rem;
}

.award-checklist li {
  background: var(--bg-primary);
  border: 1px solid var(--border-page);
  border-radius: 8px;
  padding: 0.55rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.award-checklist li.is-complete {
  border-color: var(--accent-pine);
  background: #e5f3e9;
}

#sugarSnowCanvas {
  width: 100%;
  max-width: 780px;
  height: 110px;
  display: block;
  margin: 1rem auto 0;
  border-radius: 10px;
  background: #efe2cc;
}

.book-footer {
  text-align: center;
  padding: 0.5rem 1rem 2rem;
  color: #e6d4bc;
  font-size: 0.88rem;
}

/* Modal */
.book-modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(24, 14, 8, 0.78);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 120;
}

.book-modal-mask[hidden] {
  display: none;
}

.book-modal-paper {
  width: min(560px, 94vw);
  background: var(--bg-surface);
  border: 3px solid var(--accent-ginger);
  border-radius: 14px;
  padding: 1.4rem;
}

.book-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.book-guide-list {
  padding-left: 1.25rem;
  color: var(--text-secondary);
  margin-bottom: 1.15rem;
}

.book-guide-list li {
  margin-bottom: 0.5rem;
}

@media (max-width: 920px) {
  .book-spread,
  .leaf-split {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .cookbook-binding {
    padding: 0.8rem;
  }

  .left-leaf,
  .right-leaf,
  .wide-leaf {
    padding: 1.1rem 1rem 2.2rem;
  }

  .pantry-grid,
  .house-parts-grid {
    grid-template-columns: 1fr;
  }
}

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