/* FeyForged — application theme: a sidebar workspace with dark and light modes.
   Character sheets and stat blocks have their own styles in sheet.css. */

:root,
[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0f1116;
  --bg-2: #12151b;
  --surface: #181b23;
  --surface-2: #1f232d;
  --surface-3: #282d39;
  --border: #2a2f3b;
  --border-strong: #3a4050;
  --text: #e8e6e1;
  --muted: #9ba1ad;
  --faint: #6b7280;
  --accent: #e3a33b;
  --accent-2: #f2c062;
  --accent-ink: #1a1306;
  --accent-soft: rgba(227, 163, 59, 0.14);
  --danger: #e0614f;
  --ok: #4fbf87;
  --link: #f0b45a;
  --wl-character: #7aabff;
  --wl-npc: #ff8178;
  --wl-location: #62d69c;
  --wl-map: #f0b45a;
  --wl-article: #c6a0ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.55);
  --overlay: rgba(6, 7, 10, 0.6);
}

[data-theme='light'] {
  color-scheme: light;
  --bg: #f5f4f0;
  --bg-2: #eceae4;
  --surface: #ffffff;
  --surface-2: #f8f7f3;
  --surface-3: #efede7;
  --border: #e2dfd7;
  --border-strong: #cdc8bc;
  --text: #1d2027;
  --muted: #5f6570;
  --faint: #8b909a;
  --accent: #b8701a;
  --accent-2: #d48a2a;
  --accent-ink: #ffffff;
  --accent-soft: rgba(184, 112, 26, 0.12);
  --danger: #c0392b;
  --ok: #1f8a55;
  --link: #a35f12;
  --wl-character: #2563c9;
  --wl-npc: #c0392b;
  --wl-location: #1f8a55;
  --wl-map: #a35f12;
  --wl-article: #7b4cc2;
  --shadow: 0 1px 2px rgba(30, 25, 10, 0.06), 0 4px 14px rgba(30, 25, 10, 0.07);
  --shadow-lg: 0 18px 50px rgba(30, 25, 10, 0.18);
  --overlay: rgba(30, 28, 22, 0.35);
}

:root {
  --radius: 12px;
  --radius-sm: 8px;
  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Cinzel', Georgia, serif;
  --font-deco: 'Cinzel Decorative', 'Cinzel', Georgia, serif;
  --sidebar-w: 284px;
  --topbar-h: 56px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* ---------------------------------------------------------------- base */

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

[hidden] {
  display: none !important;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--link);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

h1,
h2,
h3,
h4 {
  line-height: 1.25;
  margin: 1.6em 0 0.6em;
  font-weight: 650;
  letter-spacing: -0.01em;
}
h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2.1rem;
  letter-spacing: 0.01em;
  margin-top: 0;
}
h2 {
  font-size: 1.3rem;
}
h3 {
  font-size: 1.05rem;
}
h4 {
  font-size: 0.95rem;
}

img {
  max-width: 100%;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

code,
pre,
kbd {
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;
  font-size: 0.85em;
}
code {
  background: var(--surface-3);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}
pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.9rem;
  border-radius: var(--radius-sm);
  overflow: auto;
}
kbd {
  display: inline-block;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 0.35em;
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--surface-2);
  line-height: 1.5;
}

blockquote {
  margin: 1.2em 0;
  padding: 0.7rem 1rem;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
blockquote p:first-child {
  margin-top: 0;
}
blockquote p:last-child {
  margin-bottom: 0;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 0.95rem;
}
th,
td {
  padding: 0.55rem 0.7rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

::selection {
  background: var(--accent-soft);
}

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

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- app shell */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 0.25s var(--ease);
}
.sidebar-collapsed .app {
  grid-template-columns: 0 minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  overflow: hidden;
  z-index: 40;
}
.sidebar-collapsed .sidebar {
  border-right: 0;
}
.sb-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.9rem 0.9rem 0.6rem;
  min-width: var(--sidebar-w);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  min-width: 0;
  flex: 1;
}
.brand:hover {
  text-decoration: none;
}
.brand img {
  width: 30px;
  height: 30px;
  flex: none;
}
.brand-name {
  font-family: var(--font-deco);
  font-weight: 700;
  font-size: 1.02rem;
  line-height: 1.15;
  color: var(--accent-2);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.sb-search {
  margin: 0.2rem 0.9rem 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--faint);
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  min-width: calc(var(--sidebar-w) - 1.8rem);
  text-align: left;
}
.sb-search:hover {
  border-color: var(--border-strong);
  color: var(--muted);
}
.sb-search kbd {
  margin-left: auto;
}
.sb-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.2rem 0.5rem 1rem;
  min-width: var(--sidebar-w);
  scrollbar-width: thin;
}
.sb-link,
.sb-row > a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.32rem 0.5rem;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.89rem;
  line-height: 1.35;
  min-width: 0;
}
.sb-link:hover,
.sb-row > a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.sb-link.active,
.sb-row > a.active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}
.sb-link .ico {
  width: 1.2rem;
  text-align: center;
  flex: none;
}
.sb-section {
  margin-top: 0.9rem;
}
.sb-section-head {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0 0.2rem 0 0;
  color: var(--faint);
}
.sb-section-head > a {
  flex: 1;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 0.25rem 0.2rem;
}
.sb-section-head > a:hover {
  color: var(--text);
  text-decoration: none;
}
.sb-section-head .count {
  font-size: 0.72rem;
  color: var(--faint);
  margin-right: 0.2rem;
}
.sb-toggle,
.sb-add {
  width: 1.5rem;
  height: 1.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: none;
  color: var(--faint);
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 0;
  flex: none;
}
.sb-toggle:hover,
.sb-add:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.sb-toggle::before {
  content: '';
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s var(--ease);
}
.sb-toggle[aria-expanded='true']::before {
  transform: rotate(90deg);
}
.sb-toggle.leaf {
  visibility: hidden;
}
.sb-tree {
  list-style: none;
  margin: 0.1rem 0 0;
  padding: 0;
}
.sb-tree .sb-tree {
  padding-left: 0.9rem;
  margin-left: 0.7rem;
  border-left: 1px solid var(--border);
}
.sb-item {
  display: block;
}
.sb-row {
  display: flex;
  align-items: center;
}
.sb-row > a {
  flex: 1;
}
.sb-item a .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  flex: none;
}
.dot.t-character {
  background: var(--wl-character);
}
.dot.t-npc {
  background: var(--wl-npc);
}
.dot.t-location {
  background: var(--wl-location);
}
.dot.t-map {
  background: var(--wl-map);
}
.dot.t-article {
  background: var(--wl-article);
}
.sb-item a .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sb-item a .secret {
  margin-left: auto;
  padding-left: 0.4rem;
  font-size: 0.72rem;
  color: var(--faint);
}
.sb-more {
  font-size: 0.8rem;
  color: var(--faint);
  padding: 0.25rem 0.5rem 0.25rem 1.9rem;
  display: block;
}
.sb-empty {
  font-size: 0.8rem;
  color: var(--faint);
  padding: 0.2rem 0.5rem 0.2rem 1.9rem;
  font-style: italic;
}
.sb-foot {
  border-top: 1px solid var(--border);
  padding: 0.5rem;
  min-width: var(--sidebar-w);
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar .spacer {
  flex: 1;
}
.topbar-crumbs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.88rem;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}
.topbar-crumbs a {
  color: var(--muted);
}
.topbar-crumbs .sep {
  color: var(--faint);
}
.topbar-crumbs .current {
  color: var(--text);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tb-search {
  display: none;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.05rem;
  padding: 0;
  flex: none;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
  text-decoration: none;
}
.icon-btn svg {
  width: 18px;
  height: 18px;
}

.content {
  flex: 1;
  padding: 1.8rem 2.2rem 4rem;
  animation: page-in 0.28s var(--ease);
}
.content.loading {
  opacity: 0.55;
  transition: opacity 0.15s;
}
@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.page {
  max-width: 1180px;
  margin: 0 auto;
}
.page.narrow {
  max-width: 760px;
}
.page.wide {
  max-width: 1500px;
}

.site-footer {
  padding: 1rem 2.2rem 1.6rem;
  font-size: 0.78rem;
  color: var(--faint);
}

.sidebar-backdrop {
  display: none;
}

/* Top loading bar for in-app navigation. */
#ff-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 8px var(--accent);
  z-index: 200;
  opacity: 0;
  transition:
    width 0.3s var(--ease),
    opacity 0.3s;
}
#ff-progress.active {
  opacity: 1;
}

/* ---------------------------------------------------------------- menus */

.menu-pop {
  position: relative;
}
.menu-pop > summary {
  list-style: none;
  cursor: pointer;
}
.menu-pop > summary::-webkit-details-marker {
  display: none;
}
.menu-pop .menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 14rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 0.35rem;
  z-index: 60;
  animation: pop-in 0.14s var(--ease);
}
.menu-pop .menu.left {
  left: 0;
  right: auto;
}
@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
}
.menu a,
.menu button {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.6rem;
  color: var(--text);
  background: none;
  border: 0;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: 6px;
}
.menu a:hover,
.menu button:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.menu .danger {
  color: var(--danger);
}
.menu .menu-label {
  font-size: 0.75rem;
  color: var(--faint);
  padding: 0.35rem 0.6rem 0.25rem;
}
.menu hr {
  margin: 0.3rem 0;
}
.menu form {
  margin: 0;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), #9d2a24);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
}

/* ---------------------------------------------------------------- toasts */

.toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 150;
  max-width: min(420px, calc(100vw - 2rem));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--ok);
  box-shadow: var(--shadow-lg);
  font-size: 0.92rem;
  animation: toast-in 0.25s var(--ease);
}
.toast.error {
  border-left-color: var(--danger);
}
.toast.leaving {
  opacity: 0;
  transform: translateX(20px);
  transition:
    opacity 0.25s,
    transform 0.25s;
}
.toast button {
  margin-left: auto;
  background: none;
  border: 0;
  color: var(--faint);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

/* ---------------------------------------------------------------- page heads */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.4rem;
}
.page-head h1 {
  margin-bottom: 0.3rem;
}
.page-head .lede {
  margin: 0;
  color: var(--muted);
  max-width: 60ch;
}
.eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
}
.breadcrumbs {
  font-size: 0.82rem;
  color: var(--faint);
  margin-bottom: 0.5rem;
}
.breadcrumbs a {
  color: var(--muted);
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.86rem;
}
.meta-line {
  font-size: 0.85rem;
  color: var(--faint);
  margin: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  vertical-align: middle;
  white-space: nowrap;
}
.chip.t-character {
  color: var(--wl-character);
  background: color-mix(in srgb, var(--wl-character) 14%, transparent);
}
.chip.t-npc {
  color: var(--wl-npc);
  background: color-mix(in srgb, var(--wl-npc) 14%, transparent);
}
.chip.t-location {
  color: var(--wl-location);
  background: color-mix(in srgb, var(--wl-location) 14%, transparent);
}
.chip.t-map {
  color: var(--wl-map);
  background: color-mix(in srgb, var(--wl-map) 14%, transparent);
}
.chip.t-article {
  color: var(--wl-article);
  background: color-mix(in srgb, var(--wl-article) 14%, transparent);
}

.tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--muted);
  vertical-align: middle;
}
.tag.secret {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--accent-2);
}
.tag.att-friendly {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 45%, transparent);
  background: color-mix(in srgb, var(--ok) 12%, transparent);
}
.tag.att-hostile,
.tag.st-dead {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

/* ---------------------------------------------------------------- buttons */

.btn,
button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  white-space: nowrap;
  transition:
    background 0.15s,
    transform 0.08s,
    box-shadow 0.15s;
  text-decoration: none;
}
.btn:hover {
  background: var(--accent-2);
  text-decoration: none;
  color: var(--accent-ink);
}
.btn:active {
  transform: translateY(1px);
}
.btn.secondary,
.btn.gold {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn.secondary:hover,
.btn.gold:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn.ghost {
  background: none;
  color: var(--muted);
}
.btn.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}
.btn.danger {
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}
.btn.danger:hover {
  background: var(--danger);
  color: #fff;
}
.btn.small {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}
.btn-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
form.inline {
  display: inline;
}

/* ---------------------------------------------------------------- forms */

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
input[type='text'],
input[type='password'],
input[type='number'],
input[type='search'],
input[type='file'],
select,
textarea {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
input:hover,
select:hover,
textarea:hover {
  border-color: var(--border-strong);
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type='color'] {
  width: 3rem;
  height: 2.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 0.15rem;
}
textarea {
  min-height: 7rem;
  resize: vertical;
  line-height: 1.55;
}
textarea.tall {
  min-height: 18rem;
}
textarea.short {
  min-height: 4.5rem;
}
.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.93rem;
  font-weight: 400;
  color: var(--text);
  margin: 0.25rem 0;
}
.check input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  margin: 0;
}
.field {
  margin-bottom: 1rem;
}
.hint {
  font-size: 0.82rem;
  color: var(--faint);
  margin-top: 0.3rem;
}
.form-error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--text);
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}
.grid {
  display: grid;
  gap: 1rem;
}
.grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.grid.cols-6 {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem 0.4rem;
  margin: 0 0 1.4rem;
  background: var(--surface);
}
legend {
  font-weight: 650;
  font-size: 0.95rem;
  padding: 0 0.4rem;
}
details > summary {
  cursor: pointer;
}
.form-actions {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, transparent, var(--bg) 40%);
  padding: 1.4rem 0 0.8rem;
  display: flex;
  gap: 0.6rem;
  z-index: 5;
}
.entity-form fieldset h3 {
  margin-top: 1.2rem;
}

.repeater-row {
  display: grid;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.5rem;
}
.repeater-row.attacks {
  grid-template-columns: 2fr 1fr 2fr 2fr auto;
}
.repeater-row.spells {
  grid-template-columns: 5rem 3fr auto 3fr auto;
}
.repeater-row .check {
  height: 2.4rem;
}
.skill-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem 1.2rem;
}
.skill-grid .skill {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  padding: 0.2rem 0;
  font-size: 0.92rem;
}
.skill-grid select {
  width: auto;
  padding: 0.2rem 0.4rem;
  font-size: 0.85rem;
}
.ability-inputs .ability-input {
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem;
  background: var(--surface-2);
}
.ability-inputs input {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
}
.ability-inputs .live-mod {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-2);
  margin: 0.2rem 0;
}

/* Markdown editor with live preview */
.md-editor {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}
.md-editor:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.md-editor textarea {
  border: 0;
  border-radius: 0;
  box-shadow: none !important;
}
.md-tabs {
  display: flex;
  gap: 0.2rem;
  padding: 0.3rem 0.4rem 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.md-tabs button {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0.35rem 0.7rem;
  cursor: pointer;
}
.md-tabs button.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.md-preview {
  padding: 0.8rem 1rem;
  min-height: 7rem;
}

/* ---------------------------------------------------------------- tabs */

.tabs {
  display: flex;
  gap: 0.2rem;
  border-bottom: 1px solid var(--border);
  margin: 0 0 1.5rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs a,
.tabs button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: none;
  border: 0;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 550;
  color: var(--muted);
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}
.tabs a:hover,
.tabs button:hover {
  color: var(--text);
  text-decoration: none;
}
.tabs a.active,
.tabs button.active {
  color: var(--text);
}
.tabs a.active::after,
.tabs button.active::after {
  content: '';
  position: absolute;
  left: 0.6rem;
  right: 0.6rem;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.tabs .count {
  font-size: 0.72rem;
  background: var(--surface-3);
  color: var(--muted);
  padding: 0 0.45rem;
  border-radius: 999px;
}
.tab-panel {
  animation: page-in 0.22s var(--ease);
}

/* ---------------------------------------------------------------- cards & lists */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1rem;
}
.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  transition:
    transform 0.18s var(--ease),
    box-shadow 0.18s var(--ease),
    border-color 0.18s;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
  text-decoration: none;
  color: var(--text);
}
.card .card-img {
  aspect-ratio: 16 / 10;
  background: var(--surface-3) center / cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  color: var(--faint);
  position: relative;
}
.card.portrait .card-img {
  aspect-ratio: 1 / 1;
  background-position: top center;
}
.card .card-img .chip {
  position: absolute;
  left: 0.6rem;
  top: 0.6rem;
  backdrop-filter: blur(8px);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
}
.card .card-body {
  padding: 0.75rem 0.9rem 0.9rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.card h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}
.card .meta {
  font-size: 0.82rem;
  color: var(--muted);
}
.card p {
  margin: 0.2rem 0 0;
  font-size: 0.86rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .tags {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

/* List view */
.card-grid.as-list {
  grid-template-columns: 1fr;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.card-grid.as-list .card {
  flex-direction: row;
  align-items: center;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
}
.card-grid.as-list .card:last-child {
  border-bottom: 0;
}
.card-grid.as-list .card:hover {
  transform: none;
  box-shadow: none;
  background: var(--surface-2);
}
.card-grid.as-list .card-img {
  width: 56px;
  height: 56px;
  aspect-ratio: auto;
  flex: none;
  margin: 0.5rem 0 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 1.4rem;
}
.card-grid.as-list .card-img .chip {
  display: none;
}
.card-grid.as-list .card-body {
  flex-direction: row;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.card-grid.as-list .card p {
  -webkit-line-clamp: 1;
  flex: 1;
  min-width: 12rem;
  margin: 0;
}

.toolbar {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1.3rem;
}
.toolbar .grow {
  flex: 1;
  min-width: 14rem;
}
.toolbar select,
.toolbar input {
  width: auto;
}
.toolbar .grow input {
  width: 100%;
}
.search-input {
  position: relative;
}
.search-input input {
  padding-left: 2.1rem;
}
.search-input::before {
  content: '';
  position: absolute;
  left: 0.75rem;
  top: 50%;
  width: 11px;
  height: 11px;
  border: 2px solid var(--faint);
  border-radius: 50%;
  transform: translateY(-62%);
  pointer-events: none;
}
.search-input::after {
  content: '';
  position: absolute;
  left: 1.42rem;
  top: 58%;
  width: 6px;
  height: 2px;
  background: var(--faint);
  transform: rotate(45deg);
  pointer-events: none;
}
.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.segmented button {
  background: var(--surface);
  border: 0;
  color: var(--muted);
  padding: 0.45rem 0.65rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}
.segmented button.active {
  background: var(--surface-3);
  color: var(--text);
}
.filter-bar {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  align-items: end;
  margin-bottom: 1.2rem;
  padding: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-bar .field {
  margin: 0;
  min-width: 10rem;
}
.filter-bar .grow {
  flex: 1;
  min-width: 14rem;
}

.group-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 2rem 0 0.8rem;
}
.group-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.empty .glyph {
  font-size: 2.4rem;
  display: block;
  margin-bottom: 0.4rem;
}

/* ---------------------------------------------------------------- home */

.hero {
  position: relative;
  overflow: hidden;
  border-radius: calc(var(--radius) + 4px);
  padding: 3rem 2.4rem 2.6rem;
  margin-bottom: 1.6rem;
  background:
    radial-gradient(ellipse at 15% 0%, color-mix(in srgb, var(--accent) 30%, transparent), transparent 60%),
    radial-gradient(ellipse at 100% 100%, rgba(157, 42, 36, 0.35), transparent 55%),
    linear-gradient(135deg, #1b1712, #121419);
  color: #f3eee4;
  border: 1px solid var(--border);
  background-size: cover;
  background-position: center;
}
.hero.has-image::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(10, 10, 14, 0.92), rgba(10, 10, 14, 0.55) 60%, rgba(10, 10, 14, 0.25));
}
.hero > * {
  position: relative;
}
.hero h1 {
  font-family: var(--font-deco);
  font-size: clamp(2rem, 4.5vw, 3.1rem);
  margin: 0.2rem 0 0.4rem;
  color: #f7d58c;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
}
.hero .tagline {
  font-size: 1.1rem;
  color: rgba(243, 238, 228, 0.8);
  margin: 0 0 1.4rem;
  max-width: 50ch;
}
.hero .eyebrow {
  color: rgba(243, 238, 228, 0.6);
}
.hero .btn.secondary {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
  color: #f3eee4;
}
.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.8rem;
  margin-bottom: 2rem;
}
.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.95rem 1rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  transition:
    transform 0.18s var(--ease),
    border-color 0.18s;
}
.stat-tile:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  text-decoration: none;
  color: var(--text);
}
.stat-tile .icon {
  font-size: 1.3rem;
}
.stat-tile .num {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.1;
}
.stat-tile .label {
  font-size: 0.82rem;
  color: var(--muted);
}
.home-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 2rem;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1.2rem;
}
.panel > h2,
.panel > h3 {
  margin: 0 0 0.8rem;
  font-size: 0.95rem;
}
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}
.timeline li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.timeline li:last-child {
  border-bottom: 0;
}
.timeline .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.timeline .when {
  font-size: 0.75rem;
  color: var(--faint);
  white-space: nowrap;
}
.map-teaser {
  display: block;
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.map-teaser img {
  display: block;
  width: 100%;
  transition: transform 0.6s var(--ease);
}
.map-teaser:hover img {
  transform: scale(1.03);
}
.map-teaser .overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 1rem 1.1rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  color: #fff;
  font-weight: 600;
}

/* ---------------------------------------------------------------- entries */

.entry-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
}
.entry-head h1 {
  margin: 0.4rem 0 0.25rem;
}
.entry-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 2.2rem;
  align-items: start;
}
.entry-aside {
  position: sticky;
  top: calc(var(--topbar-h) + 1rem);
}
.entry-aside > section {
  margin-bottom: 1.2rem;
}
.entry-aside h3 {
  font-size: 0.75rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--faint);
  margin: 0 0 0.6rem;
}
.portrait-frame {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-3);
  box-shadow: var(--shadow);
}
.portrait-frame img {
  display: block;
  width: 100%;
}
.infobox {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
}
.infobox dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45rem 0.9rem;
  font-size: 0.9rem;
}
.infobox dt {
  color: var(--faint);
  font-size: 0.8rem;
  padding-top: 0.05rem;
}
.infobox dd {
  margin: 0;
}
.link-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.link-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.link-list li:last-child {
  border-bottom: 0;
}
.link-list .tlabel {
  margin-left: auto;
}
.connections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.prose {
  font-size: 1.02rem;
  line-height: 1.7;
  max-width: 75ch;
}
.prose > :first-child {
  margin-top: 0;
}
.prose img {
  border-radius: var(--radius-sm);
}
.prose h1,
.prose h2 {
  font-family: var(--font-ui);
  font-size: 1.35rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}
.summary {
  font-size: 1.12rem;
  color: var(--muted);
  margin: 0 0 1.4rem;
  max-width: 70ch;
}
.gm-notes {
  margin: 1.5rem 0;
  padding: 1rem 1.2rem;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  border-radius: var(--radius);
}
.gm-notes h3 {
  margin-top: 0;
  color: var(--accent-2);
}

a.wikilink {
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, currentColor 35%, transparent);
  transition: border-color 0.15s;
}
a.wikilink:hover {
  border-bottom-color: currentColor;
  text-decoration: none;
}
a.wl-character {
  color: var(--wl-character);
}
a.wl-npc {
  color: var(--wl-npc);
}
a.wl-location {
  color: var(--wl-location);
}
a.wl-map {
  color: var(--wl-map);
}
a.wl-article {
  color: var(--wl-article);
}
a.wikilink.missing {
  color: var(--danger);
  border-bottom-style: dashed;
  opacity: 0.85;
}
span.wikilink.secret {
  font-style: italic;
}

/* Hover preview cards for links to entries */
.hover-card {
  position: absolute;
  z-index: 120;
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop-in 0.15s var(--ease);
  pointer-events: none;
}
.hover-card .hc-img {
  height: 140px;
  background: var(--surface-3) center 25% / cover no-repeat;
}
.hover-card .hc-body {
  padding: 0.75rem 0.9rem 0.85rem;
}
.hover-card h4 {
  margin: 0.35rem 0 0.2rem;
  font-size: 1rem;
}
.hover-card .hc-meta {
  font-size: 0.8rem;
  color: var(--muted);
}
.hover-card p {
  margin: 0.45rem 0 0;
  font-size: 0.86rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Gallery & files */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.8rem;
}
.gallery figure {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.gallery figure img {
  aspect-ratio: 1 / 1;
  object-fit: cover;
  width: 100%;
  display: block;
}
.gallery figcaption {
  font-size: 0.8rem;
  padding: 0.5rem 0.6rem 0;
  word-break: break-word;
  flex: 1;
  color: var(--muted);
}
.gallery .btn-row {
  padding: 0.5rem 0.6rem 0.6rem;
}
.file-list {
  list-style: none;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.file-list li {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.file-list li:last-child {
  border-bottom: 0;
}
.file-list .fname {
  flex: 1;
  min-width: 12rem;
}
.upload-box {
  margin-top: 1.2rem;
  padding: 1.1rem;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  transition:
    border-color 0.15s,
    background 0.15s;
}
.upload-box.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ---------------------------------------------------------------- maps */

.map-stage {
  position: relative;
  height: calc(100vh - var(--topbar-h) - 9rem);
  min-height: 440px;
  overflow: hidden;
  background: #0a0b0f;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.map-stage.dragging {
  cursor: grabbing;
}
.map-canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  --inv: 1;
}
.map-canvas img {
  display: block;
  max-width: none;
  pointer-events: none;
  -webkit-user-drag: none;
}
.map-canvas svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.region {
  fill: var(--rc, #d4a017);
  fill-opacity: 0.12;
  stroke: var(--rc, #d4a017);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: fill-opacity 0.15s;
}
.map-stage.hide-regions .region {
  fill-opacity: 0;
  stroke-opacity: 0;
}
.region:hover,
.region.active {
  fill-opacity: 0.35;
  stroke-width: 3;
}
.map-stage.hide-regions .region:hover,
.map-stage.hide-regions .region.active {
  fill-opacity: 0.3;
  stroke-opacity: 1;
}
.pin {
  position: absolute;
  width: 30px;
  height: 40px;
  margin: -40px 0 0 -15px;
  transform: scale(var(--inv));
  transform-origin: 50% 100%;
  cursor: pointer;
  border: 0;
  padding: 0;
  background: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
  transition: filter 0.15s;
}
.pin svg {
  position: static;
  width: 100%;
  height: 100%;
}
.pin:hover,
.pin.active {
  filter: drop-shadow(0 0 7px #f7d58c);
}
.region-label {
  position: absolute;
  transform: translate(-50%, -50%) scale(var(--inv));
  font-weight: 650;
  font-size: 13px;
  color: #fff8e1;
  text-shadow:
    0 0 3px #000,
    0 0 7px #000;
  pointer-events: none;
  white-space: nowrap;
}
.map-stage.hide-labels .region-label {
  display: none;
}
.map-toolbar {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  z-index: 3;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  background: rgba(18, 20, 26, 0.75);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.map-toolbar button {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 6px;
  border: 0;
  background: none;
  color: #e8e6e1;
  font-size: 1.05rem;
  cursor: pointer;
}
.map-toolbar button:hover {
  background: rgba(255, 255, 255, 0.1);
}
.map-toolbar button[aria-pressed='false'] {
  opacity: 0.45;
}
.map-panel {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  bottom: 0.75rem;
  width: min(360px, calc(100% - 1.5rem));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.1rem;
  overflow: auto;
  transform: translateX(calc(100% + 1.5rem));
  transition: transform 0.28s var(--ease);
  z-index: 4;
  cursor: default;
  user-select: text;
}
.map-panel.open {
  transform: none;
}
.map-panel .close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
  background: none;
  border: 0;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--muted);
}
.map-panel .close:hover {
  background: var(--surface-3);
  color: var(--text);
}
.map-panel h3 {
  margin: 0.3rem 0 0.6rem;
  padding-right: 1.8rem;
  font-size: 1.2rem;
}
.map-panel img {
  border-radius: var(--radius-sm);
  max-height: 210px;
  object-fit: cover;
  width: 100%;
  margin-bottom: 0.6rem;
}
.map-panel .btn-row {
  margin-top: 0.9rem;
}
.map-hint {
  position: absolute;
  bottom: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(18, 20, 26, 0.78);
  backdrop-filter: blur(8px);
  color: #c9ccd3;
  font-size: 0.78rem;
  padding: 0.3rem 0.85rem;
  border-radius: 999px;
  pointer-events: none;
  z-index: 2;
  white-space: nowrap;
}
.region-legend {
  columns: 2;
  list-style: none;
  padding: 0;
}
.region-legend li {
  break-inside: avoid;
  padding: 0.2rem 0;
}
.region-legend button {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.region-legend button:hover {
  color: var(--accent-2);
}
.swatch {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 3px;
  margin-right: 0.45rem;
  vertical-align: middle;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1rem;
}
.editor-layout .map-stage {
  height: calc(100vh - var(--topbar-h) - 9rem);
}
.map-stage.drawing {
  cursor: crosshair;
}
.draft-line {
  fill: rgba(212, 160, 23, 0.2);
  stroke: #ffe58a;
  stroke-width: 2;
  stroke-dasharray: 6 4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.vertex {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #e3a33b;
  transform: scale(var(--inv));
  cursor: move;
  z-index: 2;
}
.editor-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  max-height: calc(100vh - var(--topbar-h) - 9rem);
  overflow: auto;
}
.editor-panel h3 {
  margin: 1rem 0 0.5rem;
  font-size: 0.9rem;
}
.editor-panel .tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}
.editor-panel .tools .btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}
.region-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.8rem;
  max-height: 14rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.region-list li {
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.region-list li:hover {
  background: var(--surface-2);
}
.region-list li.selected {
  background: var(--accent-soft);
  font-weight: 650;
}
.status-line {
  font-size: 0.82rem;
  min-height: 1.3em;
  color: var(--muted);
}

/* ---------------------------------------------------------------- command palette */

.palette-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  z-index: 180;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  animation: fade-in 0.15s;
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
.palette {
  width: min(620px, calc(100vw - 2rem));
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop-in 0.16s var(--ease);
}
.palette input {
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  font-size: 1.05rem;
  padding: 1rem 1.1rem;
  background: transparent;
  box-shadow: none !important;
}
.palette-results {
  max-height: min(420px, 55vh);
  overflow: auto;
  padding: 0.35rem;
}
.palette-group {
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 0.55rem 0.7rem 0.3rem;
}
.palette-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
}
.palette-item.sel {
  background: var(--accent-soft);
}
.palette-item .pi-icon {
  width: 1.5rem;
  text-align: center;
  flex: none;
}
.palette-item .pi-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette-foot {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 0.9rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--faint);
}
.palette-empty {
  padding: 1.2rem;
  text-align: center;
  color: var(--faint);
  font-size: 0.9rem;
}

/* [[Wiki link]] autocomplete */
.ac-pop {
  position: absolute;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  min-width: 260px;
  max-width: 360px;
  max-height: 260px;
  overflow: auto;
  font-size: 0.92rem;
  padding: 0.25rem;
}
.ac-pop div {
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  border-radius: 6px;
}
.ac-pop div.sel,
.ac-pop div:hover {
  background: var(--accent-soft);
}
.ac-pop small {
  color: var(--faint);
  font-size: 0.72rem;
}

/* ---------------------------------------------------------------- misc pages */

.data-table td,
.data-table th {
  vertical-align: middle;
}
.data-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  border-collapse: separate;
  border-spacing: 0;
}
.data-table tbody tr:last-child td {
  border-bottom: 0;
}
.data-table tbody tr:hover {
  background: var(--surface-2);
}
.auth-box {
  max-width: 420px;
  margin: 6vh auto 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}
.auth-box .btn {
  width: 100%;
  padding: 0.7rem;
}
.card-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
}
.spell-meta {
  color: var(--muted);
  margin: -0.6rem 0 1rem;
}
.import-results td:first-child,
.import-results th:first-child {
  width: 2rem;
}
.error-page {
  text-align: center;
  padding: 10vh 1rem;
}
.error-page .glyph {
  font-size: 3.4rem;
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 1100px) {
  .home-columns {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .entry-layout,
  .editor-layout {
    grid-template-columns: 1fr;
  }
  .entry-aside {
    position: static;
    order: -1;
    display: grid;
    grid-template-columns: minmax(0, 200px) minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
  }
  .entry-aside > section {
    margin: 0;
  }
  .grid.cols-4,
  .grid.cols-6 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .skill-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .app,
  .sidebar-collapsed .app {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(var(--sidebar-w), 86vw);
    transform: translateX(-100%);
    transition: transform 0.25s var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sb-head,
  .sb-scroll,
  .sb-foot {
    min-width: 0;
  }
  .sb-search {
    min-width: 0;
  }
  .sidebar-open .sidebar {
    transform: none;
  }
  .sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 35;
  }
  .content {
    padding: 1.2rem 1rem 3rem;
  }
  .site-footer {
    padding: 1rem;
  }
  .tb-search {
    display: inline-flex;
  }
}

@media (max-width: 640px) {
  h1 {
    font-size: 1.7rem;
  }
  .grid.cols-2,
  .grid.cols-3 {
    grid-template-columns: 1fr;
  }
  .grid.cols-4,
  .grid.cols-6 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .skill-grid {
    grid-template-columns: 1fr;
  }
  .repeater-row.attacks,
  .repeater-row.spells {
    grid-template-columns: 1fr 1fr;
  }
  .entry-aside {
    grid-template-columns: 1fr;
  }
  .hero {
    padding: 2rem 1.3rem;
  }
  .map-stage,
  .editor-layout .map-stage {
    height: 62vh;
  }
  .map-panel {
    top: auto;
    left: 0.5rem;
    right: 0.5rem;
    bottom: 0.5rem;
    width: auto;
    max-height: 60%;
    transform: translateY(calc(100% + 1rem));
  }
  .region-legend {
    columns: 1;
  }
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}

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

@media print {
  body {
    background: #fff;
    color: #000;
  }
  .sidebar,
  .topbar,
  .site-footer,
  .tabs,
  .btn,
  .btn-row,
  .upload-box,
  .toasts {
    display: none !important;
  }
  .app {
    display: block;
  }
  .tab-panel[hidden] {
    display: none !important;
  }
}
