:root {
  --bg-0: #050714;
  --bg-1: #0d0a1f;
  --bg-2: #1a1133;
  --ink: #f5e9d3;
  --ink-dim: #a89e8d;
  --ink-faint: #6e7993;
  --ink-very-faint: #3d4258;
  --gold: #d4a574;
  --gold-bright: #f0cc88;
  --rose: #e8b4c0;
  --rose-bright: #f5cdd5;
  --crimson: #b56773;
  --hairline: rgba(245, 233, 211, 0.08);
  --hairline-strong: rgba(245, 233, 211, 0.16);

  --serif: 'EB Garamond', Georgia, serif;
  --display: 'Cormorant Garamond', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

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

html, body { min-height: 100%; width: 100%; }

body {
  background:
    radial-gradient(ellipse 90% 60% at 50% 0%, var(--bg-2) 0%, transparent 60%),
    radial-gradient(ellipse 60% 70% at 50% 100%, #1a0a2e 0%, transparent 70%),
    var(--bg-0);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  position: relative;
  overflow-x: hidden;
  min-height: 100vh;
}

body::before {
  content: '';
  position: fixed; inset: 0;
  background-image:
    radial-gradient(1.2px 1.2px at 13% 22%, rgba(255,255,255,0.55), transparent 50%),
    radial-gradient(1px 1px at 87% 14%, rgba(255,255,255,0.4), transparent 50%),
    radial-gradient(1.4px 1.4px at 42% 78%, rgba(255,255,255,0.5), transparent 50%),
    radial-gradient(1px 1px at 67% 41%, rgba(255,255,255,0.35), transparent 50%),
    radial-gradient(1px 1px at 23% 60%, rgba(255,255,255,0.4), transparent 50%),
    radial-gradient(1.2px 1.2px at 91% 73%, rgba(255,255,255,0.45), transparent 50%),
    radial-gradient(0.8px 0.8px at 33% 11%, rgba(255,255,255,0.3), transparent 50%),
    radial-gradient(1px 1px at 78% 87%, rgba(255,255,255,0.35), transparent 50%),
    radial-gradient(0.9px 0.9px at 8% 84%, rgba(255,255,255,0.4), transparent 50%),
    radial-gradient(1.1px 1.1px at 56% 32%, rgba(255,255,255,0.32), transparent 50%),
    radial-gradient(0.8px 0.8px at 49% 91%, rgba(255,255,255,0.3), transparent 50%),
    radial-gradient(1px 1px at 4% 38%, rgba(255,255,255,0.4), transparent 50%);
  pointer-events: none;
  z-index: 0;
  animation: twinkle 8s ease-in-out infinite alternate;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

body::after {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.5 0'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='0.5'/></svg>");
  opacity: 0.04;
  mix-blend-mode: overlay;
  pointer-events: none;
  z-index: 1;
}

#app {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
}

.smallcaps {
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 11px;
  font-family: var(--serif);
  font-weight: 500;
  color: var(--ink-faint);
}

.italic-display {
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
}

/* ====================== INTRO ====================== */
.intro {
  max-width: 580px;
  text-align: center;
  animation: rise 1.2s cubic-bezier(.2,.7,.2,1);
}

@keyframes rise {
  0% { opacity: 0; transform: translateY(14px); }
  100% { opacity: 1; transform: translateY(0); }
}

.intro__orbs {
  width: 220px;
  height: 90px;
  margin: 0 auto 28px;
  position: relative;
}

.orb {
  position: absolute;
  width: 64px; height: 64px;
  border-radius: 50%;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}

.orb--gold {
  background: radial-gradient(circle at 30% 30%, var(--gold-bright), var(--gold) 50%, #6b4a26 100%);
  box-shadow:
    0 0 30px rgba(212, 165, 116, 0.5),
    0 0 60px rgba(212, 165, 116, 0.25),
    inset -8px -8px 16px rgba(0,0,0,0.3);
}

.orb--rose {
  background: radial-gradient(circle at 30% 30%, var(--rose-bright), var(--rose) 50%, #6f3d4c 100%);
  box-shadow:
    0 0 30px rgba(232, 180, 192, 0.45),
    0 0 60px rgba(232, 180, 192, 0.22),
    inset -8px -8px 16px rgba(0,0,0,0.3);
}

.intro .orb--gold { left: calc(50% - 50px); animation: drift 4s ease-in-out infinite alternate; }
.intro .orb--rose { left: calc(50% + 50px); animation: drift 4s ease-in-out infinite alternate-reverse; }

@keyframes drift {
  0% { transform: translate(-50%, -50%) scale(1); }
  100% { transform: translate(-50%, -55%) scale(1.04); }
}

.intro h1 {
  font-family: var(--display);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(56px, 10vw, 96px);
  line-height: 0.95;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
  color: var(--ink);
  text-shadow: 0 0 40px rgba(245, 233, 211, 0.15);
}

.intro h1 em {
  font-style: normal;
  color: var(--gold);
}

.intro__tag {
  margin-bottom: 32px;
}

.intro__lede {
  font-family: var(--display);
  font-style: italic;
  font-size: 22px;
  color: var(--ink-dim);
  margin-bottom: 36px;
  line-height: 1.45;
}

.intro__rules {
  display: inline-block;
  text-align: left;
  margin: 0 auto 40px;
  color: var(--ink-faint);
  font-size: 15px;
  line-height: 1.9;
  border-left: 1px solid var(--hairline-strong);
  padding-left: 18px;
}

.intro__rules strong {
  color: var(--ink-dim);
  font-weight: 500;
}

.intro__footer {
  margin-top: 36px;
  font-family: var(--display);
  font-style: italic;
  font-size: 14px;
  color: var(--ink-very-faint);
}

/* ====================== Buttons ====================== */
.btn {
  background: transparent;
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  font-family: var(--serif);
  font-size: 14px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  padding: 16px 38px;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(.2,.7,.2,1);
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--gold);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.4s cubic-bezier(.2,.7,.2,1);
  z-index: -1;
}

.btn:hover {
  color: var(--bg-0);
  background: var(--gold);
  box-shadow: 0 0 40px rgba(212, 165, 116, 0.4);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg-0), 0 0 0 4px var(--gold);
}

.btn:active { transform: scale(0.98); }

.btn--ghost {
  border-color: var(--hairline-strong);
  color: var(--ink-faint);
  font-size: 12px;
  padding: 12px 24px;
}

.btn--ghost:hover {
  background: transparent;
  border-color: var(--ink-dim);
  color: var(--ink);
  box-shadow: none;
}

/* ====================== SEARCHING ====================== */
.searching {
  text-align: center;
  max-width: 480px;
}

.searching__orb-wrap {
  width: 140px;
  height: 140px;
  margin: 0 auto 40px;
  position: relative;
}

.searching__orb {
  width: 100%; height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--gold-bright), var(--gold) 50%, #4d3220 100%);
  box-shadow:
    0 0 60px rgba(212, 165, 116, 0.5),
    0 0 120px rgba(212, 165, 116, 0.25);
  animation: pulseSearch 2.4s ease-in-out infinite;
}

@keyframes pulseSearch {
  0%, 100% { transform: scale(0.92); opacity: 0.85; }
  50% { transform: scale(1.04); opacity: 1; }
}

.searching__rings {
  position: absolute;
  inset: -40px;
  border-radius: 50%;
  border: 1px solid rgba(212, 165, 116, 0.2);
  animation: ringExpand 3s ease-out infinite;
}
.searching__rings:nth-child(2) { animation-delay: 1s; }
.searching__rings:nth-child(3) { animation-delay: 2s; }

@keyframes ringExpand {
  0% { transform: scale(0.6); opacity: 0.7; }
  100% { transform: scale(1.4); opacity: 0; }
}

.searching__title {
  font-family: var(--display);
  font-style: italic;
  font-size: 30px;
  color: var(--ink);
  margin-bottom: 18px;
  line-height: 1.3;
}

.searching__sub {
  color: var(--ink-faint);
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 32px;
}

.searching__time {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-very-faint);
  letter-spacing: 0.1em;
}

/* ====================== GAME ====================== */
.game {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 32px;
  padding-top: 12px;
}

.game__top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}

.player-card {
  flex: 1;
  text-align: center;
}

.player-card__orb {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  margin: 0 auto 10px;
  position: relative;
  transition: all 0.6s cubic-bezier(.2,.7,.2,1);
}

.player-card--you .player-card__orb {
  background: radial-gradient(circle at 30% 30%, var(--gold-bright), var(--gold) 50%, #4d3220 100%);
  box-shadow: 0 0 24px rgba(212, 165, 116, 0.5), 0 0 50px rgba(212, 165, 116, 0.2);
}

.player-card--them .player-card__orb {
  background: radial-gradient(circle at 30% 30%, var(--rose-bright), var(--rose) 50%, #4d2932 100%);
  box-shadow: 0 0 24px rgba(232, 180, 192, 0.5), 0 0 50px rgba(232, 180, 192, 0.2);
}

.player-card__orb.thinking {
  animation: thinking 1.6s ease-in-out infinite;
}
@keyframes thinking {
  0%, 100% { transform: scale(0.92); opacity: 0.7; }
  50% { transform: scale(1.04); opacity: 1; }
}

.player-card__orb.submitted::after {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 1px solid currentColor;
  color: var(--ink-faint);
  opacity: 0.5;
  animation: confirmRing 0.8s cubic-bezier(.2,.7,.2,1);
}

@keyframes confirmRing {
  0% { transform: scale(0.7); opacity: 0; }
  50% { opacity: 0.7; }
  100% { transform: scale(1.2); opacity: 0; }
}

.player-card__label {
  font-family: var(--display);
  font-style: italic;
  font-size: 17px;
  color: var(--ink-dim);
}

.player-card__status {
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-very-faint);
  margin-top: 4px;
  height: 14px;
}

.game__center {
  text-align: center;
  flex-shrink: 0;
  padding: 0 8px;
}

.round-counter {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-very-faint);
  letter-spacing: 0.18em;
}

.round-prompt {
  font-family: var(--display);
  font-style: italic;
  font-size: 18px;
  color: var(--ink-dim);
  margin-top: 6px;
  max-width: 220px;
}

/* ====================== Chain of rounds ====================== */
.chain {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  padding: 8px 0;
}

.chain:empty { display: none; }

.chain__row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  width: 100%;
  max-width: 520px;
  animation: revealRow 0.7s cubic-bezier(.2,.7,.2,1);
}

@keyframes revealRow {
  0% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

.chain__word {
  font-family: var(--display);
  font-style: italic;
  font-size: 26px;
  line-height: 1.2;
}
.chain__word--you {
  color: var(--gold-bright);
  text-align: right;
}
.chain__word--them {
  color: var(--rose-bright);
  text-align: left;
}

.chain__number {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-very-faint);
  letter-spacing: 0.15em;
  width: 28px;
  text-align: center;
}

/* ====================== Input area ====================== */
.input-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 32px 0 16px;
  border-top: 1px solid var(--hairline);
}

.input-area__prompt {
  font-family: var(--display);
  font-style: italic;
  font-size: 22px;
  color: var(--ink);
  text-align: center;
  line-height: 1.4;
  max-width: 420px;
}

.input-area__hint {
  font-size: 13px;
  color: var(--ink-faint);
  font-style: italic;
  text-align: center;
  max-width: 380px;
  line-height: 1.5;
}

.word-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--hairline-strong);
  color: var(--gold-bright);
  font-family: var(--display);
  font-style: italic;
  font-size: 36px;
  text-align: center;
  padding: 12px 8px;
  width: min(100%, 360px);
  outline: none;
  transition: border-color 0.3s;
  letter-spacing: 0.01em;
}

.word-input::placeholder {
  color: var(--ink-very-faint);
  font-style: italic;
}

.word-input:focus {
  border-bottom-color: var(--gold);
}

.input-area__btn-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.waiting-line {
  font-family: var(--display);
  font-style: italic;
  font-size: 20px;
  color: var(--ink-dim);
  text-align: center;
  padding: 24px 0;
  animation: breath 3s ease-in-out infinite;
}

@keyframes breath {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.your-pending-word {
  font-family: var(--display);
  font-style: italic;
  font-size: 28px;
  color: var(--gold);
  text-align: center;
  padding: 4px 0 0;
}

/* ====================== Meld ====================== */
.meld {
  text-align: center;
  max-width: 540px;
  animation: meldRise 1s cubic-bezier(.2,.7,.2,1);
}

@keyframes meldRise {
  0% { opacity: 0; transform: translateY(20px) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.meld__orb {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  margin: 0 auto 32px;
  background:
    radial-gradient(circle at 30% 30%,
      rgba(255, 255, 255, 0.95) 0%,
      var(--gold-bright) 25%,
      var(--rose-bright) 60%,
      var(--gold) 100%);
  box-shadow:
    0 0 80px rgba(255, 240, 200, 0.7),
    0 0 160px rgba(232, 180, 192, 0.4),
    0 0 240px rgba(212, 165, 116, 0.25);
  animation: meldGlow 3.5s ease-in-out infinite;
  position: relative;
}

@keyframes meldGlow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.meld__label {
  margin-bottom: 24px;
}

.meld__word {
  font-family: var(--display);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(60px, 12vw, 110px);
  line-height: 1;
  color: var(--ink);
  margin-bottom: 28px;
  text-shadow: 0 0 50px rgba(245, 233, 211, 0.25);
}

.meld__detail {
  font-family: var(--display);
  font-style: italic;
  font-size: 19px;
  color: var(--ink-dim);
  margin-bottom: 36px;
  line-height: 1.6;
}

.meld__journey {
  margin: 28px 0 36px;
  padding: 20px 0;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  font-family: var(--display);
  font-style: italic;
  color: var(--ink-faint);
  font-size: 17px;
  line-height: 1.9;
}

.meld__journey b {
  color: var(--gold-bright);
  font-weight: 400;
}

.meld__journey i {
  color: var(--rose-bright);
  font-style: italic;
}

.meld__journey-arrow {
  color: var(--ink-very-faint);
  margin: 0 8px;
}

.meld__share {
  margin-top: 24px;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-very-faint);
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--serif);
  transition: color 0.3s;
}
.meld__share:hover { color: var(--ink-dim); }
.meld__share.copied { color: var(--gold); }

/* ====================== Toast / status pill ====================== */
.pill {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  background: rgba(13, 10, 31, 0.85);
  backdrop-filter: blur(10px);
  border: 1px solid var(--hairline-strong);
  color: var(--ink-dim);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 8px 18px;
  border-radius: 100px;
  pointer-events: none;
  max-width: calc(100% - 32px);
  text-align: center;
  animation: pillIn 0.4s cubic-bezier(.2,.7,.2,1);
}

@keyframes pillIn {
  0% { opacity: 0; transform: translate(-50%, -10px); }
  100% { opacity: 1; transform: translate(-50%, 0); }
}

.pill .dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gold);
  margin-right: 8px;
  vertical-align: middle;
  animation: blink 1.6s ease-in-out infinite;
}
.pill--ai .dot { background: var(--rose); }

@keyframes blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

.sparkle {
  position: absolute;
  width: 4px; height: 4px;
  background: var(--ink);
  border-radius: 50%;
  pointer-events: none;
  animation: sparkleFly 1.6s ease-out forwards;
}

@keyframes sparkleFly {
  0% { opacity: 1; transform: translate(0,0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.3); }
}

.fade-in { animation: fadeIn 0.6s ease-out; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 600px) {
  body { font-size: 16px; }
  .intro h1 { font-size: 64px; }
  .game { gap: 24px; }
  .chain__word { font-size: 22px; }
  .word-input { font-size: 30px; }
  .input-area__prompt { font-size: 20px; }
  .meld__word { font-size: 64px; }
  .game__top { gap: 12px; }
  .player-card__orb { width: 48px; height: 48px; }
  .player-card__label { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
