/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #07070c;
  --bg-panel: #0c0a0e;
  --bg-aside: #0a0810;
  --text: #c8c8d0;
  --text-dim: #444455;
  --accent: #c8962a;
  --accent-bright: #f0c040;
  --accent-glow: #c8962a88;
  --bip39-hi: #e8d44d;
  --bip39-bg: #e8d44d18;
  --shine-color: #fffbe8;
  --orb-12: #40c0f0;
  --orb-24: #f0c040;
  --gold-dark: #7a5c10;
  --gold-mid: #c8962a;
  --header-h: 4rem;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --font-serif: 'Georgia', 'Times New Roman', serif;
  --font-gothic: 'Cinzel', 'Palatino Linotype', serif;
  --font-gothic-deco: 'Cinzel Decorative', 'Cinzel', serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 1rem;
  position: relative;
  z-index: 10;
  background: linear-gradient(180deg, #1a1208 0%, #0c0a0e 60%, #070509 100%);
  border-bottom: 1px solid var(--gold-dark);
  box-shadow: 0 1px 0 #000, 0 2px 0 #c8962a22, 0 3px 12px #00000088;
}

header::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-mid) 30%, var(--accent-bright) 50%, var(--gold-mid) 70%, transparent);
}

.header-ornament {
  font-size: 1.4rem;
  color: var(--gold-dark);
  opacity: 0.7;
  user-select: none;
  flex-shrink: 0;
}

.header-ornament-right { transform: scaleX(-1); }

.header-source-link {
  font-family: var(--font-gothic);
  font-size: 0.7rem;
  color: var(--gold-dim);
  text-decoration: none;
  background: none;
  cursor: pointer;
  border: 1px solid var(--gold-dim);
  padding: 0.25rem 0.6rem;
  border-radius: 2px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color 0.2s, border-color 0.2s;
}
.header-source-link:hover {
  color: var(--gold);
  border-color: var(--gold);
}
.header-right-links {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin-right: 0.4rem;
}

/* ── Credits modal ─────────────────────────────────────── */
#credits-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.82);
  display: flex;
  align-items: center;
  justify-content: center;
}
#credits-overlay[hidden] { display: none; }

.credits-box {
  width: min(480px, 90vw);
  max-height: 80vh;
  background: linear-gradient(160deg, #1a1208 0%, #0d0d0d 100%);
  border: 2px solid var(--gold-dim);
  box-shadow: 0 0 40px #b8860b66, inset 0 0 30px #00000088;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.credits-scroll-wrap {
  flex: 1;
  overflow: hidden;
  position: relative;
  mask-image: linear-gradient(transparent 0%, black 8%, black 92%, transparent 100%);
  -webkit-mask-image: linear-gradient(transparent 0%, black 8%, black 92%, transparent 100%);
}

.credits-scroll {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2rem 2rem 3rem;
  animation: credits-roll 28s linear infinite;
  animation-play-state: running;
}
.credits-scroll:hover { animation-play-state: paused; }

@keyframes credits-roll {
  0%   { transform: translateY(100%); }
  100% { transform: translateY(-100%); }
}

.credits-title {
  font-family: var(--font-gothic-deco);
  font-size: 1.4rem;
  color: var(--gold);
  text-shadow: 0 0 16px var(--gold);
  margin: 0 0 1.4rem;
  letter-spacing: 0.12em;
}
.credits-section {
  font-family: var(--font-gothic);
  font-size: 0.85rem;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin: 1rem 0 0.3rem;
}
.credits-role {
  font-family: var(--font-gothic);
  font-size: 0.72rem;
  color: #888;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 0.8rem 0 0.15rem;
}
.credits-name {
  font-family: var(--font-gothic);
  font-size: 0.85rem;
  color: #ccc;
  margin: 0.1rem 0;
}
.credits-divider {
  color: var(--gold-dim);
  font-size: 1.1rem;
  margin: 1.2rem 0 0.4rem;
}
.credits-fine {
  font-family: var(--font-gothic);
  font-size: 0.68rem;
  color: #555;
  font-style: italic;
  margin-top: 1.5rem;
}

.credits-close {
  font-family: var(--font-gothic);
  font-size: 0.75rem;
  color: var(--gold-dim);
  background: none;
  border: none;
  border-top: 1px solid #333;
  cursor: pointer;
  padding: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: color 0.2s;
}
.credits-close:hover { color: var(--gold); }

.header-left { flex-shrink: 0; padding: 0 0.5rem; }

header h1 {
  font-family: var(--font-gothic-deco);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  background: linear-gradient(180deg, var(--accent-bright) 0%, var(--gold-mid) 60%, #7a5010 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 6px #c8962a55);
}

.subtitle {
  font-family: var(--font-gothic);
  font-size: 0.58rem;
  color: var(--gold-dark);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: 0.15rem;
}

.header-center-divider {
  color: var(--gold-dark);
  font-size: 0.7rem;
  flex-shrink: 0;
  opacity: 0.4;
}

.header-sep {
  color: var(--gold-dark);
  opacity: 0.35;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.resource-counter {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.resource-counter .res-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  background: linear-gradient(180deg, #1a1208 0%, #100c06 100%);
  border: 1px solid var(--gold-dark);
  border-radius: 2px;
  box-shadow: inset 0 1px 3px #00000066;
}

.resource-counter .res-orb {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  display: inline-block;
}

.resource-counter .res-orb.res-12 {
  background: radial-gradient(circle at 35% 35%, #e8fbff, var(--orb-12));
  box-shadow: 0 0 4px var(--orb-12);
}

.resource-counter .res-orb.res-24 {
  background: radial-gradient(circle at 35% 35%, #fffbe8, var(--orb-24));
  box-shadow: 0 0 4px var(--orb-24);
}

.resource-counter .res-num {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent-bright);
  font-weight: bold;
  min-width: 1.2rem;
  text-align: right;
}

@keyframes select-pulse {
  0%, 100% { border-color: var(--gold-dark); box-shadow: none; }
  50%       { border-color: var(--accent-bright); box-shadow: 0 0 8px var(--accent-glow); }
}

#book-select {
  background: #110e08;
  color: var(--accent-bright);
  border: 1px solid var(--gold-dark);
  padding: 0.28rem 0.55rem;
  border-radius: 2px;
  font-family: var(--font-gothic);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: inset 0 1px 4px #00000066;
}

#book-select option { background: #110e08; color: var(--accent-bright); }
#book-select.pulse { animation: select-pulse 0.75s ease-in-out 2; }

.transport {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.transport button {
  background: linear-gradient(180deg, #1e1608 0%, #110e06 100%);
  color: var(--gold-mid);
  border: 1px solid var(--gold-dark);
  padding: 0.28rem 0.7rem;
  border-radius: 2px;
  cursor: pointer;
  font-size: 1rem;
  font-family: var(--font-gothic);
  line-height: 1.2;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  box-shadow: inset 0 1px 0 #ffffff08, 0 1px 3px #00000066;
}

.transport button:hover {
  background: linear-gradient(180deg, #2e2210 0%, #1a1408 100%);
  color: var(--accent-bright);
  border-color: var(--gold-mid);
}

.transport button:active {
  background: #0a0806;
  box-shadow: inset 0 2px 4px #00000088;
}

#speed-display {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent-bright);
  min-width: 2.2rem;
  text-align: center;
  text-shadow: 0 0 6px var(--accent-glow);
}


/* ── Main Layout ─────────────────────────────────────── */
main {
  position: relative;
  height: calc(100vh - var(--header-h));
}

#text-panel {
  position: relative;
  height: 100%;
  overflow-y: auto;
  padding: 2rem 3rem;
  scroll-behavior: smooth;
}

#text-content {
  font-size: 1.05rem;
  line-height: 1.9;
  max-width: 42rem;
  margin: 0 auto;
  color: var(--text-dim); /* plain text nodes (punctuation, spaces) match unscanned words */
}

#text-content .word {
  display: inline;
  transition: color 0.3s, background 0.3s, text-shadow 0.3s;
  border-radius: 2px;
  padding: 0 1px;
  color: var(--text-dim); /* unscanned: dim */
}

/* Scanned non-BIP39 words: grey */
#text-content .word.scanned {
  color: #3a3a4a;
}

/* Scanned BIP39 words not yet in a phrase: white */
#text-content .word.scanned.bip39 {
  color: #e8e8f0;
  background: none;
}

/* Current scan window highlight */
#text-content .word.window-active {
  color: #fff;
  background: #ffffff18;
  text-shadow: 0 0 6px #ffffff44;
}

/* ── Phrase word colors (Diablo item tier palette) ───── */

/* 1× blue (magic item blue) */
#text-content .word.phrase-12 {
  color: #5599ff !important;
  background: #2244ff12 !important;
  animation: pulse-12 3s ease-in-out infinite;
}
@keyframes pulse-12 {
  0%,100% { text-shadow: 0 0 6px #4477ff88; }
  50%     { text-shadow: 0 0 14px #66aaff, 0 0 28px #3366ff55; }
}

/* 2× blue (deep sapphire) */
#text-content .word.phrase-12x {
  color: #2244cc !important;
  background: #11228818 !important;
  animation: pulse-12x 3s ease-in-out infinite;
}
@keyframes pulse-12x {
  0%,100% { text-shadow: 0 0 8px #1133aa88; }
  50%     { text-shadow: 0 0 18px #2255dd, 0 0 36px #1133aa44; }
}

/* 1× yellow (unique item gold) */
#text-content .word.phrase-24 {
  color: #f0c040 !important;
  background: #f0c04012 !important;
  animation: pulse-24 3s ease-in-out infinite;
}
@keyframes pulse-24 {
  0%,100% { text-shadow: 0 0 6px #c8962a88; }
  50%     { text-shadow: 0 0 14px #f0c040, 0 0 28px #c8962a55; }
}

/* 2× yellow (burning orange, like Diablo set items) */
#text-content .word.phrase-24x {
  color: #ff7020 !important;
  background: #ff601012 !important;
  animation: pulse-24x 2.5s ease-in-out infinite;
}
@keyframes pulse-24x {
  0%,100% { text-shadow: 0 0 8px #dd501088; }
  50%     { text-shadow: 0 0 18px #ff8030, 0 0 36px #dd501055; }
}

/* blue + yellow overlap (runeword purple) */
#text-content .word.phrase-mix {
  color: #c050f8 !important;
  background: #8020cc12 !important;
  animation: pulse-mix 2s ease-in-out infinite;
}
@keyframes pulse-mix {
  0%,100% { text-shadow: 0 0 8px #9030cc88; }
  50%     { text-shadow: 0 0 20px #d060ff, 0 0 40px #8020cc66, 0 0 60px #5599ff22; }
}

/* ── Shine Animation (brief flash on discovery) ──────── */
@keyframes shine-sweep {
  0%   { background-position: -200% center; }
  100% { background-position: 200% center; }
}

@keyframes shine-glow {
  0%   { text-shadow: 0 0 4px var(--accent-glow); }
  50%  { text-shadow: 0 0 24px #fff, 0 0 48px var(--accent-glow); }
  100% { text-shadow: 0 0 4px var(--accent-glow); }
}

#text-content .word.shine {
  color: #fff !important;
  text-shadow: 0 0 24px #fff, 0 0 48px var(--accent-glow) !important;
  animation: shine-glow 0.8s ease-in-out;
}

/* ── Lightning SVG ────────────────────────────────────── */
#lightning-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  overflow: visible;
}

#lightning-svg .lightning-bolt {
  fill: none;
  stroke: var(--orb-12);
  stroke-width: 1;
  filter: drop-shadow(0 0 3px var(--orb-12));
  opacity: 0.6;
}

#lightning-svg .lightning-bolt.bolt-24 {
  stroke: var(--orb-24);
  filter: drop-shadow(0 0 3px var(--orb-24));
}

@keyframes lightning-flash {
  0%   { opacity: 0; stroke-width: 1.5; }
  20%  { opacity: 0.8; stroke-width: 1; }
  100% { opacity: 0.5; stroke-width: 1; }
}

/* ── Orb Anchor (inside text panel, scrolls with content) ── */
.orb-anchor {
  position: absolute;
  left: calc(50% + 21rem + 1rem);
  transform: translateY(-50%);
  z-index: 15;
  pointer-events: auto;
}

/* ── Orb ─────────────────────────────────────────────── */
@keyframes orb-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-7px); }
}

@keyframes orb-appear {
  0%   { opacity: 0; transform: scale(0) translateY(0); }
  60%  { opacity: 1; transform: scale(1.25) translateY(0); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.orb {
  width: 2.4rem;
  height: 2.4rem;
  min-width: 2.4rem;
  min-height: 2.4rem;
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  animation: orb-appear 0.4s ease-out forwards, orb-float var(--float-dur, 3s) ease-in-out infinite 0.4s;
  box-shadow: 0 0 12px var(--orb-12), inset 0 0 8px #ffffff44;
  background: radial-gradient(circle at 35% 35%, #e8fbff, var(--orb-12) 60%, #1070a0);
  display: flex;
  align-items: center;
  justify-content: center;
}

.orb .orb-label {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  font-weight: bold;
  color: #ffffffcc;
  text-shadow: 0 0 4px #00000088;
  pointer-events: none;
  line-height: 1;
}

.orb.orb-24 {
  box-shadow: 0 0 12px var(--orb-24), inset 0 0 8px #ffffff44;
  background: radial-gradient(circle at 35% 35%, #fffbe8, var(--orb-24) 60%, #a07010);
}

.orb .orb-tooltip {
  display: none;
  position: absolute;
  right: calc(100% + 0.8rem);
  top: 50%;
  transform: translateY(-50%);
  background: #1a1208ee;
  border: 1px solid var(--gold-dark);
  border-top-color: var(--gold-mid);
  border-radius: 2px;
  padding: 0.6rem 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text);
  line-height: 1.6;
  z-index: 20;
  pointer-events: none;
  box-shadow: 0 4px 16px #00000099, inset 0 1px 0 #c8962a22;
  max-width: 22rem;
  white-space: normal;
  word-break: break-word;
}

.orb:hover .orb-tooltip { display: block; }

.orb .orb-tooltip .phrase-word { color: var(--bip39-hi); }

.orb .orb-tooltip .phrase-label {
  color: var(--gold-dark);
  font-size: 0.6rem;
  display: block;
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Orange border on words when their orb is hovered */
#text-content .word.phrase-hover {
  outline: 1px solid #e87020 !important;
  box-shadow: 0 0 8px #e8702066 !important;
  border-radius: 2px;
}

/* ── Intro Overlay ───────────────────────────────────── */
#intro-overlay {
  position: fixed;
  inset: 0;
  background: #07070cee;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(6px);
}

#intro-overlay.hidden { display: none; }

.intro-box {
  text-align: center;
  max-width: 30rem;
  padding: 2.5rem 2rem;
  border: 1px solid var(--gold-dark);
  border-top-color: var(--gold-mid);
  background: linear-gradient(180deg, #1a1208cc 0%, #07070ccc 100%);
  box-shadow: 0 0 40px #00000099, inset 0 1px 0 #c8962a33;
  position: relative;
}

.intro-box::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-mid) 40%, var(--accent-bright) 50%, var(--gold-mid) 60%, transparent);
}

.intro-box h2 {
  font-family: var(--font-gothic-deco);
  background: linear-gradient(180deg, var(--accent-bright) 0%, var(--gold-mid) 70%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 1.8rem;
  margin-bottom: 1.2rem;
  filter: drop-shadow(0 0 8px #c8962a66);
}

.intro-box p {
  font-family: var(--font-gothic);
  color: #a89070;
  font-size: 0.88rem;
  line-height: 1.7;
  margin-bottom: 0.8rem;
  letter-spacing: 0.02em;
}

.intro-box button {
  margin-top: 1.2rem;
  background: linear-gradient(180deg, #2e2210 0%, #1a1408 100%);
  color: var(--accent-bright);
  border: 1px solid var(--gold-mid);
  padding: 0.6rem 1.6rem;
  border-radius: 2px;
  font-family: var(--font-gothic);
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  box-shadow: inset 0 1px 0 #ffffff0a, 0 2px 8px #00000066;
}

.intro-box button:hover {
  background: linear-gradient(180deg, #3e3018 0%, #241c0a 100%);
  border-color: var(--accent-bright);
}

/* ── Scrollbar ───────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333344; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #444466; }

/* ── Mobile Responsive ──────────────────────────────── */
@media (max-width: 640px) {
  /* Switch to flex-column so main fills exactly the space below the header,
     regardless of how tall the header grows when controls wrap. */
  html, body {
    height: 100vh;
    height: 100dvh; /* respect mobile browser chrome */
    display: flex;
    flex-direction: column;
  }

  main {
    flex: 1;
    height: auto;
    overflow: hidden;
  }

  header {
    height: auto;
    flex-shrink: 0;
    flex-wrap: wrap;
    padding: 0.35rem 0.5rem;
    row-gap: 0.2rem;
  }

  /* hide purely decorative / secondary elements */
  .header-ornament,
  .header-center-divider,
  .header-sep,
  .subtitle {
    display: none;
  }

  /* row 1: title (left) + links (right) */
  .header-left {
    order: 1;
    flex: 1;
    padding: 0;
  }

  .header-right-links {
    order: 2;
    margin-right: 0;
    flex-shrink: 0;
  }

  /* row 2: all controls, centered */
  .header-controls {
    order: 3;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding-bottom: 0.2rem;
  }

  .resource-counter .res-item {
    padding: 0.15rem 0.3rem;
  }

  #book-select {
    max-width: 8rem;
    font-size: 0.65rem;
    padding: 0.22rem 0.35rem;
  }

  .transport {
    gap: 0.15rem;
  }

  .transport button {
    padding: 0.2rem 0.4rem;
    font-size: 0.9rem;
  }

  #speed-display {
    min-width: 1.8rem;
    font-size: 0.75rem;
  }

  /* reduce side padding in the reading area */
  #text-panel {
    padding: 1rem 0.75rem;
  }

  /* orbs: anchor to right edge instead of off-screen right of text column */
  .orb-anchor {
    left: auto;
    right: 0.5rem;
  }

  /* tooltip: open to the left of the orb (orb is at right edge) */
  .orb .orb-tooltip {
    right: calc(100% + 0.6rem);
    left: auto;
    max-width: min(16rem, calc(100vw - 4rem));
  }

  /* intro box: constrain to viewport width */
  .intro-box {
    width: calc(100vw - 2rem);
    padding: 2rem 1.2rem;
  }
}

/* ── Very small phones (≤400px) ─────────────────────── */
@media (max-width: 400px) {
  .header-source-link {
    font-size: 0.6rem;
    padding: 0.2rem 0.4rem;
  }

  .transport button {
    padding: 0.18rem 0.3rem;
    font-size: 0.85rem;
  }
}
