/* ============================== THEME TOKENS & COLOR-SCHEME ============================== */
:root {
  /* palettes for each theme */
  /* White Dragon — light theme with pale blue accents */
  --bg-white-dragon: #f9fbff;
  --text-white-dragon: #071022;
  --muted-white-dragon: #6b7280;
  --card-white-dragon: #ffffff;
  --accent-white-dragon: #93c5fd;
  --subtle-white-dragon: #dbeafe;
  --shadow-overlay-white-dragon: 0 8px 30px rgba(2, 6, 23, 0.18);

  /* Black Dragon — dark greys with acid-green accents */
  --bg-black-dragon: #0f1317;
  --text-black-dragon: #e4efe4;
  --muted-black-dragon: #8fae95;
  --card-black-dragon: #1f201f;
  --accent-black-dragon: #7cbb6a;
  --subtle-black-dragon: #202f25;
  --shadow-overlay-black-dragon: 0 20px 60px rgba(0, 0, 0, 0.65);

  /* Shadow Dragon — OLED friendly dark with purple accents */
  --bg-shadow-dragon: #000;
  --text-shadow-dragon: #e6e0f5;
  --muted-shadow-dragon: #9a9aac;
  --card-shadow-dragon: #0a0a0a;
  --accent-shadow-dragon: #9C59D1;
  --subtle-shadow-dragon: #333333;
  --shadow-overlay-shadow-dragon: 0 24px 72px rgba(0, 0, 0, 0.8);

  /* active theme tokens (default to White Dragon) */
  --bg: var(--bg-white-dragon);
  --text: var(--text-white-dragon);
  --muted: var(--muted-white-dragon);
  --card: var(--card-white-dragon);
  --accent: var(--accent-white-dragon);
  --subtle: var(--subtle-white-dragon);
  --shadow-overlay: var(--shadow-overlay-white-dragon);

  /* component font-size tokens */
  --en-source-select-font-size: 10px;
  --en-count-input-font-size: 10px;

  /* link system */
  --link-base: color-mix(in srgb, var(--text) 40%, var(--accent) 60%);
  --link: var(--link-base);
  --link-visited: color-mix(in srgb, var(--link-base) 75%, black 25%);
  --link-hover: var(--accent);
  --link-underline: color-mix(in srgb, var(--link-base) 60%, transparent);

  /* menu hover veil */
  --menu-item-hover: color-mix(in srgb, var(--text) 10%, transparent);

  /* UA widget palette hint */
  color-scheme: light dark;
}

/* explicit themes */
:root[data-theme="white-dragon"] {
  --bg: var(--bg-white-dragon);
  --text: var(--text-white-dragon);
  --muted: var(--muted-white-dragon);
  --card: var(--card-white-dragon);
  --accent: var(--accent-white-dragon);
  --subtle: var(--subtle-white-dragon);
  --shadow-overlay: var(--shadow-overlay-white-dragon);
  color-scheme: light;
}

:root[data-theme="black-dragon"] {
  --bg: var(--bg-black-dragon);
  --text: var(--text-black-dragon);
  --muted: var(--muted-black-dragon);
  --card: var(--card-black-dragon);
  --accent: var(--accent-black-dragon);
  --subtle: var(--subtle-black-dragon);
  --shadow-overlay: var(--shadow-overlay-black-dragon);
  color-scheme: dark;
}

:root[data-theme="shadow-dragon"] {
  --bg: var(--bg-shadow-dragon);
  --text: var(--text-shadow-dragon);
  --muted: var(--muted-shadow-dragon);
  --card: var(--card-shadow-dragon);
  --accent: var(--accent-shadow-dragon);
  --subtle: var(--subtle-shadow-dragon);
  --shadow-overlay: var(--shadow-overlay-shadow-dragon);
  color-scheme: dark;
}

/* system theme fallback when no data-theme is set */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: var(--bg-black-dragon);
    --text: var(--text-black-dragon);
    --muted: var(--muted-black-dragon);
    --card: var(--card-black-dragon);
    --accent: var(--accent-black-dragon);
    --subtle: var(--subtle-black-dragon);
    color-scheme: dark;
  }
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: var(--bg-white-dragon);
    --text: var(--text-white-dragon);
    --muted: var(--muted-white-dragon);
    --card: var(--card-white-dragon);
    --accent: var(--accent-white-dragon);
    --subtle: var(--subtle-white-dragon);
    color-scheme: light;
  }
}

/* themed closed <select> control */
@layer theme {
  :where(select) {
    color: var(--text);
    background-color: var(--card);
    border: 1px solid var(--subtle);
    border-radius: 8px;
    padding: 8px 10px;
    line-height: 1.2;
    appearance: auto;
    background-image: none;
    forced-color-adjust: auto;
  }

  :where(select:hover) {
    border-color: color-mix(in srgb, var(--subtle) 60%, var(--text) 40%);
  }

  :where(select:focus-visible) {
    outline: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
    outline-offset: 2px;
  }

  select::-ms-expand {
    display: none;
  }
}

/* preserve OS look for OPEN menu items */
:where(select)>option,
:where(select)>optgroup,
:where(select)>option:hover,
:where(select)>option:checked,
:where(select)>optgroup:hover {
  all: revert;
  -webkit-text-fill-color: revert;
}

/* ============================== Brand lockup (auto-height icon) ============================== */
/* Brand lockup sized from text height */
:root {
  --brand-base-size: clamp(16px, 2.3vw, 24px);
  --brand-disco-scale: 1;
  --brand-line-gap: 2px;
  /* gap between the two lines */
  --brand-icon-side: calc((var(--brand-base-size) * 1) + (var(--brand-base-size) * var(--brand-disco-scale)) + var(--brand-line-gap));
}

/* Compact variant used in headers */
.brand-lockup--compact {
  --brand-base-size: clamp(14px, 2vw, 22px);
}

/* Grid puts icon and text side by side */
.brand-lockup {
  display: grid;
  grid-template-columns: var(--brand-icon-side) 1fr;
  align-items: center;
  column-gap: 10px;
  text-decoration: none;
  color: inherit;
  line-height: 1.02;
  font-family: "League Spartan", Inter, system-ui, -apple-system, Segoe UI,
    Roboto, Arial, sans-serif;
}

/* Icon is a square matching the text block height */
.brand-icon {
  inline-size: var(--brand-icon-side);
  block-size: var(--brand-icon-side);
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: none;
}

/* Image/SVG fills the square */
.brand-icon>img,
.brand-icon>svg {
  inline-size: 100%;
  block-size: 100%;
  object-fit: contain;
  display: block;
}

/* Two-line text */
.brand-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}

.brand-line {
  display: block;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  font-size: var(--brand-base-size);
  line-height: 1;
}

.brand-line.dragon {
  color: var(--muted);
}

.brand-line.disco {
  color: var(--accent);
  font-size: calc(var(--brand-base-size) * var(--brand-disco-scale));
  margin-top: var(--brand-line-gap);
}

/* Focus ring */
.brand-lockup:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Brand icon painted by currentColor via mask */
.brand-icon--mask {
  background: var(--accent);
  -webkit-mask: url("./dragon-disco.svg") center / contain no-repeat;
  mask: url("./dragon-disco.svg") center / contain no-repeat;
}

/* Ensure the square box is still controlled by your lockup sizing */
.brand-icon--mask {
  inline-size: var(--brand-icon-side, auto);
  block-size: var(--brand-icon-side, auto);
}

/* ============================== BASE & LAYOUT ============================== */
html,
body {
  height: 100%;
  margin: 0;
  font-size: 11px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, Arial, sans-serif;
}

html {
  overflow-y: auto;
}

.app {
  max-width: 95vw;
  margin: 0 auto;
  padding: 0 14px;
  min-block-size: 100dvb;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app main {
  flex: 1 0 auto;
  min-height: 0;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-block: 18px 6px;
  padding-inline: 0;
}

header h1 {
  margin: 0;
}

nav {
  display: flex;
  gap: 8px;
  align-items: center;
}

nav button {
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}

nav button.active {
  background: var(--accent);
  color: #fff;
}

/* Header action icons alignment */
/* Header action icons (Donate/Settings) — works for <a> and <button> */
header>.nav-actions .btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0px;
  font-size: 14px;
}

header>.nav-actions .btn-icon .icon {
  width: 2em;
  height: 2em;
  vertical-align: -0.2em;
}

nav label {
  margin-left: 12px;
}

/* Header as a 3-column grid so the middle group is truly centered */
header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding-block: 18px 6px;
}

/* Left title stays in col 1 automatically */
header>.nav-group {
  grid-column: 2;
  justify-self: center;
  text-align: center;
}

header>.nav-actions {
  grid-column: 3;
  justify-self: end;
  display: inline-flex;
  gap: 8px;
}

/* Encounter label above tabs */
.nav-group-label {
  font-size: 12px;
  line-height: 1;
  margin-bottom: 6px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Tabs still look like tabs even as <a> */
.nav-tabs {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.nav-tabs .tab {
  text-decoration: none;
  background: transparent;
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
}

.nav-tabs .tab.active {
  background: var(--accent);
  color: #fff;
}

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

/* Icon-only donate (and any icon-only buttons) */
#donateTop .label {
  display: none;
}

.btn-icon.icon-only .label {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Center group layout */

/* Encounter label with underline */
.nav-group-label {
  font-size: 12px;
  line-height: 1;
  margin-bottom: 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--subtle);
  width: 100%;
  text-align: center;
}

/* Pill around Builder/Table with 1px border */
.nav-tabs {
  display: flex;
  justify-content: center;
}

.nav-tabs-pill {
  display: inline-flex;
  align-items: stretch;
  gap: 0;
  /* separators handle spacing */
  border: 1px solid var(--subtle);
  border-radius: 9999px;
  background: var(--card);
  overflow: hidden;
  /* so separators stay flush */
}

/* Tabs as segments inside the pill */
.nav-tabs-pill .tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  text-decoration: none;
  color: var(--text);
  border-radius: 0;
  /* pill handles rounding */
  position: relative;
  line-height: 1;
}

/* Divider between Builder and Table */
.nav-tabs-pill .tab+.tab {
  box-shadow: -1px 0 0 0 var(--subtle) inset;
  /* 1px vertical separator */
}

/* Active state */
.nav-tabs-pill .tab.active {
  background: var(--accent);
  color: #fff;
}

/* Focus ring */
.nav-tabs-pill .tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* cards */
.card {
  background: var(--card);
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 4px 18px rgba(2, 6, 23, 0.06);
}

.card h2,
.card h3 {
  margin: 0 0 6px 0;
}

/* section headers */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.section-header .header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.section-header .controls {
  margin: 0 0 6px 0;
}

.section-header .keep-synced {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.section-header .keep-synced:hover {
  color: var(--text);
}

/* switch (scoped) */
.section-header .keep-synced .switch {
  appearance: none;
  display: inline-block;
  overflow: hidden;
  inline-size: 42px;
  block-size: 24px;
  box-sizing: border-box;
  border-radius: 999px;
  position: relative;
  border: 1px solid var(--subtle);
  background: var(--switch-track-off,
      color-mix(in srgb, var(--text) 15%, transparent));
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  vertical-align: middle;
  padding: 0;
  line-height: 0;
}

.section-header .keep-synced .switch::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 3px;
  inline-size: 18px;
  block-size: 18px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 1px 2px rgba(2, 6, 23, 0.2);
  transform: translateY(-50%);
  transition: left 0.2s ease, right 0.2s ease, transform 0.2s ease;
}

.section-header .keep-synced .switch:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.section-header .keep-synced .switch:checked::after {
  left: auto;
  right: 3px;
  transform: translateY(-50%);
}

.section-header .keep-synced .switch:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.section-header .keep-synced .switch:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* actions */
.section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.controls {
  display: flex;
  gap: 0;
  flex-wrap: wrap;
  margin-top: 12px;
}

button.cta,
a.cta {
  background: transparent;
  color: var(--accent);
  border: 0;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.small {
  font-size: 13px;
}

.muted {
  color: var(--muted);
}

.note {
  background: rgba(99, 102, 241, 0.06);
  padding: 8px;
  border-radius: 8px;
  margin-bottom: 8px;
}

/* ============================== INPUTS & FORMS ============================== */

#avraeInfo .controls input {
  border: 1px solid var(--subtle);
  background-color: transparent;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: smaller;
  margin-bottom: 8px;
}

:where(input[type="text"],
  input[type="number"],
  input[type="search"],
  textarea) {
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--subtle);
  border-radius: 8px;
  padding: 8px 10px;
}

input.count-input {
  background-color: var(--card);
  border: 1px solid var(--subtle);
}

/* header-area selects slightly tighter */
header :where(select),
.header-right :where(select),
.en-wrap #enTable td:nth-child(8) select {
  padding-top: 6px;
  padding-bottom: 6px;
}

/* Replace UA focus ring with theme-consistent one */
:where(input[type="text"],
  input[type="number"],
  input[type="search"],
  textarea):focus {
  outline: none;
  /* suppress native dotted/blue ring */
  border-color: var(--accent);
  /* box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); */
}

/* Keyboard focus stays visible and crisp */
:where(input[type="text"],
  input[type="number"],
  input[type="search"],
  textarea):focus-visible {
  outline: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: -2px;
}

#avraeInfo .controls input:focus {
  outline: none;
  /* suppress native dotted/blue ring */
  border-color: var(--accent);
  outline: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: -2px;
}

/* ============================== HYPERLINKS ============================== */
:where(a):not(.cta) {
  color: var(--link);
  text-decoration-color: var(--link-underline);
  text-underline-offset: 2px;
  text-decoration-thickness: from-font;
}

:where(a:visited):not(.cta) {
  color: var(--link-visited);
}

:where(a:hover, a:focus-visible):not(.cta) {
  color: var(--link-hover);
  text-decoration-color: currentColor;
}

:where(a:active):not(.cta) {
  color: color-mix(in srgb, var(--link-base) 60%, black 40%);
}

/* fallback when color-mix unsupported */
@supports not (color: color-mix(in srgb, red, white)) {
  :root {
    --link: var(--text);
    --link-visited: color-mix(in srgb, var(--text) 70%, black 30%);
    --link-hover: var(--text);
    --link-underline: var(--text);
    --menu-item-hover: rgba(0, 0, 0, 0.06);
  }

  [data-theme="black-dragon"],
  [data-theme="shadow-dragon"] {
    --menu-item-hover: rgba(255, 255, 255, 0.08);
  }
}

/* ============================== TABLES (GLOBAL) ============================== */
table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

th,
td {
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 1;
}

/* Entire clickable cells (and everything inside them) use pointer */
td.clickable,
td.clickable * {
  cursor: pointer;
}
/* ===== ANCHOR: FILL DOWN (handle + highlight) ===== */

/* Positioning context */
td.dd-fillable { position: relative; }

/* Click target stays ~16×16; the triangle is drawn with ::before */
.dd-fill-handle {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 16px;             /* bigger hit area */
  height: 16px;
  opacity: 0;
  cursor: pointer;
  pointer-events: auto;
  transition: opacity .12s ease;
  z-index: 1;
  user-select: none;              /* <- stop highlight */
  -webkit-user-select: none;
}

/* Draw a small down triangle */
.dd-fill-handle::before {
  content: "";
  position: absolute;
  right: 2px;              /* nudge into the corner */
  bottom: 2px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid var(--accent);  /* down-pointing triangle */
  /* Subtle separation from busy backgrounds */
  filter: drop-shadow(0 0 1px rgba(0,0,0,.35));
}

/* Reveal on hover (desktop) */
td.dd-fillable:hover .dd-fill-handle { opacity: .9; }

/* Optional row highlight you already had */
.dd-fill-hl { background: color-mix(in srgb, var(--accent) 12%, transparent) !important; }

/* Hide the handle on touch; mobile uses overlay/shortcut flows */
@media (pointer: coarse) {
  .dd-fill-handle { display: none; }
}




/* ============================== ENCOUNTER VIEW ============================== */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  margin-top: 12px;
  align-items: stretch;
}

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

.encounter-card {
  background: var(--card);
  padding: 8px;
  border-radius: 12px;
}

.encounter-card .section-header .header-left h3 {
  padding-left: 0;
}

/* avatars & tokens */
.avatar,
.avatar.placeholder,
.enemy-token {
  width: 64px;
  height: 64px;
  border-radius: 6px;
}

.avatar {
  object-fit: cover;
}

.avatar.placeholder {
  background: rgba(0, 0, 0, 0.06);
  display: inline-block;
}

.token-td {
  width: 64px;
  height: 64px;
}

.enemy-token {
  object-fit: cover;
}

/* pills & misc */
.pill {
  display: inline-block;
  /* padding: 6px 8px; */
  /* border-radius: 10px;
  background: color-mix(in srgb, var(--subtle) 50%, transparent); */
  font-size: 12px;
}

#diff {
  margin-left: 8px;
}

#diff.pill {
  color: var(--text);
  text-align: right;
}

#diff.pill .diff-word {
  font-weight: 700;
}

#diff.pill #pill-xptext {
  font-weight: lighter;
  font-size: smaller;
}

.editable {
  cursor: text;
}

/* autocomplete dropdown */
.autocomplete-items {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 2000;
  background: var(--card);
  border: 1px solid var(--subtle);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(2, 6, 23, 0.12);
  max-height: 300px;
  max-width: 350px;
  overflow-y: auto;
  font-size: 13px;
}

.autocomplete-items div {
  padding: 4px 8px;
  cursor: pointer;
}

.autocomplete-items div:hover,
.autocomplete-items div.autocomplete-active {
  background: rgba(0, 0, 0, 0.06);
}

/* enemy name input */
.enemy-name-input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid var(--subtle);
  border-radius: 6px;
  background: transparent;
  color: inherit;
}

/* scroll wrappers (container queries host) */
.table-wrap {
  container-type: inline-size;
  display: block;
  min-width: 0;
  padding-left: 8px;
  padding-right: 8px;
}

/* fixed layout for <colgroup> widths */
#pcsTable,
#enTable {
  width: 100%;
  table-layout: fixed;
}

/* card chrome for sections inside grid */
.grid section {
  border: 1px solid var(--subtle);
  border-radius: 10px;
  margin-bottom: 5px;
}

.grid section h3 {
  background-color: var(--card);
  padding: 2px 0 6px 8px;
  margin-bottom: 0;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

/* tidy overflow + numeric width */
#pcsTable th,
#pcsTable td,
#enTable th,
#enTable td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  background-color: var(--card);
}

/* scroll areas and headers */
.pcs-wrap,
.en-wrap {
  max-height: 70vh;
  overflow: auto;
  border-radius: 0;
}

.pcs-wrap #pcsTable,
.en-wrap #enTable {
  min-width: 900px;
  background-color: var(--card);
}

#pcsTable thead th,
#enTable thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

/* Hide table footers */
#pcsTable tfoot,
#enTable tfoot {
  display: none;
}

/* encounter table layout: footer outside scroll */
.encounter-table.table-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.encounter-table.table-card>.table-wrap {
  flex: 1 1 auto;
  min-height: 0;
}

.table-footer {
  padding: 8px;
  border-top: 1px solid var(--subtle);
  background: var(--card);
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
}

@media (min-width: 1600px) {

  .pcs-wrap,
  .en-wrap {
    max-height: none;
  }
}

.pcs-wrap>table,
.en-wrap>table {
  height: auto;
}

/* enemy table: source select + count input sizing */
.en-wrap #enTable td:nth-child(8) select {
  font-size: var(--en-source-select-font-size);
  line-height: 1.2;
}

.en-wrap .count-input {
  font-size: var(--en-count-input-font-size);
  padding-top: 6px;
  padding-bottom: 6px;
  padding-right: 0;
}

/* count input (standalone) */
.count-input {
  width: 3.5ch;
  min-width: 4ch;
  text-align: center;
  padding-inline: 0.25rem;
  box-sizing: content-box;
  color-scheme: light dark;
}

[data-theme="white-dragon"] .count-input {
  color-scheme: light;
}

[data-theme="black-dragon"] .count-input,
[data-theme="shadow-dragon"] .count-input {
  color-scheme: dark;
}

.count-input::-webkit-inner-spin-button,
.count-input::-webkit-outer-spin-button {
  margin: 0;
  transform: scale(0.75);
  opacity: 0.8;
}

.count-input:hover::-webkit-inner-spin-button,
.count-input:hover::-webkit-outer-spin-button,
.count-input:focus::-webkit-inner-spin-button,
.count-input:focus::-webkit-outer-spin-button {
  transform: scale(0.75);
  opacity: 1;
}

/* count stepper (buttons outside field) */
.count-stepper {
  display: inline-flex;
  align-items: stretch;
  gap: 0;
  white-space: nowrap;
  flex-wrap: nowrap;
  vertical-align: middle;
  background: var(--card);
  border: 1px solid var(--subtle);
  border-radius: 8px;
  overflow: hidden;
  box-sizing: content-box;
  height: calc(1.2em + 13px);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.count-stepper:focus-within {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.count-stepper .count-input {
  border: 0;
  border-radius: 0;
  background: transparent;
  appearance: textfield;
  -moz-appearance: textfield;
  padding-block: 8px;
  line-height: 1.2;
}

.count-stepper .step-col {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  align-self: stretch;
  justify-content: center;
  background: transparent;
  border-left: 1px solid var(--subtle);
}

.count-stepper .step {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 0;
  display: flex;
  place-items: center;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 0;
  font-weight: 0;
  color: var(--text);
  user-select: none;
  transition: transform 0.06s ease, filter 0.12s ease, background 0.12s ease;
  flex: 1 1 0;
  min-height: 0;
  margin: 0;
}

.count-stepper .step:hover {
  background: color-mix(in srgb, var(--card) 50%, var(--accent));
}

.count-stepper .step:active {
  transform: translateY(1px);
}

.count-stepper .step+.step {
  box-shadow: inset 0 1px 0 var(--subtle);
}

.count-stepper .step::before {
  content: "+";
}

.count-stepper .step.down::before {
  content: "−";
}

.count-stepper .count-input::-webkit-inner-spin-button,
.count-stepper .count-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.count-stepper .count-input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

/* PCs table column ratios */
#pcsTable {
  --pc-name-w: 15%;
  --pc-species-w: 12%;
  --pc-classes-w: 16%;
  --pc-resist-w: 12%;
  --pc-immune-w: 12%;
  --pc-notes-w: 33%;
}

#pcsTable col.col-avatar {
  width: 80px;
}

/* 64px img + padding */
#pcsTable col.col-level {
  width: 7ch;
}

#pcsTable col.col-ac {
  width: 5ch;
}

#pcsTable col.col-pp {
  width: 5ch;
}

#pcsTable col.col-hp {
  width: 12ch;
}

#pcsTable col.col-name {
  width: var(--pc-name-w);
}

#pcsTable col.col-species {
  width: var(--pc-species-w);
}

#pcsTable col.col-classes {
  width: var(--pc-classes-w);
}

#pcsTable col.col-resist {
  width: var(--pc-resist-w);
}

#pcsTable col.col-immune {
  width: var(--pc-immune-w);
}

#pcsTable col.col-notes {
  width: var(--pc-notes-w);
}

#pcsTable col.col-actions {
  width: 24px;
}

/* Enemies table ratios */
#enTable {
  --en-name-w: 28%;
  --en-stat-w: 23%;
  --en-subtype-w: 13%;
  --en-displayname-w: 12%;
  --en-initargs-w: 12%;
  --en-initeffects-w: 12%;
}

#enTable col.col-token {
  width: 80px;
}

/* 64px token + padding */
#enTable col.col-count {
  width: 10ch;
}

#enTable col.col-cr {
  width: 6ch;
}

#enTable col.col-size {
  width: 12.5ch;
}

#enTable col.col-type {
  width: 12.5ch;
}

#enTable col.col-source {
  width: 16ch;
}

#enTable col.col-hp {
  width: 6ch;
}

#enTable col.col-totalhp {
  width: 10ch;
}

#enTable col.col-actions {
  width: 24px;
}

#enTable col.col-name {
  width: var(--en-name-w);
}

#enTable col.col-subtype {
  width: var(--en-subtype-w);
}

#enTable col.col-stat {
  width: var(--en-stat-w);
  max-width: 10ch;
}

#enTable col.col-displayname {
  width: var(--en-displayname-w);
}

#enTable col.col-initargs {
  width: var(--en-initargs-w);
}

#enTable col.col-initeffects {
  width: var(--en-initeffects-w);
}

/* Outer shell: border/background + 2-column layout */
.codeblock-wrap {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  /* left fills, right hugs content */
  align-items: start;
  /* button aligned to top */
  max-inline-size: 100%;
  border: 1px solid var(--subtle);
  border-radius: 8px;
  background: color-mix(in srgb, var(--card) 90%, var(--subtle));
  overflow: hidden;
  /* keep corners clipped */
}

/* Left column must be allowed to shrink so its contents can scroll */
.codeblock-col {
  min-width: 0;
  /* critical for horizontal scrolling inside */
}

/* The code itself: no wrap; scroll inside the left column */
.codeblock {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono",
    monospace;
  white-space: pre;
  /* prevent soft wrapping */
  margin: 0;
  /* remove <pre> default margin */
  padding: 10px;
  color: var(--text);
  background: transparent;

  /* scrolling */
  max-height: 50vh;
  overflow-x: auto;
  /* H-scroll for long lines */
  overflow-y: auto;
  /* V-scroll for tall blocks */
  scrollbar-gutter: stable both-edges;
  -webkit-overflow-scrolling: touch;
}

/* Right column: keep button pinned at the top-right */
.copy-col {
  display: flex;
  align-items: flex-start;
  /* top align the actual button */
  padding: 6px;
  /* breathing room around the button */
  /* optional visual divider:
  border-left: 1px solid var(--subtle);
  */
}

/* Button sits in normal flow now (not absolute) */
.codeblock-copy {
  position: static;
}

/* ============================== TRUNCATION & CLAMP HELPERS ============================== */

/* multiline clamp helper used in enemies/players */
.en-clamp-4,
#view-tables .en-clamp-4 {
  display: -webkit-box;
  line-clamp: 4;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
  line-height: 1.2;
}

/* truncation helpers */
.truncate-1 {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clamp-2 {
  display: -webkit-box;
  line-clamp: 4;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
}

/* ============================== MONSTERS: CONTAINER & TABLE ============================== */
/* Monster DB empty state — block inside .table-scroll, using <div id="monEmptyState"> */
#monEmptyState {
  margin: 16px;
  /* space from table header edges */
}

#monEmptyState .empty-card {
  /* visible without scrolling and clearly distinct */
  min-height: 180px;
  /* keep this tall enough to feel like a card */
  display: grid;
  place-items: center;
  text-align: center;

  /* “card” chrome */
  padding: 18px;
  border: 1px solid var(--subtle);
  border-radius: 10px;
  background: var(--card);
}

#monEmptyState h3 {
  margin: 0 0 6px 0;
  font-weight: 700;
}

#monEmptyState .muted {
  color: var(--muted);
}

#monEmptyState .empty-actions {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Make the CTA look like a button (overrides the global .cta link style) */
#monEmptyState .empty-actions .cta,
#monEmptyState .empty-actions button,
#monEmptyState .empty-actions a {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;

  padding: 8px 12px;
  border: 1px solid var(--subtle);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  line-height: 1.2;
  font-size: 13px;
  text-decoration: none;
}

#monEmptyState .empty-actions .cta:hover,
#monEmptyState .empty-actions button:hover,
#monEmptyState .empty-actions a:hover {
  border-color: color-mix(in srgb, var(--subtle) 60%, var(--text) 40%);
}

/* Monsters table helpers */

.table-scroll {
  max-height: 70vh;
  overflow: auto;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

#monTable thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--card);
}

#monTable {
  table-layout: fixed;
  width: 100%;
  min-width: 900px;
}

#monTable th,
#monTable td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#monTable tr.spacer td {
  padding: 0;
  border: 0;
  height: 0;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  padding-right: 22px;
}

th.sortable::after {
  content: "▲";
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%) rotate(0deg);
  opacity: 0.25;
  transition: transform 120ms ease, opacity 120ms ease;
}

th.sortable[data-sort="asc"]::after {
  opacity: 0.9;
  transform: translateY(-50%) rotate(0deg);
}

th.sortable[data-sort="desc"]::after {
  opacity: 0.9;
  transform: translateY(-50%) rotate(180deg);
}

/* column widths (with or without <colgroup>) */
#monTable col.col-actions {
  width: 50px;
}

#monTable col.col-name {
  width: 28ch;
}

#monTable col.col-cr {
  width: 7ch;
}

#monTable col.col-type {
  width: 20ch;
}

#monTable col.col-subtype {
  width: 18ch;
}

#monTable col.col-source {
  width: 18ch;
}

#monTable col.col-stat {
  width: 24ch;
}

#monTable col.col-image {
  width: 20ch;
}

#monTable col.col-token {
  width: 20ch;
}

#monTable col.col-hdice {
  width: 12ch;
}

#monTable col.col-size {
  width: 10ch;
}

#monTable col.col-hp {
  width: 7ch;
}

#monTable col.col-id {
  width: 14ch;
}

/* fallback widths when no colgroup present */
#monTable thead th:nth-child(1),
#monTable tbody td:nth-child(1) {
  width: 28ch;
}

/* Name */
#monTable thead th:nth-child(2),
#monTable tbody td:nth-child(2) {
  width: 7ch;
}

/* CR */
#monTable thead th:nth-child(3),
#monTable tbody td:nth-child(3) {
  width: 20ch;
}

/* Type */
#monTable thead th:nth-child(4),
#monTable tbody td:nth-child(4) {
  width: 18ch;
}

/* Subtype */
#monTable thead th:nth-child(5),
#monTable tbody td:nth-child(5) {
  width: 10ch;
}

/* Size */
#monTable thead th:nth-child(6),
#monTable tbody td:nth-child(6) {
  width: 12ch;
}

/* Hit Dice */
#monTable thead th:nth-child(7),
#monTable tbody td:nth-child(7) {
  width: 7ch;
}

/* HP */
#monTable thead th:nth-child(8),
#monTable tbody td:nth-child(8) {
  width: 18ch;
}

/* Source */
#monTable thead th:nth-child(9),
#monTable tbody td:nth-child(9) {
  width: 24ch;
}

/* Statblock */
#monTable thead th:nth-child(10),
#monTable tbody td:nth-child(10) {
  width: 20ch;
}

/* Image */
#monTable thead th:nth-child(11),
#monTable tbody td:nth-child(11) {
  width: 20ch;
}

/* Token */
#monTable thead th:nth-child(12),
#monTable tbody td:nth-child(12) {
  width: 14ch;
}

/* ID */
#monTable thead th:nth-child(13),
#monTable tbody td:nth-child(13) {
  width: 110px;
}

/* Actions */

/* ============================== MENUS, TINY BUTTONS, ETC. ============================== */
.tiny-btn {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
}

.icon-btn {
  border: 1px solid var(--subtle);
  background: transparent;
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.menu,
.row-menu,
.autocomplete-items {
  background: var(--card);
  border: 1px solid var(--subtle);
  box-shadow: 0 8px 18px rgba(2, 6, 23, 0.15);
  border-radius: 8px;
}

.menu {
  position: absolute;
  right: 0;
  top: 36px;
  min-width: 220px;
  padding: 6px;
  z-index: 2000;
}

.menu-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.menu-item:hover {
  background: rgba(0, 0, 0, 0.06);
}

.hide {
  display: none !important;
}

/* sticky row action cell + kebab replacement patterns */
.row-action-cell {
  position: sticky;
  right: -8px;
  text-align: center;
  background: var(--card);
  z-index: 1;
  isolation: isolate;
  padding-left:0px;
  padding-right:0px;
  margin-left:0px;
  margin-right: 0px;
}

.kebab-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 0 4px;
  color: var(--muted);
}

.kebab-btn:hover {
  color: var(--accent);
}

.row-menu {
  position: fixed;
  padding: 6px;
  min-width: 140px;
  max-width: 200px;
  max-height: min(60vh, 320px);
  overflow-y: auto;
  z-index: 5000;
  pointer-events: auto;
  isolation: isolate;
  will-change: transform;
}

.row-menu-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}

.row-menu-item:hover {
  background: var(--menu-item-hover);
}

/* ============================== OVERLAYS & TOASTS ============================== */
#overlay-root {
  position: fixed;
  inset: 0;
  z-index: 4000;
  pointer-events: none;
}

.overlay-editor {
  position: absolute;
  z-index: 4100;
  pointer-events: auto;
  background: var(--card);
  border-radius: 10px;
  padding: 10px;
  box-shadow: var(--shadow-overlay);
  min-width: 280px;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  /* overflow-y: auto;
  overflow-x: clip; */
  overflow: visible;

  will-change: transform;
  transform: translateZ(0);
}

/* Optional descriptive content above the field(s) */
.overlay-editor .oe-desc {
  margin-bottom: 8px;
}

/* Collapsible “hidden summary” (only shown when both parts are provided) */
.overlay-editor details.oe-summary {
  margin-bottom: 8px;
}

.overlay-editor details.oe-summary > summary {
  cursor: pointer;
  font-weight: 600;
}

.overlay-editor details.oe-summary .oe-summary-text {
  margin-top: 6px;
}

/* Ensure overlay prose wraps instead of expanding width */
.overlay-editor .oe-desc,
.overlay-editor details.oe-summary,
.overlay-editor details.oe-summary > summary,
.overlay-editor details.oe-summary .oe-summary-text {
  /* Allow shrink within flex column and keep content inside */
  min-width: 0;
  max-width: 100%;

  /* Wrap long words and URLs */
  white-space: normal;
  overflow-wrap: anywhere; /* modern */
  word-break: break-word;  /* fallback */
  hyphens: auto;
}

/* If callers include <pre> or code blocks, wrap those too */
.overlay-editor .oe-desc pre,
.overlay-editor .oe-summary-text pre {
  white-space: pre-wrap;
  word-break: break-word;
}

/* Prevent images in prose from forcing horizontal growth */
.overlay-editor .oe-desc img,
.overlay-editor .oe-summary-text img {
  max-width: 100%;
  height: auto;
}

.overlay-editor .oe-summary-text ul, overlay-editor .oe-desc ul
{
  list-style: none;
  list-style-type: disc;
  padding-left:4ch;
}

/* Let the scroller itself shrink inside the flex column */
.overlay-editor .oe-scroll {
  min-width: 0;
}


.oe-close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--muted);
}

.oe-close:hover {
  color: var(--accent);
}

.overlay-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.16);
}

/* Shared transparent backdrop layer for overlays */
.overlay-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.20);
  z-index: 4090;
  /* Just below .overlay-editor (4100) */
  pointer-events: auto;
  touch-action: none;
}

/* Overlay Editor: field rows (GLOBAL: desktop + mobile) */
  .overlay-editor .oe-field {
    display: grid;
    grid-template-columns: max-content 1fr;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
    max-inline-size: 100%;
  }


  .overlay-editor .oe-field>* {
    min-inline-size: 0;
    /* allow controls to shrink within the grid */
  }

  /* Ensure native selects (and other controls) never overflow their column */
  .overlay-editor .oe-field select,
  .overlay-editor .oe-field input,
  .overlay-editor .oe-field textarea {
    width: 100%;
    max-inline-size: 100%;
    max-width: 100% !important;
  }

.overlay-editor.diff {
  max-width: min(92vw, 520px);
  max-height: min(90vh, 640px);
  overflow: auto;
}

.overlay-editor .oe-title {
  font-weight: 600;
  margin-bottom: 6px;
}

.overlay-editor .oe-input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px;
  font: inherit;
  border-radius: 6px;
  border: 1px solid var(--subtle);
  background: var(--card);
  color: var(--text);
}

.overlay-editor .oe-actions {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--subtle);
  background: var(--card);
  position: sticky;
  bottom: 0;
}

.overlay-editor .oe-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* Overlay editor action row — small breathing room */
.overlay-editor .oe-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.overlay-editor .oe-actions .tiny-btn {
  min-width: 76px;
  padding: 6px 10px;
}

@media (max-width: 480px) {
  .overlay-editor .oe-actions .tiny-btn {
    min-width: 68px;
  }
}

/* Overlay internals */
.overlay-editor .oe-scroll {
  overflow: auto;
  /* scrolling lives here */
  -webkit-overflow-scrolling: touch;
}

/* Make native controls fill the overlay column, never exceed it */
.overlay-editor select {
  /* width: 100%; */
  max-width: 100% !important;
  /* exact behavior of your inline test */
  max-inline-size: 100%;
  box-sizing: border-box;
}


/* toasts */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 260px;
}

.toast {
  background: var(--card);
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: 0 6px 22px rgba(2, 6, 23, 0.12);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  border-left: 4px solid var(--accent);
}

.toast .t-body {
  flex: 1;
  font-size: 13px;
  color: var(--text);
}

.toast .t-close {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
}

/* creature selector overlay (fixed, responsive) */
.overlay-editor.creature-selector {
  position: fixed !important;
  left: 50%;
  transform: translateX(-50%);
  top: 10vh;
  width: min(90vw, 900px);
  max-height: 80vh;
  overflow-y: auto;
  z-index: 4200;
  padding: 16px;
}

.cs-row.is-active {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--subtle);
}

.creature-selector .cs-token {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
}

.creature-selector table {
  width: 100%;
  border-collapse: collapse;
}

.creature-selector thead th {
  text-align: left;
  padding: 4px 6px;
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 2;
}

.creature-selector tbody td {
  padding: 4px 6px;
  border-top: 1px solid var(--subtle);
  cursor: pointer;
}

.creature-selector table thead th,
.creature-selector table tbody td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.creature-selector table th:nth-child(1),
.creature-selector table td:nth-child(1) {
  width: 40px;
}

/* token */
.creature-selector table th:nth-child(3),
.creature-selector table td:nth-child(3) {
  width: 7ch;
}

/* CR */
.creature-selector table th:nth-child(7),
.creature-selector table td:nth-child(7) {
  width: 10ch;
}

/* Size */
.creature-selector table th:nth-child(8),
.creature-selector table td:nth-child(8) {
  width: 7ch;
}

/* HP */
.creature-selector table th:nth-child(9),
.creature-selector table td:nth-child(9) {
  width: 9ch;
}

/* XP */

/* theme-safe hover/focus in selector */
:where(.creature-selector) tbody tr:hover>td {
  background: var(--menu-item-hover);
}

:where(.creature-selector) :is(tr.is-active, .cs-row.is-active)>td {
  background: color-mix(in oklab, var(--accent) 22%, transparent);
}

:where(.creature-selector) :is(input[type="text"],
  input[type="number"],
  select,
  .tiny-btn):focus-visible {
  outline: 0 solid color-mix(in oklab, var(--accent) 0%, transparent);
  outline-offset: 2px;
  border-color: var(--accent);
}

/* ============================== SETTINGS VIEW ============================== */
.settings-section {
  margin-bottom: 20px;
}

.settings-section>summary {
  padding-bottom: 8px;
}

.settings-section>summary h3 {
  display: inline;
  margin: 0;
}

/* Monster Sources table */
#s_mon_src_table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
  margin-top: 8px;
}

#s_mon_src_table th,
#s_mon_src_table td {
  padding: 6px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  text-align: left;
}

#s_mon_src_table input {
  width: 100%;
  box-sizing: border-box;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--subtle);
  background: transparent;
  color: var(--text);
}

/* ============================== DIFFICULTY NUMBER LINE ============================== */
.difficulty-viz {
  margin-top: 10px;
}

.difficulty-viz .dv-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.difficulty-viz .dv-rail {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--subtle);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
  margin-top: 40px;
  margin-bottom: 45px;
}

.difficulty-viz .dv-point,
.difficulty-viz .dv-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
}

.difficulty-viz .dv-point {
  width: 10px;
  height: 10px;
  border: 2px solid var(--card);
  box-shadow: 0 1px 3px rgba(2, 6, 23, 0.15);
}

.difficulty-viz .dv-marker {
  width: 20px;
  height: 20px;
  border: 2px solid var(--card);
  box-shadow: 0 2px 10px rgba(2, 6, 23, 0.25);
}

.difficulty-viz .dv-label {
  position: absolute;
  top: 100%;
  transform: translateX(-50%);
  margin-top: 10px;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}

.difficulty-viz .dv-label span {
  display: block;
  font-size: 12px;
  font-weight: 600;
}

.difficulty-viz .dv-label em {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-style: normal;
}

.difficulty-viz .dv-toplabel {
  position: absolute;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
  text-align: center;
}

.difficulty-viz .dv-toplabel b {
  color: var(--text);
  font-weight: 600;
}

.difficulty-viz .dv-toplabel span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.difficulty-viz .dv-toplabel em {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-style: normal;
}

/* ============================== BUTTON ICONS ============================== */
.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 0;
  color: var(--accent);
}

.btn-icon .icon {
  width: 1.75em;
  height: 1.75em;
  flex: 0 0 auto;
  vertical-align: -0.2em;
}

.icon-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.icon-only .icon {
  margin: 0;
}

.icon-only .label {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================== FOOTER & LEGAL ============================== */
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
}

.site-footer .footer-left,
.site-footer .footer-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.site-footer .sep {
  opacity: 0.5;
}

.site-footer .legal-link {
  color: var(--link);
  text-decoration-color: var(--link-underline);
}

.site-footer .legal-link:hover {
  color: var(--link-hover);
  text-decoration-color: currentColor;
}

#view-legal .legal-block {
  margin-bottom: 16px;
}

#view-legal .legal-block h3 {
  margin: 0 0 6px 0;
}

#view-legal .codeblock {
  max-height: 40vh;
}

/* Legal page: wrap code blocks instead of scrolling horizontally */
#view-legal .codeblock {
  white-space: pre-wrap;
  overflow-x: hidden;
  overflow-y: auto;
  overflow-wrap: anywhere;
  max-height: 40vh;
}

/* ============================== TABLES VIEW (Encounter Tables tab) ============================== */
#view-tables .table-card {
  margin-top: 8px;
}

.table-card {
  border: 1px solid var(--subtle);
  border-radius: 10px;
}

#tablesTable {
  table-layout: fixed;
  width: 100%;
  min-width: 900px;
}

#view-tables .table-wrap {
  max-height: 80vh;
  overflow: auto;
}

#tablesTable th,
#tablesTable td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* explainer card below the table */
#view-tables .tables-explainer {
  margin-top: 10px;
}

#view-tables .tables-explainer .explain-card {
  background: var(--card);
  border: 1px solid var(--subtle);
  border-radius: 10px;
  padding: 12px;
}

#view-tables .tables-explainer h3 {
  margin: 0 0 6px 0;
}

#view-tables .tables-explainer h4 {
  margin: 10px 0 4px 0;
}

#view-tables .tables-explainer p {
  margin: 6px 0;
  line-height: 1.35;
}

/* ANCHOR: CSS_TABLE_PERF */
#view-tables table {
  table-layout: fixed; /* Chrome: avoid repeated intrinsic measurement */
  width: 100%;
}

#tablesTbody tr {
  /* Chrome-only performance win: skip full layout until needed */
  content-visibility: auto;
  contain-intrinsic-size: 40px; /* fallback height to prevent jumps */
}

/* Best-effort containment for heavy multi-line clamps */
#tablesTbody td .en-clamp-4 {
  contain: layout paint;
}

/* Optional: stabilize column widths (tweak ch values as desired) */
#view-tables .col-encounter { width: 40ch; }
#view-tables .col-content  { width: 40ch; }
#view-tables .col-notes    { width: 30ch; }


/* small pill in tables cells */
.pill.sm {
  padding: 2px 6px;
  font-size: 12px;
  border-radius: 999px;
  display: inline-block;
}

.pill.sm .diff-word {
  font-weight: 700;
}

/* columns & left alignment */
#tablesTable .col-encounter {
  width: 30%;
}

#tablesTable .col-weight {
  width: 3ch;
}

#tablesTable .col-chance {
  width: 5ch;
  text-align: left;
}

#tablesTable .col-content {
  width: 24%;
}

#tablesTable .col-xp {
  width: 6.8ch;
}

#tablesTable .col-pcs {
  width: 10ch;
  text-align: left;
}

#tablesTable .col-others {
  width: 22%;
}

#tablesTable .col-notes {
  width: 16%;
}

#tablesTable .col-actions {
  width: 6ch;
}

#tablesTable .col-party {
  width: 10ch;
}

/* ============================== SELECT OPEN-MENU RESETS (FINAL) ============================== */
:where(select)>option,
:where(select)>optgroup,
:where(select)>option:hover,
:where(select)>option:checked,
:where(select)>optgroup:hover {
  all: revert;
  -webkit-text-fill-color: revert;
}

/* ============================== Header: two-area nav (merged) ============================== */
.nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* The container that holds the pill; centered */
.nav-tabs {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
}

/* Generic tab defaults (kept light; pill-specific rules override below) */
.nav-tabs .tab {
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  line-height: 1;
  user-select: none;
}

/* Actions cluster to the right */
.nav-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* ============================== Pill around Builder/Table ============================== */
.nav-tabs .nav-tabs-pill {
  /* The pill owns rounding/border/background so inner tabs can be square */
  border: 1px solid var(--subtle);
  border-radius: 9999px;
  background: var(--card);
  overflow: hidden;
  /* clips active bg perfectly */
  isolation: isolate;
  /* local z-index for focus rings */
  display: inline-flex;
  /* default layout for >2 tabs */
  align-items: stretch;
  gap: 0;
}

/* If there are exactly two tabs, lock them to 50/50 */
.nav-tabs .nav-tabs-pill:has(> .tab:nth-child(2):last-child) {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
}

/* Tabs as segments inside the pill */
.nav-tabs .nav-tabs-pill>.tab {
  border-radius: 0;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  background: transparent;
  color: var(--text);
}

/* Divider between segments (theme color) */
.nav-tabs .nav-tabs-pill>.tab+.tab {
  border-left: 1px solid var(--subtle);
}

/* Active state (clipped by overflow on the pill) */
.nav-tabs .nav-tabs-pill>.tab.active,
.nav-tabs .nav-tabs-pill>.tab[aria-selected="true"] {
  background: var(--accent);
  color: #fff;
}

/* Accessible focus ring that sits inside the pill cleanly */
.nav-tabs .nav-tabs-pill>.tab:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--accent);
  z-index: 1;
}

/* Remove old id-specific radius/width tweaks — the pill handles it now */
#nav-encbuilder,
#nav-enctable {
  border-radius: 0;
  max-width: none;
}

/* ============================== Two-tab pill: exact halves, no accent “gap” ============================== */
.nav-tabs .nav-tabs-pill {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--subtle);
  border-radius: 8px;
  background: var(--card);
  overflow: hidden;
  isolation: isolate;
}

.nav-tabs .nav-tabs-pill>.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 8px 14px;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  line-height: 1;
  border-radius: 0;
  margin: 0;
  box-shadow: none;
}

/* Active state (clipped) */
.nav-tabs .nav-tabs-pill>.tab.active,
.nav-tabs .nav-tabs-pill>.tab[aria-selected="true"] {
  background: var(--accent);
  color: #fff;
}

/* ============================== Docs page layout (About & Documentation) ============================== */
.doc-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
}

.doc-toc {
  /* desktop / wide: keep sticky in the sidebar */
  position: sticky;
  top: 12px;
  align-self: start;
  border: 1px solid var(--subtle);
  border-radius: 10px;
  padding: 10px;
  background: var(--card);
}

/* mobile: single column, ToC is in normal flow — NOT sticky */
@media (max-width: 900px) {
  .doc-layout {
    grid-template-columns: 1fr;
  }

  .doc-toc {
    position: static;
    top: auto;
  }
}

#aboutToc ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

#aboutToc li {
  margin: 4px 0;
}

#aboutToc .toc-h3>a {
  font-weight: 600;
}

#aboutToc .toc-h4 a {
  font-size: 0.95em;
  color: var(--muted);
}

#aboutToc a {
  text-decoration: none;
  color: var(--link);
}

#aboutToc a:hover {
  text-decoration: underline;
}

#aboutToc a.is-active {
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

/* UTILITIES ETC*/

.table-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* utility to push the gear to the right end of the row */
.push-right {
  margin-left: auto;
}

/* Overlay: compact list of switches/checkboxes */
.oe-list {
  display: grid;
  gap: 6px;
  margin: 8px 0;
}

.oe-list .oe-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.oe-list .oe-row label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* ============================== MOBILE OVERRIDES ============================== */

.overlay-editor {
  inline-size: auto;
  max-inline-size: min(100svw, 820px);
  overflow-wrap: anywhere;
}

/* 2) Mobile-specific refinements */
@media (max-width: 700px) {

  /* Full-bleed app shell + section cards on mobile */
  .app {
    max-width: none;
    padding-inline: 0;
  }

  /* remove side gutters */
  .view.card {
    border-radius: 0;
    margin-inline: 0;
  }

  /* outermost sections touch edges */
  header,
  .site-footer {
    padding-inline: 8px;
  }

  /* keep comfortable edge padding for header/footer only */

  /* Overlays: tighter padding and guaranteed width cap (all overlay types) */
  .overlay-editor {
    padding: 8px;
  }

  .overlay-editor .oe-actions {
    bottom: 0;
  }


  .overlay-editor,
  .overlay-editor.creature-selector {
    inline-size: min(100svw, 820px);
    max-inline-size: 100svw;
    /* also override any wider desktop rule */
  }

  /* Scrollers: avoid accidental viewport overflow */
  .table-wrap,
  .pcs-wrap,
  .en-wrap {
    overflow-x: auto;
    box-sizing: border-box;
  }

  /* Slightly tighter general spacing on phones */
  header {
    padding-block: 10px 4px;
    gap: 8px;
  }

  .btn-icon .icon {
    width: 1.5em;
    height: 1.5em;
  }

  th,
  td {
    padding: 6px 8px;
  }

  .encounter-card {
    padding: 6px;
    border-radius: 10px;
  }
}

/* Even tighter cells on very small devices */
@media (max-width: 480px) {

  th,
  td {
    padding: 4px 6px;
  }
}

/* Tabs: allow wrapping and keep big tap targets */
.nav-tabs {
  flex-wrap: wrap;
  gap: 4px;
}

/* Buttons: better touch on mobile without layout shifts */
.btn-icon {
  touch-action: manipulation;
}

/* Creature Selector (mobile): show Token, Name, CR, Type, and Source; hide other columns. */
@media (max-width: 700px) {

  .creature-selector table th:nth-child(n + 5),
  .creature-selector table td:nth-child(n + 5) {
    display: none;
  }

  .creature-selector table th:nth-child(6),
  .creature-selector table td:nth-child(6) {
    display: table-cell;
    /* keep Source visible */
  }
}

@media (max-width: 700px) {

  .difficulty-viz,
  .overlay-editor .table-wrap {
    max-inline-size: 100%;
    overflow-x: auto;
  }

  .difficulty-viz :is(canvas, svg, img) {
    max-width: 100%;
    height: auto;
  }

  .difficulty-viz .small {
    font-size: smaller;
  }

  .difficulty-viz .small #creatures-disclaimer {
    font-size: 1.5ch;
  }

  .difficulty-viz {
    overflow: hidden;
  }

  .dv-rail {
    max-width: 88vw !important;
  }
}

