:root {
  color-scheme: dark;
  --paper: #f3efe2;
  --brass: #c59b57;
  --neon: #ff5a3c;
  --shadow: #080708;
  /* The alley's neon language: purple lettering, green sign borders, and the
     sodium street lamp. The chat HUD borrows exactly these three. */
  --neon-purple: #b45cff;
  --neon-green: #49ff9e;
  --warm: #ffb45e;
  --glass: rgba(10, 8, 14, 0.55);
  /* Quiet violet-grey for resting edges; full neon is reserved for focus. */
  --glass-border: rgba(196, 189, 209, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: #050505;
  color: var(--paper);
  /* Classical East-Asian serif (mincho) for an ancient, oriental feel, with a
     system-mincho fallback stack when the web font is unavailable. */
  font-family: "Shippori Mincho", "Yu Mincho", "Hiragino Mincho ProN",
    "Songti SC", "Noto Serif JP", Georgia, "Times New Roman", serif;
  letter-spacing: 0.01em;
}

button,
input {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.scene {
  position: relative;
  min-height: 100svh;
  overflow: hidden;
  background: #050505;
}

.webgl-scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 62% 40%, rgba(255, 60, 34, 0.1), transparent 24rem),
    radial-gradient(circle at 30% 30%, rgba(255, 180, 106, 0.08), transparent 20rem),
    radial-gradient(circle at 78% 62%, rgba(196, 80, 255, 0.05), transparent 16rem),
    linear-gradient(90deg, #040303, #170f0c 42%, #080505);
}

.webgl-scene canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.scene::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 50%, transparent 42%, rgba(0, 0, 0, 0.64) 100%),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.12), transparent 40%, rgba(0, 0, 0, 0.28));
}

.ritual {
  position: relative;
  z-index: 2;
  min-height: 100svh;
  pointer-events: none;
}

.console {
  position: fixed;
  left: 50%;
  bottom: max(clamp(0.8rem, 2vw, 1.6rem), calc(env(safe-area-inset-bottom, 0px) + 0.6rem));
  z-index: 4;
  width: min(43rem, calc(100vw - 2rem - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  transform: translateX(-50%);
  pointer-events: auto;
}

.transcript {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.38rem;
  max-height: min(12rem, 32svh);
  overflow: auto;
  overscroll-behavior: contain;
  margin-bottom: 0.75rem;
  padding: 1.2rem 0.3rem 0;
  scrollbar-width: none;
  /* Old lines dissolve into the rain instead of hitting a hard edge. */
  -webkit-mask-image: linear-gradient(to bottom, transparent, black 1.4rem);
  mask-image: linear-gradient(to bottom, transparent, black 1.4rem);
}

.transcript:not(:empty) {
  min-height: 4rem;
}

.line {
  width: fit-content;
  max-width: min(34rem, 84vw);
  margin: 0;
  padding: 0.6rem 0.9rem;
  border: 1px solid rgba(243, 239, 226, 0.14);
  border-radius: 0.9rem 0.9rem 0.9rem 0.25rem;
  background: var(--glass);
  backdrop-filter: blur(14px);
  font-size: clamp(0.9rem, 1.8vw, 1rem);
  line-height: 1.4;
  text-shadow: 0 1px 0 #000;
}

@media (prefers-reduced-motion: no-preference) {
  .line {
    animation: lineRise 0.25s ease-out;
  }
}

@keyframes lineRise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.line.user {
  margin-left: auto;
  align-self: flex-end;
  border-radius: 0.9rem 0.9rem 0.25rem 0.9rem;
  border-color: rgba(255, 180, 94, 0.35);
  box-shadow: 0 0 1.1rem rgba(255, 180, 94, 0.1);
  color: #ffe6d2;
}

.line.cat {
  border-color: var(--glass-border);
  box-shadow: 0 0 1.2rem rgba(180, 92, 255, 0.05);
  color: #fff3d5;
}

/* The "keep your fortune" slip button, sitting in the transcript flow. */
.omikuji-button {
  width: fit-content;
  min-height: 2.75rem;
  padding: 0.5rem 1.1rem;
  border: 1px solid rgba(73, 255, 158, 0.4);
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(14px);
  color: #d7ffe9;
  font-family: inherit;
  font-size: clamp(0.82rem, 1.7vw, 0.94rem);
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 0 0.9rem rgba(73, 255, 158, 0.1);
  transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
  align-items: center;
}

input {
  min-width: 0;
  min-height: 2.75rem;
  border: 1px solid rgba(243, 239, 226, 0.14);
  border-radius: 999px;
  padding: 0.65rem 1.2rem;
  color: #f4ecdd;
  background: var(--glass);
  outline: none;
  backdrop-filter: blur(14px);
  /* 16px floor keeps iOS Safari from zooming the page on focus. */
  font-size: max(1rem, 1em);
  transition: border-color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
}

input::placeholder {
  color: rgba(226, 214, 190, 0.4);
}

input:focus {
  border-color: var(--neon-purple);
  background: rgba(14, 10, 20, 0.62);
  box-shadow:
    0 0 0 1px rgba(180, 92, 255, 0.35),
    0 0 14px rgba(180, 92, 255, 0.3);
}

@media (prefers-reduced-motion: no-preference) {
  input:focus {
    /* The focus ring warms up like one of the alley's tubes being struck. */
    animation: tubeStrike 0.3s steps(2, jump-none);
  }
}

@keyframes tubeStrike {
  0% { box-shadow: none; }
  50% { box-shadow: 0 0 0 1px rgba(180, 92, 255, 0.18), 0 0 6px rgba(180, 92, 255, 0.14); }
}

button {
  border: 1px solid rgba(226, 214, 190, 0.2);
  border-radius: 0.55rem;
  padding: 0.78rem 1.15rem;
  color: #ece2cf;
  background: rgba(20, 17, 14, 0.42);
  backdrop-filter: blur(14px);
  cursor: pointer;
  transition: border-color 0.25s ease, color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
}

/* The send control: a round neon-edged key, sized for thumbs. */
#sendButton {
  width: 2.75rem;
  height: 2.75rem;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  border-color: var(--glass-border);
  color: #e8d4ff;
  font-size: 1.05rem;
  line-height: 1;
}

#sendButton span {
  transform: translateX(1px); /* the ➤ glyph sits optically left of center */
}

#sendButton:focus-visible {
  outline: none;
  border-color: var(--neon-purple);
  box-shadow: 0 0 0 1px rgba(180, 92, 255, 0.35), 0 0 14px rgba(180, 92, 255, 0.3);
}

@media (hover: hover) {
  button:hover:not(:disabled) {
    border-color: rgba(226, 214, 190, 0.42);
    color: #fff6e6;
    background: rgba(28, 23, 19, 0.55);
  }

  #sendButton:hover:not(:disabled) {
    border-color: var(--neon-purple);
    color: #f4e8ff;
    box-shadow: 0 0 12px rgba(180, 92, 255, 0.35);
    background: rgba(24, 14, 34, 0.6);
  }

  .omikuji-button:hover {
    border-color: rgba(73, 255, 158, 0.8);
    box-shadow: 0 0 1.1rem rgba(73, 255, 158, 0.25);
    background: rgba(8, 20, 14, 0.65);
  }
}

button:disabled,
input:disabled {
  cursor: default;
  opacity: 0.4;
}

/* Four-pillars breakdown: quiet, serif, kanji intact — edged in the green of
   the alley's sign borders. */
.line.pillars {
  white-space: pre-line;
  font-size: clamp(0.82rem, 1.7vw, 0.98rem);
  letter-spacing: 0.06em;
  line-height: 1.65;
  color: #efe6d2;
  border-color: rgba(73, 255, 158, 0.25);
  box-shadow: 0 0 1.1rem rgba(73, 255, 158, 0.08);
}

/* Tap-to-enter veil that unlocks audio for the opening greeting. */
.start-veil {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: inherit;
  background:
    radial-gradient(circle at 50% 46%, rgba(255, 120, 60, 0.08), transparent 40%),
    rgba(4, 3, 3, 0.62);
  backdrop-filter: blur(6px);
  transition: opacity 0.6s ease;
}

.start-veil[hidden] {
  display: none;
}

.start-veil__prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  animation: veilPulse 3.4s ease-in-out infinite;
}

.start-veil__title {
  font-size: clamp(2.6rem, 9vw, 4.4rem);
  color: #f4ead2;
  text-shadow: 0 0 2rem rgba(255, 120, 60, 0.4);
  letter-spacing: 0.14em;
}

.start-veil__sub {
  font-family: "Cinzel", Georgia, serif;
  font-size: clamp(0.78rem, 2vw, 0.98rem);
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: rgba(232, 220, 196, 0.62);
}

/* Shown when the fortune teller's API budget for the day is spent. */
.closed-veil {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  text-align: center;
  background:
    radial-gradient(circle at 50% 46%, rgba(180, 92, 255, 0.06), transparent 42%),
    rgba(4, 3, 3, 0.85);
  backdrop-filter: blur(8px);
}

.closed-veil[hidden] {
  display: none;
}

.closed-veil__prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
}

.closed-veil__title {
  font-size: clamp(2.2rem, 8vw, 3.6rem);
  color: #f4ead2;
  letter-spacing: 0.14em;
  text-shadow: 0 0 2rem rgba(180, 92, 255, 0.35);
}

.closed-veil__sub {
  font-family: "Cinzel", Georgia, serif;
  font-size: clamp(0.78rem, 2vw, 0.98rem);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: rgba(232, 220, 196, 0.7);
}

.closed-veil__note {
  max-width: 26rem;
  font-size: clamp(0.9rem, 2vw, 1rem);
  line-height: 1.6;
  color: rgba(230, 220, 199, 0.85);
}

/* "What is this?" affordance and explanatory panel. */
.info-toggle {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid rgba(226, 214, 190, 0.16);
  border-radius: 0.5rem;
  background: rgba(10, 9, 8, 0.4);
  backdrop-filter: blur(12px);
  color: #e9dfca;
  cursor: pointer;
  pointer-events: auto;
  line-height: 1.1;
  transition: border-color 0.25s ease, background 0.25s ease, opacity 0.6s ease;
}

/* The veil is translucent, so the toggle would ghost through it. Keep it
   hidden until the visitor has entered the alley. */
body:not(.entered) .info-toggle {
  opacity: 0;
  pointer-events: none;
}

.info-toggle:hover {
  border-color: rgba(226, 214, 190, 0.4);
  background: rgba(20, 17, 14, 0.55);
}

.info-toggle span {
  font-size: 1rem;
  letter-spacing: 0.08em;
}

.info-toggle small {
  font-family: "Cinzel", Georgia, serif;
  font-size: 0.58rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(226, 214, 190, 0.55);
}

.info-panel {
  position: fixed;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(4, 3, 3, 0.72);
  backdrop-filter: blur(8px);
}

.info-panel[hidden] {
  display: none;
}

.info-panel__card {
  max-width: 34rem;
  padding: clamp(1.6rem, 4vw, 2.6rem);
  border: 1px solid rgba(226, 214, 190, 0.2);
  border-radius: 0.9rem;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 120, 60, 0.08), transparent 60%),
    rgba(12, 10, 9, 0.92);
  box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.55);
}

.info-panel__title {
  margin: 0;
  font-size: clamp(2rem, 6vw, 2.8rem);
  letter-spacing: 0.12em;
  color: #f4ead2;
  text-align: center;
  text-shadow: 0 0 1.6rem rgba(255, 120, 60, 0.3);
}

.info-panel__eyebrow {
  margin: 0.4rem 0 1.4rem;
  font-family: "Cinzel", Georgia, serif;
  font-size: clamp(0.72rem, 1.8vw, 0.86rem);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  text-align: center;
  color: rgba(226, 214, 190, 0.6);
}

.info-panel__card p {
  margin: 0 0 1rem;
  font-size: clamp(0.92rem, 2vw, 1.02rem);
  line-height: 1.62;
  color: #e6dcc7;
}

.info-panel__card em {
  font-style: normal;
  color: #f6c98a;
}

.info-panel__close {
  display: block;
  margin: 1.4rem auto 0;
}

@keyframes veilPulse {
  0%, 100% { opacity: 0.78; }
  50% { opacity: 1; }
}

/* Matches the 700px breakpoint where the 3D scene enters narrow mode. */
@media (max-width: 700px) {
  .console {
    width: calc(100vw - 1.2rem - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  }

  .transcript {
    max-height: min(11rem, 30svh);
  }

  .line {
    max-width: calc(100vw - 2.4rem);
  }
}
