/* J.S. Warden — theme-aware primitives.
   Everything here reads tokens from tokens/themes.css. No hex codes below this line:
   if a component needs a color, add a token to themes.json instead. */

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--body-size);
  font-weight: var(--body-weight);
  line-height: var(--body-leading);
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s ease, color .25s ease;
}

/* The per-world texture (hatch / scanlines / ledger lines) + vignette, behind everything. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: var(--texture);
  box-shadow: var(--vignette);
}
body > * { position: relative; z-index: 1; }

/* ---- Type ---- */
.jsw-display, h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: var(--display-weight);
  text-transform: var(--display-transform);
  letter-spacing: var(--display-tracking);
  line-height: var(--display-leading);
  color: var(--heading);
  font-variant-numeric: lining-nums;
  margin: 0;
  text-wrap: balance;
}
h1, .jsw-display { font-size: calc(clamp(2.75rem, 9vw, 6.5rem) * var(--display-scale)); } /* wide display faces need a smaller size, so each theme sets its own scale */
h2 { font-size: clamp(1.75rem, 4vw, 2.375rem); }
h3 { font-size: clamp(1.375rem, 3vw, 1.75rem); }

/* The one accented phrase in a headline. Italic in Ebonspire, red-ghosted in Echoes. */
.jsw-accent {
  color: var(--accent);
  font-style: var(--display-accent-style);
  text-shadow: var(--display-accent-shadow);
}

.jsw-label, .jsw-kicker {
  font-family: var(--font-label);
  font-size: var(--label-size);
  font-weight: var(--label-weight);
  letter-spacing: var(--label-tracking);
  text-transform: uppercase;
  line-height: 1.6;
  color: var(--text-muted);
}
.jsw-kicker { color: var(--accent); }
.jsw-kicker::before { content: var(--kicker-prefix); }

.jsw-lede { font-size: 1.18em; color: var(--text-muted); max-width: 46em; }
p { margin: 0 0 1em; max-width: 68ch; }

a { color: var(--accent); text-underline-offset: .18em; }
a:hover { color: var(--accent-strong); }

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

/* ---- Rules & dividers ---- */
.jsw-rule { height: 1px; border: 0; margin: 0; background: var(--line); }
.jsw-rule--strong { height: var(--rule-weight); background: var(--line-strong); }
.jsw-rule--accent { background: linear-gradient(90deg, var(--accent-line), transparent); }

/* Short accent line + glyph (the ◆ in Warden / Ebonspire; just the line in Echoes). */
.jsw-divider { display: flex; align-items: center; gap: 14px; color: var(--accent); font-size: .85em; line-height: 1; }
.jsw-divider::before { content: ""; width: 54px; height: 1px; background: var(--accent); }
.jsw-divider::after { content: var(--divider-glyph); }

/* Section head: title, rule that fades out, small aside. */
.jsw-section-head { display: flex; align-items: baseline; gap: 24px; }
.jsw-section-head > .jsw-rule { flex: 1; align-self: center; }

/* ---- Buttons & chips ---- */
.jsw-btn, .jsw-chip {
  display: inline-flex; align-items: center; gap: .6em;
  font-family: var(--font-label);
  font-size: var(--label-size);
  font-weight: var(--label-weight-strong);
  letter-spacing: calc(var(--label-tracking) * .6);
  text-transform: uppercase;
  line-height: 1.2;
  text-decoration: none;
  border-radius: var(--radius);
  border: 1px solid transparent;
}
.jsw-btn { padding: 14px 26px; min-height: 44px; cursor: pointer; background: var(--accent); color: var(--on-accent); transition: background-color .16s ease; }
.jsw-btn:hover { background: var(--accent-strong); color: var(--on-accent); }
.jsw-btn--ghost { background: transparent; color: var(--heading); border-color: var(--line-strong); }
.jsw-btn--ghost:hover { background: transparent; color: var(--accent-strong); border-color: var(--accent); }
.jsw-chip { padding: 9px 16px; font-weight: var(--label-weight); color: var(--text-muted); border-color: var(--line-strong); }
.jsw-chip--solid { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: var(--label-weight-strong); }

/* ---- Surfaces ---- */
.jsw-card { background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(20px, 4vw, 36px); }
.jsw-frame { border: 1px solid var(--accent-line); } /* the inset keyline used on every pin */

/* Book cover with the accent halo behind it. */
.jsw-cover { position: relative; display: inline-block; }
.jsw-cover::before { content: ""; position: absolute; inset: -12px; background: radial-gradient(circle, var(--glow), transparent 70%); filter: blur(30px); }
.jsw-cover img { position: relative; display: block; max-width: 100%; height: auto; border: 1px solid var(--accent-line); box-shadow: var(--shadow); }

/* ---- Forms ---- */
.jsw-input {
  font: inherit; color: var(--heading); background: var(--bg-sunk);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 12px 14px; min-height: 44px; width: 100%;
}
.jsw-input::placeholder { color: var(--text-dim); opacity: 1; }
.jsw-error { color: var(--alert); }

/* ---- Numbers ----
   Dice results, initiative, HP, counts. Always the numeric face, never the label face:
   two themes use a typewriter label font whose digits are too rough to read at a glance. */
.jsw-num {
  font-family: var(--font-numeric);
  font-weight: var(--numeric-weight);
  font-variant-numeric: tabular-nums lining-nums;
  letter-spacing: 0;
  text-transform: none;
}

/* ---- Status messages ----
   Colour is never the only signal: every message starts with a word (Error, Warning, Done). */
.jsw-msg {
  display: block;
  margin: 0;
  padding: 12px 16px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-left: 4px solid var(--text-muted);
  border-radius: var(--radius);
  color: var(--text);
  max-width: none;
}
.jsw-msg strong { font-family: var(--font-label); font-size: var(--label-size); font-weight: var(--label-weight-strong); letter-spacing: calc(var(--label-tracking) * .6); text-transform: uppercase; margin-right: .6em; }
.jsw-msg--error { border-left-color: var(--alert); }
.jsw-msg--error strong { color: var(--alert); }
.jsw-msg--warning { border-left-color: var(--warning); }
.jsw-msg--warning strong { color: var(--warning); }
.jsw-msg--success { border-left-color: var(--success); }
.jsw-msg--success strong { color: var(--success); }

.jsw-visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* ---- Theme switcher ---- */
.jsw-themes { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.jsw-theme-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 44px; min-height: 44px; padding: 8px 12px; cursor: pointer;
  font-family: var(--font-label); font-size: .75rem; font-weight: var(--label-weight); letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-muted); background: transparent;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.jsw-theme-btn:hover { color: var(--heading); border-color: var(--line-strong); }
.jsw-theme-btn[aria-pressed="true"] { color: var(--heading); border-color: var(--accent); }
/* The swatch previews the TARGET theme, so it reads the fixed --swatch-* tokens, not the live ones. */
.jsw-swatch { flex: none; width: 18px; height: 18px; border-radius: 50%; background: var(--sw-bg); border: 1px solid var(--line-strong); box-shadow: inset -6px 0 0 var(--sw-fg); }
[data-theme-set="warden"] .jsw-swatch { --sw-bg: var(--swatch-warden-bg); --sw-fg: var(--swatch-warden-accent); }
[data-theme-set="echoes"] .jsw-swatch { --sw-bg: var(--swatch-echoes-bg); --sw-fg: var(--swatch-echoes-accent); }
[data-theme-set="ebonspire"] .jsw-swatch { --sw-bg: var(--swatch-ebonspire-bg); --sw-fg: var(--swatch-ebonspire-accent); }
[data-theme-set="casefile"] .jsw-swatch { --sw-bg: var(--swatch-casefile-bg); --sw-fg: var(--swatch-casefile-accent); }

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