/* ==========================================================================
   Shadow Slave Tracker — design system
   The Spell appraisal window: near-black, ornate glowing frames, rune text.
   Palettes are pure CSS custom properties; per-character themes only swap
   variables, never structure.
   ========================================================================== */

@font-face {
  font-family: 'Cinzel';
  src: url('../assets/fonts/cinzel-latin.woff2') format('woff2');
  font-weight: 400 900;
  font-display: swap;
}
@font-face {
  font-family: 'Noto Sans Runic';
  src: url('../assets/fonts/runic.woff2') format('woff2');
  font-display: swap;
}

/* ---- Palettes -------------------------------------------------------- */

:root, [data-theme='spell'] {
  /* Spell default: near-black, deep crimson atmosphere, gold ornament */
  --bg: #0a0507;
  --bg-glow-1: rgba(90, 16, 22, 0.28);
  --bg-glow-2: rgba(60, 30, 8, 0.18);
  --panel-a: rgba(44, 11, 15, 0.88);
  --panel-b: rgba(20, 5, 7, 0.96);
  --frame: #c9a227;
  --frame-bright: #f0d284;
  --frame-dim: rgba(201, 162, 39, 0.42);
  --frame-faint: rgba(201, 162, 39, 0.16);
  --glow: rgba(240, 196, 80, 0.20);
  --accent: #e8c96a;
  --text: #f0e7d6;
  --dim: #a3937a;
  --obscure: #a08bb0;
  --dust: #e8c96a;
  --danger: #c65353;
  --ok: #7fb069;
}

[data-theme='sunny'] {
  /* Sunny: shadow-purple over black */
  --bg: #060509;
  --bg-glow-1: rgba(58, 38, 110, 0.26);
  --bg-glow-2: rgba(28, 16, 60, 0.20);
  --panel-a: rgba(26, 18, 46, 0.88);
  --panel-b: rgba(10, 7, 20, 0.96);
  --frame: #7d63c9;
  --frame-bright: #b7a4f0;
  --frame-dim: rgba(125, 99, 201, 0.45);
  --frame-faint: rgba(125, 99, 201, 0.16);
  --glow: rgba(150, 120, 255, 0.20);
  --accent: #b7a4f0;
  --text: #eae6f4;
  --dim: #918aa8;
  --obscure: #8f84b8;
  --dust: #a78bfa;
}

/* ---- Base ------------------------------------------------------------- */

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 700px at 20% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(1000px 800px at 90% 110%, var(--bg-glow-2), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  transition: background 0.4s ease;
}

h1, h2, h3, .kicker, .rune-label, .spell-button {
  font-family: 'Cinzel', 'Palatino', 'Iowan Old Style', Georgia, serif;
}

/* ---- Particle dust ----------------------------------------------------- */

#dust {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
#dust span {
  position: absolute;
  border-radius: 50%;
  background: var(--dust);
  box-shadow: 0 0 6px var(--dust);
  animation: dust-drift linear infinite;
}
@keyframes dust-drift {
  0%   { transform: translateY(0); }
  50%  { transform: translateY(-45vh) translateX(12px); }
  100% { transform: translateY(-90vh) translateX(-6px); }
}

/* ---- The Spell panel (signature element) ------------------------------- */

.spell-panel {
  position: relative;
  border: 1px solid var(--frame-dim);
  background: linear-gradient(160deg, var(--panel-a), var(--panel-b));
  box-shadow:
    0 0 26px var(--glow),
    inset 0 0 50px rgba(0, 0, 0, 0.55),
    inset 0 0 2px var(--frame-faint);
  padding: 22px 26px;
}
.spell-panel::before {
  /* inner hairline frame */
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid var(--frame-faint);
  pointer-events: none;
}

.corner {
  position: absolute;
  width: 16px;
  height: 16px;
  pointer-events: none;
}
.corner::before {
  content: '';
  position: absolute;
  inset: 0;
  border-top: 2px solid var(--frame-bright);
  border-left: 2px solid var(--frame-bright);
  filter: drop-shadow(0 0 3px var(--glow));
}
.corner::after {
  /* corner gem */
  content: '';
  position: absolute;
  top: -3.5px;
  left: -3.5px;
  width: 7px;
  height: 7px;
  background: var(--frame-bright);
  transform: rotate(45deg);
  box-shadow: 0 0 8px var(--frame-bright);
}
.corner.tl { top: -1px; left: -1px; }
.corner.tr { top: -1px; right: -1px; transform: rotate(90deg); }
.corner.br { bottom: -1px; right: -1px; transform: rotate(180deg); }
.corner.bl { bottom: -1px; left: -1px; transform: rotate(270deg); }

/* ---- Typography atoms --------------------------------------------------- */

.kicker {
  font-size: 10px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--dim);
  text-align: center;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
}
.panel-title::before, .panel-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--frame-dim));
}
.panel-title::after {
  background: linear-gradient(90deg, var(--frame-dim), transparent);
}

.list-title {
  margin: 14px 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ---- Rune rows (label/value pairs) -------------------------------------- */

.rune-rows {
  display: grid;
  grid-template-columns: minmax(96px, auto) 1fr;
  gap: 0;
  margin: 0;
}
.rune-rows dt {
  padding: 7px 14px 7px 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  border-bottom: 1px solid var(--frame-faint);
  align-content: center;
}
.rune-rows dd {
  margin: 0;
  padding: 7px 0;
  border-bottom: 1px solid var(--frame-faint);
  color: var(--text);
}
.rune-rows dt:last-of-type, .rune-rows dd:last-of-type { border-bottom: none; }

.rune-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.rune-item {
  padding: 5px 0;
  border-bottom: 1px solid var(--frame-faint);
}
.rune-item:last-child { border-bottom: none; }

.since-chip {
  margin-left: 8px;
  font-size: 10px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  color: var(--dim);
  opacity: 0.85;
  white-space: nowrap;
}

/* ---- Obscured runes ------------------------------------------------------ */

.obscured {
  font-family: 'Noto Sans Runic', monospace;
  color: var(--obscure);
  letter-spacing: 0.22em;
  filter: blur(2.2px);
  opacity: 0.75;
  user-select: none;
  cursor: help;
  animation: rune-shimmer 3.8s ease-in-out infinite alternate;
}
@keyframes rune-shimmer {
  from { opacity: 0.55; filter: blur(2.6px); }
  to   { opacity: 0.85; filter: blur(1.8px); }
}

/* ---- Buttons ------------------------------------------------------------- */

.spell-button {
  display: inline-block;
  margin-top: 18px;
  padding: 10px 26px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--frame-dim);
  cursor: pointer;
  transition: box-shadow 0.25s ease, color 0.25s ease;
}
.spell-button:hover, .spell-button:focus-visible {
  color: var(--frame-bright);
  box-shadow: 0 0 16px var(--glow), inset 0 0 10px var(--frame-faint);
  outline: none;
}

/* ---- Site header ---------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  padding: 12px 22px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0.68));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--frame-faint);
}
.site-title {
  font-family: 'Cinzel', Georgia, serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.12em;
  white-space: nowrap;
}
.site-title .sigil { color: var(--accent); margin-right: 6px; }
.site-title .dim { color: var(--dim); font-size: 12px; font-weight: 400; }

.chapter-control {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 260px;
}
.cc-label {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
  white-space: nowrap;
}
.chapter-control output {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 12px;
  color: var(--accent);
  min-width: 92px;
  text-align: right;
}
#chapterNum {
  width: 64px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--frame-faint);
  color: var(--text);
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 12px;
  padding: 4px 6px;
}

input[type='range'] {
  flex: 1;
  appearance: none;
  height: 3px;
  background: linear-gradient(90deg, var(--frame-dim), var(--frame-bright));
  border-radius: 2px;
  cursor: pointer;
}
input[type='range']::-webkit-slider-thumb {
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--frame-bright);
  box-shadow: 0 0 10px var(--glow), 0 0 3px var(--frame-bright);
  border: 1px solid var(--panel-b);
}
input[type='range']::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--frame-bright);
  box-shadow: 0 0 10px var(--glow);
  border: 1px solid var(--panel-b);
}

.unified-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
  cursor: pointer;
  white-space: nowrap;
}
.unified-toggle input { accent-color: var(--frame); }

/* ---- Overlays -------------------------------------------------------------- */

.overlay-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}
.prompt-panel, .detail-panel {
  max-width: 520px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
}
.prompt-title, .detail-name {
  margin: 8px 0 4px;
  text-align: center;
  font-size: 22px;
  letter-spacing: 0.1em;
  color: var(--frame-bright);
  text-shadow: 0 0 18px var(--glow);
}
.prompt-text { color: var(--dim); font-size: 13px; text-align: center; }
.prompt-slider-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 18px 0 4px;
}
.prompt-value {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  color: var(--accent);
  min-width: 64px;
  text-align: right;
}
.prompt-panel .spell-button, .detail-panel .spell-button {
  display: block;
  margin: 18px auto 0;
}

/* ---- Stat index (the Spell's six-attribute appraisal) -------------------- */

.stat-wrap { margin-top: 20px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.stat-cell {
  text-align: center;
  padding: 10px 4px 12px;
  border: 1px solid var(--frame-faint);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.28), rgba(0, 0, 0, 0.05));
}
.stat-label {
  font-family: 'Cinzel', Georgia, serif;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}
.stat-value {
  margin-top: 4px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 17px;
  color: var(--frame-bright);
  text-shadow: 0 0 12px var(--glow);
  min-height: 22px;
}
.stat-note {
  margin-top: 7px;
  text-align: center;
  font-size: 10.5px;
  color: var(--dim);
}

/* Estimated (range/weak) stats stay fully readable — no blur — just a
   quieter color plus the caption underneath. */
.stat-estimated .stat-value {
  font-size: 12.5px;
  color: var(--text);
  opacity: 0.85;
}
.stat-mode-note {
  margin-top: 6px;
  text-align: center;
  font-size: 10.5px;
  font-style: italic;
  color: var(--dim);
}
.stat-mode-note-compact { font-size: 9px; margin-top: 2px; }

.stat-compact { grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 8px 0 10px; }
.stat-compact .stat-cell { padding: 5px 2px 7px; }
.stat-compact .stat-label { font-size: 8px; letter-spacing: 0.1em; }
.stat-compact .stat-value { font-size: 11.5px; min-height: 15px; }

@media (max-width: 760px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---- Frame tiers (peak revealed rank; gated) ------------------------------ */

.frame-tier-2 .spell-panel.sheet,
.spell-panel.frame-tier-2 {
  box-shadow: 0 0 34px var(--glow), inset 0 0 50px rgba(0, 0, 0, 0.55), inset 0 0 3px var(--frame-dim);
}
.frame-tier-2 .sheet > .corner::after,
.frame-tier-2.char-card > .corner::after {
  width: 9px;
  height: 9px;
}

.frame-tier-3 .spell-panel.sheet,
.spell-panel.frame-tier-3 {
  border-width: 2px;
  box-shadow: 0 0 46px var(--glow), 0 0 90px var(--glow), inset 0 0 60px rgba(0, 0, 0, 0.6);
}
.frame-tier-3 .sheet > .corner::before,
.frame-tier-3.char-card > .corner::before {
  border-width: 3px;
}
.frame-tier-3 .sheet > .corner::after,
.frame-tier-3.char-card > .corner::after {
  width: 10px;
  height: 10px;
  animation: now-pulse 3s ease-in-out infinite;
}

/* ---- Motion ------------------------------------------------------------------ */

.materialize {
  animation: materialize 0.7s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}
@keyframes materialize {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.992);
    filter: blur(9px) brightness(1.7);
  }
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

@keyframes now-pulse {
  0%, 100% { box-shadow: 0 0 4px var(--glow); }
  50%      { box-shadow: 0 0 14px var(--frame-bright); }
}

.rune-in {
  animation: rune-in 0.6s ease-out both;
}
@keyframes rune-in {
  from { opacity: 0.1; filter: blur(4px); text-shadow: 0 0 14px var(--frame-bright); }
  to   { opacity: 1; filter: none; }
}

/* ---- "Since you last read" recap ---------------------------------------- */

.recap-offer {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--frame-dim);
  background: linear-gradient(160deg, var(--panel-a), var(--panel-b));
  box-shadow: 0 0 22px var(--glow);
  max-width: calc(100vw - 36px);
  flex-wrap: wrap;
}
.recap-text { font-size: 12.5px; color: var(--text); }
.recap-view-btn { margin-top: 0; padding: 7px 14px; font-size: 10.5px; }
.recap-dismiss {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
}
.recap-dismiss:hover { color: var(--text); }

.recap-panel { max-width: 620px; }
.recap-name {
  margin: 14px 0 4px;
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--frame-bright);
}
.recap-panel .rune-item { font-size: 13px; }

/* ---- Keyboard focus ------------------------------------------------------- */

a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--frame-bright);
  outline-offset: 2px;
  border-radius: 1px;
}

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