/* Amethyst: very dark glassmorphism with a purple accent. */

/* Cinzel (SIL Open Font License, see /fonts/Cinzel-OFL.txt): the default title font. Self-hosted so it
   works under the strict CSP and offline. */
@font-face {
  font-family: "Cinzel"; font-style: normal; font-weight: 600; font-display: swap;
  src: url("/fonts/cinzel-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Cinzel"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("/fonts/cinzel-latin-700-normal.woff2") format("woff2");
}

:root {
  --font-title: "Cinzel", "Trajan Pro", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: dark;
  --bg: #07050d;
  --text: #ece8f6;
  --muted: #a59cb8;
  --accent: #a374ff;
  --accent-strong: #8b5cf6;
  --accent-deep: #6d3fd9;
  --accent-glow: rgba(139, 92, 246, .35);
  /* Dark, violet-tinted glass: stays readable over the bright centre of the forest photo. */
  --panel: linear-gradient(145deg, rgba(38, 24, 70, .60), rgba(14, 9, 30, .66));
  --campaign-bg: url("/images/amethyst_forest.png");
  --glass: rgba(255, 255, 255, .045);
  --glass-strong: rgba(255, 255, 255, .075);
  --glass-border: rgba(255, 255, 255, .09);
  --glass-highlight: rgba(255, 255, 255, .14);
  --field: rgba(8, 5, 18, .55);
  --danger: #ff8f8f;
  --danger-bg: rgba(255, 90, 90, .1);
  --ok: #4ade80;
  --radius: 16px;
  --blur: blur(22px) saturate(160%);
}
/* Campaign tints: the DM shifts one campaign away from purple. Scoped to <body data-campaign-tint>. */
body[data-campaign-tint="red"] {
  --accent: #ff7b7b; --accent-strong: #e03131; --accent-deep: #a61e1e; --accent-glow: rgba(224, 49, 49, .35);
  --panel: linear-gradient(145deg, rgba(70, 22, 22, .60), rgba(28, 9, 12, .66)); --bg: #0d0507;
}
body[data-campaign-tint="blue"] {
  --accent: #7ab8ff; --accent-strong: #3b82f6; --accent-deep: #1e40af; --accent-glow: rgba(59, 130, 246, .35);
  --panel: linear-gradient(145deg, rgba(22, 38, 70, .60), rgba(9, 14, 30, .66)); --bg: #05070d;
}
body[data-campaign-tint="green"] {
  --accent: #7ce38b; --accent-strong: #22c55e; --accent-deep: #166534; --accent-glow: rgba(34, 197, 94, .35);
  --panel: linear-gradient(145deg, rgba(22, 58, 32, .60), rgba(9, 24, 14, .66)); --bg: #050d07;
}
body[data-campaign-tint="brown"] {
  --accent: #e0a878; --accent-strong: #b08968; --accent-deep: #7f5539; --accent-glow: rgba(176, 137, 104, .35);
  --panel: linear-gradient(145deg, rgba(58, 40, 26, .62), rgba(24, 16, 10, .66)); --bg: #0d0806;
}
body[data-campaign-tint="black"] {
  --accent: #d9d9d9; --accent-strong: #9c9c9c; --accent-deep: #525252; --accent-glow: rgba(255, 255, 255, .25);
  --panel: linear-gradient(145deg, rgba(38, 38, 40, .68), rgba(14, 14, 15, .72)); --bg: #070707; --muted: #9c9c9c;
}
* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
}
/* Amethyst forest art behind everything. A fixed layer (not background-attachment) so it also works on
   phones. The dark overlay keeps text readable; the glass panels blur and tint whatever shows through. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -2; pointer-events: none;
  background:
    radial-gradient(95rem 60rem at 50% 40%, transparent 30%, rgba(7, 5, 13, .62) 100%),
    linear-gradient(rgba(7, 5, 13, .30), rgba(7, 5, 13, .52)),
    var(--campaign-bg) center / cover no-repeat;
}
/* Fireflies sit above the photo and below the content. */
#fireflies {
  position: fixed; inset: 0; z-index: -1; pointer-events: none; display: block;
  width: 100%; height: 100%;
}
a { color: var(--accent); text-decoration-color: rgba(163, 116, 255, .4); text-underline-offset: 3px; }
a:hover { color: #c4a5ff; }
h1, h2, h3, .brand { font-family: var(--font-title); font-weight: 700; }
h1 { font-size: 1.9rem; margin: 0 0 .35rem; letter-spacing: .03em; text-shadow: 0 0 28px var(--accent-glow); }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; color: #f4f0ff; letter-spacing: .05em; font-weight: 600; }
h3 { font-size: .95rem; margin: 0 0 .4rem; color: #f4f0ff; letter-spacing: .04em; font-weight: 600; }
p { margin: 0 0 .75rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .7rem 1.1rem; background: rgba(10, 6, 20, .6);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--glass-border);
}
.brand { font-weight: 700; text-decoration: none; font-size: 1.15rem; color: var(--text); letter-spacing: .02em; }
.brand:hover { color: var(--text); }
#nav { display: flex; align-items: center; gap: .75rem; font-size: .95rem; color: var(--muted); }

main { max-width: 960px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

/* Glass surfaces */
.card, .notice-card {
  background: var(--panel);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1.15rem;
  margin-bottom: 1rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .45), inset 0 1px 0 var(--glass-highlight);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
}
.notice-card {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem;
  border-color: rgba(163, 116, 255, .4); background: linear-gradient(145deg, rgba(139, 92, 246, .2), rgba(139, 92, 246, .06));
}
.danger-zone { border-color: rgba(255, 120, 120, .25); }
.grid { display: grid; gap: 1rem; }
@media (min-width: 720px) { .grid.two { grid-template-columns: 1fr 1fr; } }
.muted { color: var(--muted); font-size: .9rem; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.row.between { justify-content: space-between; }
.row.end { align-items: flex-end; margin-bottom: .75rem; }
.row.end .field { margin: 0; width: 9rem; }
.row.end .field input { width: 100%; }

ul.list { list-style: none; margin: 0; padding: 0; }
ul.list li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem; padding: .65rem 0; border-top: 1px solid var(--glass-border); }
ul.list li:first-child { border-top: 0; }
ul.activity li { font-size: .95rem; }

.badge {
  display: inline-block; font-size: .7rem; padding: .08rem .55rem; border-radius: 999px;
  background: rgba(163, 116, 255, .16); color: #d3bcff; border: 1px solid rgba(163, 116, 255, .35);
  text-transform: uppercase; letter-spacing: .06em;
}
.badge.archived { background: rgba(255, 255, 255, .07); color: var(--muted); border-color: var(--glass-border); }

/* Forms */
label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .25rem; color: #d9d2ea; }
input, textarea, select {
  width: 100%; font: inherit; padding: .55rem .7rem; color: var(--text);
  background: var(--field); border: 1px solid var(--glass-border); border-radius: 10px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .4);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: #6f6684; }
input:hover, textarea:hover { border-color: var(--glass-highlight); }
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
input:disabled, textarea:disabled { background: rgba(255, 255, 255, .03); color: var(--text); opacity: .85; box-shadow: none; }
textarea { min-height: 7rem; resize: vertical; }
.field { margin-bottom: .8rem; }
.field.invalid input, .field.invalid textarea { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .85rem; margin-top: .25rem; }
.fields { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-bottom: .8rem; }
.fields .field { margin-bottom: 0; }

/* Buttons */
button, .btn {
  font: inherit; font-weight: 600; cursor: pointer; color: #fff; text-decoration: none; display: inline-block;
  padding: .5rem 1rem; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .18);
  background: linear-gradient(180deg, var(--accent-strong), var(--accent-deep));
  box-shadow: 0 4px 18px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: transform .1s, box-shadow .15s, filter .15s;
}
button:hover, .btn:hover { color: #fff; filter: brightness(1.12); box-shadow: 0 6px 24px rgba(139, 92, 246, .5), inset 0 1px 0 rgba(255, 255, 255, .3); }
button:active, .btn:active { transform: translateY(1px); }
button.secondary, .btn.secondary {
  background: var(--glass); color: var(--accent); border-color: rgba(163, 116, 255, .45); box-shadow: none;
}
button.secondary:hover, .btn.secondary:hover { background: rgba(163, 116, 255, .15); box-shadow: none; color: #c9b0ff; }
button.danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(255, 120, 120, .45); box-shadow: none; }
button.danger:hover { background: rgba(255, 90, 90, .2); box-shadow: none; color: #ffb0b0; }
button.link { background: var(--glass); border-color: var(--glass-border); box-shadow: none; padding: .3rem .8rem; font-weight: 500; }
button:focus-visible, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button[disabled] { opacity: .55; cursor: default; filter: none; transform: none; }

.code {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1rem; color: #e0ceff;
  background: rgba(139, 92, 246, .14); border: 1px solid rgba(163, 116, 255, .3);
  padding: .1rem .5rem; border-radius: 8px; user-select: all;
}
.error-banner { background: var(--danger-bg); border: 1px solid rgba(255, 120, 120, .4); color: var(--danger); padding: .6rem .8rem; border-radius: 10px; margin-bottom: .8rem; }
.notice { padding: 1rem; }

#toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: grid; gap: .5rem; z-index: 10; width: min(92vw, 420px); }
.toast {
  padding: .7rem .95rem; border-radius: 12px; color: var(--text);
  background: rgba(20, 14, 38, .8); border: 1px solid rgba(74, 222, 128, .45);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
.toast.error { border-color: rgba(255, 120, 120, .55); color: #ffd0d0; }

/* Character sheet */
.portrait { width: 96px; height: 96px; object-fit: cover; border-radius: 14px; border: 1px solid var(--glass-highlight); background: var(--glass); box-shadow: 0 0 24px var(--accent-glow); }
.sheet-head { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.abilities { grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); }
.abilities input { text-align: center; font-size: 1.25rem; font-weight: 700; color: #e0ceff; }
.auth { max-width: 420px; margin: 2.5rem auto; }

/* Tabs: a flat underlined tab strip, not buttons. */
.tablist { display: flex; margin: 1.1rem 0 1.25rem; border-bottom: 1px solid var(--glass-border); }
.tab {
  flex: 1; margin-bottom: -1px; padding: .65rem .5rem; border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  background: transparent; box-shadow: none; color: var(--muted); font-weight: 600; letter-spacing: .02em; filter: none;
}
.tab:hover { background: rgba(163, 116, 255, .08); color: var(--text); box-shadow: none; filter: none; }
.tab[aria-selected="true"] { color: #fff; border-bottom-color: var(--accent); box-shadow: 0 8px 14px -10px var(--accent-glow); }
.tab:focus-visible { outline-offset: -3px; border-radius: 6px 6px 0 0; }

/* Navigation */
.nav-link { color: var(--muted); text-decoration: none; padding: .25rem .1rem; border-bottom: 2px solid transparent; }
.nav-link:hover { color: var(--text); }
.nav-link[aria-current="page"] { color: #fff; border-bottom-color: var(--accent); }
.nav-user { padding-left: .5rem; border-left: 1px solid var(--glass-border); }

/* Dictation: input with a trailing microphone button */
.input-wrap { display: flex; align-items: stretch; gap: .4rem; }
.input-wrap.top { align-items: flex-start; }
.input-wrap.other { margin-top: .4rem; }
.input-wrap > input, .input-wrap > textarea { flex: 1; min-width: 0; }
button.mic {
  flex: none; width: 2.6rem; padding: 0; display: inline-flex; align-items: center; justify-content: center;
  background: var(--glass); color: var(--accent); border-color: rgba(163, 116, 255, .4); box-shadow: none;
}
button.mic:hover { background: rgba(163, 116, 255, .18); color: #d3bcff; box-shadow: none; filter: none; }
button.mic.listening { background: rgba(255, 90, 90, .18); color: var(--danger); border-color: rgba(255, 120, 120, .6); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(255, 120, 120, .18); } }

select {
  width: 100%; font: inherit; padding: .55rem .7rem; color: var(--text); background: var(--field);
  border: 1px solid var(--glass-border); border-radius: 10px; box-shadow: inset 0 1px 3px rgba(0, 0, 0, .4);
}
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
select option { background: #15102a; color: var(--text); }
select:disabled { background: rgba(255, 255, 255, .03); opacity: .85; }
.field.check label { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.field.check input { width: auto; accent-color: var(--accent-strong); }

/* Dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { text-align: center; padding: .9rem; border-radius: var(--radius); border: 1px solid var(--glass-border); background: var(--panel); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); }
.stat-value { font-family: var(--font-title); font-size: 1.9rem; font-weight: 700; color: #e0ceff; }
.stat-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
.char-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.char-card { padding: .9rem; border-radius: 12px; border: 1px solid var(--glass-border); background: rgba(255, 255, 255, .03); }
.char-card h3 { margin: 0; font-size: 1.05rem; }
.char-card p { margin: .2rem 0 .6rem; }
.hp-bar { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .08); overflow: hidden; margin-bottom: .45rem; }
.hp-fill { height: 100%; background: linear-gradient(90deg, #7c4df0, #c4a5ff); border-radius: 99px; }
.hp-bar.low .hp-fill { background: linear-gradient(90deg, #ff6b6b, #ffb0a0); }
.pill { padding: .05rem .6rem; border-radius: 99px; background: rgba(163, 116, 255, .16); border: 1px solid rgba(163, 116, 255, .35); font-size: .85rem; }

/* Custom option chips */
.option-group { margin-bottom: .5rem; }
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 .6rem; padding: 0; }
.chip { display: inline-flex; align-items: center; gap: .2rem; padding: .1rem .2rem .1rem .7rem; border-radius: 99px; background: rgba(163, 116, 255, .14); border: 1px solid rgba(163, 116, 255, .35); font-size: .9rem; }
button.chip-x { padding: 0 .5rem; background: transparent; border: 0; box-shadow: none; color: var(--muted); font-size: 1.1rem; line-height: 1.4; }
button.chip-x:hover { background: transparent; color: var(--danger); box-shadow: none; filter: none; }

/* Fallbacks */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .card, .notice-card { background: #15102a; }
  .topbar { background: #0d0919; }
  .toast { background: #1a1230; }
}
@media (prefers-reduced-transparency: reduce) {
  .card, .notice-card { background: #15102a; -webkit-backdrop-filter: none; backdrop-filter: none; }
  .topbar { background: #0d0919; -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.option-group .row.end .field { width: auto; flex: 1; min-width: 10rem; }
.row.end .field select, .row.end .field .input-wrap { width: 100%; }

/* Author display rules must not override the hidden attribute. */
[hidden] { display: none !important; }

/* Narrow screens: keep the header on one row without widening the page. */
.brand { white-space: nowrap; }
#nav { flex-wrap: wrap; justify-content: flex-end; gap: .4rem .75rem; min-width: 0; }
@media (max-width: 520px) {
  .topbar { padding: .6rem .75rem; gap: .5rem; }
  .brand { font-size: 1rem; }
  .nav-user { display: none; }
  #nav { gap: .3rem .6rem; font-size: .9rem; }
  button.link { padding: .25rem .6rem; }
}

.attribution { max-width: 960px; margin: 0 auto; padding: 0 1rem 2rem; color: var(--muted); font-size: .8rem; }
.attribution a { color: var(--muted); }
.attribution a:hover { color: var(--accent); }

/* Derived stats on the character sheet */
.ability-tile { text-align: center; }
.mod {
  display: inline-block; margin-top: .35rem; padding: .05rem .8rem; border-radius: 99px; min-width: 3rem;
  font-weight: 700; color: #e0ceff; background: rgba(163, 116, 255, .16); border: 1px solid rgba(163, 116, 255, .35);
}
.prof-grid { display: grid; gap: .35rem 1.5rem; grid-template-columns: 1fr; }
@media (min-width: 720px) { .prof-grid { grid-template-columns: 1fr 1fr; } }
.prof-row { display: flex; align-items: center; gap: .6rem; padding: .3rem 0; border-bottom: 1px solid var(--glass-border); }
.prof-row label { margin: 0; font-weight: 500; flex: 1; }
.prof-row select { width: auto; padding: .3rem .5rem; font-size: .9rem; }
.prof-row .val { min-width: 3rem; text-align: right; font-weight: 700; color: #e0ceff; font-variant-numeric: tabular-nums; }
.check-label { display: flex; align-items: center; gap: .5rem; }
.check-label input, .death-group input { width: auto; accent-color: var(--accent-strong); }
.death-saves { display: flex; flex-wrap: wrap; gap: .75rem 2rem; margin-top: .5rem; }
.death-group { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.death-label { font-weight: 600; min-width: 5.5rem; }
.death-group .row { gap: .6rem; }
.death-group input { width: 1.25rem; height: 1.25rem; }

/* ---- Themed dropdown (see js/dropdown.js) ---- */
.dropdown { display: block; position: relative; }
button.dropdown-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: .6rem; text-align: left;
  font: inherit; font-weight: 400; color: var(--text); letter-spacing: normal; cursor: pointer;
  padding: .55rem .7rem; background: var(--field); border: 1px solid var(--glass-border); border-radius: 10px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .4); filter: none; transition: border-color .15s, box-shadow .15s;
}
button.dropdown-btn:hover { background: var(--field); border-color: var(--glass-highlight); filter: none; box-shadow: inset 0 1px 3px rgba(0, 0, 0, .4); color: var(--text); }
button.dropdown-btn:active { transform: none; }
button.dropdown-btn:focus-visible, button.dropdown-btn[aria-expanded="true"] {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow);
}
button.dropdown-btn[disabled] { background: rgba(255, 255, 255, .03); opacity: .85; cursor: default; box-shadow: none; }
.dropdown-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown-btn.is-placeholder .dropdown-text { color: var(--muted); }
.dropdown-caret {
  flex: none; width: .5rem; height: .5rem; margin: -.2rem .15rem 0 0;
  border-right: 2px solid var(--accent); border-bottom: 2px solid var(--accent);
  transform: rotate(45deg); transition: transform .15s;
}
.dropdown-btn[aria-expanded="true"] .dropdown-caret { transform: translateY(.2rem) rotate(225deg); }
.dropdown-btn[disabled] .dropdown-caret { opacity: .35; }

.dropdown-menu {
  position: fixed; z-index: 1000; overflow-y: auto; padding: .35rem; max-width: calc(100vw - 16px);
  background: linear-gradient(145deg, rgba(40, 26, 74, .94), rgba(15, 10, 32, .96));
  border: 1px solid rgba(163, 116, 255, .35); border-radius: 12px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .65), 0 0 0 1px rgba(0, 0, 0, .3), inset 0 1px 0 var(--glass-highlight);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
}
.dropdown-group { padding: .55rem .65rem .2rem; font-size: .7rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.dropdown-group:first-child { padding-top: .25rem; }
.dropdown-option {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .45rem .65rem; border-radius: 8px; cursor: pointer; color: var(--text);
}
.dropdown-option.is-active { background: rgba(163, 116, 255, .22); color: #fff; }
.dropdown-option[aria-selected="true"] { color: #e0ceff; font-weight: 600; }
.dropdown-option[aria-selected="true"]::after { content: "\2713"; color: var(--accent); font-weight: 700; }

.prof-row .dropdown { width: auto; }
.prof-row button.dropdown-btn { min-width: 8.75rem; padding: .3rem .6rem; font-size: .9rem; }
.row.end .field:has(.dropdown) { width: auto; min-width: 12rem; }
.row.end .field .dropdown { width: 100%; }

/* ---- Scrollbars ---- */
/* Chromium/Safari: custom track and glowing violet thumb. Firefox: standard properties. */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: rgba(8, 5, 18, .55); border-left: 1px solid var(--glass-border); }
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #8b5cf6, #5b2fc4); border-radius: 99px;
  border: 3px solid transparent; background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: linear-gradient(180deg, #a374ff, #7c4df0); background-clip: padding-box; }
::-webkit-scrollbar-thumb:active { background: linear-gradient(180deg, #c4a5ff, #8b5cf6); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }
@supports (-moz-appearance: none) {
  * { scrollbar-width: thin; scrollbar-color: #8b5cf6 rgba(8, 5, 18, .55); }
}
.dropdown-menu::-webkit-scrollbar { width: 10px; }
.dropdown-menu::-webkit-scrollbar-track { background: transparent; border-left: 0; }

/* ---- Dice roller ---- */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.dice-buttons { margin-bottom: .8rem; }
button.die-btn { min-width: 3.2rem; padding: .35rem .6rem; font-family: var(--font-title); letter-spacing: .03em; }
.roll-latest:empty { display: none; }
.roll-latest { text-align: center; padding: .9rem; margin: 1rem 0 .5rem; border-radius: 12px; border: 1px solid rgba(163, 116, 255, .35); background: rgba(139, 92, 246, .10); }
.roll-total { font-family: var(--font-title); font-size: 3rem; line-height: 1.1; font-weight: 700; color: #f0e6ff; text-shadow: 0 0 24px var(--accent-glow); }
.roll-total.nat20 { color: #ffe08a; text-shadow: 0 0 28px rgba(255, 200, 80, .6); }
.roll-total.nat1 { color: var(--danger); text-shadow: 0 0 28px rgba(255, 90, 90, .5); }
.roll-history-title { margin-top: 1.1rem; }
.roll-item { display: block !important; }
.roll-main { display: flex; justify-content: space-between; align-items: baseline; gap: .75rem; }
.roll-total-small { font-family: var(--font-title); font-size: 1.25rem; font-weight: 700; color: #e0ceff; }
.roll-detail { margin-top: .15rem; }
.die { font-variant-numeric: tabular-nums; color: var(--text); }
.die.dropped { text-decoration: line-through; opacity: .5; }
.badge.nat20 { color: #ffe08a; border-color: rgba(255, 200, 80, .5); background: rgba(255, 200, 80, .12); }
.badge.nat1 { color: var(--danger); border-color: rgba(255, 120, 120, .5); background: var(--danger-bg); }
button.roll-btn { padding: .15rem .65rem; font-size: .8rem; }

/* Skill/save rows must never push the page wider than the screen. */
.prof-row { flex-wrap: wrap; }
.prof-row label { min-width: 7rem; }
@media (max-width: 520px) {
  .prof-row { gap: .4rem; }
  .prof-row button.dropdown-btn { min-width: 6.25rem; }
}

/* ---- Combat tracker ---- */
.combat-title { margin: 0; }
.turn-line { margin: .4rem 0 .75rem; font-size: 1.05rem; }
.combat-controls { margin-bottom: .9rem; }
.combat-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .5rem; }
.combat-row {
  display: grid; grid-template-columns: 1.4rem 1fr auto auto; align-items: center; gap: .6rem;
  padding: .6rem .75rem; border-radius: 12px; border: 1px solid var(--glass-border); background: rgba(255, 255, 255, .035);
}
.combat-row.is-current { border-color: rgba(163, 116, 255, .8); background: rgba(139, 92, 246, .20); box-shadow: 0 0 22px var(--accent-glow); }
.combat-row.unrolled { opacity: .75; }
.turn-marker { color: var(--accent); font-size: 1.1rem; }
.combat-init { text-align: right; }
.init { font-family: var(--font-title); font-size: 1.5rem; font-weight: 700; color: #e0ceff; }
.combat-row.is-current .init { color: #fff; }
input.mini { width: 4.5rem; padding: .3rem .5rem; text-align: center; font-size: 1rem; }
.hp-edit input.mini { width: 3.8rem; padding: .15rem .35rem; font-size: .9rem; }
button.small { padding: .25rem .7rem; font-size: .85rem; }
.add-combatants { margin-top: .5rem; border-top: 1px solid var(--glass-border); padding-top: .75rem; }
.add-combatants summary { cursor: pointer; font-weight: 600; margin-bottom: .75rem; color: var(--accent); }
.add-combatants form { margin-top: .75rem; }
@media (max-width: 520px) {
  .combat-row { grid-template-columns: 1.2rem 1fr auto; }
  .combat-actions { grid-column: 2 / -1; }
}

/* ---- Campaign lore ---- */
.lore-grid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); margin-top: .5rem; }
.lore-grid > p { grid-column: 1 / -1; }
a.lore-card {
  display: block; padding: .9rem; border-radius: 12px; text-decoration: none; color: var(--text);
  border: 1px solid var(--glass-border); background: rgba(255, 255, 255, .035); transition: border-color .15s, background .15s, transform .1s;
}
a.lore-card:hover { border-color: rgba(163, 116, 255, .6); background: rgba(139, 92, 246, .14); color: var(--text); }
a.lore-card:active { transform: translateY(1px); }
.lore-card h3 { margin: .5rem 0 .2rem; font-size: 1.05rem; }
.lore-card p { margin: 0; }
.lore-summary { font-size: 1.1rem; margin: .75rem 0; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.badge.kind-npc { color: #ffd6a5; border-color: rgba(255, 190, 120, .45); background: rgba(255, 190, 120, .10); }
.badge.kind-location { color: #a8e6cf; border-color: rgba(120, 220, 180, .45); background: rgba(120, 220, 180, .10); }
.badge.kind-faction { color: #ffb3c7; border-color: rgba(255, 130, 170, .45); background: rgba(255, 130, 170, .10); }
.badge.kind-quest { color: #ffe08a; border-color: rgba(255, 200, 80, .45); background: rgba(255, 200, 80, .10); }
.badge.status-completed { color: var(--ok); border-color: rgba(74, 222, 128, .5); background: rgba(74, 222, 128, .10); }
.badge.status-failed { color: var(--danger); border-color: rgba(255, 120, 120, .5); background: var(--danger-bg); }
.link-chip a { padding: 0; }
.link-chip { padding-right: .7rem; gap: .35rem; }
.linkpick { max-height: 18rem; overflow-y: auto; padding: .25rem .5rem; border: 1px solid var(--glass-border); border-radius: 10px; background: var(--field); }
.linkpick-group { margin: .6rem 0 .2rem; font-size: .7rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.linkpick .check-label { padding: .2rem 0; font-weight: 400; }

/* Tab strips never widen the page: they scroll inside their container when there are many tabs. */
.tablist { overflow-x: auto; overscroll-behavior-x: contain; }
.tablist::-webkit-scrollbar { height: 4px; }
.tablist::-webkit-scrollbar-track { background: transparent; border: 0; }
.tab { flex: 1 0 auto; white-space: nowrap; padding-inline: .9rem; }

/* ---- Sessions ---- */
.session-when { font-size: 1.1rem; margin: .75rem 0; }
.badge.session-scheduled { color: #a8d8ff; border-color: rgba(120, 190, 255, .5); background: rgba(120, 190, 255, .10); }
.badge.session-completed { color: var(--ok); border-color: rgba(74, 222, 128, .5); background: rgba(74, 222, 128, .10); }
.badge.session-cancelled { color: var(--danger); border-color: rgba(255, 120, 120, .5); background: var(--danger-bg); }
.badge.rsvp-yes { color: var(--ok); border-color: rgba(74, 222, 128, .5); background: rgba(74, 222, 128, .10); }
.badge.rsvp-maybe { color: #ffe08a; border-color: rgba(255, 200, 80, .5); background: rgba(255, 200, 80, .10); }
.badge.rsvp-no { color: var(--danger); border-color: rgba(255, 120, 120, .5); background: var(--danger-bg); }
button.rsvp-btn { background: var(--glass); color: var(--accent); border-color: rgba(163, 116, 255, .45); box-shadow: none; min-width: 5rem; }
button.rsvp-btn:hover { background: rgba(163, 116, 255, .15); box-shadow: none; }
button.rsvp-btn.selected { background: linear-gradient(180deg, var(--accent-strong), var(--accent-deep)); color: #fff; box-shadow: 0 4px 18px var(--accent-glow); }
input[type="datetime-local"] { color-scheme: dark; }

/* ---- Graph view ---- */
.graph-card { padding: .5rem; }
.graph-wrap { position: relative; height: clamp(420px, 68vh, 820px); border-radius: 12px; overflow: hidden; background: radial-gradient(circle at 50% 40%, rgba(60, 35, 110, .35), rgba(6, 4, 14, .75)); border: 1px solid var(--glass-border); }
.graph-wrap.small { height: 280px; }
canvas.graph-canvas { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
canvas.graph-canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.graph-legend { margin: .5rem 0 .9rem; }
.graph-controls { margin-bottom: .5rem; }
.graph-controls .field { margin: 0; width: min(16rem, 100%); }
button.legend-chip {
  display: inline-flex; align-items: center; gap: .45rem; padding: .25rem .75rem; font-size: .85rem; font-weight: 500;
  background: var(--glass); color: var(--text); border-color: var(--glass-border); box-shadow: none; border-radius: 99px;
}
button.legend-chip .dot { width: .7rem; height: .7rem; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
button.legend-chip[aria-pressed="false"] { opacity: .45; }
button.legend-chip[aria-pressed="false"] .dot { filter: grayscale(1); }
button.legend-chip:hover { background: rgba(163, 116, 255, .15); box-shadow: none; filter: none; }
button.secondary.small.selected { background: rgba(163, 116, 255, .22); color: #fff; }
a.btn.small { padding: .25rem .7rem; font-size: .85rem; }
.text-view summary { cursor: pointer; font-weight: 600; color: var(--accent); }
a.wikilink { color: #c9b0ff; text-decoration: underline dotted; text-underline-offset: 3px; }
a.wikilink:hover { color: #fff; text-decoration-style: solid; }
.wikilink-unresolved { color: var(--muted); border-bottom: 1px dashed rgba(165, 156, 184, .6); cursor: help; }

/* ---- Wikilink editing ---- */
.ac-menu, .kind-menu { min-width: 14rem; max-width: min(24rem, calc(100vw - 16px)); }
.ac-dot { flex: none; width: .65rem; height: .65rem; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.ac-menu .dropdown-option, .kind-menu .dropdown-option { justify-content: flex-start; }
.dropdown-option .ac-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown-option .ac-type { flex: none; font-size: .75rem; color: var(--muted); }
.kind-menu .dropdown-option { cursor: pointer; }
.kind-menu .dropdown-option:focus { outline: none; background: rgba(163, 116, 255, .22); color: #fff; }
button.wikilink-create {
  display: inline; padding: 0; margin: 0; font: inherit; font-weight: inherit; color: #d9b8ff; cursor: pointer;
  background: none; border: 0; border-bottom: 1px dashed rgba(217, 184, 255, .8); border-radius: 0; box-shadow: none; filter: none;
}
button.wikilink-create:hover { background: rgba(163, 116, 255, .18); color: #fff; box-shadow: none; filter: none; }
button.wikilink-create::after { content: " +"; opacity: .7; font-size: .85em; }

/* The name field has a microphone button, so it gets more room: a full row on phones, two columns otherwise. */
.fields > .field:has(#f-name) { grid-column: 1 / -1; }
@media (min-width: 640px) {
  .fields > .field:has(#f-name) { grid-column: span 2; }
}

/* ---- Image uploads ---- */
input[type="file"] { color: var(--text); }
input[type="file"]::file-selector-button {
  font: inherit; font-weight: 600; cursor: pointer; color: var(--accent);
  padding: .4rem .9rem; border-radius: 10px; border: 1px solid rgba(163, 116, 255, .45);
  background: var(--glass); margin-right: .6rem;
}
input[type="file"]::file-selector-button:hover { background: rgba(163, 116, 255, .15); color: #c9b0ff; }
.bg-preview {
  height: 10rem; border-radius: 12px; border: 1px solid var(--glass-border);
  background: linear-gradient(rgba(7,5,13,.3), rgba(7,5,13,.5)), var(--campaign-bg) center / cover no-repeat;
  margin-bottom: .8rem;
}
.resources-list li { display: block !important; }

/* ---- Animated dice ---- */
.dice-faces { font-size: 1.05rem; margin-top: .2rem; }
.die-box {
  display: inline-block; min-width: 2.1rem; padding: .15rem .35rem; margin: 0 .1rem;
  border-radius: 8px; border: 1px solid rgba(163, 116, 255, .5); background: rgba(139, 92, 246, .18);
  font-weight: 700; color: #f0e6ff; font-variant-numeric: tabular-nums; text-align: center;
}
.die-box.dropped { text-decoration: line-through; opacity: .5; }
.dice-faces.rolling .die-box { animation: dice-shake .12s ease-in-out infinite alternate; }
@keyframes dice-shake {
  from { transform: translateY(0) rotate(-3deg); }
  to { transform: translateY(-2px) rotate(3deg); }
}
.roll-total.pop { animation: dice-pop .3s ease-out; }
@keyframes dice-pop {
  0% { transform: scale(1.6); }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .dice-faces.rolling .die-box, .roll-total.pop { animation: none; }
}
