:root {
  --ink: #f6ead2;
  --muted: rgba(246, 234, 210, 0.66);
  --gold: #d8b26a;
  --gold-2: #f3d595;
  --glass: rgba(20, 12, 7, 0.55);
  --line: rgba(216, 178, 106, 0.28);
  --amazon: #ffb43a;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0a0705;
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }

#stage, #stage canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 45%, rgba(0, 0, 0, 0.55) 100%);
}
#grain {
  position: fixed;
  inset: -50%;
  pointer-events: none;
  opacity: 0.6;
  mix-blend-mode: overlay;
  animation: grain 0.9s steps(4) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-3%, 2%); }
  50% { transform: translate(2%, -3%); }
  75% { transform: translate(-1%, -2%); }
  100% { transform: translate(3%, 1%); }
}

/* ---------- Intro ---------- */
#intro {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background:
    radial-gradient(ellipse at 50% 60%, rgba(255, 170, 80, 0.14), transparent 60%),
    radial-gradient(ellipse at 50% 50%, #1a110a 0%, #070504 75%);
  z-index: 20;
  transition: opacity 1.4s ease, visibility 1.4s;
}
#intro.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-inner { max-width: 640px; animation: rise 1.4s cubic-bezier(.2,.7,.2,1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(24px); } }
.eyebrow {
  font: 600 12px/1 var(--sans);
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 18px;
}
#intro h1 {
  font: 600 clamp(40px, 7vw, 76px)/1.02 var(--serif);
  margin: 0 0 20px;
  letter-spacing: -0.01em;
  background: linear-gradient(180deg, #fff3d6 10%, #d8b26a 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(255, 180, 90, 0.15);
}
.lead { color: var(--muted); font-size: clamp(15px, 2vw, 18px); line-height: 1.6; margin: 0 0 34px; }
#loader { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 26px; transition: opacity .6s; }
#loader.done { opacity: 0; height: 0; margin: 0; overflow: hidden; }
#loader .bar { width: 200px; height: 2px; background: rgba(255, 255, 255, 0.12); border-radius: 2px; overflow: hidden; }
#loader .bar i { display: block; height: 100%; background: var(--gold); transform: scaleX(0); transform-origin: left; transition: transform .3s; }
#loader .pct { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; width: 36px; text-align: left; }
#enter {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 16px 30px;
  border-radius: 999px;
  border: 1px solid rgba(243, 213, 149, 0.6);
  background: linear-gradient(180deg, rgba(216, 178, 106, 0.22), rgba(216, 178, 106, 0.06));
  color: var(--gold-2);
  font: 600 15px/1 var(--sans);
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 0 0 0 rgba(243, 213, 149, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transition: transform .25s, box-shadow .25s, opacity .4s, background .25s;
  animation: halo 2.6s ease-in-out infinite;
}
#enter svg { width: 18px; height: 18px; transition: transform .25s; }
#enter:hover { transform: translateY(-2px); background: linear-gradient(180deg, rgba(216, 178, 106, 0.34), rgba(216, 178, 106, 0.1)); }
#enter:hover svg { transform: translateX(4px); }
#enter:disabled { opacity: 0.25; cursor: wait; animation: none; }
@keyframes halo { 50% { box-shadow: 0 0 0 10px rgba(243, 213, 149, 0), 0 0 40px rgba(255, 180, 90, 0.25), inset 0 1px 0 rgba(255,255,255,.12); } }
.small { margin-top: 22px; font-size: 12px; color: rgba(246, 234, 210, 0.4); letter-spacing: .04em; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0 0 auto 0;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: max(16px, env(safe-area-inset-top)) 22px 16px;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 1.2s 1.6s, transform 1.2s 1.6s;
}
#hud.on { opacity: 1; transform: none; }
body.reading #hud { opacity: 0; transition-delay: 0s; transition-duration: .5s; }
#hud > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.brand svg { width: 34px; height: 34px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.5)); }
.brand strong { display: block; font: 600 22px/1.1 var(--serif); color: var(--gold-2); }
.brand span { display: block; font-size: 11px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; margin-top: 3px; }
.chips { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.chips button { border: 0; background: transparent; padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer; transition: background .2s, color .2s; }
.chips button:hover { color: var(--ink); }
.chips button.on { background: rgba(216, 178, 106, 0.22); color: var(--gold-2); }
#sound { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass); display: grid; place-items: center; cursor: pointer; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
#sound svg { width: 20px; height: 20px; color: var(--gold-2); }
#sound .x { display: none; }
#sound.off .x { display: block; }
#sound.off .w { display: none; }
.hint-shelf {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: bob 3s ease-in-out infinite;
}
.hint-shelf .touch { display: none; }
@media (hover: none) { .hint-shelf .desk { display: none; } .hint-shelf .touch { display: inline; } }
@keyframes bob { 50% { transform: translate(-50%, -4px); } }

/* ---------- Tooltip ---------- */
#tooltip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 6;
  pointer-events: none;
  width: max-content;
  max-width: 280px;
  padding: 12px 16px 13px;
  border-radius: 14px;
  background: rgba(18, 11, 6, 0.82);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  opacity: 0;
  margin-top: -14px;
  transition: opacity .25s, margin .25s;
  text-align: center;
}
#tooltip.on { opacity: 1; margin-top: -22px; }
#tooltip > * { display: block; }
.t-badge { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); margin-bottom: 4px; }
.t-title { font: 600 22px/1.1 var(--serif); color: #fff6e2; }
.t-tag { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.4; }
#tooltip em { font-style: normal; font-size: 11px; color: var(--gold-2); margin-top: 8px; letter-spacing: .06em; }
body.reading #tooltip { opacity: 0; }

/* ---------- Lector ---------- */
#reader-ui { position: fixed; inset: 0; z-index: 8; pointer-events: none; }
#reader-ui > * { pointer-events: auto; }
#reader-ui .r-top {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: max(18px, env(safe-area-inset-top)) 22px 0;
  pointer-events: none;
}
.r-top > * { pointer-events: auto; }
#r-cat { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); }
#r-title { margin: 6px 0 0; font: 600 clamp(22px, 3vw, 34px)/1.05 var(--serif); color: #fff3d8; }
#r-close, .r-nav {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--glass);
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background .2s, transform .2s, opacity .3s;
  flex: none;
}
#r-close:hover, .r-nav:hover:not(:disabled) { background: rgba(216, 178, 106, 0.25); transform: scale(1.06); }
#r-close svg, .r-nav svg { width: 22px; height: 22px; color: var(--gold-2); }
.r-nav { position: absolute; top: 50%; margin-top: -24px; }
#r-prev { left: 22px; }
#r-next { right: 22px; }
.r-nav:disabled { opacity: 0.2; cursor: default; }
.r-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}
.r-bottom > * { pointer-events: auto; }
#r-pages { margin: 0; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
#r-buy {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 26px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd06a, #f59b1d);
  color: #2a1503;
  font: 700 15px/1 var(--sans);
  text-decoration: none;
  box-shadow: 0 10px 30px rgba(245, 155, 29, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  transition: transform .2s, box-shadow .2s;
}
#r-buy svg { width: 20px; height: 20px; }
#r-buy:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 16px 40px rgba(245, 155, 29, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.6); }
#r-buy.pulse { animation: buyPulse 1.2s ease-out 2; }
#reader-ui.at-end #r-buy { padding: 17px 32px; font-size: 16px; }
@keyframes buyPulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 190, 70, 0.75), 0 10px 30px rgba(245, 155, 29, 0.35); }
  100% { box-shadow: 0 0 0 26px rgba(255, 190, 70, 0), 0 10px 30px rgba(245, 155, 29, 0.35); }
}
#r-hint { margin: 0; font-size: 12px; color: rgba(246, 234, 210, 0.45); transition: opacity .6s; }
#r-hint.gone { opacity: 0; }

#reader-ui .r-top, #reader-ui .r-nav, #reader-ui .r-bottom { opacity: 0; transition: opacity .5s; }
#reader-ui.on .r-top, #reader-ui.on .r-nav, #reader-ui.on .r-bottom { opacity: 1; transition-delay: .7s; }
#reader-ui.on .r-nav:disabled { opacity: .2; }

/* ---------- Accesibilidad ---------- */
.sr-only-focusable { position: fixed; left: 16px; bottom: 16px; z-index: 30; }
.sr-only-focusable ul { list-style: none; margin: 0; padding: 0; }
.sr-only-focusable button, .sr-only-focusable a {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.sr-only-focusable button:focus, .sr-only-focusable a:focus {
  position: fixed;
  left: 16px;
  bottom: 70px;
  width: auto; height: auto;
  clip: auto;
  padding: 10px 16px;
  border-radius: 10px;
  background: #1a1009;
  border: 1px solid var(--gold);
  color: var(--gold-2);
  text-decoration: none;
  font-size: 14px;
}
:focus-visible { outline: 2px solid var(--gold-2); outline-offset: 3px; }

#no-webgl { display: none; }
body.no-webgl #no-webgl { display: grid; place-items: center; position: fixed; inset: 0; padding: 30px; text-align: center; z-index: 50; background: #0a0705; }
.noscript { position: fixed; inset: auto 0 40% 0; text-align: center; z-index: 50; }

/* ---------- Móvil ---------- */
@media (max-width: 760px) {
  #hud { flex-wrap: wrap; padding: 12px 14px; gap: 10px; }
  .brand strong { font-size: 18px; }
  .brand span { display: none; }
  .chips { order: 3; width: 100%; justify-content: center; }
  .chips button { padding: 7px 12px; font-size: 12px; }
  .hint-shelf { font-size: 12px; white-space: normal; text-align: center; width: max-content; max-width: calc(100% - 32px); }
  #reader-ui .r-top { padding: 12px 14px 0; }
  .r-nav { top: auto; bottom: max(18px, env(safe-area-inset-bottom)); margin: 0; width: 44px; height: 44px; }
  #r-prev { left: 14px; }
  #r-next { right: 14px; }
  .r-bottom { bottom: calc(max(18px, env(safe-area-inset-bottom)) + 2px); }
  #r-buy { padding: 13px 18px; font-size: 13px; }
  #reader-ui.at-end #r-buy { padding: 14px 18px; font-size: 13px; }
  #r-hint { display: none; }
  #tooltip { max-width: 220px; }
}

@media (prefers-reduced-motion: reduce) {
  #grain, .hint-shelf, #enter { animation: none; }
}

/* ---------- Idioma ---------- */
.lang-switch { display: flex; padding: 3px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.lang-switch button { border: 0; background: transparent; padding: 7px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; letter-spacing: .06em; color: var(--muted); cursor: pointer; }
.lang-switch button.on { background: rgba(216, 178, 106, 0.22); color: var(--gold-2); }
.intro-lang { display: inline-flex; margin-top: 18px; }
@media (max-width: 760px) { #hud .lang-switch button { padding: 6px 8px; } }

/* ---------- Colorear ---------- */
#r-color {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 999px;
  border: 1px solid rgba(243, 213, 149, 0.55);
  background: rgba(30, 18, 10, 0.7);
  color: var(--gold-2); font: 600 14px/1 var(--sans); cursor: pointer;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: background .2s, transform .2s;
}
#r-color[hidden] { display: none; }
.r-actions { display: flex; align-items: center; gap: 12px; }
#r-color:hover { background: rgba(216, 178, 106, 0.25); transform: translateY(-1px); }
#r-color svg { width: 18px; height: 18px; }

#coloring {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column;
  background: radial-gradient(ellipse at 50% 40%, #2a1b10 0%, #0c0805 75%);
  opacity: 0; transition: opacity .3s;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  gap: 10px;
}
#coloring.on { opacity: 1; }
#coloring[hidden] { display: none; }
.c-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.c-head { display: flex; flex-direction: column; min-width: 0; }
.c-book { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-head strong { font: 600 clamp(19px, 2.6vw, 26px)/1.1 var(--serif); color: #fff3d8; }
.c-pager { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.c-ico {
  width: 42px; height: 42px; flex: none; border-radius: 50%;
  border: 1px solid var(--line); background: var(--glass); color: var(--gold-2);
  display: grid; place-items: center; cursor: pointer; padding: 0;
  transition: background .2s, transform .15s, opacity .2s;
}
.c-ico svg { width: 22px; height: 22px; }
.c-ico:hover:not(:disabled) { background: rgba(216, 178, 106, 0.22); }
.c-ico:disabled { opacity: .3; cursor: default; }
.c-ico.on { background: var(--gold-2); color: #2a1503; border-color: var(--gold-2); }
.c-close { width: 46px; height: 46px; }

.c-stage { flex: 1; min-height: 0; display: grid; place-items: center; }
.c-paper {
  position: relative; background: #fff; border-radius: 4px; overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  cursor: crosshair;
}
.c-paper[data-tool="fill"] { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'%3E%3Cpath d='M5 11l7-7 7 7-7 7z' fill='white' stroke='black' stroke-width='1.6' stroke-linejoin='round'/%3E%3Cpath d='M20 15.5c0 1.2-.8 2-1.7 2s-1.6-.8-1.6-2c0-1 1.6-3 1.6-3s1.7 2 1.7 3z' fill='black'/%3E%3C/svg%3E") 4 22, crosshair; }
.c-paper canvas, .c-paper img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.c-lines { mix-blend-mode: multiply; }
.c-loading { position: absolute; inset: 0; display: grid; place-items: center; color: #b49a6a; font-size: 28px; background: #fff; }
.c-loading[hidden] { display: none; }

.c-bar { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.c-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; }
.c-sizes { display: flex; gap: 4px; padding: 0 4px; }
.c-size { width: 34px; height: 34px; border-radius: 50%; border: 1px solid transparent; background: transparent; display: grid; place-items: center; cursor: pointer; padding: 0; }
.c-size i { display: block; border-radius: 50%; background: var(--muted); }
.c-size.on { border-color: var(--gold-2); }
.c-size.on i { background: var(--gold-2); }
.c-sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; }
.c-palette { display: flex; gap: 7px; flex-wrap: wrap; justify-content: center; max-width: 900px; }
.c-swatch {
  width: 34px; height: 34px; border-radius: 50%; padding: 0; cursor: pointer;
  background: var(--c); border: 2px solid rgba(255, 255, 255, .18);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .15);
  transition: transform .15s;
}
.c-swatch:hover { transform: scale(1.1); }
.c-swatch.on { border-color: #fff; transform: scale(1.15); box-shadow: 0 0 0 3px rgba(243, 213, 149, .6); }
.c-custom { position: relative; overflow: hidden; background: conic-gradient(#f44, #fd4, #4d6, #4cf, #64f, #f4c, #f44); display: inline-block; }
.c-custom input { position: absolute; inset: -8px; width: 60px; height: 60px; opacity: 0; cursor: pointer; }

.c-done { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(8, 5, 3, .72); padding: 20px; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.c-done[hidden] { display: none; }
.c-card { width: min(420px, 100%); max-height: 100%; overflow: auto; text-align: center; padding: 22px 22px 18px; border-radius: 18px; background: #1b110a; border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0, 0, 0, .6); }
.c-thumb { width: 150px; border-radius: 4px; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); transform: rotate(-2deg); background: #fff; }
.c-card h3 { margin: 16px 0 6px; font: 600 28px/1.1 var(--serif); color: var(--gold-2); }
.c-more { margin: 0 0 16px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.c-buy { display: inline-flex; padding: 14px 26px; border-radius: 999px; background: linear-gradient(180deg, #ffd06a, #f59b1d); color: #2a1503; font: 700 15px/1 var(--sans); text-decoration: none; box-shadow: 0 10px 30px rgba(245, 155, 29, .35); }
.c-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }
.c-btn { border: 1px solid var(--line); background: transparent; color: var(--ink); padding: 9px 14px; border-radius: 999px; font: 500 13px/1 var(--sans); cursor: pointer; }
.c-btn:hover { background: rgba(216, 178, 106, 0.15); }

@media (max-width: 760px) {
  .r-actions { flex-direction: column; gap: 10px; }
  #r-color { padding: 9px 14px; font-size: 13px; }
  .c-ico { width: 40px; height: 40px; }
  .c-head strong { font-size: 18px; }
  .c-pager .c-ico { width: 34px; height: 34px; }
  .c-swatch { width: 30px; height: 30px; }
  .c-palette { gap: 6px; flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; max-width: 100%; padding: 4px 4px 6px; scrollbar-width: none; }
  .c-palette::-webkit-scrollbar { display: none; }
  .c-swatch { flex: none; }
  .c-sizes .c-size { width: 30px; height: 30px; }
}
