:root {
  --brand-navy: #071d35;
  --brand-gold: #e7c269;
  --brand-cream: #f3ead7;
  --brand-background-image: none;
  --background-overlay: rgba(3, 12, 27, .38);
  --night: #061d38;
  --night-soft: #102c4b;
  --cream: var(--brand-cream);
  --muted: #c6ced1;
  --gold: var(--brand-gold);
  --gold-light: #f1d99e;
  --line: rgba(216, 182, 110, .34);
  --serif: Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --wheel-size: min(76vw, 340px);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--night);
  color-scheme: dark;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--cream);
  font-family: var(--sans);
  background-color: var(--night);
  background-image:
    linear-gradient(var(--background-overlay), var(--background-overlay)),
    var(--brand-background-image);
  background-position: var(--brand-background-position, center center);
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

body.is-saving-story { overflow: hidden; }


button { font: inherit; }

.particles {
  position: fixed;
  z-index: 0;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.particles i {
  position: absolute;
  top: var(--y);
  left: var(--x);
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--gold-light);
  box-shadow: 0 0 8px rgba(241, 217, 158, .6);
  opacity: .16;
  animation: particle-drift var(--duration) ease-in-out var(--delay) infinite alternate;
}

.app {
  position: relative;
  z-index: 1;
  display: flex;
  width: 100%;
  max-width: 764px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: auto;
  padding: calc(env(safe-area-inset-top) + 26px) 22px calc(env(safe-area-inset-bottom) + 24px);
  flex-direction: column;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  color: var(--gold-light);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: .24em;
  line-height: 1;
  text-align: center;
  text-shadow: 0 2px 12px var(--night);
}

.brand-header { margin-bottom: clamp(24px, 5vh, 48px); }

.brand-star { font-size: 12px; }

.screen {
  display: none;
  width: 100%;
  min-height: 0;
  padding: clamp(30px, 6vh, 64px) 0 18px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
}

.screen-content {
  position: relative;
  isolation: isolate;
}

.screen-content::before {
  position: absolute;
  z-index: -1;
  inset: -50px -28px;
  background: radial-gradient(circle at center, rgba(3, 24, 48, .4) 0%, rgba(3, 24, 48, .19) 48%, transparent 76%);
  content: "";
  pointer-events: none;
}

.screen--intro { padding-top: clamp(24px, 4vh, 48px); }
.screen--spinning { padding-top: clamp(26px, 5vh, 52px); }
.screen--result { padding-top: 12px; }

.screen.is-active {
  display: flex;
  animation: screen-in .65s ease both;
}

.screen.is-leaving { animation: screen-out .22s ease both; }

.eyebrow {
  color: var(--gold);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .2em;
  line-height: 1.5;
  text-transform: uppercase;
}

.hero-flourish,
.card-ornament {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--gold-light);
}

.hero-flourish {
  width: 150px;
  margin: 28px 0 20px;
}

.hero-flourish span,
.card-ornament span {
  width: 44px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold));
}

.hero-flourish span:last-child,
.card-ornament span:last-child { transform: scaleX(-1); }

.hero-flourish i,
.card-ornament i {
  font-size: 13px;
  font-style: normal;
}

h1 {
  margin: 0 0 22px;
  font: 400 clamp(43px, 10vw, 68px) / .99 var(--serif);
  letter-spacing: -.035em;
  text-shadow: 0 4px 24px rgba(3, 10, 22, .72);
}

h1 em {
  color: var(--gold-light);
  font-weight: 400;
}

.lead {
  max-width: 550px;
  margin: 0 auto 30px;
  color: #e3dfd3;
  font: 400 16px / 1.7 var(--serif);
  text-shadow: 0 2px 12px var(--night);
}

.button {
  min-height: 54px;
  padding: 0 26px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 720;
  letter-spacing: .005em;
  transition: transform .2s ease, box-shadow .2s ease, background-color .2s ease;
}

.button:hover { transform: translateY(-2px); }
.button:active { transform: translateY(0); }
.button:focus-visible { outline: 2px solid var(--cream); outline-offset: 4px; }
.button:disabled { cursor: wait; opacity: .58; transform: none; box-shadow: none; }

.button-primary {
  color: #142033;
  background: linear-gradient(135deg, #f0d99f, #cda85d);
  box-shadow: 0 12px 34px rgba(202, 164, 89, .2);
}

.button-primary:hover,
.button-primary:focus-visible {
  background: linear-gradient(135deg, #f8e7b7, var(--brand-gold));
  box-shadow: 0 14px 40px rgba(231, 194, 105, .38), 0 0 0 1px rgba(248, 231, 183, .24);
}

.button-primary:active {
  background: linear-gradient(135deg, var(--brand-gold), #c99f50);
  box-shadow: 0 7px 20px rgba(231, 194, 105, .3);
}

.button-secondary {
  color: var(--cream);
  border: 1px solid var(--line);
  background: rgba(7, 23, 42, .58);
  backdrop-filter: blur(8px);
}

.whisper {
  margin: 21px 0 0;
  color: #d2cec1;
  font-size: 12px;
  letter-spacing: .065em;
  text-shadow: 0 2px 10px var(--night);
}

/* Ruleta */
.wheel-screen h2 {
  max-width: 550px;
  margin: 12px 0 30px;
  font: 400 clamp(27px, 7vw, 39px) / 1.15 var(--serif);
}

.wheel-wrap {
  position: relative;
  width: var(--wheel-size);
  aspect-ratio: 1;
}

.wheel {
  width: 100%;
  height: 100%;
  padding: 9px;
  border: 1px solid var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 0 7px rgba(216, 182, 110, .06), 0 28px 65px rgba(0, 0, 0, .35);
  will-change: transform;
}

.wheel-inner {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: repeating-conic-gradient(
    from -22.5deg,
    rgba(216, 182, 110, .14) 0deg 44deg,
    rgba(16, 44, 75, .86) 45deg 89deg
  );
}

.wheel-inner::after {
  position: absolute;
  inset: 12%;
  border: 1px solid rgba(216, 182, 110, .23);
  border-radius: 50%;
  content: "";
}

.wheel-inner span {
  --angle: calc(var(--i) * 45deg);
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px;
  color: var(--gold-light);
  font: 22px / 28px var(--serif);
  transform: rotate(var(--angle)) translateY(calc(var(--wheel-size) * -.39)) rotate(calc(0deg - var(--angle)));
}

.wheel-center {
  position: absolute;
  z-index: 2;
  inset: 36%;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, #102b49, #081a30 72%);
  box-shadow: inset 0 0 18px rgba(2, 11, 23, .5), 0 0 13px rgba(231, 194, 105, .1);
}

.wheel-center-symbol {
  width: 48%;
  height: 48%;
  overflow: visible;
  fill: var(--brand-gold);
  filter: drop-shadow(0 0 7px rgba(230, 193, 103, .25));
  transform-origin: center;
}

.wheel.is-spinning .wheel-center-symbol {
  animation: wheel-symbol-breathe 1.25s ease-in-out infinite alternate;
}

.wheel.has-stopped .wheel-center-symbol {
  animation: wheel-symbol-settle .45s ease-out both;
}

.pointer {
  position: absolute;
  z-index: 3;
  top: -17px;
  left: 50%;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: #14213a;
  background: var(--gold-light);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  transform: translateX(-50%);
}

.thinking {
  margin: 27px 0 0;
  color: var(--muted);
  font: italic 14px var(--serif);
  transition: opacity .18s ease, transform .18s ease, color .18s ease;
}

.thinking.is-changing { opacity: 0; transform: translateY(3px); }
.thinking.is-registered { color: var(--gold-light); font-style: normal; letter-spacing: .06em; }

/* Resultado */
.result-screen { padding-top: 30px; }

.result-card {
  position: relative;
  width: 100%;
  overflow: hidden;
  padding: 34px clamp(24px, 6vw, 48px) 30px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: linear-gradient(145deg, rgba(15, 42, 70, .95), rgba(6, 21, 39, .96));
  box-shadow: 0 24px 70px rgba(0, 0, 0, .32);
  backdrop-filter: blur(10px);
  animation: card-reveal .65s cubic-bezier(.2, .8, .2, 1) both;
}

.result-card::before {
  position: absolute;
  inset: 9px;
  border: 1px solid rgba(216, 182, 110, .12);
  border-radius: 19px;
  content: "";
  pointer-events: none;
}

.card-ornament { margin-bottom: 19px; }

.case-number {
  margin: -7px 0 15px;
  color: #98a7af;
  font-size: 9px;
  font-weight: 650;
  letter-spacing: .17em;
  text-transform: uppercase;
}

.excuse {
  max-width: 580px;
  margin: 24px auto 14px;
  color: var(--gold-light);
  font: 400 clamp(30px, 7vw, 45px) / 1.13 var(--serif);
}

.reason {
  max-width: 500px;
  margin: 0 auto;
  color: var(--muted);
  font: italic 15px / 1.6 var(--serif);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 27px 0 21px;
  color: var(--gold);
  font-size: 10px;
}

.divider::before,
.divider::after {
  height: 1px;
  flex: 1;
  background: linear-gradient(90deg, transparent, var(--line));
  content: "";
}

.divider::after { transform: scaleX(-1); }

.verdict h3 {
  margin: 23px 0 10px;
  color: var(--cream);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .14em;
  line-height: 1.45;
  text-transform: uppercase;
}

.verdict p {
  max-width: 520px;
  margin: auto;
  color: #aeb9bf;
  font-size: 12px;
  line-height: 1.6;
}

.approval {
  display: inline-flex;
  margin-top: 21px;
  align-items: center;
  gap: 9px;
  color: var(--approval-color, var(--gold-light));
  animation: approval-pop .48s cubic-bezier(.2, 1.5, .4, 1) .42s both;
}

.approval > div { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left; }

.approval span {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  border-radius: 50%;
  color: #102139;
  background: var(--approval-color, var(--gold));
  font-size: 14px;
  font-weight: 800;
}

.approval small {
  font-size: 9px;
  font-weight: 750;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.approval b {
  color: #aeb9bf;
  font: italic 11px var(--serif);
}

.signature {
  display: flex;
  margin-top: 20px;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  color: #8998a1;
}

.signature span { width: 115px; height: 1px; background: rgba(216, 182, 110, .28); }
.signature small { font: italic 10px var(--serif); }

.actions {
  display: flex;
  width: 100%;
  margin-top: 18px;
  gap: 12px;
}

.actions .button { flex: 1; }

.download-status {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--gold-light);
  font-size: 12px;
}

.brand-footer {
  width: fit-content;
  max-width: 100%;
  min-height: 0;
  margin-top: clamp(34px, 6vh, 62px);
  padding: 8px 14px;
  border-radius: 14px;
  color: #b8c0c2;
  background: rgba(3, 20, 39, .22);
  font-size: 11px;
  letter-spacing: .05em;
  line-height: 1.5;
  text-align: center;
  text-shadow: 0 2px 10px var(--night);
}

.brand-footer strong { color: var(--gold-light); }

.future-actions {
  display: flex;
  margin-top: 22px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 22px;
}

.future-actions[hidden], .auxiliary-status[hidden] { display: none; }

.text-action {
  padding: 5px;
  border: 0;
  color: #bfc8cb;
  background: transparent;
  font-size: 11px;
  cursor: pointer;
  transition: color .2s ease;
}

.text-action:hover, .text-action:focus-visible { color: var(--gold-light); }
.auxiliary-status { min-height: 16px; margin: 3px 0 0; color: var(--gold-light); font-size: 11px; text-align: center; }

.stats-dialog {
  width: min(90vw, 480px);
  padding: 34px;
  border: 1px solid rgba(231, 194, 105, .55);
  border-radius: 25px;
  color: var(--cream);
  background: rgba(5, 25, 47, .98);
  text-align: center;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .55);
}
.stats-dialog::backdrop { background: rgba(2, 10, 22, .74); backdrop-filter: blur(3px); }
.stats-dialog h2 { margin: 22px 0 14px; font: italic 31px var(--serif); color: var(--gold-light); }
.stats-dialog p { margin: 0 0 25px; color: var(--muted); line-height: 1.65; }

.debug-panel {
  position: fixed;
  z-index: 20;
  right: 12px;
  bottom: 12px;
  width: min(340px, calc(100vw - 24px));
  padding: 14px;
  border: 1px solid rgba(231, 194, 105, .45);
  border-radius: 12px;
  color: #dce2df;
  background: rgba(3, 16, 31, .96);
  font: 12px/1.55 ui-monospace, Consolas, monospace;
  white-space: pre-wrap;
}

.story-save-view {
  position: fixed;
  z-index: 50;
  inset: 0;
  overflow-y: auto;
  padding: max(24px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom));
  color: var(--cream);
  background: #031326;
}

.story-save-view[hidden] { display: none; }

.story-save-shell {
  width: min(100%, 620px);
  margin: 0 auto;
  text-align: center;
}

.story-save-shell h2 {
  margin: 4px 0 10px;
  color: var(--gold-light);
  font: italic clamp(30px, 8vw, 42px) var(--serif);
}

.story-save-shell > p {
  max-width: 480px;
  margin: 0 auto 20px;
  color: #d1d7d6;
  font-size: 14px;
  line-height: 1.6;
}

.story-preview-image {
  display: block;
  width: min(100%, 430px);
  height: auto;
  margin-inline: auto;
  border: 1px solid rgba(231, 194, 105, .4);
  border-radius: 14px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .45);
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}

.story-save-actions {
  display: grid;
  width: min(100%, 430px);
  margin: 20px auto 0;
  gap: 10px;
}

.story-save-actions .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 56px;
  padding-block: 0;
  line-height: 1.2;
  text-decoration: none;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

@keyframes screen-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(-5px); }
}

@keyframes card-reveal {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes approval-pop {
  from { opacity: 0; transform: scale(.82); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes particle-drift {
  from { transform: translate3d(-4px, 8px, 0); opacity: .08; }
  to { transform: translate3d(7px, -12px, 0); opacity: .25; }
}

@keyframes wheel-symbol-breathe {
  from { opacity: .82; transform: scale(.94); }
  to { opacity: 1; transform: scale(1.04); }
}

@keyframes wheel-symbol-settle {
  0% { transform: scale(.92); }
  55% { transform: scale(1.09); }
  100% { transform: scale(1); }
}

@media (max-width: 540px) {
  :root { --wheel-size: clamp(245px, 76vw, 330px); }
  body { background-attachment: scroll; }
  .app { padding: calc(env(safe-area-inset-top) + 16px) 17px calc(env(safe-area-inset-bottom) + 18px); }
  .brand { gap: 7px; padding: 7px 11px; border-radius: 999px; background: rgba(4, 24, 47, .2); font-size: 8px; letter-spacing: .16em; backdrop-filter: blur(2px); }
  .brand-header { margin-bottom: 18px; }
  .brand-star { font-size: 10px; }
  .screen { min-height: 0; padding-bottom: 8px; }
  .screen--intro { padding-top: 18px; }
  .screen--spinning { padding-top: 20px; }
  .screen--result { padding-top: 8px; }
  .screen-content::before { inset: -35px 0; }
  .lead { font-size: 15px; }
  .result-card { border-radius: 23px; }
  .actions { flex-direction: column; }
  .actions .button { width: 100%; }
  .button-primary:active,
  .button-primary:focus {
    background: linear-gradient(135deg, #f8e7b7, var(--brand-gold));
    box-shadow: 0 10px 30px rgba(231, 194, 105, .4), 0 0 0 1px rgba(248, 231, 183, .24);
  }
  .brand-footer { margin-top: 28px; padding: 8px 12px; font-size: 11px; background: rgba(3, 20, 39, .3); }
  .future-actions { margin-top: 18px; flex-direction: column; gap: 2px; }
}

@media (max-width: 540px) and (min-height: 700px) {
  .app[data-screen="intro"],
  .app[data-screen="wheelScreen"] {
    justify-content: center;
  }
}

/* En escritorio, la portada ocupa el espacio disponible entre la marca y el pie.
   Así el bloque principal queda visualmente centrado sin mover las otras pantallas. */
@media (min-width: 541px) and (min-height: 700px) {
  .app[data-screen="intro"] .screen--intro {
    flex: 1;
    padding-top: 20px;
    padding-bottom: 20px;
  }

  .app[data-screen="intro"] .brand-footer {
    margin-top: 18px;
  }
}

@media (max-width: 360px) {
  :root { --wheel-size: min(84vw, 300px); }
  .app { padding-right: 14px; padding-left: 14px; }
  h1 { font-size: clamp(38px, 12vw, 48px); }
  .screen--intro, .screen--spinning { padding-top: 14px; }
  .result-card { padding-right: 21px; padding-left: 21px; }
  .excuse { font-size: clamp(28px, 9vw, 36px); }
  .button { min-height: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
  .particles { display: none; }
  .approval, .result-card { animation-name: screen-in; }
}
