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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  background: var(--swamp-night);
  color: var(--ivory);
  font: 16px/1.55 var(--type-ui);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#reader[hidden], #shell[hidden], [hidden] {
  display: none !important;
}

/* =========================================================
   ESCENARIO DE LA CABAÑA (CAPAS DE PROFUNDIDAD)
   ========================================================= */
#shell {
  --paper: var(--onion-parchment);
  --surface: rgba(243, 230, 196, 0.94);
  --surface-dark: rgba(27, 38, 20, 0.88);
  --ink: var(--swamp-deep);
  --ink-on-cabin: var(--ivory);
  --muted-on-cabin: #d8d0b6;
  --muted: #4b5539;
  --line: rgba(122, 92, 62, 0.36);
  position: relative;
  min-height: 100dvh;
  isolation: isolate;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}

#cottage-backdrop {
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  overflow: hidden;
  background: #141c0f;
}

.cottage-wall {
  position: absolute;
  inset: -2%;
  background:
    linear-gradient(180deg, rgba(16, 23, 12, 0.64) 0%, rgba(20, 28, 15, 0.45) 45%, rgba(15, 21, 11, 0.84) 100%),
    url("art/cottage-hearth.webp") center 42% / cover no-repeat;
  transform: scale(1.03);
}

.cottage-hearth-glow {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 16% 68%, rgba(233, 166, 107, 0.24) 0%, rgba(233, 166, 107, 0.06) 34%, transparent 62%),
    radial-gradient(circle at 84% 26%, rgba(139, 164, 58, 0.14) 0%, transparent 48%);
  animation: hearth-breathe 5.8s var(--ease-out-snappy) infinite alternate;
}

.cottage-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 42%, rgba(12, 17, 9, 0.72) 100%);
}

.cottage-vines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 76px;
}

#swamp-canvas {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

@keyframes hearth-breathe {
  from { opacity: 0.78; }
  to { opacity: 1; }
}

/* Modos de accesibilidad y noche */
#shell.dark .cottage-wall {
  filter: brightness(0.68) contrast(1.06);
}
#shell.hc {
  --paper: #ffffff;
  --surface: #ffffff;
  --ink: #0e140a;
  --muted: #1e2816;
  --line: #23351f;
}
#shell.hc #cottage-backdrop,
#shell.hc #swamp-canvas {
  display: none;
}
#shell.hc {
  background: #ffffff;
  color: #0e140a;
}
#shell.dark.hc {
  background: #000000;
  color: #ffffff;
  --paper: #000000;
  --surface: #111610;
  --ink: #ffffff;
  --muted: #f2e7cc;
  --line: #f2d785;
}

/* =========================================================
   CABECERA DE LA CABAÑA
   ========================================================= */
.cabin-header {
  position: sticky;
  top: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) clamp(14px, 4vw, 32px) 10px;
  background:
    linear-gradient(180deg, rgba(20, 29, 14, 0.72), rgba(24, 34, 17, 0.64)),
    url("art/wood-plank.webp") center / cover no-repeat;
  border-bottom: 1.5px solid rgba(197, 161, 92, 0.52);
  box-shadow: 0 6px 20px rgba(8, 12, 6, 0.48);
  color: var(--ivory);
}

.seal {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 2px;
  border-radius: 50%;
  border: 1.5px solid var(--old-gold);
  background: radial-gradient(circle at 35% 30%, #375126, #192412);
  display: grid;
  place-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.seal img {
  width: 34px;
  height: 34px;
  display: block;
}

.brand-wrap {
  min-width: 0;
  flex: 1 1 auto;
}
.brand {
  display: block;
  font: 700 clamp(1.18rem, 3.2vw, 1.5rem)/1.12 var(--type-display);
  color: var(--ivory);
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#offline-status {
  display: block;
  font: 500 0.72rem/1.25 var(--type-ui);
  color: var(--firefly);
}
#offline-status:empty, #offline-status[hidden] {
  display: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

#quick-magic, #profile {
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--firefly);
  background: rgba(25, 36, 18, 0.72);
  border: 1px solid rgba(197, 161, 92, 0.45);
}

/* =========================================================
   CONTENEDOR PRINCIPAL & CONTROLES BASE
   ========================================================= */
main#main {
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(16px, 3.5vw, 36px) clamp(14px, 3.5vw, 38px) 28px;
}

h1, h2, h3 {
  font-family: var(--type-display);
  font-weight: 700;
  line-height: 1.12;
  margin: 0;
  text-wrap: balance;
}
h1 {
  font-size: clamp(2.1rem, 5vw, 3.6rem);
  letter-spacing: -0.02em;
}
h2 {
  font-size: clamp(1.45rem, 3.2vw, 2.05rem);
}
h3 {
  font-size: 1.25rem;
}

button, input, select, textarea {
  font: inherit;
}
button {
  color: inherit;
  cursor: pointer;
  min-height: var(--target-touch);
  background: none;
  border: 0;
  padding: 8px 14px;
  border-radius: var(--radius-control);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform var(--motion-press) var(--ease-out-snappy),
              background-color 180ms var(--ease-out-snappy),
              border-color 180ms var(--ease-out-snappy);
}
button:active:not(:disabled) {
  transform: scale(0.97);
}
button:disabled {
  opacity: 0.55;
  cursor: default;
}

:is(button, input, select, textarea, a):focus-visible {
  outline: 3px solid var(--firefly);
  outline-offset: 2px;
}

.parchment-panel :is(button, input, select, textarea, a):focus-visible,
#modal :is(button, input, select, textarea, a):focus-visible {
  outline-color: var(--focus-on-paper);
}

.primary {
  background: linear-gradient(180deg, #4b6923, #395119);
  color: var(--ivory);
  border: 1px solid rgba(232, 242, 107, 0.42);
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(10, 15, 7, 0.35);
}
.hero .primary,
.welcome .primary {
  background: linear-gradient(180deg, #eef67d, #d4e04e);
  color: #162010;
  border: 1px solid #8a6c30;
}
.secondary {
  background: rgba(31, 42, 23, 0.68);
  color: var(--ivory);
  border: 1px solid rgba(197, 161, 92, 0.5);
}
.parchment-panel .secondary,
#modal .secondary {
  background: rgba(250, 245, 233, 0.85);
  color: var(--swamp-deep);
  border: 1px solid rgba(90, 62, 40, 0.45);
}
.danger {
  background: rgba(156, 59, 59, 0.12);
  color: #822828;
  border: 1px solid #9c3b3b;
  font-weight: 700;
}

@media (hover: hover) and (pointer: fine) {
  .primary:hover:not(:disabled) {
    background: linear-gradient(180deg, #698b39, #4f6b2a);
  }
  .hero .primary:hover:not(:disabled),
  .welcome .primary:hover:not(:disabled) {
    background: linear-gradient(180deg, #f5fa9d, #dce85a);
  }
  .secondary:hover:not(:disabled) {
    border-color: var(--old-gold);
  }
}

.sw-icon {
  flex-shrink: 0;
  display: inline-block;
}

/* =========================================================
   CABECERAS DE SECCIÓN & ESCENAS
   ========================================================= */
.scene-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px 18px;
  border-radius: var(--radius-card);
  background:
    linear-gradient(180deg, rgba(24, 34, 17, 0.65), rgba(18, 26, 13, 0.72)),
    url("art/wood-plank.webp") center / cover no-repeat;
  border: 1px solid rgba(197, 161, 92, 0.45);
  box-shadow: 0 8px 24px rgba(10, 14, 7, 0.36);
  color: var(--ivory);
}
.scene-heading h1 {
  color: var(--ivory);
}
.scene-heading .scene-meta {
  font-variant-numeric: tabular-nums;
  color: var(--firefly);
  font-weight: 600;
  font-size: 0.92rem;
}

.sectionhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin: 26px 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(197, 161, 92, 0.35);
  color: var(--ivory);
}
.sectionhead h2 {
  color: var(--ivory);
}
.sectionhead button {
  color: var(--firefly);
  border: 1px solid rgba(232, 242, 107, 0.38);
  background: rgba(25, 36, 18, 0.65);
  font-size: 0.9rem;
}

.actions, .tools {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* =========================================================
   INICIO: VENTANA AL PANTANO & CHIMENEA (HERO)
   ========================================================= */
.hero.window-stage {
  position: relative;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  align-items: stretch;
  border-radius: 18px;
  overflow: hidden;
  background:
    linear-gradient(145deg, rgba(35, 24, 15, 0.96), rgba(23, 33, 17, 0.95));
  border: 2px solid rgba(197, 161, 92, 0.55);
  box-shadow: 0 18px 42px rgba(7, 11, 5, 0.56);
  isolation: isolate;
}

.hero .words {
  padding: clamp(22px, 4vw, 44px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  z-index: 2;
}
.hero .words h1 {
  color: var(--ivory);
  font-size: clamp(2.4rem, 5.4vw, 4.1rem);
  line-height: 1.02;
}
.hero .words .hero-sub {
  margin: 0;
  color: #efe3c2;
  font-size: 1.06rem;
  max-width: 44ch;
}
.hero .words .hero-book-title {
  margin: 0;
  font-family: var(--type-display);
  font-size: clamp(1.25rem, 2.4vw, 1.65rem);
  color: var(--firefly);
}
.hero .words small {
  color: #e4d8b6;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}
.hero-cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.hero-window-frame {
  position: relative;
  min-height: 250px;
  overflow: hidden;
  box-shadow: inset 3px 0 0 #3a2617;
}
.hero-window-frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 600ms var(--ease-out-snappy);
}
.hero.dawn .hero-window-frame img { filter: sepia(0.08) brightness(1.04); }
.hero.dusk .hero-window-frame img { filter: sepia(0.18) saturate(1.12) brightness(0.95); }
.hero.night .hero-window-frame img { filter: brightness(0.76) saturate(0.88); }

.hero-window-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at center, transparent 48%, rgba(22, 30, 16, 0.72) 100%),
    linear-gradient(90deg, rgba(26, 22, 14, 0.65) 0%, transparent 32%);
  pointer-events: none;
}

/* =========================================================
   ESTANTERÍAS FÍSICAS DE MADERA & LIBROS 3D
   ========================================================= */
.shelf-case {
  display: grid;
  gap: 22px;
  margin: 10px 0 18px;
}

.shelf-tier {
  position: relative;
  padding: 16px 14px 0;
  border-radius: 14px 14px 8px 8px;
  background: linear-gradient(180deg, rgba(20, 28, 15, 0.45) 0%, rgba(30, 21, 13, 0.72) 100%);
  border: 1px solid rgba(197, 161, 92, 0.24);
  box-shadow: inset 0 10px 26px rgba(8, 12, 6, 0.55);
}

.shelf-props {
  position: absolute;
  bottom: 20px;
  right: 14px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
  z-index: 1;
}

/* Vela de cera de oído animada */
.earwax-candle {
  position: relative;
  width: 14px;
  height: 26px;
  border-radius: 3px 3px 1px 1px;
  background: linear-gradient(90deg, #7f8e3b, #a3b34c 55%, #6a7630);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
.earwax-candle::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 50%;
  width: 7px;
  height: 11px;
  transform: translateX(-50%);
  border-radius: 50% 50% 40% 40%;
  background: linear-gradient(180deg, #fff6c9, #e9a66b);
  box-shadow: 0 -2px 8px rgba(233, 166, 107, 0.45);
}
@keyframes candle-flicker {
  0% { transform: translateX(-50%) scale(0.95) rotate(-2deg); opacity: 0.88; }
  100% { transform: translateX(-50%) scale(1.06) rotate(2deg); opacity: 1; }
}

.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(146px, 1fr));
  gap: 18px 16px;
  padding: 4px 6px 16px;
  align-items: end;
}

.shelf-plank {
  position: relative;
  height: 20px;
  margin: 0 -2px;
  border-radius: 4px 4px 8px 8px;
  background:
    linear-gradient(180deg, rgba(233, 166, 107, 0.24) 0%, transparent 25%, rgba(16, 10, 5, 0.55) 100%),
    url("art/wood-plank.webp") center / cover no-repeat;
  border-top: 1px solid rgba(233, 189, 134, 0.45);
  box-shadow:
    0 8px 16px rgba(6, 9, 4, 0.72),
    inset 0 -4px 8px rgba(15, 9, 4, 0.65);
}

/* Libro físico en 3D */
.book-object {
  position: relative;
  min-width: 0;
  perspective: 800px;
}

.book-object .opener {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  width: 100%;
  padding: 0;
  background: none;
  border-radius: 8px;
  transition: transform 280ms var(--spring-snappy);
}

@media (hover: hover) and (pointer: fine) {
  .book-object .opener:hover {
    transform: translateY(-7px) rotateY(-4deg);
  }
}
.book-object .opener:active {
  transform: scale(0.97);
}
.book-object.book-opening .opener {
  transform: translateY(-14px) scale(1.04) rotateY(-14deg);
  opacity: 0.75;
}

.cover {
  position: relative;
  aspect-ratio: 3 / 4;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px 9px 9px 4px;
  overflow: hidden;
  background: #2b3f23;
  box-shadow:
    -4px 0 0 #21150c,
    4px 2px 0 #ebe1c6,
    6px 4px 0 #cfc09b,
    0 10px 18px rgba(6, 9, 4, 0.68);
}

/* Lomo izquierdo realista */
.cover::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 12px;
  z-index: 2;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.42), rgba(255, 255, 255, 0.14) 55%, rgba(0, 0, 0, 0.25));
  pointer-events: none;
}

.cover img,
.cover svg {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Cinta marcadora carmesí de Fiona en libros con progreso */
.book-ribbon {
  position: absolute;
  top: 0;
  right: 14px;
  width: 12px;
  height: 28px;
  z-index: 3;
  background: linear-gradient(180deg, #b54545, #7d2525);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 76%, 0 100%);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.book-object strong {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 9px;
  font: 600 1.04rem/1.22 var(--type-display);
  color: var(--ivory);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.75);
}

.book-object small {
  display: block;
  margin-top: 2px;
  font-size: 0.78rem;
  color: #d9cfa8;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-prog {
  height: 5px;
  background: rgba(15, 21, 11, 0.72);
  border: 1px solid rgba(197, 161, 92, 0.32);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 6px;
}
.book-prog i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--ogre-green), var(--firefly));
}

.book-object .more {
  position: absolute;
  right: 6px;
  top: 6px;
  z-index: 4;
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 50%;
  background: rgba(24, 34, 17, 0.88);
  color: var(--firefly);
  border: 1px solid rgba(197, 161, 92, 0.65);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

/* Vista Cuadrícula y Lista */
.cards.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(156px, 1fr));
  gap: 18px;
  padding: 12px 0;
}
.cards.list {
  display: grid;
  gap: 10px;
  padding: 10px 0;
}
.cards.list .book-object {
  background: rgba(27, 38, 20, 0.84);
  border: 1px solid rgba(197, 161, 92, 0.32);
  border-radius: 12px;
  padding: 10px 54px 10px 12px;
}
.cards.list .opener {
  display: grid;
  grid-template-columns: 58px 1fr;
  column-gap: 14px;
  align-items: center;
}
.cards.list .cover {
  grid-row: span 3;
}
.cards.list .more {
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
}

/* =========================================================
   PERGAMINOS, TARJETAS DE INICIO & CARTAS DE FIONA
   ========================================================= */
.parchment-panel {
  background:
    linear-gradient(180deg, rgba(250, 244, 224, 0.42), rgba(239, 222, 184, 0.48)),
    url("art/parchment-texture.webp") center / cover no-repeat;
  color: var(--swamp-deep);
  border: 1.5px solid rgba(122, 92, 62, 0.55);
  border-radius: var(--radius-card);
  padding: clamp(14px, 3vw, 22px);
  box-shadow: 0 10px 26px rgba(9, 13, 6, 0.36);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 16px;
  text-align: left;
  border-radius: var(--radius-card);
  background:
    linear-gradient(180deg, rgba(248, 240, 214, 0.45), rgba(235, 217, 177, 0.52)),
    url("art/parchment-texture.webp") center / cover no-repeat;
  color: var(--swamp-deep);
  border: 1px solid rgba(122, 92, 62, 0.5);
  box-shadow: 0 6px 18px rgba(8, 12, 6, 0.3);
}
.tile b {
  font: 700 1.85rem/1.05 var(--type-display);
  color: #364d1b;
  font-variant-numeric: tabular-nums;
}
.tile span {
  font-size: 0.9rem;
  color: #3c3422;
}

.quote-parchment {
  margin: 10px 0;
  padding: 18px 22px;
  border-radius: var(--radius-card);
  background:
    linear-gradient(180deg, rgba(248, 240, 214, 0.45), rgba(236, 218, 178, 0.52)),
    url("art/parchment-texture.webp") center / cover no-repeat;
  color: var(--swamp-deep);
  border: 1px solid rgba(197, 161, 92, 0.65);
  box-shadow: 0 8px 22px rgba(8, 12, 6, 0.32);
  font: italic 1.2rem/1.5 var(--type-reading);
}

.letters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}
.letter-card {
  display: grid;
  justify-items: start;
  gap: 6px;
  text-align: left;
  padding: 16px;
  border-radius: var(--radius-card);
  background:
    linear-gradient(180deg, rgba(248, 240, 214, 0.48), rgba(235, 217, 177, 0.54)),
    url("art/parchment-texture.webp") center / cover no-repeat;
  color: var(--swamp-deep);
  border: 1.5px solid rgba(156, 59, 59, 0.42);
  box-shadow: 0 6px 18px rgba(8, 12, 6, 0.32);
}
.letter-seal {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 30%, #b54545, #7d2525);
  color: #f9ebd0;
  box-shadow: 0 2px 6px rgba(75, 22, 22, 0.45);
}
.letter-card strong {
  font: 700 1.05rem/1.25 var(--type-display);
}
.letter-card small {
  color: #544632;
}

/* Estado vacío temático */
.empty-swamp {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 22px;
  border-radius: var(--radius-card);
  background:
    linear-gradient(180deg, rgba(31, 42, 23, 0.88), rgba(22, 31, 16, 0.94));
  border: 1.5px dashed rgba(197, 161, 92, 0.55);
  color: var(--ivory);
}
.empty-swamp h3 {
  color: var(--firefly);
  margin-bottom: 4px;
}
.empty-swamp p {
  margin: 0;
  color: #e2d6b4;
}

/* =========================================================
   BIBLIOTECA: FILTROS & CHIPS DE COLECCIÓN
   ========================================================= */
.library-controls {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}
.collection-rail {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  scrollbar-width: thin;
}
.wood-pill {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(31, 42, 23, 0.82);
  color: #ebe0c2;
  border: 1px solid rgba(197, 161, 92, 0.4);
  font-size: 0.86rem;
  font-weight: 600;
}
.wood-pill[aria-pressed="true"] {
  background: var(--moss-green);
  color: var(--ivory);
  border-color: var(--firefly);
}

/* =========================================================
   EL BAÚL: TABLÓN DE CORCHO Y MADERA
   ========================================================= */
.chest-board {
  padding: clamp(14px, 3vw, 24px);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(22, 16, 10, 0.55), rgba(18, 25, 13, 0.72)),
    url("art/chest-cork-wood.webp") center / cover no-repeat;
  border: 2px solid rgba(197, 161, 92, 0.48);
  box-shadow: inset 0 12px 32px rgba(8, 10, 5, 0.65), 0 14px 32px rgba(7, 10, 5, 0.45);
}

#noterows {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 1fr));
  gap: 16px;
  margin-top: 16px;
}
.pinned-note {
  position: relative;
  padding: 20px 18px 16px;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(248, 240, 214, 0.52), rgba(235, 217, 177, 0.58)),
    url("art/parchment-texture.webp") center / cover no-repeat;
  color: var(--swamp-deep);
  border: 1px solid rgba(122, 92, 62, 0.55);
  box-shadow: 0 8px 20px rgba(8, 10, 5, 0.48);
}
.pin-dot {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #2b1d12;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}
.pinned-note small {
  display: block;
  font-size: 0.8rem;
  color: #4f412d;
  padding-right: 24px;
}
.pinned-note .quote {
  margin: 10px 0;
  font: italic 1.08rem/1.45 var(--type-reading);
  color: #1f2a17;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.pinned-note .actions button {
  background: rgba(90, 62, 40, 0.1);
  border: 1px solid rgba(90, 62, 40, 0.35);
  color: var(--swamp-deep);
  font-size: 0.86rem;
}

.note-tools {
  border-bottom: 1px solid rgba(122, 92, 62, 0.35);
}
.note-tools summary {
  min-height: var(--target-touch);
  padding: 10px 0;
  cursor: pointer;
  font-weight: 700;
}
.note-tools .actions {
  padding: 4px 0 12px;
}

/* =========================================================
   MI AVENTURA: CEBOLLA DE PROGRESO, RACHAS & DIARIO
   ========================================================= */
.onion-banner {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: center;
  margin: 14px 0;
}
.progress {
  width: 100%;
  height: 12px;
  border-radius: 99px;
  overflow: hidden;
  appearance: none;
  border: 1px solid rgba(90, 62, 40, 0.45);
  background: rgba(90, 62, 40, 0.16);
}
.progress::-webkit-progress-bar {
  background: rgba(90, 62, 40, 0.16);
}
.progress::-webkit-progress-value {
  background: linear-gradient(90deg, var(--moss-green), var(--ogre-green));
}

.calendar-grid {
  list-style: none;
  padding: 0;
  margin: 10px 0 18px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}
.cal-day {
  padding: 8px 4px;
  text-align: center;
  border-radius: 8px;
  border: 1px solid rgba(122, 92, 62, 0.4);
  background: rgba(250, 245, 233, 0.72);
  color: var(--swamp-deep);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
.cal-day.lvl-1 { background: #d4e0b8; color: #1b2814; }
.cal-day.lvl-2 { background: #9db864; color: #141d0f; font-weight: 700; }
.cal-day.lvl-3 { background: #4f6b2a; color: var(--ivory); font-weight: 700; border-color: var(--old-gold); }

.journal-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}
.journal-list button {
  width: 100%;
  justify-content: space-between;
  text-align: left;
  padding: 12px 14px;
  background: rgba(250, 245, 233, 0.78);
  border: 1px solid rgba(122, 92, 62, 0.35);
  color: var(--swamp-deep);
}
.journal-list strong {
  font-family: var(--type-display);
  font-size: 1.15rem;
}

.badges {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}
.badge {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(122, 92, 62, 0.38);
  background: rgba(250, 245, 233, 0.62);
  color: var(--swamp-deep);
  opacity: 0.62;
}
.badge.earned {
  opacity: 1;
  background: rgba(250, 245, 233, 0.94);
  border-color: var(--old-gold);
  box-shadow: 0 4px 12px rgba(122, 92, 62, 0.2);
}
.badge svg {
  width: 40px;
  height: 40px;
}
.badge strong {
  display: block;
  font-size: 0.95rem;
}
.badge small {
  color: #544632;
  font-size: 0.8rem;
}

/* =========================================================
   MI REFUGIO: FORMULARIOS, MEZCLADOR & CONTROLES
   ========================================================= */
#preferences {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 16px;
}
#preferences fieldset {
  min-width: 0;
  margin: 0;
  padding: 14px 18px 18px;
  border-radius: var(--radius-card);
  border: 1px solid rgba(122, 92, 62, 0.48);
  background:
    linear-gradient(180deg, rgba(248, 240, 214, 0.5), rgba(235, 217, 177, 0.56)),
    url("art/parchment-texture.webp") center / cover no-repeat;
  color: var(--swamp-deep);
}
#preferences legend {
  font: 700 1.2rem var(--type-display);
  padding: 2px 12px;
  border-radius: 8px;
  background: #f5ebd0;
  border: 1px solid rgba(122, 92, 62, 0.48);
  color: var(--swamp-deep);
}
#preferences > button {
  grid-column: 1 / -1;
  justify-self: start;
}

label {
  display: block;
  margin: 10px 0;
  font-weight: 600;
  font-size: 0.92rem;
}
input:not([type=checkbox]):not([type=range]),
textarea,
select {
  width: 100%;
  max-width: 100%;
  margin-top: 4px;
  background: var(--ivory);
  color: var(--swamp-deep);
  border: 1px solid rgba(122, 92, 62, 0.55);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: var(--target-touch);
}
textarea {
  min-height: 82px;
  resize: vertical;
}
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--target-touch);
  font-weight: 500;
}
.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--moss-green);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}
.chip {
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(122, 92, 62, 0.45);
  background: rgba(250, 245, 233, 0.88);
  color: var(--swamp-deep);
  font-size: 0.88rem;
  font-weight: 600;
}
.chip[aria-pressed="true"] {
  background: var(--moss-green);
  color: var(--ivory);
  border-color: var(--old-gold);
}

/* =========================================================
   NAVEGACIÓN: TABLÓN INFERIOR MÓVIL / RAIL EN ESCRITORIO
   ========================================================= */
nav#nav {
  position: fixed;
  z-index: 15;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 4px;
  padding: 6px 6px max(6px, env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, rgba(24, 34, 17, 0.72), rgba(16, 23, 12, 0.82)),
    url("art/wood-plank.webp") center / cover no-repeat;
  border-top: 2px solid rgba(197, 161, 92, 0.55);
  box-shadow: 0 -8px 24px rgba(6, 9, 4, 0.6);
  color: var(--onion-parchment);
}
nav#nav button {
  flex: 1 1 0;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
  padding: 6px 4px;
  min-height: 50px;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 10px;
  color: #dfd3b2;
}
nav#nav button[aria-current="page"] {
  background: rgba(79, 107, 42, 0.65);
  color: var(--firefly);
  border: 1px solid rgba(232, 242, 107, 0.35);
}

@media (min-width: 1000px) {
  #shell {
    padding-left: 196px;
    padding-bottom: 32px;
  }
  nav#nav {
    inset: 0 auto 0 0;
    width: 196px;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    padding: 20px 12px;
    gap: 8px;
    border-top: 0;
    border-right: 2px solid rgba(197, 161, 92, 0.45);
    box-shadow: 8px 0 26px rgba(6, 9, 4, 0.48);
  }
  nav#nav button {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 14px;
    font-size: 0.98rem;
  }
}

/* =========================================================
   MODALES COMO PERGAMINOS DESPLEGABLES & TOAST
   ========================================================= */
dialog {
  background:
    linear-gradient(180deg, rgba(248, 240, 214, 0.56), rgba(235, 217, 177, 0.62)),
    url("art/parchment-texture.webp") center / cover no-repeat;
  color: var(--swamp-deep);
  border: 2px solid var(--old-gold);
  border-radius: 16px;
  padding: 22px;
  width: min(94vw, 540px);
  max-height: 88dvh;
  overflow: auto;
  box-shadow: 0 22px 54px rgba(6, 9, 4, 0.65);
  transition: transform 220ms var(--ease-out-snappy), opacity 220ms var(--ease-out-snappy);
}
@starting-style {
  dialog[open] {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
}
dialog::backdrop {
  background: rgba(12, 18, 9, 0.82);
}
.cross {
  float: right;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  background: rgba(90, 62, 40, 0.12);
  color: var(--swamp-deep);
}

.welcome {
  text-align: center;
}
.welcome img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 42% 42% 10px 10px;
  border: 2px solid var(--old-gold);
  margin-bottom: 10px;
}
.welcome h2 {
  font-size: clamp(1.65rem, 4vw, 2.15rem);
  margin-bottom: 8px;
}
.welcome-steps {
  text-align: left;
  background: rgba(250, 245, 233, 0.85);
  border: 1px solid rgba(197, 161, 92, 0.7);
  border-radius: 10px;
  padding: 12px 16px;
  margin: 14px 0 18px;
  font-size: 0.94rem;
}

.preview-canvas {
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--old-gold);
  margin: 12px 0;
  display: block;
}

#toast:not(:empty) {
  position: fixed;
  z-index: 40;
  bottom: calc(82px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(24, 34, 17, 0.96);
  color: var(--ivory);
  border: 1.5px solid var(--old-gold);
  padding: 10px 18px;
  border-radius: 12px;
  width: max-content;
  max-width: 92vw;
  box-shadow: 0 10px 28px rgba(6, 9, 4, 0.6);
}

/* Drag & drop overlay */
body.swamp-drag-over::after {
  content: "Suelta aquí tus libros PDF o ePub";
  position: fixed;
  inset: 16px;
  z-index: 60;
  display: grid;
  place-items: center;
  font: 700 1.6rem var(--type-display);
  color: var(--firefly);
  background: rgba(20, 29, 14, 0.88);
  border: 3px dashed var(--firefly);
  border-radius: 20px;
  pointer-events: none;
}

/* =========================================================
   RESPONSIVE MÓVIL (320px - 680px)
   ========================================================= */
@media (max-width: 680px) {
  .hero.window-stage {
    grid-template-columns: 1fr;
  }
  .hero-window-frame {
    order: -1;
    min-height: 180px;
    border-left: 0;
    border-bottom: 3px solid #3a2617;
  }
  .shelf-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 12px;
  }
}

@media (max-width: 350px) {
  .cabin-header {
    padding-inline: 10px;
    gap: 8px;
  }
  nav#nav button {
    font-size: 0.66rem;
    padding: 4px 2px;
  }
}

/* =========================================================
   REDUCCIÓN DE MOVIMIENTO
   ========================================================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
#shell.reduced *, #shell.reduced *::before, #shell.reduced *::after {
  animation: none !important;
  transition: none !important;
}
