/* ==========================================================
   Glyphcaster — Design Tokens & Base

   Palette: deep indigo night sky grounded by warm amber
   accents, evoking candlelit grimoires and arcane ink.
   Type: Cinzel (display, inscriptions) + Nunito (body, soft
   readable companion — warmth against the formality).
   Layout: single-column, content-centered, generous vertical
   rhythm. Left-aligned body text, centered headings.
   ========================================================== */

:root {
  /* Night sky to warm flame */
  --ink:        #1a1525;
  --parchment:  #f5f0e8;
  --indigo:     #3d2c6e;
  --violet:     #6b4fa2;
  --amber:      #d4a04a;
  --ember:      #c0583a;
  --smoke:      #8a8399;
  --glass:      rgba(255, 255, 255, 0.06);

  /* Semantic */
  --bg:         var(--parchment);
  --bg-surface: #eee8dc;
  --text:       var(--ink);
  --text-muted: #635b72;
  --accent:     var(--indigo);
  --accent-glow: var(--violet);
  --highlight:  var(--amber);
  --danger:     var(--ember);

  /* Type */
  --font-display: 'Cinzel', 'Palatino Linotype', 'Georgia', serif;
  --font-body:    'Nunito', 'Segoe UI', system-ui, sans-serif;

  /* Scale */
  --space-xs: 0.5rem;
  --space-sm: 1rem;
  --space-md: 1.5rem;
  --space-lg: 3rem;
  --space-xl: 5rem;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;

  color-scheme: light;
}

/* ---- Dark theme ---- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:         #0e0b16;
    --bg-surface: #1a1525;
    --text:       #e8e2f0;
    --text-muted: #9990a8;
    --accent:     #9b7fd4;
    --accent-glow: #b89aef;
    --highlight:  #e4b85a;
    --danger:     #e07050;
    --glass:      rgba(255, 255, 255, 0.04);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg:         #0e0b16;
  --bg-surface: #1a1525;
  --text:       #e8e2f0;
  --text-muted: #9990a8;
  --accent:     #9b7fd4;
  --accent-glow: #b89aef;
  --highlight:  #e4b85a;
  --danger:     #e07050;
  --glass:      rgba(255, 255, 255, 0.04);
  color-scheme: dark;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  padding-inline: 20px;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
  text-wrap: balance;
  letter-spacing: 0.02em;
}

img { max-width: 100%; }
[hidden] { display: none !important; }

/* Ashwick's Sanctum page shell */
:root {
  color-scheme: light;
  --ink: #17120f;
  --paper: #e9dcc0;
  --red: #c92f17;
  --c: #f2a516;
  --font-display: 'Caveat', cursive;
  --font-body: 'Patrick Hand', cursive;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --ink: #17120f; } }
:root[data-theme="dark"] { --ink: #17120f; }
html, body { width: 100%; height: 100%; min-height: 100%; min-height: 100vh; min-height: 100dvh; }
html { scroll-behavior: auto; }
body {
  overflow: hidden;
  padding: 0;
  color: var(--ink);
  font: 18px 'Patrick Hand', 'Segoe Print', cursive;
  line-height: normal;
  background: radial-gradient(ellipse at 50% 45%, #f1e6c9 0, #e2d1a9 55%, #b39a68 125%);
  -webkit-tap-highlight-color: transparent;
}
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .3;
  mix-blend-mode: multiply;
  z-index: 4;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2'/><feColorMatrix type='saturate' values='0'/></filter><rect width='180' height='180' filter='url(%23n)'/></svg>");
}
header {
  position: fixed;
  top: 18px;
  top: max(env(safe-area-inset-top, 0px), 18px);
  left: 18px;
  left: max(env(safe-area-inset-left, 0px), 18px);
  width: auto;
  max-width: calc(100vw - 116px);
  max-width: calc(100vw - 116px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  text-align: left;
  z-index: 3;
  pointer-events: none;
  padding: 0 12px;
  padding: 0 clamp(12px, 5vw, 40px);
}
header h1 {
  font: 600 36px 'Caveat', 'Segoe Print', cursive;
  font-size: clamp(30px, 5vw, 44px);
  letter-spacing: .035em;
  text-shadow: 2px 1.5px 0 var(--red);
  transform: rotate(-.6deg);
}
header p { font-style: italic; color: #4b3b2c; font-size: 18px; font-size: clamp(16px, 2vw, 20px); margin-top: 2px; }
#dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 16px;
  bottom: max(env(safe-area-inset-bottom, 0px), 16px);
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  gap: clamp(8px, 1.5vh, 12px);
  padding: 0 12px 0;
  padding: 0 max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
}
#hint { font-style: italic; color: #4b3b2c; font-size: clamp(12px, 3.5vw, 14px); transition: opacity .6s; text-align: center; padding: 0 8px; }
#hint.off { opacity: 0; }
#row { display: flex; flex-wrap: wrap; gap: clamp(6px, 2vw, 10px); justify-content: center; max-width: 900px; }
button {
  font: 18px 'Patrick Hand', 'Segoe Print', cursive;
  color: var(--ink);
  background: #efe3c4;
  border: 2px solid var(--ink);
  border-radius: 255px 14px 225px 14px/14px 225px 14px 255px;
  padding: 7px 12px;
  padding: 7px clamp(12px, 3.5vw, 17px);
  min-height: 44px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--red);
  transition: .12s;
  transform: rotate(-1.2deg);
  touch-action: manipulation;
}
button:nth-child(even) { transform: rotate(1deg); border-radius: 14px 225px 14px 255px/225px 14px 255px 14px; }
button:hover, button:focus-visible { transform: translate(2px, 2px) rotate(0); box-shadow: 1px 1px 0 var(--red); outline: none; }
#sound-toggle {
  position: fixed;
  top: 12px;
  top: max(env(safe-area-inset-top, 0px), 12px);
  right: 12px;
  right: max(env(safe-area-inset-right, 0px), 12px);
  z-index: 6;
  min-height: 44px;
  padding: 5px 12px;
  font-size: 14px;
  transform: none;
  border-radius: 14px 8px 14px 8px;
  box-shadow: 2px 2px 0 var(--red);
}
#sound-toggle:hover, #sound-toggle:focus-visible { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--red); }
@media (max-width: 520px) {
  header { left: 12px; left: max(env(safe-area-inset-left, 0px), 12px); max-width: calc(100vw - 104px); max-width: calc(100vw - 104px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)); }
  header h1 { letter-spacing: .025em; line-height: .95; }
  header p { margin-top: 4px; }
  #dock { bottom: 10px; bottom: max(env(safe-area-inset-bottom, 0px), 10px); }
  #row { padding: 0 4px; gap: 6px; }
  button { min-height: 44px; padding-inline: 11px; }
}
@media (max-height: 560px) and (orientation: landscape) {
  header { top: 8px; top: max(env(safe-area-inset-top, 0px), 8px); }
  header p, #hint { display: none; }
  #dock { bottom: 8px; bottom: max(env(safe-area-inset-bottom, 0px), 8px); gap: 5px; }
  #row { max-width: 70vw; gap: 4px; }
  button { min-height: 34px; padding: 4px 9px; font-size: 14px; }
}
#row { max-height: 45vh; max-height: 45dvh; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
@media (max-height: 520px) and (orientation: portrait) {
  #stage { top: 42%; }
  #hint { display: none; }
  #dock { gap: 5px; }
}

/* Focus */
:focus-visible {
  outline: 2px solid var(--accent-glow);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

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

/* ---- Hero ---- */
.hero {
  min-height: 85vh;
  min-height: 85dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  gap: var(--space-lg);
  padding-block: var(--space-xl);
}

.hero-content {
  position: relative;
  z-index: 2;
}

.hero-title {
  font-size: clamp(2.8rem, 7vw, 5.5rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: var(--space-xs);
  position: relative;
}

.hero-sub {
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  color: var(--text-muted);
  font-weight: 300;
  margin-bottom: var(--space-md);
}

/* CTA */
.cta {
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  padding: 0.8em 2em;
  background: var(--accent);
  color: var(--parchment);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.25s, transform 0.15s;
  position: relative;
  overflow: hidden;
}
.cta:hover {
  background: var(--accent-glow);
  transform: translateY(-1px);
}
.cta:active {
  transform: translateY(0);
}

/* Particle BG */
#particle-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  width: 100%;
  height: 100%;
}

/* ---- Casting area ---- */
.casting-area {
  max-width: 740px;
  margin: 0 auto;
  padding-block: var(--space-xl);
  position: relative;
  z-index: 1;
}

.casting-header {
  text-align: center;
  margin-bottom: var(--space-lg);
}
.casting-header h2 {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  color: var(--accent);
  margin-bottom: var(--space-xs);
}
.casting-header p {
  color: var(--text-muted);
}

/* ---- Spell result ---- */
.spell-result {
  max-width: 560px;
  margin: 0 auto;
  padding-block: var(--space-md) var(--space-xl);
  position: relative;
  z-index: 1;
}

.spell-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: spellReveal 0.6s ease-out;
}

@keyframes spellReveal {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.96);
  }
}

.spell-visual {
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.spell-info {
  padding: var(--space-md) var(--space-md) var(--space-sm);
}

.spell-school {
  font-family: var(--font-display);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--highlight);
}

.spell-name {
  font-size: 1.6rem;
  margin-top: 0.25em;
  margin-bottom: 0.4em;
  color: var(--accent);
}

.spell-desc {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
  max-width: 50ch;
}

.spell-stats {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-sm);
  padding-top: var(--space-sm);
  border-top: 1px solid var(--glass);
  font-variant-numeric: tabular-nums;
}

.spell-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.spell-stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}
.spell-stat-value {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--highlight);
}

.spell-again {
  margin: var(--space-sm) var(--space-md) var(--space-md);
  width: calc(100% - var(--space-md) * 2);
}

/* ---- Grimoire ---- */
.grimoire {
  max-width: 740px;
  margin: 0 auto;
  padding-block: var(--space-lg) var(--space-xl);
  position: relative;
  z-index: 1;
}

.grimoire h2 {
  text-align: center;
  font-size: clamp(1.3rem, 3.5vw, 1.8rem);
  color: var(--accent);
  margin-bottom: var(--space-xs);
}
.grimoire-sub {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

.grimoire-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-sm);
}

.grimoire-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--space-lg);
  color: var(--text-muted);
}
.grimoire-empty-icon {
  font-size: 2rem;
  display: block;
  margin-bottom: var(--space-xs);
  opacity: 0.4;
}

.grimoire-entry {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
  cursor: default;
  transition: transform 0.2s;
  animation: spellReveal 0.4s ease-out;
}
.grimoire-entry:hover {
  transform: translateY(-2px);
}
.grimoire-entry-school {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--highlight);
  font-family: var(--font-display);
}
.grimoire-entry-name {
  font-family: var(--font-display);
  font-size: 1rem;
  margin-top: 0.2em;
  color: var(--accent);
}
.grimoire-entry-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.3em;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- Footer ---- */
.site-footer {
  text-align: center;
  padding-block: var(--space-lg);
  color: var(--text-muted);
  font-size: 0.85rem;
  position: relative;
  z-index: 1;
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
  .hero { min-height: 75vh; min-height: 75dvh; padding-block: var(--space-lg); }
  .spell-stats { flex-wrap: wrap; }
  .grimoire-grid { grid-template-columns: 1fr; }
}

@media (min-width: 1200px) {
  .hero { flex-direction: row; text-align: left; justify-content: center; gap: var(--space-xl); }
  .hero-content { max-width: 480px; }
}
