:root {
  color-scheme: dark;
  --bg: #000;
  --fg: #fff;
  --muted: #a3a3a3;
  --line: #2a2a2a;
  --tick-seen: #303030;
  --sheet: #0d0d0d;
  /* El único color de la página. Se usa sólo en la marca de la ruleta. */
  --accent: #86a5ec;
  --font: "Inter Tight", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --soft: cubic-bezier(.22, .61, .2, 1);
}

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

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

body {
  color: var(--fg);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; touch-action: manipulation; cursor: pointer; }

:focus-visible { outline: 2px solid var(--fg); outline-offset: 3px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

.icon {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  transition: opacity .7s ease;
}

body:not([data-acceso="abierto"]) .app { visibility: hidden; opacity: 0; }

/* Pantalla del código. Va en la parte de arriba para que el teclado no la tape. */

.gate {
  position: fixed;
  z-index: 2;
  inset: 0;
  padding: max(16vh, env(safe-area-inset-top)) 20px 20px;
  background: var(--bg);
  transition: opacity .5s ease, visibility 0s linear .5s;
}

body[data-acceso="abierto"] .gate { visibility: hidden; opacity: 0; }

.gate-form {
  display: flex;
  flex-direction: column;
  max-width: 440px;
  margin: 0 auto;
  transition: opacity .3s ease;
}

body[data-acceso="verificando"] .gate-form { visibility: hidden; opacity: 0; }

.gate-title { font-size: clamp(30px, 9vw, 38px); font-weight: 600; line-height: 1.05; letter-spacing: -.03em; }

.gate-label { margin-top: 10px; color: var(--muted); font-size: 17px; }

.gate-input {
  width: 100%;
  height: 58px;
  margin-top: 28px;
  padding: 0 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--fg);
  font: 500 18px var(--font);
  letter-spacing: .04em;
  transition: border-color .3s ease;
}

.gate-input:focus { border-color: var(--accent); outline: 0; }

.gate-error { min-height: 22px; margin: 8px 22px 0; color: var(--muted); font-size: 15px; }

.gate-submit {
  height: 58px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 18px;
  font-weight: 600;
  transition: opacity .3s ease;
}

.gate-submit:disabled { opacity: .3; cursor: default; }

.gate-help {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 15px;
  text-decoration: none;
}

/* Encabezado */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px 8px 20px;
}

.brand { font-size: 15px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }

.top-right { display: flex; align-items: center; gap: 2px; min-width: 0; }

.handle {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 8px;
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
}

.saved-open {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 44px;
  height: 44px;
  padding: 0 8px;
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.saved-open .icon { width: 22px; height: 22px; }

/* Categorías */

.chips {
  display: flex;
  flex: none;
  gap: 8px;
  padding: 0 20px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
  transition: background-color .35s var(--soft), color .35s var(--soft), border-color .35s var(--soft), opacity .4s var(--soft);
}

.chip[aria-pressed="true"] { background: var(--fg); border-color: var(--fg); color: var(--bg); }

body[data-state="spinning"] .chip { opacity: .4; }

/* Escenario: la ruleta y los textos se mueven sólo con transform, que en el celular va mucho más suave. */

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  scrollbar-width: none;
}

/* Sólo un tema largo en un celular muy chico puede necesitar scroll. */
body[data-state="result"] .stage { overflow-y: auto; }

.stage::-webkit-scrollbar { display: none; }

.wheel {
  --size: min(82vw, 50vh, 400px);
  position: absolute;
  top: 0;
  left: 50%;
  display: block;
  width: var(--size);
  height: var(--size);
  margin-left: calc(var(--size) / -2);
  border-radius: 50%;
  container-type: size;
  transform: translateY(var(--wheel-y, 0)) scale(var(--wheel-s, 1));
  transform-origin: top center;
  -webkit-user-select: none;
  user-select: none;
}

@supports (height: 1dvh) {
  .wheel { --size: min(82vw, 50dvh, 400px); }
}

.ready .wheel { transition: transform .9s var(--soft); }

.dial-clip {
  position: absolute;
  inset: 0;
  display: block;
  overflow: hidden;
  border-radius: 50%;
  transition: opacity .25s ease;
}

.dial-clip.fading { opacity: 0; }

.dial { position: absolute; inset: 0; display: block; will-change: transform; }

.dial svg { display: block; width: 100%; height: 100%; }

.tick { stroke: var(--fg); stroke-width: 2.4; stroke-linecap: round; transition: stroke .7s ease; }
.tick.seen { stroke: var(--tick-seen); }
.tick.landed { stroke: var(--accent); }

.pointer {
  position: absolute;
  z-index: 1;
  top: -1.5%;
  left: 50%;
  width: max(4px, 1.6%);
  height: 11%;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--bg);
  transform: translateX(-50%);
}

.count {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.count-num {
  font-size: 40px;
  font-size: 19cqw;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}

.count-label {
  margin-top: 1.5cqw;
  color: var(--muted);
  font-size: 14px;
  font-size: max(13px, 5cqw);
  transition: opacity .5s ease;
}

body[data-state="result"] .count-label { opacity: 0; }

/* Textos */

.intro,
.result {
  position: absolute;
  top: 0;
  left: 20px;
  right: 20px;
  text-align: center;
}

.intro {
  color: var(--muted);
  font-size: 17px;
  transform: translateY(var(--y, 0));
  transition: opacity .6s ease .2s;
}

body:not([data-state="idle"]) .intro { opacity: 0; transition: opacity .3s ease; }
body[data-state="result"] .intro { transform: none; }

.result {
  opacity: 0;
  visibility: hidden;
  transform: translateY(calc(var(--y, 0px) + 14px));
  transition: opacity .3s ease, transform .3s ease, visibility 0s linear .3s;
}

body[data-state="result"] .result {
  opacity: 1;
  visibility: visible;
  transform: translateY(var(--y, 0));
  transition: opacity .8s ease .2s, transform .9s var(--soft) .1s, visibility 0s;
}

.result-cat { color: var(--muted); font-size: 15px; font-weight: 500; }

.result-title {
  margin-top: 6px;
  font-size: clamp(27px, 8vw, 36px);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -.025em;
  text-wrap: balance;
}

.result-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 44px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.eye {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: -14px;
}

.eye .icon { grid-area: 1 / 1; width: 20px; height: 20px; transition: opacity .3s ease; }
.icon-eye-off { opacity: 0; }
.eye[aria-pressed="true"] .icon-eye { opacity: 0; }
.eye[aria-pressed="true"] .icon-eye-off { opacity: 1; }

.result-hook {
  font-size: 18px;
  line-height: 1.35;
  text-wrap: pretty;
  transition: opacity .4s ease;
}

.result-hook.oculta { opacity: 0; visibility: hidden; transition: opacity .4s ease, visibility 0s linear .4s; }

/* Botones */

.actions {
  flex: none;
  display: flex;
  padding: 8px 20px max(20px, env(safe-area-inset-bottom));
}

.secondary {
  flex: none;
  display: flex;
  gap: 10px;
  width: 0;
  margin-right: 0;
  overflow: hidden;
  opacity: 0;
  transition: width .6s var(--soft), margin-right .6s var(--soft), opacity .3s ease;
}

body[data-state="result"] .secondary {
  width: 126px;
  margin-right: 10px;
  opacity: 1;
  transition: width .7s var(--soft), margin-right .7s var(--soft), opacity .6s ease .15s;
}

.round {
  flex: none;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 1px solid var(--line);
  border-radius: 50%;
  transition: background-color .3s ease, color .3s ease, border-color .3s ease;
}

.round:focus-visible { outline-offset: -4px; }

.round .icon { grid-area: 1 / 1; }

#save[aria-pressed="true"] { background: var(--fg); border-color: var(--fg); color: var(--bg); }
#save[aria-pressed="true"] .icon { fill: currentColor; }

.icon-check { display: none; }
.round.done .icon-share { display: none; }
.round.done .icon-check { display: block; }

.spin {
  flex: 1;
  min-width: 0;
  height: 58px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 18px;
  font-weight: 600;
  transition: opacity .5s ease, transform .3s var(--soft);
}

.spin:active { transform: scale(.985); }
.spin:disabled { opacity: .3; cursor: default; }

/* Guardados */

.sheet {
  width: 100%;
  max-width: 480px;
  max-height: 82vh;
  max-height: 82dvh;
  margin: auto auto 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 24px 24px 0 0;
  background: var(--sheet);
  color: var(--fg);
}

.sheet[open] { display: flex; animation: sheet-in .55s var(--soft); }
.sheet::backdrop { background: rgba(0, 0, 0, .6); animation: fade-in .4s ease; }
.sheet.closing { animation: sheet-out .32s ease forwards; }
.sheet.closing::backdrop { animation: fade-out .32s ease forwards; }

@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

.sheet-inner {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.sheet-top {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 6px 20px;
}

.sheet-top h2 { font-size: 20px; font-weight: 600; letter-spacing: -.02em; }

.sheet-close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: var(--muted);
}

.sheet-empty { padding: 8px 20px 28px; color: var(--muted); font-size: 16px; line-height: 1.35; }
.sheet-empty[hidden] { display: none; }

.sheet-list {
  min-height: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.saved-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 14px 10px 14px 20px;
  border-top: 1px solid var(--line);
  transition: opacity .3s ease;
}

.saved-item.leaving { opacity: 0; }

.saved-text { flex: 1; min-width: 0; }
.saved-cat { color: var(--muted); font-size: 13px; }
.saved-title { margin-top: 2px; font-size: 18px; font-weight: 600; line-height: 1.15; letter-spacing: -.015em; }
.saved-hook { margin-top: 6px; color: var(--muted); font-size: 15px; line-height: 1.35; }

.saved-remove {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: var(--muted);
}

.saved-remove .icon { width: 20px; height: 20px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, ::backdrop {
    transition-duration: .01ms !important;
    transition-delay: 0s !important;
    animation-duration: .01ms !important;
  }
}
