:root {
  --night: #0f1d24;
  --slate: #22343d;
  --bone: #e9e0cc;
  --lichen: #a3b5a0;
  --neon-soft: rgba(47, 201, 237, 0.45);
  --neon-glow: 0 0 6px rgba(47, 201, 237, 0.9), 0 0 18px rgba(47, 201, 237, 0.55);
  --jade: #9dc2ae;
  --neon: #2fc9ed;
  --ember: #e38a6d;

  --serif: 'Alegreya', Georgia, serif;
  --display: 'Uncial Antiqua', 'Alegreya', serif;
  --runic: 'Noto Sans Runic', 'Segoe UI Historic', sans-serif;

  --panel: min(420px, 38vw);
  --gutter: clamp(16px, 4vw, 56px);
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--night);
  color: var(--bone);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
}

.ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
}
.ui > * { pointer-events: auto; }

/* ---------- ask panel ---------- */
.ask {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: calc(var(--panel) + var(--gutter) * 2);
  padding: clamp(24px, 5vh, 64px) var(--gutter);
  overflow-y: auto;
  background: linear-gradient(90deg, rgba(15, 29, 36, 0.94) 0%, rgba(15, 29, 36, 0.8) 62%, rgba(15, 29, 36, 0) 100%);
  transition: opacity 0.5s ease, transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.ask > * { max-width: var(--panel); }
.ask.away {
  opacity: 0;
  transform: translateX(-24px);
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.5s ease, transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1), visibility 0s linear 0.6s;
}

.wordmark {
  margin: 0;
  line-height: 0;
}
.wordmark-svg {
  width: clamp(200px, 22vw, 320px);
  height: auto;
  overflow: visible;
}
.carve path {
  stroke: var(--bone);
  stroke-width: 9;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: carve 0.9s cubic-bezier(0.6, 0, 0.3, 1) forwards;
  animation-delay: calc(var(--i) * 90ms + 200ms);
}
.carve {
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.6));
  animation: ignite 1.6s ease-out 1.3s forwards;
}
@keyframes carve { to { stroke-dashoffset: 0; } }
/* Neon catches like a tube warming up: flicker, then hold. */
@keyframes ignite {
  0% { filter: drop-shadow(0 2px 0 rgba(0,0,0,.6)); }
  10% { filter: drop-shadow(0 0 8px rgba(47,201,237,.9)) drop-shadow(0 0 22px rgba(47,201,237,.5)); }
  16% { filter: drop-shadow(0 2px 0 rgba(0,0,0,.6)); }
  24%, 100% { filter: drop-shadow(0 0 6px rgba(47,201,237,.75)) drop-shadow(0 0 20px rgba(47,201,237,.35)); }
}

.futhark {
  font-family: var(--runic);
  color: var(--neon);
  text-shadow: var(--neon-glow);
  letter-spacing: 0.5em;
  margin: 0.6rem 0 0;
  font-size: 1rem;
  opacity: 0.85;
}

.lede {
  margin: 1.1rem 0 1.5rem;
  font-size: 1.12rem;
  color: var(--bone);
  opacity: 0.85;
  max-width: 34ch;
}

.field-label {
  display: block;
  font-style: italic;
  color: var(--lichen);
  font-size: 0.98rem;
  margin: 0 0 0.45rem;
  padding: 0;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 4.4em;
  font: inherit;
  font-size: 1.1rem;
  line-height: 1.5;
  color: var(--bone);
  background: rgba(34, 52, 61, 0.55);
  border: 1px solid rgba(163, 181, 160, 0.3);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  transition: border-color 0.2s, background 0.2s;
}
textarea::placeholder { color: rgba(233, 224, 204, 0.38); font-style: italic; }
textarea:focus { outline: none; border-color: var(--neon); box-shadow: 0 0 0 3px rgba(47, 201, 237, 0.15); background: rgba(34, 52, 61, 0.8); }

.count {
  min-height: 1.2em;
  text-align: right;
  font-size: 0.82rem;
  color: var(--lichen);
  margin-top: 0.2rem;
}

.spreads {
  border: 0;
  margin: 0.3rem 0 1.3rem;
  padding: 0;
  display: grid;
  gap: 0.25rem;
}

.spread {
  display: grid;
  grid-template-columns: 44px 1fr;
  grid-template-rows: auto auto;
  column-gap: 0.9rem;
  align-items: center;
  padding: 0.4rem 0.7rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--lichen);
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.spread input { position: absolute; opacity: 0; pointer-events: none; }
.spread-map { grid-row: 1 / 3; }
.spread-name { font-size: 1.08rem; line-height: 1.25; }
.spread-hint { font-size: 0.88rem; opacity: 0.8; line-height: 1.3; }
.spread:hover { color: var(--bone); }
.spread:has(input:checked) {
  color: var(--bone);
  border-color: var(--neon-soft);
  background: rgba(47, 201, 237, 0.06);
}
.spread:has(input:focus-visible) { outline: 2px solid var(--neon); outline-offset: 2px; }

/* Tiny diagrams of where the stones will land. */
.spread-map {
  position: relative;
  width: 44px;
  height: 36px;
}
.spread-map i {
  position: absolute;
  width: 10px;
  height: 12px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.55;
  left: 17px;
  top: 12px;
}
.spread:has(input:checked) .spread-map i { background: var(--neon); opacity: 1; box-shadow: var(--neon-glow); }
[data-layout="norns"] i:nth-child(1) { left: 3px; }
[data-layout="norns"] i:nth-child(3) { left: 31px; }
[data-layout="cross"] i:nth-child(2) { left: 3px; }
[data-layout="cross"] i:nth-child(3) { left: 31px; }
[data-layout="cross"] i:nth-child(4) { top: 0; }
[data-layout="cross"] i:nth-child(5) { top: 24px; }

/* Two-way choices: digital bag or own runes, Elder or Younger. */
.toggle {
  border: 0;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}
.toggle legend { grid-column: 1 / -1; }
.toggle label { position: relative; display: flex; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle span {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0.55rem 0.8rem;
  border-radius: 10px;
  border: 1px solid rgba(163, 181, 160, 0.16);
  color: var(--lichen);
  font-size: 1rem;
  line-height: 1.25;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.toggle small { font-size: 0.8rem; opacity: 0.8; }
.toggle label:hover span { color: var(--bone); }
.toggle input:checked + span {
  color: var(--bone);
  border-color: var(--neon);
  background: rgba(47, 201, 237, 0.1);
  box-shadow: 0 0 12px rgba(47, 201, 237, 0.22);
}
.toggle input:focus-visible + span { outline: 2px solid var(--neon); outline-offset: 2px; }

/* Entering runes drawn from your own bag. */
.picker { margin: 0 0 1.2rem; }
.picker[hidden] { display: none; }
.slots {
  list-style: none;
  margin: 0 0 0.8rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.slot-wrap { display: grid; justify-items: center; gap: 0.3rem; }
.slot {
  appearance: none;
  width: 68px;
  display: grid;
  justify-items: center;
  gap: 0.2rem;
  padding: 0.3rem 0.2rem 0.35rem;
  background: none;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--lichen);
}
.slot-glyph {
  width: 42px;
  height: 50px;
  border-radius: 50% / 46%;
  display: grid;
  place-items: center;
  font-family: var(--runic);
  font-size: 1.5rem;
  border: 1.5px dashed rgba(163, 181, 160, 0.45);
}
.slot.filled .slot-glyph {
  border: 0;
  color: #dff8ff;
  background: radial-gradient(circle at 35% 30%, #c5ddcf, #8fb8a3 60%, #6f9985);
  text-shadow: 0 0 4px var(--neon), 0 0 12px var(--neon);
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.25);
}
.slot.reversed .slot-glyph { transform: rotate(180deg); }
.slot-pos { font-size: 0.78rem; line-height: 1.2; font-style: italic; text-align: center; }
.slot.filled .slot-pos { color: var(--bone); font-style: normal; }
.slot-wrap.active .slot { border-color: var(--neon-soft); background: rgba(47, 201, 237, 0.06); }
.slot-wrap.active .slot-glyph:empty { border-color: var(--neon); box-shadow: 0 0 10px rgba(47, 201, 237, 0.35); }
.slot:focus-visible, .flip:focus-visible, .rune-key:focus-visible { outline: 2px solid var(--neon); outline-offset: 2px; }
.flip {
  appearance: none;
  background: none;
  border: 1px solid rgba(233, 224, 204, 0.25);
  border-radius: 999px;
  color: var(--bone);
  font-size: 0.74rem;
  padding: 0.1rem 0.55rem;
}
.flip[aria-pressed="true"] { color: var(--ember); border-color: rgba(227, 138, 109, 0.6); }

.rune-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.25rem;
}
.rune-key {
  appearance: none;
  display: grid;
  justify-items: center;
  padding: 0.3rem 0 0.25rem;
  min-height: 44px;
  background: rgba(34, 52, 61, 0.5);
  border: 1px solid rgba(163, 181, 160, 0.18);
  border-radius: 8px;
  color: var(--bone);
  transition: border-color 0.15s, background 0.15s;
}
.key-glyph {
  font-family: var(--runic);
  font-size: 1.25rem;
  line-height: 1.2;
  color: var(--neon);
  text-shadow: 0 0 6px rgba(47, 201, 237, 0.6);
}
.key-name { font-size: 0.6rem; line-height: 1.1; color: var(--lichen); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.rune-key:hover:not(:disabled) { border-color: var(--neon-soft); background: rgba(47, 201, 237, 0.08); }
.rune-key:disabled { opacity: 0.28; cursor: default; }

button { font: inherit; cursor: pointer; }

.draw {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.8rem 1.8rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: #04212b;
  background: linear-gradient(180deg, #5fd8f3, var(--neon));
  box-shadow: 0 0 0 1px rgba(47, 201, 237, 0.5), 0 6px 28px rgba(47, 201, 237, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
}
.draw:hover { transform: translateY(-1px); box-shadow: 0 0 0 1px rgba(47, 201, 237, 0.7), 0 10px 36px rgba(47, 201, 237, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.45); }
.draw:active { transform: translateY(1px); }
.draw:disabled { opacity: 0.5; cursor: progress; transform: none; }
.draw:focus-visible, .quiet:focus-visible { outline: 2px solid var(--bone); outline-offset: 3px; }

.quiet {
  appearance: none;
  background: none;
  border: 1px solid rgba(233, 224, 204, 0.3);
  color: var(--bone);
  border-radius: 999px;
  padding: 0.75rem 1.4rem;
  font-size: 1rem;
  transition: border-color 0.2s;
}
.quiet:hover { border-color: var(--neon); color: var(--neon); }

.tip {
  margin: 0.9rem 0 0;
  font-size: 0.92rem;
  font-style: italic;
  color: var(--lichen);
}

/* ---------- reading panel ---------- */
.reading {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: calc(var(--panel) + 60px + var(--gutter));
  padding: clamp(28px, 6vh, 64px) var(--gutter) 48px 60px;
  overflow-y: auto;
  background: linear-gradient(270deg, rgba(15, 29, 36, 0.97) 0%, rgba(15, 29, 36, 0.95) calc(100% - 64px), rgba(15, 29, 36, 0) 100%);
  animation: slide-in 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  scrollbar-width: thin;
  scrollbar-color: var(--slate) transparent;
}
.reading[hidden] { display: none; }
@keyframes slide-in {
  from { opacity: 0; transform: translateX(28px); }
  to { opacity: 1; transform: none; }
}

.asked {
  margin: 0 0 1.4rem;
  font-size: 1.3rem;
  line-height: 1.35;
  font-style: italic;
  color: var(--bone);
}
.asked.none { color: var(--lichen); font-size: 1.1rem; }
.asked-runes {
  margin: -0.9rem 0 1.4rem;
  font-family: var(--runic);
  font-size: 0.95rem;
  line-height: 1.5;
  letter-spacing: 0.18em;
  color: var(--neon);
  text-shadow: var(--neon-glow);
  opacity: 0.85;
  overflow-wrap: anywhere;
}
.asked-runes:empty { display: none; }

.drawn {
  list-style: none;
  margin: 0 0 1.6rem;
  padding: 0;
  display: grid;
  gap: 0.2rem;
}
.drawn li {
  display: grid;
  grid-template-columns: 52px 1fr;
  column-gap: 0.9rem;
  align-items: center;
  padding: 0.55rem 0.6rem;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.2s, border-color 0.2s;
  opacity: 0;
  animation: rise 0.5s ease forwards;
}
.drawn li:hover, .drawn li:focus-visible { background: rgba(34, 52, 61, 0.6); outline: none; }
.drawn li.active { border-color: var(--neon-soft); background: rgba(47, 201, 237, 0.07); }
@keyframes rise { to { opacity: 1; } }

.rune-chip {
  grid-row: 1 / 4;
  width: 46px;
  height: 54px;
  border-radius: 50% / 46%;
  display: grid;
  place-items: center;
  font-family: var(--runic);
  font-size: 1.6rem;
  color: #dff8ff;
  background: radial-gradient(circle at 35% 30%, #c5ddcf, #8fb8a3 60%, #6f9985);
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.25), 0 3px 10px rgba(0, 0, 0, 0.35);
  text-shadow: 0 0 4px var(--neon), 0 0 12px var(--neon), 0 0 22px rgba(47, 201, 237, 0.6);
}
.rune-chip.reversed span { transform: rotate(180deg); display: inline-block; }
.pos { font-size: 0.86rem; color: var(--lichen); font-style: italic; line-height: 1.3; }
.name { font-size: 1.2rem; line-height: 1.3; color: var(--bone); }
.name .rev { font-size: 0.86rem; color: var(--ember); font-style: italic; margin-left: 0.35rem; }
.keys { font-size: 0.9rem; color: var(--bone); opacity: 0.7; line-height: 1.35; }

.interpretation {
  font-size: 1.08rem;
  line-height: 1.7;
  max-width: 62ch;
  min-height: 6rem;
}
.interpretation p { margin: 0 0 1em; }
.interpretation p:last-child { font-style: italic; color: var(--jade); }
.interpretation .reading-wait {
  color: var(--lichen);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.reading-wait .pulse {
  font-family: var(--runic);
  color: var(--neon);
  text-shadow: var(--neon-glow);
  letter-spacing: 0.3em;
  animation: breathe 1.8s ease-in-out infinite;
}
@keyframes breathe { 50% { opacity: 0.35; } }
.interpretation .fade-in { animation: rise 0.9s ease forwards; opacity: 0; }

.reading-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-top: 1.8rem;
}

/* ---------- drawing: the question up top, the next step below ---------- */
.stage-q, .hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: rgba(15, 29, 36, 0.72);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: 1px solid rgba(47, 201, 237, 0.28);
  border-radius: 999px;
  animation: pill-in 0.5s ease both;
}
.stage-q[hidden], .hint[hidden] { display: none; }
.stage-q { top: max(18px, env(safe-area-inset-top)); padding: 0.4rem 0.45rem 0.4rem 1.2rem; }
.stage-q-text { font-style: italic; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint { bottom: max(26px, calc(env(safe-area-inset-bottom) + 12px)); padding: 0.45rem 0.45rem 0.45rem 1.3rem; font-size: 1.02rem; white-space: nowrap; }
.hint .draw[hidden] { display: none; }
.hint:has(.draw[hidden]) { padding-right: 1.3rem; }
.draw.small, .quiet.small { padding: 0.45rem 1.1rem; font-size: 0.95rem; white-space: nowrap; }
@keyframes pill-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- labels projected under stones ---------- */
.labels { position: absolute; inset: 0; pointer-events: none; }
.label {
  position: absolute;
  transform: translate(-50%, 0);
  white-space: nowrap;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--bone);
  opacity: 0;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9), 0 0 2px rgba(0, 0, 0, 0.9);
  transition: opacity 0.5s;
}
.label.on { opacity: 0.85; }

.noscript { position: fixed; bottom: 2rem; left: 2rem; color: var(--bone); }

/* ---------- short landscape screens (tablets, small laptops) ---------- */
@media (min-width: 821px) and (max-height: 900px) {
  .ask { padding-top: 22px; padding-bottom: 22px; }
  .wordmark-svg { width: clamp(150px, 15vw, 210px); }
  .futhark { margin-top: 0.3rem; font-size: 0.85rem; }
  .lede { margin: 0.6rem 0 0.9rem; font-size: 1rem; line-height: 1.45; }
  .toggle { margin-bottom: 0.7rem; }
  .toggle span { padding: 0.4rem 0.7rem; font-size: 0.95rem; }
  textarea { min-height: 3.2em; font-size: 1rem; }
  .spreads { margin-bottom: 0.9rem; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
  .spread { grid-template-columns: 1fr; text-align: center; justify-items: center; padding: 0.35rem 0.3rem; }
  .spread-map { grid-row: auto; transform: scale(0.85); }
  .spread-hint { display: none; }
  .spread-name { font-size: 0.95rem; }
  .tip { margin-top: 0.6rem; }
}
@media (min-width: 821px) and (max-height: 800px) {
  .lede { display: none; }
  .futhark { margin-bottom: 0.9rem; }
}

/* ---------- small screens: scene on top, panels as sheets ---------- */
@media (max-width: 820px) {
  .ask {
    top: auto;
    width: 100%;
    max-height: 64vh;
    padding: 3.5rem 16px calc(16px + env(safe-area-inset-bottom));
    background: linear-gradient(0deg, rgba(15, 29, 36, 0.97) 0%, rgba(15, 29, 36, 0.92) 78%, rgba(15, 29, 36, 0) 100%);
  }
  .ask > * { max-width: none; }
  .ask.away { transform: translateY(24px); }
  .wordmark-svg { width: 132px; }
  .ask { padding-top: 3rem; }
  .lede { margin: 0.5rem 0 0.9rem; font-size: 0.98rem; line-height: 1.45; }
  textarea { min-height: 3.2em; font-size: 1rem; }
  .count { min-height: 0; }
  .spreads { margin: 0.2rem 0 0.9rem; }
  .futhark { display: none; }
  .spreads { grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
  .spread { grid-template-columns: 1fr; text-align: center; justify-items: center; padding: 0.4rem 0.3rem; }
  .spread-map { grid-row: auto; margin-bottom: 0.15rem; transform: scale(0.85); }
  .spread-hint { display: none; }
  .spread-name { font-size: 0.95rem; }
  .draw { width: 100%; }
  .tip { text-align: center; margin-top: 0.5rem; }
  .ask:has(.picker:not([hidden])) { max-height: 80vh; }
  .lede { display: none; }
  .toggle { margin-bottom: 0.6rem; gap: 0.3rem; }
  .toggle.source { margin-top: 0.9rem; }
  .toggle span { padding: 0.4rem 0.6rem; font-size: 0.92rem; }
  .toggle small { display: none; }
  .toggle .field-label { display: none; }
  .slots { justify-content: center; }
  .key-name { display: none; }
  .rune-key { min-height: 40px; }

  .reading {
    top: auto;
    width: 100%;
    max-height: 56vh;
    padding: 3.5rem 16px calc(28px + env(safe-area-inset-bottom));
    background: linear-gradient(0deg, rgba(15, 29, 36, 0.98) 0%, rgba(15, 29, 36, 0.94) 85%, rgba(15, 29, 36, 0) 100%);
    animation-name: sheet-in;
  }
  @keyframes sheet-in { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: none; } }
  .asked { font-size: 1.12rem; }
  .reading-actions .draw, .reading-actions .quiet { flex: 1 1 auto; }
  .hint .draw { width: auto; }
  .hint { font-size: 0.95rem; }
  .stage-q-text { font-size: 0.98rem; }
}

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