/* ═══════════════════════════════════════════════════════════════
   RUBY 1.01 — The Flourish Layer
   ───────────────────────────────────────────────────────────────
   Site-wide signature polish for Arcanist's Guidebook.
   Loaded AFTER theme.css and shell.css on every page.

   RULES
   • Tokens only — every colour references theme.css custom properties.
   • Additive only — no display/layout overrides of existing classes.
   • Pseudo-elements are used ONLY on ruby-/bran- prefixed classes,
     never hijacked on shared shell/module classes.
   • Everything animated is disabled under prefers-reduced-motion.
   ═══════════════════════════════════════════════════════════════ */

/* ── Entry reveal: content breathes in on page load ─────────── */
@keyframes rubyRise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes rubyFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.shell-main, .app, .auth-card, .page {
  animation: rubyRise 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* ── Gilded interactive states ──────────────────────────────── */
.global-nav-btn, .ritual-list-btn, .mode-btn, .tradition-btn,
.auth-btn, .module-card, .topbar-settings-btn {
  transition: box-shadow 0.28s ease, transform 0.28s ease,
              border-color 0.28s ease, filter 0.28s ease;
}
.global-nav-btn:hover, .ritual-list-btn:hover, .mode-btn:hover,
.tradition-btn:hover, .topbar-settings-btn:hover {
  box-shadow: 0 0 14px rgba(var(--accent-rgb, 200,150,42), 0.22);
}
.auth-btn:hover, .module-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(0,0,0,0.35),
              0 0 18px rgba(var(--accent-rgb, 200,150,42), 0.25);
}
.auth-btn:active, .mode-btn:active, .ritual-list-btn:active {
  transform: translateY(0) scale(0.985);
}

/* Active nav entry: soft candle-glow pulse */
@keyframes rubyCandle {
  0%, 100% { box-shadow: 0 0 8px  rgba(var(--accent-rgb, 200,150,42), 0.18); }
  50%      { box-shadow: 0 0 16px rgba(var(--accent-rgb, 200,150,42), 0.38); }
}
.global-nav-btn.active { animation: rubyCandle 3.6s ease-in-out infinite; }

/* Link hover: faint gold breath */
.shell-main a:hover, .page a:hover, .letter a:hover {
  text-shadow: 0 0 10px rgba(var(--accent-rgb, 200,150,42), 0.55);
}

/* Keyboard focus: unmistakable gold ring */
:focus-visible {
  outline: 2px solid var(--accent, var(--gold));
  outline-offset: 2px;
  border-radius: 2px;
}

/* Scrollbar, gilded */
* { scrollbar-width: thin; scrollbar-color: var(--accent-dim, var(--gold-dim)) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--accent-dim, var(--gold-dim));
  border-radius: 4px;
}

/* ── Selection flair: sparkle burst (spawned by whimsy.js) ──── */
.ruby-spark {
  position: fixed;
  width: 7px; height: 7px;
  pointer-events: none;
  z-index: 10001; /* above the page-turn overlay — sparks must never be buried */
  background: var(--accent-bright, var(--gold-light));
  clip-path: polygon(50% 0%, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0% 50%, 39% 39%);
  animation: rubySpark 0.7s ease-out forwards;
}
@keyframes rubySpark {
  0%   { opacity: 1; transform: translate(0,0) scale(0.4) rotate(0deg); }
  100% { opacity: 0; transform: translate(var(--sx, 0px), var(--sy, -40px)) scale(1.1) rotate(160deg); }
}

/* ── Page-turn transition overlay (whimsy.js) ───────────────── */
.ruby-pageturn {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  background: linear-gradient(100deg,
    transparent 0%,
    rgba(var(--accent-rgb, 200,150,42), 0.10) 42%,
    var(--content-bg, #0f1225) 55%,
    var(--content-bg, #0f1225) 100%);
  transform: translateX(-104%);
}
.ruby-pageturn.turning {
  animation: rubyTurn 0.46s cubic-bezier(0.55, 0, 0.55, 1) forwards;
}
@keyframes rubyTurn {
  to { transform: translateX(0); }
}

/* ── Bran, the Archivist ────────────────────────────────────── */
.bran {
  position: fixed;
  right: 18px;
  bottom: 14px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  animation: rubyFadeIn 0.8s ease both;
}
.bran-figure {
  width: 92px;
  height: 92px;
  cursor: pointer;
  border: none;
  background: transparent;
  padding: 0;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.45));
  transition: transform 0.3s ease;
}
.bran-figure:hover { transform: translateY(-3px) rotate(-2deg); }
.bran-figure img { width: 100%; height: 100%; object-fit: contain; display: block; }
.bran-figure svg { width: 100%; height: 100%; display: block; }

@keyframes rubyPerch {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}
.bran-idle .bran-figure { animation: rubyPerch 4.5s ease-in-out infinite; }

.bran-bubble {
  max-width: 250px;
  background: var(--card-bg, var(--panel, #141828));
  color: var(--card-text, var(--text, #d4cbb8));
  border: 1px solid var(--accent-border, var(--border));
  border-radius: 10px 10px 2px 10px;
  padding: 0.6rem 0.85rem;
  font-family: var(--font-body, 'IM Fell English', Georgia, serif);
  font-size: 0.85rem;
  font-style: italic;
  line-height: 1.5;
  box-shadow: 0 6px 18px rgba(0,0,0,0.4),
              0 0 12px rgba(var(--accent-rgb, 200,150,42), 0.12);
  animation: rubyRise 0.4s ease both;
  position: relative;
}
.bran-bubble::after {
  content: '';
  position: absolute;
  bottom: -7px; right: 14px;
  width: 12px; height: 12px;
  background: inherit;
  border-right: 1px solid var(--accent-border, var(--border));
  border-bottom: 1px solid var(--accent-border, var(--border));
  transform: rotate(45deg) skew(8deg, 8deg);
}
.bran-bubble b { color: var(--accent-bright, var(--gold-light)); font-style: normal; }

.bran-dismiss {
  position: absolute;
  top: 2px; right: 5px;
  background: none; border: none;
  color: var(--content-text-muted, var(--text-muted));
  font-size: 0.7rem;
  cursor: pointer;
  padding: 2px 4px;
}
.bran-dismiss:hover { color: var(--accent-bright, var(--gold-light)); }
.bran.bran-quiet .bran-bubble { display: none; }

/* (Sound toggle styles removed in round 3 — sound feature dropped.) */

/* ── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 780px) {
  .bran { right: 10px; bottom: 10px; }
  .bran-figure { width: 64px; height: 64px; }
  .bran-bubble { max-width: 190px; font-size: 0.78rem; }
}

/* ── Reduced motion: stillness is also an aesthetic ─────────── */
@media (prefers-reduced-motion: reduce) {
  .shell-main, .app, .auth-card, .page,
  .bran, .bran-bubble, .ruby-spark, .ruby-pageturn,
  .global-nav-btn.active, .bran-idle .bran-figure {
    animation: none !important;
  }
  .ruby-pageturn { display: none !important; }
  .global-nav-btn, .ritual-list-btn, .mode-btn, .tradition-btn,
  .auth-btn, .module-card, .topbar-settings-btn, .bran-figure {
    transition: none !important;
  }
}
