/* SOBREPIENSO — un juego de FANTASEAR · MANI */

:root {
  --bg: #000;
  --ink: #f3f3f1;
  --dim: rgba(243, 243, 241, .52);
  --faint: rgba(243, 243, 241, .16);
  --serif: "Instrument Serif", "Times New Roman", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --beat: .7229s; /* 83 BPM */
  --fs: 22px;
}

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

html, body { height: 100%; background: var(--bg); color: var(--ink); }

body {
  font-family: var(--mono);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 1px solid var(--ink); outline-offset: 4px; }
[hidden] { display: none !important; }

.code {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .18em;
  text-transform: uppercase;
}
.dim { color: var(--dim); }
.ink { color: var(--ink); }
.sep { opacity: .5; }

/* ── escenario del juego ─────────────────────── */

.stage {
  position: fixed;
  inset: 0;
  touch-action: none;
  background: var(--bg);
}
.stage canvas { position: absolute; left: 0; top: 0; display: block; }
.inv .stage { background: #fff; }

/* pensamientos: texto real, nítido en cualquier pantalla */
.thoughts { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.thought {
  position: absolute;
  left: 0;
  top: 0;
  padding: .14em .62em .24em;
  border: 1px solid rgba(255, 255, 255, .42);
  border-radius: 999px;
  background: rgba(0, 0, 0, .9);
  color: #fff;
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--fs);
  line-height: 1.12;
  white-space: nowrap;
  will-change: transform, opacity;
  backface-visibility: hidden;
}
.thought--letter {
  padding: .02em .42em .1em;
  border-radius: 12px;
  font-style: normal;
  font-size: calc(var(--fs) * 2);
}
.thought--final { font-style: italic; font-size: calc(var(--fs) * 1.9); }
.thought--custom { background: #fff; color: #000; border-color: #fff; }
.inv .thought { background: rgba(255, 255, 255, .92); color: #000; border-color: rgba(0, 0, 0, .45); }
.inv .thought--custom { background: #000; color: #fff; border-color: #000; }

.grain {
  position: fixed;
  inset: -50%;
  width: 200%;
  height: 200%;
  pointer-events: none;
  z-index: 60;
  opacity: .07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 1.4 -.35'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain .8s steps(5) infinite;
}
@keyframes grain {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(-3%, 2%); }
  40%  { transform: translate(2%, -3%); }
  60%  { transform: translate(-2%, -1%); }
  80%  { transform: translate(3%, 3%); }
  100% { transform: translate(0, 0); }
}

.flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 55;
}

.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 20px 0;
  pointer-events: none;
}
.hud__right { font-size: 13px; letter-spacing: .12em; font-variant-numeric: tabular-nums; }
.inv .hud { color: #000; }

.progress {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  z-index: 50;
  background: var(--faint);
  opacity: 0;
  transition: opacity .6s;
}
.progress.is-on { opacity: 1; }
.progress i { display: block; height: 100%; width: 100%; background: var(--ink); transform-origin: left; transform: scaleX(0); }
.inv .progress i { background: #000; }

.mute {
  position: fixed;
  left: 20px;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 51;
  padding: 8px 12px 8px 0;
  color: var(--dim);
}
.mute:hover { color: var(--ink); }
.inv .mute { color: rgba(0, 0, 0, .6); }

/* ── escenas (capas sobre el juego) ─────────── */

.scene {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: max(56px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity .7s ease, visibility 0s linear .7s;
}
.scene.is-active {
  opacity: 1;
  visibility: visible;
  transition: opacity .7s ease, visibility 0s;
}

.scene--gate { background: radial-gradient(ellipse at center, rgba(0, 0, 0, .35), rgba(0, 0, 0, .85)); }

.title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(62px, 14vw, 190px);
  line-height: .9;
  letter-spacing: -.025em;
  text-shadow: 0 0 28px rgba(255, 255, 255, .28);
}

.line {
  font-family: var(--serif);
  font-size: clamp(22px, 2.6vw, 30px);
  line-height: 1.25;
  color: var(--dim);
}

.gate__alt { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 20px; margin-top: 4px; }
.gate__hint { font-size: 10px; letter-spacing: .26em; margin-top: 2px; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.hud { transition: opacity .6s; }
.is-gate .hud { opacity: 0; }

.btn {
  margin-top: 10px;
  min-width: 240px;
  padding: 17px 28px;
  border: 1px solid var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .24em;
  text-transform: uppercase;
  transition: background .25s, color .25s, border-color .25s, opacity .4s, transform .4s;
}
.btn:hover:not(:disabled) { background: var(--ink); color: var(--bg); }
.btn:disabled { border-color: var(--faint); color: var(--dim); cursor: progress; }
.btn.is-ready { animation: breathe calc(var(--beat) * 4) ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
  50% { box-shadow: 0 0 34px 2px rgba(255, 255, 255, .2); }
}
.btn--small { margin-top: 0; min-width: 0; padding: 14px 18px; font-size: 11px; letter-spacing: .16em; }
.btn--ghost { border-color: var(--faint); }

.quiet { padding: 8px; color: var(--dim); transition: color .25s; }
.quiet:hover { color: var(--ink); }

/* ── intro narrada ───────────────────────────── */

.scene--intro { justify-content: flex-start; pointer-events: none; }

.narr {
  position: absolute;
  left: 16px;
  right: 16px;
  top: calc(50% + var(--ring-gap, 96px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  pointer-events: none;
  transition: top .6s cubic-bezier(.2, .7, .2, 1);
}
.scene--intro.is-asking .narr { top: 13%; }
.choices, .ask, .skip { pointer-events: auto; }
/* lo que "dice" la voz: letra recta y clara, fácil de leer en el móvil */
.narr__text {
  max-width: 24ch;
  min-height: 1.3em;
  font-family: var(--sans);
  font-weight: 500;
  font-size: clamp(22px, 2.8vw, 34px);
  line-height: 1.32;
  letter-spacing: -.005em;
  text-shadow: 0 0 10px #000, 0 0 4px #000, 0 0 2px #000; /* que nada de fondo pise las letras */
  transition: opacity .35s;
}
.narr__text.is-out { opacity: 0; }
.narr__text.is-echo { font-style: italic; font-weight: 400; color: var(--dim); }
.narr__text .caret {
  display: inline-block;
  width: .08em;
  height: .9em;
  margin-left: .06em;
  vertical-align: -.08em;
  background: currentColor;
  animation: caret .7s steps(2, jump-none) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

.choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; max-width: 560px; }
.choice {
  padding: 13px 18px;
  border: 1px solid var(--faint);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .16em;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(6px);
  animation: rise .5s ease forwards;
  transition: background .2s, color .2s, border-color .2s;
}
.choice:hover, .choice:focus-visible { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.choice--main { border-color: var(--ink); }
@keyframes rise { to { opacity: 1; transform: none; } }

.ask { display: flex; flex-direction: column; align-items: center; gap: 14px; width: min(100%, 420px); animation: rise .5s ease forwards; }
.ask__input {
  width: 100%;
  padding: 10px 2px;
  border: 0;
  border-bottom: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 22px;
  text-align: center;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
.ask__input::placeholder { color: var(--dim); }
.ask__row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.ask__note { letter-spacing: .12em; }

.skip {
  position: absolute;
  right: 16px;
  bottom: max(14px, env(safe-area-inset-bottom));
}

/* ── final ───────────────────────────────────── */

.scene--end {
  justify-content: flex-start;
  overflow-y: auto;
  background: rgba(0, 0, 0, .82);
  user-select: text;
  -webkit-user-select: text;
}

.end__inner {
  margin: auto 0;
  width: min(100%, 1040px);
  display: grid;
  grid-template-columns: 1fr;
  gap: 36px;
  align-items: center;
  padding: 8px 0 20px;
}
@media (min-width: 760px) {
  .end__inner { grid-template-columns: 1fr 1fr; gap: 40px; }
}

.result, .listen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.pct {
  font-family: var(--serif);
  font-size: clamp(96px, 22vw, 210px);
  line-height: .82;
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 40px rgba(255, 255, 255, .25);
}
@media (min-width: 760px) { .pct { font-size: clamp(96px, 15vw, 210px); } }
.rank {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(26px, 3.4vw, 38px);
  line-height: 1.1;
  max-width: 18ch;
}
.rank__sub { font-family: var(--serif); font-size: 18px; color: var(--dim); max-width: 30ch; }
.rank__sub:empty { display: none; }
.rank__custom { color: var(--ink); font-style: italic; }
.stats { max-width: 46ch; line-height: 1.8; }
.record:empty { display: none; }
.result__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 8px; }

.listen__cta {
  display: flex;
  align-items: center;
  gap: 14px;
  width: min(100%, 460px);
  font-family: var(--mono);
  font-size: clamp(15px, 1.6vw, 18px);
  font-weight: 500;
  letter-spacing: .34em;
  text-transform: uppercase;
  white-space: nowrap;
}
.listen__cta::before, .listen__cta::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--faint);
}

.cover {
  width: min(72vw, 330px, 38vh);
  aspect-ratio: 1;
  box-shadow: 0 0 0 1px #1c1c1c, 0 0 70px rgba(255, 255, 255, .08);
  transition: filter .08s;
}
.cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
.cover.is-pulse { filter: invert(1); }

.title--end { font-size: clamp(54px, 9vw, 104px); margin-top: 4px; }

.links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 460px);
  margin-top: 4px;
}
.link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 50px;
  padding: 14px;
  border: 1px solid var(--faint);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  text-decoration: none;
  text-align: left;
  transition: background .25s, color .25s, border-color .25s;
}
.link:hover { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.link--main { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.link--main:hover { background: transparent; color: var(--ink); }

.friday { line-height: 1.9; }
.friday a { text-underline-offset: 4px; white-space: nowrap; }
.friday a:hover { color: var(--ink); }

.noscript { position: fixed; inset: auto 16px 16px; font-size: 13px; z-index: 70; }

@media (max-width: 520px) {
  .hud { padding-left: 16px; padding-right: 16px; }
  .mute { left: 16px; }
}
@media (max-width: 759px) {
  .is-end .mute { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .grain, .btn.is-ready, .narr__text .caret { animation: none; }
}
