:root {
  --bg-1: #06080e;
  --bg-2: #090b13;
  --bg-3: #12121a;
  --ink: #f4ede1;
  --muted: rgba(244, 237, 225, 0.56);
  --accent: #e7d6b9;
  --accent-strong: #f4e5cb;
  --error: #ffb7ab;
  --width: 480px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 100%;
  font-size: 16px;
  background: #06080e;
  overflow-x: clip;
}

body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  color: var(--ink);
  background-color: var(--bg-1);
  background:
    radial-gradient(circle at 50% -10%, rgba(136, 167, 230, 0.12), transparent 30%),
    radial-gradient(circle at 50% 120%, rgba(0, 0, 0, 0.78), transparent 32%),
    linear-gradient(180deg, var(--bg-3) 0%, var(--bg-2) 42%, var(--bg-1) 100%);
  font-family: Georgia, "Times New Roman", serif;
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  position: relative;
  width: 100%;
  max-width: none;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(1.25rem, calc(env(safe-area-inset-top) + 0.25rem))
    clamp(0.75rem, 3vw, 1rem)
    max(1.45rem, calc(env(safe-area-inset-bottom) + 0.25rem));
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: clip;
}

.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.haze {
  position: absolute;
  inset: 0;
  opacity: 0.42;
  background:
    radial-gradient(circle at 50% 34%, rgba(102, 143, 228, 0.1), transparent 18%),
    radial-gradient(circle at 50% 78%, rgba(244, 218, 176, 0.05), transparent 16%);
}

.haze-a {
  transform: translateY(0);
}

.haze-b {
  opacity: 0.22;
  background:
    radial-gradient(circle at 50% 50%, rgba(92, 126, 196, 0.08), transparent 24%);
}

.stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 14% 22%, rgba(255, 255, 255, 0.22) 0 1px, transparent 1.5px),
    radial-gradient(circle at 72% 18%, rgba(255, 255, 255, 0.18) 0 1px, transparent 1.5px),
    radial-gradient(circle at 62% 34%, rgba(255, 255, 255, 0.12) 0 1px, transparent 1.5px),
    radial-gradient(circle at 28% 64%, rgba(255, 255, 255, 0.14) 0 1px, transparent 1.5px),
    radial-gradient(circle at 80% 72%, rgba(255, 255, 255, 0.16) 0 1px, transparent 1.5px);
  opacity: 0.45;
}

.chrome,
.vision,
.invocation {
  position: relative;
  z-index: 1;
}

.chrome {
  width: min(100%, 36rem);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
}

.result-heading,
.error,
.cast-label,
.digit-input,
.dataset-select {
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.dataset-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.oracle-switch {
  flex: 1 1 auto;
  min-width: 0;
}

.source-switch {
  flex: 0 0 clamp(8.5rem, 28vw, 10.5rem);
}

.source-switch .dataset-select {
  padding-left: 0.78rem;
  padding-right: 1.7rem;
  font-size: 0.59rem;
  letter-spacing: 0.1em;
}

.source-switch::after {
  right: 0.64rem;
  font-size: 0.66rem;
}

.dataset-switch::after {
  content: "▾";
  position: absolute;
  right: 0.8rem;
  color: rgba(244, 237, 225, 0.56);
  font-size: 0.72rem;
  pointer-events: none;
}

.dataset-select {
  width: 100%;
  border: 1px solid rgba(244, 237, 225, 0.14);
  border-radius: 999px;
  padding: 0.5rem 2rem 0.5rem 0.9rem;
  color: rgba(244, 237, 225, 0.72);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.015)),
    rgba(7, 10, 18, 0.5);
  font-size: 0.64rem;
  line-height: 1;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.dataset-select:hover,
.dataset-select:focus-visible {
  border-color: rgba(244, 237, 225, 0.24);
  color: rgba(244, 237, 225, 0.92);
  outline: none;
}

.vision {
  --focus-size: min(78vw, 24rem);
  --focus-offset-y: -46%;
  width: 100%;
  display: grid;
  place-items: center;
  padding: 1.15rem 0 0.25rem;
}

.aura {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--focus-size);
  height: var(--focus-size);
  transform: translate(-50%, var(--focus-offset-y));
  pointer-events: none;
}

.aura-ring {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 999px;
}

.aura-ring-a {
  width: 124%;
  height: 124%;
  background:
    radial-gradient(
      circle,
      rgba(74, 112, 192, 0.12) 0%,
      rgba(74, 112, 192, 0.065) 24%,
      rgba(74, 112, 192, 0.024) 46%,
      rgba(74, 112, 192, 0.008) 62%,
      transparent 78%
    );
  opacity: 0.34;
  animation: breathe 10s ease-in-out infinite;
  will-change: transform, opacity;
}

.aura-ring-b {
  width: 92%;
  height: 92%;
  background:
    radial-gradient(
      circle,
      rgba(232, 213, 179, 0.05) 0%,
      rgba(232, 213, 179, 0.02) 28%,
      rgba(232, 213, 179, 0.008) 48%,
      transparent 68%
    );
  opacity: 0.18;
  animation: breathe 6.8s ease-in-out infinite reverse;
  will-change: transform, opacity;
}

.result-heading[hidden] {
  display: none;
}

.result-card {
  position: relative;
  width: min(100%, 28rem);
  min-height: min(56vh, 34rem);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.8rem 1.15rem 1.2rem;
}

.result-card::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--focus-size);
  height: var(--focus-size);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 36%, rgba(255, 255, 255, 0.035), transparent 24%),
    radial-gradient(circle at 50% 60%, rgba(76, 112, 183, 0.12), transparent 28%),
    radial-gradient(circle at 50% 70%, rgba(0, 0, 0, 0.58), transparent 64%);
  opacity: 0.78;
  transform: translate(-50%, var(--focus-offset-y));
  animation: focus-breathe 11s ease-in-out infinite;
  will-change: transform, opacity;
}

.result-card.is-active::before {
  animation: focus-breathe-active 9s ease-in-out infinite;
}

.result-card::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(var(--focus-size) * 0.78);
  height: calc(var(--focus-size) * 0.78);
  border-radius: 50%;
  background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, 0.06) 50%, transparent 70%);
  opacity: 0.12;
  transform: translate(-62%, calc(var(--focus-offset-y) + 2%));
  animation: veil 12s ease-in-out infinite;
}

.empty-state,
.translation,
.result-meta,
.greek,
.citation,
.status-note {
  position: relative;
  z-index: 1;
  text-align: center;
}

.empty-state {
  max-width: 16rem;
  margin: 0;
  color: rgba(244, 237, 225, 0.44);
  font-size: 0.95rem;
  line-height: 1.65;
}

.translation {
  max-width: 15ch;
  margin: 0;
  font-size: clamp(1.96rem, 6.9vw, 3.3rem);
  line-height: 1.06;
  text-wrap: balance;
  overflow-wrap: anywhere;
  text-shadow: 0 0 18px rgba(244, 237, 225, 0.03);
  animation: surface 560ms ease;
}

.result-card.is-mary .translation {
  max-width: 22ch;
  font-size: clamp(1.26rem, 4.15vw, 1.95rem);
  line-height: 1.24;
}

.result-card.is-mary .result-meta {
  margin-top: 0.45rem;
}

.result-card.is-mary .citation,
.result-card.is-mary .status-note {
  max-width: 18rem;
}

.result-meta {
  display: grid;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.greek {
  max-width: 19rem;
  margin: 0 auto;
  color: rgba(244, 237, 225, 0.68);
  font-size: 0.86rem;
  line-height: 1.42;
  animation: surface 700ms ease;
}

.citation,
.status-note {
  max-width: 16rem;
  margin: 0 auto;
  color: rgba(244, 237, 225, 0.44);
  font-size: 0.78rem;
  line-height: 1.4;
  animation: surface 860ms ease;
}

.status-note {
  padding-top: 0.15rem;
}

.invocation {
  --cast-size: min(11rem, 48vw);
  --cast-ring-offset: 22%;
  width: min(100%, 18rem);
  margin: 0 auto;
  display: grid;
  gap: 1rem;
  padding-top: 0.25rem;
}

.cast-button {
  position: relative;
  width: var(--cast-size);
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.2), transparent 18%),
    radial-gradient(circle at 50% 50%, rgba(228, 208, 177, 0.12), transparent 54%),
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0) 62%);
  box-shadow:
    0 0 40px rgba(90, 127, 205, 0.08),
    inset 0 0 34px rgba(255, 255, 255, 0.04);
  cursor: pointer;
  animation: cast-breathe 8.4s ease-in-out infinite;
  will-change: transform, opacity;
}

.cast-button::before,
.cast-button::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  top: 50%;
  left: 50%;
}

.cast-button::before {
  width: 116%;
  height: 116%;
  background:
    radial-gradient(
      circle,
      rgba(244, 237, 225, 0.06) 0%,
      rgba(244, 237, 225, 0.02) 26%,
      rgba(244, 237, 225, 0.008) 46%,
      transparent 68%
    );
  transform: translate(-50%, -50%);
  opacity: 0.34;
}

.cast-button::after {
  width: 132%;
  height: 132%;
  background:
    radial-gradient(
      circle,
      rgba(97, 131, 203, 0.08) 0%,
      rgba(97, 131, 203, 0.028) 24%,
      rgba(97, 131, 203, 0.01) 42%,
      transparent 66%
    );
  transform: translate(-50%, -50%);
  opacity: 0.26;
  animation: ring 4.4s ease-in-out infinite;
}

.cast-core {
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(100% - (var(--cast-ring-offset) * 2));
  height: calc(100% - (var(--cast-ring-offset) * 2));
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 38%, rgba(255, 255, 255, 0.18), transparent 18%),
    radial-gradient(circle at 50% 60%, rgba(19, 24, 39, 0.98), rgba(5, 7, 12, 1) 74%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -14px 20px rgba(0, 0, 0, 0.32);
  transform: translate(-50%, -50%);
  animation: core-breathe 8.4s ease-in-out infinite;
  will-change: transform, opacity;
}

.cast-label {
  position: relative;
  z-index: 1;
  color: var(--accent);
  font-size: 0.8rem;
}

.cast-button:focus-visible,
.digit-input:focus-visible {
  outline: 2px solid rgba(229, 208, 173, 0.34);
  outline-offset: 4px;
}

.manual-form {
  display: grid;
  gap: 0.55rem;
}

.slots {
  display: flex;
  justify-content: center;
  gap: 0.9rem;
}

.slot {
  position: relative;
  width: 2.8rem;
  height: 2.9rem;
}

.slot::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.25rem;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(244, 237, 225, 0.34), transparent);
}

.digit-input {
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  color: rgba(244, 237, 225, 0.74);
  font-size: 1.05rem;
  text-align: center;
  caret-color: transparent;
  appearance: none;
  -webkit-appearance: none;
}

.digit-input::placeholder {
  color: rgba(244, 237, 225, 0.22);
  opacity: 1;
}

.slot.is-rolling {
  animation: flicker 280ms ease;
}

.error {
  min-height: 0.9rem;
  margin: 0;
  color: var(--error);
  font-size: 0.72rem;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes breathe {
  0%,
  100% {
    transform: scale(0.98);
    opacity: 0.75;
  }

  50% {
    transform: scale(1.03);
    opacity: 1;
  }
}

@keyframes focus-breathe {
  0%,
  100% {
    transform: translate(-50%, var(--focus-offset-y)) scale(0.985);
    opacity: 0.72;
  }

  50% {
    transform: translate(-50%, var(--focus-offset-y)) scale(1.01);
    opacity: 0.82;
  }
}

@keyframes focus-breathe-active {
  0%,
  100% {
    transform: translate(-50%, var(--focus-offset-y)) scale(1);
    opacity: 0.76;
  }

  50% {
    transform: translate(-50%, var(--focus-offset-y)) scale(1.03);
    opacity: 0.86;
  }
}

@keyframes cast-breathe {
  0%,
  100% {
    transform: translateY(0) scale(0.992);
    opacity: 0.94;
  }

  50% {
    transform: translateY(-1px) scale(1.012);
    opacity: 1;
  }
}

@keyframes core-breathe {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(0.985);
    opacity: 0.96;
  }

  50% {
    transform: translate(-50%, -50%) scale(1.015);
    opacity: 1;
  }
}

@keyframes ring {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.45;
  }

  50% {
    transform: translate(-50%, -50%) scale(1.05);
    opacity: 0.15;
  }
}

@keyframes veil {
  0%,
  100% {
    transform: translate(-62%, calc(var(--focus-offset-y) + 2%));
  }

  50% {
    transform: translate(-38%, calc(var(--focus-offset-y) + 2%));
  }
}

@keyframes surface {
  0% {
    opacity: 0;
    transform: translateY(16px) scale(0.985);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes flicker {
  0% {
    transform: translateY(0);
    opacity: 1;
  }

  50% {
    transform: translateY(-2px);
    opacity: 0.8;
  }

  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .haze-a,
  .haze-b,
  .aura-ring-a,
  .aura-ring-b,
  .result-card::before,
  .cast-button::after,
  .cast-button,
  .cast-core,
  .result-card::after,
  .translation,
  .greek,
  .citation,
  .status-note,
  .slot.is-rolling {
    animation: none;
  }
}

@media (max-width: 640px) {
  .chrome {
    width: 100%;
    gap: 0.55rem;
  }

  .oracle-switch {
    flex-basis: auto;
  }

  .source-switch {
    flex-basis: clamp(7.4rem, 31vw, 8.8rem);
  }

  .dataset-select {
    padding-left: 0.8rem;
    padding-right: 1.85rem;
    font-size: 0.6rem;
  }

  .oracle-switch .dataset-select {
    padding-left: 0.7rem;
    padding-right: 1.55rem;
    font-size: 0.56rem;
    letter-spacing: 0.11em;
  }

  .oracle-switch::after {
    right: 0.68rem;
    font-size: 0.66rem;
  }

  .source-switch .dataset-select {
    padding-left: 0.66rem;
    padding-right: 1.45rem;
    font-size: 0.52rem;
    letter-spacing: 0.08em;
  }

  .source-switch::after {
    right: 0.54rem;
    font-size: 0.6rem;
  }

  .stage {
    padding:
      max(0.95rem, calc(env(safe-area-inset-top) + 0.2rem))
      0.75rem
      max(1.2rem, calc(env(safe-area-inset-bottom) + 0.2rem));
  }

  .result-card {
    width: 100%;
    min-height: 54vh;
    min-height: 52vh;
    padding: 1.15rem 1.05rem 1rem;
  }

  .vision {
    --focus-size: min(84vw, 22rem);
    --focus-offset-y: -40%;
  }

  .translation {
    max-width: 14ch;
    font-size: clamp(1.7rem, 7.05vw, 2.6rem);
    line-height: 1.05;
  }

  .result-card.is-mary .translation {
    max-width: 18ch;
    font-size: clamp(1.08rem, 4.85vw, 1.46rem);
    line-height: 1.28;
  }

  .result-meta,
  .empty-state {
    max-width: 16rem;
  }

  .haze-a,
  .haze-b,
  .aura-ring-b,
  .result-card::after,
  .cast-button::after {
    animation: none;
  }
}

@media (max-height: 820px) {
  .stage {
    padding:
      max(0.75rem, calc(env(safe-area-inset-top) + 0.15rem))
      clamp(0.75rem, 3vw, 1rem)
      max(0.9rem, calc(env(safe-area-inset-bottom) + 0.15rem));
  }

  .vision {
    padding-top: 0.5rem;
    padding-bottom: 0;
  }

  .result-card {
    min-height: min(46vh, 25rem);
    padding-top: 1rem;
    padding-bottom: 0.5rem;
  }

  .invocation {
    gap: 0.7rem;
    padding-top: 0;
  }

  .cast-button {
    width: min(9.5rem, 42vw);
  }

  .result-card.is-mary .translation {
    max-width: 19ch;
    font-size: clamp(1rem, 4.2vw, 1.34rem);
    line-height: 1.22;
  }
}

@media (max-height: 720px) {
  .result-card {
    min-height: min(40vh, 21rem);
    padding-top: 0.75rem;
    padding-bottom: 0.35rem;
  }

  .result-card.is-mary .translation {
    max-width: 20ch;
    font-size: clamp(0.96rem, 3.85vw, 1.2rem);
    line-height: 1.18;
  }

  .result-card.is-mary .result-meta {
    margin-top: 0.3rem;
  }

  .invocation {
    gap: 0.45rem;
  }

  .cast-button {
    width: min(8.5rem, 38vw);
  }
}
