/* ============================================
   D&D AMIGOS — design tokens
   ============================================ */
:root {
  /* color */
  --void:         #0B0605;
  --panel:        #2B1A10;
  --panel-2:      #34210F;
  --blood:        #7A1F1F;
  --blood-bright: #A5271F;
  --ember:        #D1622E;
  --gold:         #C6A64B;
  --gold-dim:     #8A7433;
  --parchment:    #EFE3C8;
  --parchment-2:  #E4D3AA;
  --ink:          #2A1810;
  --ink-soft:     #5A4430;
  --text:         #E9DCC3;
  --text-dim:     rgba(233, 220, 195, 0.68);

  /* type */
  --font-display: "Cinzel Decorative", "Cinzel", serif;
  --font-heading: "Cinzel", serif;
  --font-body:    "EB Garamond", Georgia, serif;

  /* layout */
  --radius-lg: 6px;
  --radius-md: 4px;
  --max-width: 1860px;
}

/* ============================================
   RESET
   ============================================ */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  /* The two radial-gradients below size themselves to 100% of body's
     own box, which is only as tall as its content — on a short page
     (few journal/character cards, a light dashboard) that box can end
     up shorter than the viewport, so the gradient fades to transparent
     partway down and flat --void shows for the remainder, reading as a
     hard seam across the screen instead of one continuous background.
     Forcing body to at least one viewport tall keeps the gradient's
     reference box consistent regardless of how much content a given
     page has. */
  min-height: 100vh;
  background: var(--void);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(122, 31, 31, 0.16), transparent 55%),
    radial-gradient(ellipse at 85% 15%, rgba(198, 166, 75, 0.06), transparent 45%);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, h3 { margin: 0; font-family: var(--font-heading); }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
  border-radius: 2px;
}

/* subtle grain / parchment texture overlay */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* rising embers */
.embers {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}
.embers .ember-particle {
  position: absolute;
  bottom: -10px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--ember);
  box-shadow: 0 0 6px 1px rgba(209, 98, 46, 0.8);
  animation: rise linear infinite;
  opacity: 0;
}
@keyframes rise {
  0% { transform: translateY(0) translateX(0); opacity: 0; }
  10% { opacity: 0.8; }
  90% { opacity: 0.3; }
  100% { transform: translateY(-100vh) translateX(20px); opacity: 0; }
}

/* ============================================
   UTILITIES
   ============================================ */
.eyebrow {
  font-family: var(--font-heading);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gold);
  margin: 0 0 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 30px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--gold-dim);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease, border-color 0.2s ease;
}

.btn-primary {
  background: linear-gradient(180deg, var(--blood-bright), var(--blood));
  color: var(--parchment);
  border-color: var(--gold);
  box-shadow: 0 2px 0 var(--ink), 0 6px 18px rgba(122, 31, 31, 0.45);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 0 var(--ink), 0 10px 24px rgba(122, 31, 31, 0.55);
}
.btn-primary:active { transform: translateY(0); box-shadow: 0 1px 0 var(--ink); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--ink-soft);
}
.btn-outline:hover { border-color: var(--gold); color: var(--gold); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text);
  padding: 10px 18px;
  text-transform: none;
  font-family: var(--font-body);
  font-style: italic;
  letter-spacing: 0;
}
.btn-ghost:hover { color: var(--gold); }

.btn-block { width: 100%; }
.btn-lg { padding: 18px 40px; font-size: 1rem; }

.btn-primary[disabled] {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none !important;
}

/* ============================================
   HEADER
   ============================================ */
.site-header {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 30px 32px 0;
  position: relative;
  z-index: 10;
}
.wordmark {
  display: flex;
  align-items: center;
  gap: 14px;
}
.wordmark-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--parchment);
  letter-spacing: 0.02em;
}

.torch { position: relative; width: 10px; height: 26px; display: flex; align-items: flex-end; justify-content: center; }
.flame {
  position: relative;
  width: 12px;
  height: 18px;
  background: radial-gradient(ellipse at 50% 100%, var(--ember) 0%, var(--blood-bright) 55%, transparent 80%);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  filter: blur(0.3px);
  animation: flicker 2.2s ease-in-out infinite;
  transform-origin: bottom center;
}
.flame::after {
  content: "";
  position: absolute;
  inset: 30% 25% 10% 25%;
  background: radial-gradient(ellipse at 50% 100%, var(--gold) 0%, var(--ember) 70%, transparent 100%);
  border-radius: 50%;
  opacity: 0.85;
}
@keyframes flicker {
  0%, 100% { transform: scaleY(1) scaleX(1) rotate(0deg); opacity: 1; }
  25% { transform: scaleY(1.08) scaleX(0.92) rotate(-2deg); opacity: 0.92; }
  50% { transform: scaleY(0.94) scaleX(1.05) rotate(1.5deg); opacity: 1; }
  75% { transform: scaleY(1.05) scaleX(0.96) rotate(-1deg); opacity: 0.95; }
}

.site-nav { display: flex; align-items: center; gap: 6px; }
.site-nav a {
  padding: 10px 16px;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: color 0.15s ease;
}
.site-nav a:hover { color: var(--gold); }

.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  padding: 8px;
}
.nav-toggle span {
  width: 24px;
  height: 2px;
  background: var(--gold);
  border-radius: 2px;
}

/* ============================================
   HERO
   ============================================ */
.hero {
  position: relative;
  z-index: 2;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 70px 32px 130px;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  justify-content: center;
  gap: 56px;
  align-items: start;
}

.hero-content { max-width: 640px; justify-self: end; }

.hero-title {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 4.6vw, 3.6rem);
  font-weight: 700;
  line-height: 1.12;
  color: var(--parchment);
  text-shadow: 0 2px 24px rgba(122, 31, 31, 0.35);
}
.hero-title-highlight {
  color: var(--ember);
  position: relative;
}

.hero-sub {
  margin-top: 26px;
  max-width: 48ch;
  font-size: 1.18rem;
  font-style: italic;
  color: var(--text-dim);
}

.hero-actions {
  margin-top: 34px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.hero-stats {
  margin-top: 58px;
  display: flex;
  gap: 44px;
  flex-wrap: wrap;
  border-top: 1px solid rgba(198, 166, 75, 0.25);
  padding-top: 28px;
}
.stat { display: flex; flex-direction: column; }
.stat-num {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2rem;
  color: var(--gold);
}
.stat-label {
  font-size: 0.76rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 4px;
}

/* ============================================
   LOGIN "SCROLL" CARD
   ============================================ */
.login-scroll {
  position: relative;
  width: 100%;
  max-width: 480px;
  justify-self: start;
  background: var(--parchment);
  background-image:
    radial-gradient(ellipse at 15% 10%, rgba(122, 31, 31, 0.06), transparent 40%),
    radial-gradient(ellipse at 90% 90%, rgba(122, 31, 31, 0.06), transparent 40%);
  color: var(--ink);
  padding: 48px 34px 32px;
  margin-top: 6px;
  border: 1px solid var(--parchment-2);
  clip-path: polygon(
    0% 2%, 2% 0%, 98% 0%, 100% 2%,
    99% 6%, 100% 10%, 99% 15%, 100% 20%,
    99% 30%, 100% 40%, 99% 50%, 100% 60%,
    99% 70%, 100% 80%, 99% 88%, 100% 94%,
    100% 98%, 98% 100%, 2% 100%, 0% 98%,
    1% 94%, 0% 88%, 1% 80%, 0% 70%,
    1% 60%, 0% 50%, 1% 40%, 0% 30%,
    1% 20%, 0% 12%, 1% 6%
  );
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0,0,0,0.2);
}

.scroll-pin {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #E8C97A, var(--gold-dim) 70%);
  box-shadow: 0 3px 6px rgba(0,0,0,0.5);
}

.wax-seal {
  position: absolute;
  top: -26px;
  right: 30px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--blood-bright), var(--blood) 70%, #4a1010 100%);
  border: 2px solid #4a1010;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--gold);
  font-size: 0.9rem;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5), inset 0 2px 4px rgba(255,255,255,0.15);
  transform: rotate(8deg);
}

.login-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  padding-right: 60px;
}
.login-sub {
  margin-top: 8px;
  color: var(--ink-soft);
  font-size: 0.96rem;
  font-style: italic;
}

#login-form { margin-top: 28px; display: flex; flex-direction: column; gap: 18px; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field-label {
  font-family: var(--font-heading);
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

input[type="email"],
input[type="password"],
input[type="text"] {
  font-family: var(--font-body);
  font-size: 1.02rem;
  padding: 12px 15px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--ink-soft);
  background: #F7EED9;
  color: var(--ink);
  width: 100%;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
input::placeholder { color: rgba(42, 24, 16, 0.4); }
input:focus {
  outline: none;
  border-color: var(--blood);
  box-shadow: 0 0 0 3px rgba(122, 31, 31, 0.18);
}
input.is-invalid { border-color: var(--blood-bright); }
input.is-invalid:focus { box-shadow: 0 0 0 3px rgba(165, 39, 31, 0.2); }

.password-wrap { position: relative; display: flex; }
.password-wrap input { padding-right: 68px; }
.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--gold);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 6px 12px;
  color: var(--ink);
}
.password-toggle:hover { background: #D9BC6C; }

.field-error {
  font-size: 0.78rem;
  color: var(--blood-bright);
  font-weight: 600;
  min-height: 1em;
}

.login-status {
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 1.2em;
}
.login-status.success { color: #3D6B3A; }
.login-status.error { color: var(--blood-bright); }

.login-footnote {
  margin-top: 22px;
  text-align: center;
  font-size: 0.9rem;
  font-style: italic;
  color: var(--ink-soft);
}
.login-footnote a {
  color: var(--blood);
  font-weight: 600;
  font-style: normal;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ============================================
   MARQUEE
   ============================================ */
.marquee {
  position: relative;
  z-index: 2;
  border-top: 1px solid var(--gold-dim);
  border-bottom: 1px solid var(--gold-dim);
  background: var(--panel-2);
  color: var(--gold);
  overflow: hidden;
  padding: 14px 0;
}
.marquee-track {
  display: flex;
  gap: 20px;
  white-space: nowrap;
  width: max-content;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  animation: marquee 30s linear infinite;
}
@keyframes marquee {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

/* ============================================
   TOAST
   ============================================ */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel);
  border: 1px solid var(--gold-dim);
  color: var(--parchment);
  padding: 14px 24px;
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 1000;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 960px) {
  .hero { grid-template-columns: 1fr; padding-bottom: 90px; }
  .login-scroll { max-width: 480px; }
}

@media (max-width: 720px) {
  .site-nav { display: none; }
  .nav-toggle { display: flex; }
  .site-header.nav-open .site-nav {
    display: flex;
    position: absolute;
    top: 64px;
    right: 24px;
    left: 24px;
    background: var(--panel);
    border: 1px solid rgba(198, 166, 75, 0.25);
    border-radius: var(--radius-md);
    flex-direction: column;
    padding: 14px;
    z-index: 20;
  }
  .hero { padding-left: 20px; padding-right: 20px; }
  .hero-stats { gap: 30px; }
}

/* Lore notes: the notes panel on an NPC or place (pages/lore-notes.js), and the Foundry-managed badge. */
.lore-notes { margin: 16px 0; padding-top: 12px; border-top: 1px solid rgba(198,166,75,0.25); }
.lore-notes-title { font-family: var(--font-heading); color: var(--gold); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 10px; }
.lore-notes-empty { color: var(--text-dim); font-size: 0.88rem; font-style: italic; margin-bottom: 8px; }
.lore-note { background: rgba(0,0,0,0.22); border: 1px solid rgba(198,166,75,0.15); border-radius: var(--radius-md); padding: 8px 12px; margin-bottom: 8px; }
.lore-note-meta { font-size: 0.78rem; color: var(--text-dim); margin-bottom: 3px; }
.lore-note-meta strong { color: var(--parchment); }
.lore-note-body { color: var(--text); font-size: 0.92rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.lore-note-tools { display: flex; gap: 12px; margin-top: 4px; }
.lore-note-link { background: none; border: none; padding: 0; color: var(--gold); font-size: 0.78rem; cursor: pointer; text-decoration: underline; }
.lore-notes-form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.lore-notes-form textarea, .lore-note textarea { width: 100%; padding: 8px 10px; background: rgba(0,0,0,0.3); color: var(--parchment); border: 1px solid rgba(198,166,75,0.3); border-radius: var(--radius-md); font: inherit; font-size: 0.92rem; resize: vertical; }
.lore-notes-form .btn { align-self: flex-end; }
.lore-notes-status { min-height: 1.1em; font-size: 0.82rem; color: var(--blood-bright); margin-top: 6px; }
.lore-note-count { font-size: 0.78rem; color: var(--text-dim); margin-top: 2px; }
.lore-foundry-badge { font-size: 0.78rem; color: var(--text-dim); border-left: 3px solid var(--gold); padding: 2px 8px; margin-bottom: 12px; }

/* Character full sheet (pages/character-sheet.js) */
.character-full-sheet { margin: 14px 0; }
.csheet { border-top: 1px solid rgba(198,166,75,0.25); padding-top: 12px; }
.csheet-source { color: var(--text-dim); font-size: 0.78rem; margin-bottom: 6px; }
.csheet-who { color: var(--parchment); font-size: 0.92rem; margin-bottom: 8px; }
.csheet-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.csheet-chip { background: rgba(0,0,0,0.25); border: 1px solid rgba(198,166,75,0.2); border-radius: 12px; padding: 2px 10px; font-size: 0.82rem; color: var(--text); }
.csheet-chip b { color: var(--gold); font-weight: 600; }
.csheet-abilities { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 12px; }
.csheet-ability { background: rgba(0,0,0,0.25); border: 1px solid rgba(198,166,75,0.2); border-radius: var(--radius-md); text-align: center; padding: 4px 2px; }
.csheet-ability .k { display: block; font-size: 0.68rem; color: var(--text-dim); letter-spacing: 0.05em; }
.csheet-ability .v { display: block; font-family: var(--font-display); color: var(--gold); font-size: 1.05rem; }
.csheet-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; border-bottom: 1px solid rgba(198,166,75,0.25); }
.csheet-tab { background: none; border: 1px solid transparent; border-bottom: none; color: var(--text-dim); padding: 6px 12px; cursor: pointer; font-family: var(--font-heading); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; border-radius: 6px 6px 0 0; }
.csheet-tab.is-active { color: var(--gold); border-color: rgba(198,166,75,0.35); background: rgba(0,0,0,0.2); }
.csheet-body h4 { font-family: var(--font-heading); color: var(--gold); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; margin: 12px 0 6px; }
.csheet-list { list-style: none; padding: 0; margin: 0; }
.csheet-list li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px solid rgba(198,166,75,0.1); font-size: 0.9rem; }
.csheet-list li.csheet-nested { padding-left: 18px; }
.csheet-list .nm { color: var(--parchment); } .csheet-list .meta { color: var(--text-dim); font-size: 0.78rem; text-align: right; }
.csheet-cols { columns: 2; column-gap: 24px; } .csheet-cols li { break-inside: avoid; }
.csheet-coins, .csheet-rank { font-size: 0.9rem; margin: 4px 0; } .csheet-rank b { color: var(--gold); }
.csheet-text { white-space: pre-wrap; font-size: 0.88rem; color: var(--text-dim); } .csheet-empty { color: var(--text-dim); font-style: italic; font-size: 0.88rem; }
@media (max-width: 520px) { .csheet-abilities { grid-template-columns: repeat(3, 1fr); } .csheet-cols { columns: 1; } }
