:root {
  --sun: #e09410;
  --sun-hot: #f0b01c;
  --sun-deep: #b86a00;
  --void: #0a0a0a;
  --paper: #fff6e4;
  --blood: #c41616;
  --mute: rgba(10, 10, 10, 0.62);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --mx: 50%;
  --my: 42%;
  --split: 50%;
  --pad-x: max(1.15rem, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  --pad-top: max(1.25rem, env(safe-area-inset-top, 0px));
  --pad-bot: max(1.4rem, env(safe-area-inset-bottom, 0px));
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  min-height: 100%;
  min-height: 100dvh;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  color: var(--void);
  background: var(--sun);
  font-family: "Fragment Mono", ui-monospace, monospace;
  font-size: 16px;
  letter-spacing: 0.03em;
  overscroll-behavior-x: none;
  -webkit-font-smoothing: antialiased;
}

/* —— Atmosphere —— */
.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.sun {
  position: absolute;
  /* Bleed past the frame so the spotlight/grain never seams at the viewport top */
  inset: -42% -14% -14% -14%;
  background:
    radial-gradient(circle 48vmax at var(--mx) var(--my), var(--sun-hot) 0%, transparent 62%),
    radial-gradient(160% 140% at 50% 0%, #f3bc2e 0%, var(--sun) 38%, var(--sun-deep) 100%);
}

.other {
  position: absolute;
  inset: 0;
  background: var(--void);
  clip-path: inset(0 0 0 var(--split));
  opacity: 0.14;
  transition: opacity 0.45s var(--ease);
}

body.is-awake .other {
  opacity: 1;
  clip-path: none;
}

.presence {
  position: absolute;
  left: 50%;
  top: 40%;
  /* Room for a soft fade past the old 58rem column — not a 100vw aura */
  width: min(214vw, 70rem);
  translate: -50% -52%;
  opacity: 0.94;
  isolation: isolate;
  transition: opacity 0.55s var(--ease), filter 0.55s var(--ease);
  /* Top fade: cover gold never clips as a hard line at the viewport */
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    transparent 8%,
    #000 28%,
    #000 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    transparent 8%,
    #000 28%,
    #000 100%
  );
}

.presence img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: auto;
  /* Day: large enough for the star; gold blends into the yellow field */
  -webkit-mask-image: radial-gradient(
    ellipse 70% 64% at 50% 38%,
    #000 12%,
    transparent 82%
  );
  mask-image: radial-gradient(
    ellipse 70% 64% at 50% 38%,
    #000 12%,
    transparent 82%
  );
}

/* Soft gold halo — same visual weight as the old band, extra width is only fade */
body.is-awake .presence::before {
  content: "";
  position: absolute;
  inset: -6%;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(
    ellipse min(28rem, 44vw) min(36rem, 54vh) at 50% 40%,
    rgba(240, 176, 28, 0.5) 0%,
    rgba(224, 148, 16, 0.28) 34%,
    rgba(224, 148, 16, 0.1) 58%,
    transparent 100%
  );
}

body.is-awake .presence {
  opacity: 0.8;
  filter: saturate(1.12) brightness(0.9) contrast(1.06);
}

/* Night: keep the star; crop the cover’s flat gold so it can’t form a box */
body.is-awake .presence img {
  -webkit-mask-image: radial-gradient(
    ellipse min(20rem, 34vw) min(26rem, 42vh) at 50% 40%,
    #000 0%,
    #000 52%,
    transparent 86%
  );
  mask-image: radial-gradient(
    ellipse min(20rem, 34vw) min(26rem, 42vh) at 50% 40%,
    #000 0%,
    #000 52%,
    transparent 86%
  );
}

.seam {
  position: absolute;
  top: -10%;
  bottom: -10%;
  left: var(--mx);
  width: 2px;
  translate: -50% 0;
  background: var(--void);
  opacity: 0.28;
}

body.is-awake .seam {
  opacity: 0;
  visibility: hidden;
}

.grain {
  position: absolute;
  inset: -32%;
  width: 164%;
  height: 164%;
  opacity: 0.34;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.75'/%3E%3C/svg%3E");
  animation: grain 0.7s steps(2) infinite;
}

.vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 42%, transparent 34%, rgba(90, 40, 0, 0.42) 100%);
}

body.is-awake .vignette {
  background: radial-gradient(ellipse 82% 84% at 50% 42%, transparent 40%, rgba(0, 0, 0, 0.58) 100%);
}

/* Fade the gold glow into black at the viewport top — no clip seam */
body.is-awake .atmosphere::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: min(34vh, 15rem);
  background: linear-gradient(
    to bottom,
    var(--void) 0%,
    var(--void) 28%,
    rgba(10, 10, 10, 0.62) 58%,
    transparent 100%
  );
  z-index: 4;
  pointer-events: none;
}

body.is-awake {
  color: var(--paper);
  background: var(--void);
  color-scheme: dark;
}

body.is-awake .sun {
  opacity: 0;
  visibility: hidden;
}

body.is-awake .grain {
  mix-blend-mode: overlay;
  opacity: 0.3;
}

@keyframes grain {
  0%,
  100% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(-1%, 0.8%);
  }
}

/* —— Stage —— */
.stage {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  padding:
    var(--pad-top)
    max(1.15rem, env(safe-area-inset-right, 0px))
    var(--pad-bot)
    max(1.15rem, env(safe-area-inset-left, 0px));
  text-align: center;
}

.stack {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(100%, 22rem);
  flex: 0 0 auto;
}

.hero {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.name {
  margin: 0;
  width: min(100%, 22rem);
  line-height: 0.82;
}

.name-btn {
  appearance: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 4.6rem;
  margin: 0;
  padding: 0.35rem 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.name-btn:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 8px;
}

.name-ghost,
.name-line {
  font-family: "Archivo Black", "Arial Black", sans-serif;
  font-weight: 400;
  font-size: clamp(2.35rem, 11.2vw, 8.4rem);
  letter-spacing: -0.03em;
  white-space: nowrap;
  line-height: 0.82;
}

.name-ghost {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: calc(-50% + 5px) calc(-50% - 4px);
  color: var(--paper);
  opacity: 0.42;
  pointer-events: none;
  mix-blend-mode: overlay;
}

.name-line {
  position: relative;
  display: block;
  color: var(--void);
  opacity: 0;
  animation: rise 1.35s var(--ease) 0.12s forwards;
}

.name-line .ch {
  display: inline-block;
}

.name-line.is-glitching .ch:nth-child(odd) {
  transform: translate(2px, -1px);
}

.name-line.is-glitching .ch:nth-child(even) {
  transform: translate(-3px, 1px);
}

.name-line::before,
.name-line::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  color: var(--paper);
  white-space: nowrap;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: difference;
}

.name-line.is-glitching::before,
body.is-awake .name-line::before {
  opacity: 0.9;
  clip-path: inset(0 0 56% 0);
  transform: translate(-5px, -2px);
  color: var(--paper);
  mix-blend-mode: normal;
}

.name-line.is-glitching::after,
body.is-awake .name-line::after {
  opacity: 0.85;
  clip-path: inset(56% 0 0 0);
  transform: translate(6px, 2px);
  color: var(--blood);
  mix-blend-mode: normal;
}

body.is-awake .name-ghost {
  opacity: 0.2;
  color: var(--sun);
  mix-blend-mode: normal;
  translate: calc(-50% - 7px) calc(-50% + 5px);
}

body.is-awake .name-line {
  animation: none;
  opacity: 1;
  color: var(--sun);
}

body.is-awake .name-line::before {
  color: var(--sun);
}

.stitch {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 58%;
  height: 0;
  border-top: 3px dashed var(--blood);
  transform: scaleX(0);
  transform-origin: center;
  pointer-events: none;
  opacity: 0;
}

body.is-awake .stitch {
  opacity: 1;
  transform: scaleX(1);
  transition: transform 0.55s var(--ease) 0.08s, opacity 0.2s linear;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.whisper {
  margin: 1.15rem 0 0;
  max-width: 22rem;
  color: rgba(10, 10, 10, 0.78);
  font-size: clamp(1rem, 3.8vw, 1.12rem);
  font-style: italic;
  line-height: 1.45;
  letter-spacing: 0.01em;
  opacity: 0;
  animation: rise 1.2s var(--ease) 0.45s forwards;
}

body.is-awake .whisper {
  color: rgba(255, 246, 228, 0.62);
}

.awaken {
  margin-top: 1.65rem;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--void);
  font: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  cursor: pointer;
  min-height: 48px;
  min-width: 48px;
  padding: 0.85rem 1.1rem 0.7rem;
  opacity: 0;
  animation: rise 1.2s var(--ease) 0.7s forwards;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.awaken::after {
  content: "";
  display: block;
  width: 100%;
  height: 3px;
  margin-top: 0.45rem;
  background: repeating-linear-gradient(
    90deg,
    var(--blood) 0 10px,
    transparent 10px 16px
  );
  transform: scaleX(max(0.22, var(--hold, 0)));
  transform-origin: center;
}

.awaken:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 4px;
}

body.is-awake .awaken {
  color: var(--paper);
}

/* —— Gate —— */
.gate {
  position: absolute;
  top: 100%;
  left: 50%;
  width: 100%;
  margin-top: 1.05rem;
  display: grid;
  gap: 1.15rem;
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition:
    opacity 0.65s var(--ease),
    transform 0.65s var(--ease);
}

.gate.is-open {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.gate[hidden] {
  display: none;
}

.gate:not([hidden]) {
  display: grid;
}

.notify {
  display: grid;
  gap: 0.85rem;
  text-align: left;
}

.honey {
  position: absolute;
  left: -9999px;
  opacity: 0;
  height: 0;
  width: 0;
}

.field {
  display: grid;
  gap: 0.45rem;
}

.field-label {
  color: var(--mute);
  font-size: 0.72rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

body.is-awake .field-label {
  color: rgba(255, 246, 228, 0.55);
}

.field input {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-bottom: 1px solid rgba(10, 10, 10, 0.28);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 16px;
  letter-spacing: 0.04em;
  padding: 0.75rem 0;
  border-radius: 0;
  outline: none;
}

body.is-awake .field input {
  border-bottom-color: rgba(255, 246, 228, 0.28);
}

.field input::placeholder {
  color: rgba(10, 10, 10, 0.38);
}

body.is-awake .field input::placeholder {
  color: rgba(255, 246, 228, 0.35);
}

.field input:focus {
  border-bottom-color: var(--blood);
}

.submit {
  appearance: none;
  margin-top: 0.2rem;
  border: 1px solid var(--void);
  background: var(--void);
  color: var(--sun);
  font: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  min-height: 48px;
  padding: 0.9rem 1rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body.is-awake .submit {
  border-color: var(--sun);
  background: var(--sun);
  color: var(--void);
}

.submit:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

.submit:disabled {
  opacity: 0.45;
  cursor: wait;
}

.form-status {
  min-height: 1.25em;
  margin: 0;
  color: var(--mute);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

.form-status.is-ok,
.form-status.is-err {
  color: inherit;
}

.exits {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  width: 100%;
  gap: 0.35rem 0.8rem;
  white-space: nowrap;
}

.exits a {
  color: var(--mute);
  text-decoration: none;
  font-size: 0.62rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 0;
  flex: 0 0 auto;
  white-space: nowrap;
  touch-action: manipulation;
}

body.is-awake .exits a {
  color: rgba(255, 246, 228, 0.55);
}

.exits a:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .awaken:hover::after,
  .awaken:focus-visible::after {
    transform: scaleX(1);
  }

  .submit:hover {
    background: var(--blood);
    border-color: var(--blood);
    color: var(--paper);
  }

  body.is-awake .submit:hover {
    background: var(--paper);
    border-color: var(--paper);
    color: var(--void);
  }

  .exits a:hover {
    color: var(--void);
  }

  body.is-awake .exits a:hover {
    color: var(--paper);
  }
}

@media (hover: none) {
  .sun {
    background:
      radial-gradient(circle 54vmax at 50% 40%, var(--sun-hot) 0%, transparent 64%),
      radial-gradient(160% 140% at 50% 0%, #f3bc2e 0%, var(--sun) 38%, var(--sun-deep) 100%);
  }

  .other {
    animation: split-breathe 7s var(--ease) infinite alternate;
  }

  body.is-awake .other {
    animation: none;
  }
}

@keyframes split-breathe {
  from {
    clip-path: inset(0 0 0 42%);
  }
  to {
    clip-path: inset(0 0 0 58%);
  }
}

@media (min-width: 700px) and (min-height: 720px) {
  .presence {
    top: 34%;
    width: min(110vw, 55rem);
  }

  .exits a {
    font-size: 0.72rem;
    letter-spacing: 0.12em;
  }
}

@media (max-width: 430px) {
  .name {
    width: 100%;
  }

  .name-ghost,
  .name-line {
    font-size: min(3.4rem, calc((100vw - 2.5rem) / 5.55));
  }

  .awaken {
    letter-spacing: 0.28em;
  }

  .presence {
    width: min(205vw, 60rem);
    top: 36%;
  }

  .exits a {
    font-size: 0.58rem;
    letter-spacing: 0.05em;
  }
}

@media (max-height: 760px) {
  .gate {
    margin-top: 0.7rem;
    gap: 0.85rem;
  }

  .notify {
    gap: 0.55rem;
  }

  .field input,
  .submit {
    min-height: 44px;
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
  }

  .exits a {
    min-height: 40px;
    padding: 0.35rem 0;
  }
}

@media (max-height: 700px) {
  .name-btn {
    min-height: 3.6rem;
  }

  .presence {
    opacity: 0.7;
    width: min(190vw, 53rem);
  }

  body.is-awake .presence {
    opacity: 0.38;
  }
}

@media (prefers-reduced-motion: reduce) {
  .grain,
  .name-line,
  .whisper,
  .awaken,
  .gate,
  .other,
  .stitch,
  .presence {
    animation: none !important;
    transition: none !important;
  }

  .name-line,
  .whisper,
  .awaken {
    opacity: 1;
    transform: none;
  }

  .other {
    clip-path: inset(0 0 0 50%);
  }
}
