/* ── Buttons ── */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
              transform 0.1s ease, box-shadow var(--transition);
  white-space: nowrap;
}
button:hover { background: var(--border); }
button:active { transform: translateY(1px) scale(0.98); }
button:disabled { cursor: not-allowed; opacity: 0.5; transform: none; }

.btn-primary {
  background: var(--gold-dim);
  border-color: var(--gold);
  color: #fff;
}
.btn-primary:hover { background: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }

.btn-danger {
  background: var(--danger-dim);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: var(--danger); }

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-full { width: 100%; }

/* ── Inputs ── */
input[type="text"],
input[type="email"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 0.5rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
textarea { resize: vertical; min-height: 60px; }
input::placeholder, textarea::placeholder { color: var(--text-muted); }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* Custom select (js/custom-select.js): a themed trigger button + option panel
   replacing the native <select> outright, since no browser lets CSS restyle an
   open <select> list. The <select> itself is hidden but stays in the DOM as
   the source of truth — every <select> in the app gets enhanced, so there is
   no unenhanced fallback state to style here. */
.cs-select { position: relative; }
.cs-select select { display: none; }
.cs-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.cs-trigger-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cs-trigger:hover { border-color: var(--gold-dim); }
.cs-trigger.open,
.cs-trigger:focus-visible {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
  outline: none;
}
.cs-trigger-arrow {
  flex-shrink: 0;
  width: 0.85rem;
  height: 0.85rem;
  color: var(--text-muted);
  transition: transform var(--transition);
}
.cs-trigger.open .cs-trigger-arrow { transform: rotate(180deg); }

.cs-panel {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  z-index: var(--z-dropdown);
  display: none;
  flex-direction: column;
  gap: 1px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  animation: window-in 0.15s var(--ease-out);
  padding: 0.25rem;
}
.cs-panel.visible { display: flex; }
.cs-option {
  padding: 0.4rem 0.6rem;
  font-size: 0.82rem;
  text-align: left;
  background: none;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--transition), color var(--transition);
}
.cs-option:hover, .cs-option:focus-visible { background: var(--surface); color: var(--text); outline: none; }
.cs-option.active { color: var(--gold); }

/* Custom color picker (js/color-picker.js): a hue/saturation wheel + a
   lightness strip, replacing the native <input type="color"> popup outright —
   its open dialog is OS/browser chrome no CSS can restyle. */
.cp-popover {
  position: fixed;
  z-index: var(--z-color-picker);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  animation: window-in 0.15s var(--ease-out);
}
.cp-wheel {
  position: relative;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
}
/* The gradient paint overscans the circle by 2px on an inner layer instead of
   exactly meeting the outer element's own border-radius clip — when a gradient's
   own edge and its clip boundary coincide exactly, Chromium can leave a faint
   antialiasing seam right at the rim. Letting the clip (a plain shape, which
   antialiases cleanly on its own) do the edge work instead removes it. */
.cp-wheel::before {
  content: '';
  position: absolute;
  inset: -2px;
  background:
    radial-gradient(circle at center, #fff 0%, transparent 70%),
    conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
}
.cp-wheel-cursor,
.cp-lightness-cursor {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
.cp-lightness {
  position: relative;
  width: 160px;
  height: 14px;
  border-radius: 99px;
  overflow: hidden;
  cursor: pointer;
  touch-action: none;
}
/* Same overscan-past-the-clip approach as .cp-wheel::before, and for the same
   reason. The fill color itself is set from JS via the --cp-hue-full custom
   property (an inline style can't target a pseudo-element directly). */
.cp-lightness::before {
  content: '';
  position: absolute;
  inset: -2px;
  background: linear-gradient(to right, #000, var(--cp-hue-full, red));
}
.cp-lightness-cursor { top: 50%; background: var(--surface); }
.cp-preview-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 160px;
}
.cp-preview {
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.cp-select-btn { flex: 1; }

/* ── Form groups ── */
.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-group label { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }

.field-error {
  font-size: 0.78rem;
  color: var(--danger);
  min-height: 1rem;
}

/* Locks background scroll while a full-screen modal (setup wizard, contact
   form) is open. `overflow: hidden` alone doesn't stop iOS Safari's touch
   scroll from moving the body underneath a fixed overlay — position: fixed
   is what actually takes it out of the scrollable flow there. `top` is set
   inline by JS to the negative of the scroll position being locked in, so
   the page doesn't visibly jump to the top while it's applied. */
body.modal-open {
  position: fixed;
  left: 0;
  right: 0;
  overflow: hidden;
}

/* ── Generic modal shell (setup wizard, contact form) ── */
.setup-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  /* Matches the character-wizard overlay's scrim (css/wizard.css) — 0.38 barely
     dims an already near-black background, so the page reads as still
     "there" behind the modal instead of properly blocked. */
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  /* max() keeps the 1rem minimum on non-notched devices while still clearing
     the notch/home-indicator on ones that have it (needs viewport-fit=cover,
     already set in index.html/privacy.html/terms.html's viewport meta). */
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  animation: overlay-in 0.18s ease;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.setup-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--gold);
  border-radius: var(--radius);
  box-shadow: 0 16px 56px rgba(0, 0, 0, 0.65);
  width: 100%;
  max-width: 680px;
  /* `dvh` tracks Safari's dynamic toolbar as it shows/hides, unlike `vh` (which
     iOS Safari sizes against the toolbar-hidden viewport) — without it, this
     modal could size taller than what's actually visible whenever the toolbar
     is showing, pushing the footer's Launch button into the strip Safari's own
     chrome occupies, so a tap there hit Safari's UI instead of the button.
     The 88vh stays first as the fallback for browsers that don't support dvh —
     an unsupported unit makes the whole declaration invalid, so the browser
     just keeps the previous valid one instead of falling through to nothing. */
  max-height: 88vh;
  max-height: 88dvh;
  animation: modal-in 0.26s var(--ease-out);
  display: flex;
  flex-direction: column;
}

.setup-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.setup-modal-title {
  font-size: 1.2rem;
  color: var(--gold);
  margin-bottom: 0.25rem;
  letter-spacing: 0.02em;
}

.setup-modal-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.setup-modal-body {
  flex: 1;
  overflow-y: auto;
  /* Without this, scrolling to the end of the modal's own content "chains"
     into the page underneath — the classic iOS Safari modal bug where the
     background visibly scrolls/bounces once this list runs out of room to
     scroll itself. Paired with the body scroll lock in landing.js/contact.js. */
  overscroll-behavior: contain;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.setup-modal-footer {
  flex-shrink: 0;
  padding: 1rem 1.5rem calc(1rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* Visually hidden but announced by screen readers — for fields whose purpose
   is already clear on-screen from a placeholder or nearby heading, but still
   need a programmatic label for assistive tech. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Columnar form (shared header + input grid) ── */
.col-form {
  display: grid;
  gap: 0.25rem 0.4rem;
  align-items: center;
}
.col-form-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.col-form-label--center { text-align: center; }
.col-form input { padding-left: 0.3rem; padding-right: 0.3rem; }

/* ── HP bar ── */
.hp-bar-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.hp-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.hp-bar-fill {
  height: 100%;
  background: var(--success);
  border-radius: 99px;
  transition: width 0.3s ease, background 0.3s ease;
}
.hp-bar-fill.wounded  { background: var(--gold); }
.hp-bar-fill.critical { background: var(--danger); }
.hp-label { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; min-width: 50px; text-align: right; }

/* ── Player cards ── */
.player-card {
  padding: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--accent-color, var(--border-soft));
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: none;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition), transform 0.1s ease;
}
.player-card:hover { background: var(--surface-3); box-shadow: var(--shadow-2); }
.player-card:active { transform: scale(0.99); }
.player-card.is-you { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.player-card .card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.card-avatar {
  position: relative;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.22);
}
/* Image/letter content is clipped to the circle by this inner wrapper — kept separate
   from .card-avatar itself so the upload/clear badges below can sit just outside the
   circle's edge without being cut off by overflow:hidden. */
.card-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.card-avatar-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-avatar.uploadable { cursor: pointer; }
.card-avatar.uploadable .card-avatar-img { transition: opacity var(--transition); }
.card-avatar.uploadable:hover .card-avatar-img { opacity: 0.72; }

/* Click-to-open menu with real, normal-sized options — replaces a prior design with
   two tiny overlapping corner badges that were too small to see or click reliably. */
.avatar-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: var(--z-dropdown);
  display: none;
  flex-direction: column;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-2);
  min-width: 150px;
  cursor: default;
}
.avatar-menu.visible { display: flex; animation: window-in 0.15s var(--ease-out); }
.avatar-menu-option {
  padding: 0.5rem 0.8rem;
  font-size: 0.8rem;
  text-align: left;
  white-space: nowrap;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.avatar-menu-option:hover { background: var(--surface); color: var(--text); }
.avatar-menu-option.danger { color: var(--danger); }
.avatar-menu-option.danger:hover { background: rgba(200,60,60,0.12); }
.card-header-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}
.card-header-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}
.player-card .card-name { font-weight: 600; font-size: var(--text-md); }
.player-card .card-class { font-size: var(--text-xs); color: var(--text-muted); }
.player-card .card-xp { font-size: var(--text-2xs); color: var(--text-muted); opacity: 0.7; }

/* ── XP footer (GM only, party panel) ── */
#xp-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 0.5rem 0.75rem;
}

.xp-footer-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.xp-footer-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

#xp-amount {
  flex: 1;
  min-width: 0;
}

/* ── Log ── */
.log-entry {
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}
.log-entry:last-child { border-bottom: none; }

/* ── Currency bar (player panel, above items) ── */
.currency-bar {
  display: flex;
  gap: 0.4rem;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.currency-chip {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.4rem 0.35rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  min-width: 0;
  gap: 0.1rem;
}

.cc-name {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  text-align: center;
}

.cc-amount {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
  line-height: 1.1;
}

/* ── Currency tags in DM panel ── */
.currency-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 500;
  margin: 0.15rem 0.15rem 0 0;
}

.currency-delete-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--danger);
  font-size: 0.65rem;
  cursor: pointer;
  line-height: 1;
  opacity: 0.5;
  transition: opacity var(--transition);
}
.currency-delete-btn:hover { opacity: 1; }

#dm-currency-list {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 0.25rem;
}

/* ── Drag and drop ── */
.item-card[draggable="true"] { cursor: grab; }
.item-card[draggable="true"]:active { cursor: grabbing; }
.item-card.dragging { opacity: 0.35; }

.drag-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  font-style: italic;
}

.player-card .entity-controls { margin-top: 0.35rem; }
.player-card .condition-chips { margin-top: 0.35rem; }

.player-card .drop-hint {
  font-size: 0.7rem;
  color: transparent;
  margin-top: 0.25rem;
  transition: color var(--transition);
}
.player-card.drag-over .drop-hint { color: var(--gold); }
.player-card.drag-over {
  border-color: var(--map-accent);
  box-shadow: 0 0 0 2px var(--map-accent);
}
.player-card.dragging-to-map,
.entity-card.dragging-to-map {
  border-color: var(--map-accent);
  box-shadow: inset 0 0 0 1px var(--map-accent);
  background: color-mix(in srgb, var(--map-accent) 8%, transparent);
}

.card-stats {
  margin-top: 0.5rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.card-stats-row {
  display: flex;
  justify-content: space-between;
  gap: 0.15rem;
}
.card-stat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border-radius: calc(var(--radius) - 2px);
  padding: 0.3rem 0.1rem;
  text-align: center;
}
.card-stat-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  line-height: 1;
  margin-bottom: 0.1rem;
}
.card-stat-value {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.card-stat-mod {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.item-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  background: var(--gold-dim);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 99px;
  margin-left: auto;
}

/* ── Items list ── */
.item-card {
  padding: 0.65rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: none;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s, transform 0.1s ease;
}
.item-card:hover { background: var(--surface-3); box-shadow: var(--shadow-2); }
.item-card:active { transform: scale(0.99); }
.item-card .item-name { font-weight: 600; font-size: var(--text-md); margin-bottom: 0.2rem; }
.item-card .item-desc { font-size: var(--text-xs); color: var(--text-muted); }
.item-card .item-effects { font-size: var(--text-xs); color: var(--gold); margin-top: 0.2rem; }
.item-category-header {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.5rem 0 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}
.item-cat-badge {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1rem 0.35rem;
  vertical-align: middle;
  margin-left: 0.3rem;
}

/* ── Chest & NPC loot windows ── */
.window-title-icon {
  display: inline-block;
  margin-right: 0.4rem;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.4));
}
.window-title-icon img {
  width: 1.15em;
  height: 1.15em;
  object-fit: contain;
  vertical-align: -0.2em;
}
.chest-card-icon {
  width: 15px;
  height: 15px;
  object-fit: contain;
  vertical-align: -2px;
}
.loot-trap-banner {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.7rem;
  background: color-mix(in srgb, var(--danger) 14%, var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border));
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 0.8rem;
  line-height: 1.3;
}

/* ── Dice grid ── */
.dice-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}
.dice-grid button {
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.5rem;
  border-color: var(--gold-dim);
  color: var(--gold);
}
.dice-grid button:hover { background: var(--gold-dim); color: #fff; }

.dice-result {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold);
  padding: 0.5rem 0;
  min-height: 2rem;
}

/* ── Entity cards (shared base: NPC cards, chest cards) ── */
.entity-card {
  padding: 0.6rem 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--accent-color, var(--border-soft));
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  position: relative;
  cursor: pointer;
  box-shadow: none;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s, transform 0.1s ease;
}
.entity-card:hover { background: var(--surface-3); box-shadow: var(--shadow-2); }
.entity-card:active { transform: scale(0.99); }
.entity-card.linked-highlight {
  border-color: var(--map-accent);
  box-shadow: 0 0 0 1px var(--map-accent), 0 0 10px color-mix(in srgb, var(--map-accent) 35%, transparent);
}

.entity-card .card-header {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.entity-card .card-name {
  font-weight: 600;
  font-size: var(--text-md);
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entity-card .card-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.card-actions-spacer { flex: 1 1 auto; }

/* ── Card overflow ("more options") menu — clone / resize / delete tucked away
   to keep the main card surface uncluttered; reuses .avatar-menu-option styling. ── */
.card-more-wrap { position: relative; flex-shrink: 0; }
.card-more-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  background: none;
  border: none;
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.card-more-btn:hover { background: var(--surface-3); color: var(--text); }
.card-more-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: var(--z-dropdown);
  display: none;
  flex-direction: column;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-2);
  min-width: 180px;
  cursor: default;
}
.card-more-menu.visible { display: flex; animation: window-in 0.15s var(--ease-out); }
.more-menu-size {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.8rem;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.more-menu-size .size-label { font-size: 0.7rem; color: var(--text-muted); flex-shrink: 0; }
.more-menu-size .npc-size-slider { flex: 1; min-width: 0; accent-color: var(--gold); cursor: pointer; height: 4px; }
.more-menu-size .size-val { font-size: 0.7rem; color: var(--gold); font-weight: 600; width: 2.4rem; text-align: right; flex-shrink: 0; }

.npc-group-heading {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0.6rem 0 0.3rem;
}
.npc-group-heading:first-child { margin-top: 0; }

.npc-loot-count {
  font-size: var(--text-xs);
  margin: 0.1rem 0 0;
  color: var(--text-muted);
}

/* NPC cards read HP at a glance during combat — make the bar and number more
   prominent than the base .hp-bar (shared with player cards, left unchanged). */
.npc-card .hp-bar { height: 8px; }
.npc-card .hp-label { font-size: 0.8rem; font-weight: 600; color: var(--text); }

/* Wraps the color swatch in a padded circular hit target — the swatch itself stays
   small so it doesn't dominate the header, but the clickable area is ~24px. */
.npc-color-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  background: none;
  border: none;
  border-radius: 50%;
  flex-shrink: 0;
  cursor: pointer;
  transition: background var(--transition);
}
.npc-color-btn:hover { background: var(--surface-3); }
.npc-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.15);
  transition: box-shadow 0.12s;
}
.npc-color-btn:hover .npc-dot {
  box-shadow: 0 0 0 1px rgba(255,255,255,0.3), 0 0 0 2px var(--gold);
}

/* Smaller than .card-avatar's 40px default to leave more header width for the name —
   still a single, unambiguous click target since upload/remove live in a menu instead
   of two tiny overlapping corner badges. */
.npc-avatar {
  width: 30px;
  height: 30px;
  border-width: 1px;
}

.player-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
  margin-right: 0.3rem;
  transition: box-shadow 0.12s;
}
.player-dot:hover {
  box-shadow: 0 0 0 2px var(--gold);
}

.badge-wrap {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.npc-tier-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  text-transform: capitalize;
  white-space: nowrap;
  transition: border-color var(--transition), color var(--transition);
}
.npc-tier-badge:hover {
  border-color: var(--gold);
  color: var(--text);
}
.npc-tier-badge.tier-elite    { border-color: #7a6020; color: #c8a030; }
.npc-tier-badge.tier-champion { border-color: #5a2080; color: #a060d0; }
/* The literals above are tuned for the near-black default map/panel background and
   read at ~1.5:1 contrast (nearly invisible) against every light-leaning theme's pale
   surface — darker, theme-independent shades restore readability there. */
body.light .npc-tier-badge.tier-elite,
body.amber .npc-tier-badge.tier-elite,
body.sage .npc-tier-badge.tier-elite,
body.wisteria .npc-tier-badge.tier-elite { border-color: #63450e; color: #63450e; }
body.light .npc-tier-badge.tier-champion,
body.amber .npc-tier-badge.tier-champion,
body.sage .npc-tier-badge.tier-champion,
body.wisteria .npc-tier-badge.tier-champion { border-color: #5c1a80; color: #5c1a80; }

.npc-disposition-badge {
  font-size: 0.58rem;
  font-weight: 600;
  padding: 0.1rem 0.35rem;
  border-radius: 99px;
  border: 1px solid;
  background: none;
  cursor: pointer;
  white-space: nowrap;
  text-transform: lowercase;
  flex-shrink: 0;
  transition: opacity 0.12s;
}
.npc-disposition-badge:hover { opacity: 0.65; }
.npc-disposition-badge.disposition-hostile { border-color: var(--danger); color: var(--danger); }
.npc-disposition-badge.disposition-ally    { border-color: var(--success); color: var(--success); }
.npc-disposition-badge.disposition-passive { border-color: var(--text-muted); color: var(--text-muted); }

.npc-tier-dropdown,
.npc-disposition-dropdown {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  z-index: var(--z-dropdown);
  flex-direction: column;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-2);
  animation: window-in 0.15s var(--ease-out);
  min-width: 80px;
}
.tier-option,
.disposition-option {
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  text-transform: capitalize;
  transition: background var(--transition), color var(--transition);
}
.tier-option:hover, .disposition-option:hover     { background: var(--surface); color: var(--text); }
.tier-option.active, .disposition-option.active   { color: var(--gold); }

.entity-controls {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}
.entity-controls .entity-amt {
  width: 70px;
  flex-shrink: 0;
  padding: 0.25rem 0.4rem;
  font-size: 0.78rem;
}

.entity-delete-btn {
  background: none;
  border: none;
  padding: 0.2rem 0.3rem;
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 0.7rem;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity var(--transition), background var(--transition);
  line-height: 1;
}
.entity-delete-btn:hover { opacity: 1; background: rgba(200,60,60,0.12); }

/* ── Quick-create recent chips ── */
.quick-create-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.3rem;
}

.quick-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
  white-space: nowrap;
  font-weight: normal;
}
.quick-chip:hover {
  border-color: var(--gold-dim);
  color: var(--text);
  background: var(--surface-2);
}
.quick-chip-sub {
  font-size: 0.65rem;
  opacity: 0.65;
}

.quick-chip-fill,
.quick-chip-del {
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 0 0.15rem;
  cursor: pointer;
  font-size: 0.65rem;
  line-height: 1;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition);
}
.quick-chip-fill { color: var(--text-muted); }
.quick-chip-del  { color: var(--danger); }

.quick-chip:hover .quick-chip-fill,
.quick-chip:hover .quick-chip-del { opacity: 0.7; }
.quick-chip:hover .quick-chip-fill:hover { opacity: 1; color: var(--gold); }
.quick-chip:hover .quick-chip-del:hover  { opacity: 1; }

.quick-chip-tier-icon {
  width: 14px;
  height: 14px;
  object-fit: contain;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ── NPC tier & disposition pickers ── */
#npc-tier-picker,
#npc-disposition-picker {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
#npc-tier-picker.disabled {
  opacity: 0.4;
  pointer-events: none;
}
.tier-btn,
.disposition-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.3rem 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
  text-transform: capitalize;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.tier-btn img {
  width: 16px;
  height: 16px;
  object-fit: contain;
}
.tier-btn:hover,
.disposition-btn:hover {
  border-color: var(--gold-dim, var(--gold));
  color: var(--text);
}
.tier-btn.active,
.disposition-btn.active {
  border-color: var(--gold);
  background: var(--surface-2);
  color: var(--text);
}

/* ── Condition chips ── */
/* ── Condition chips (active-only display + picker) ── */
.condition-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px;
}

.cond-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.5;
  color: #fff;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity var(--transition);
}
.cond-chip:hover { opacity: 0.75; }

.cond-chip-del {
  font-size: 0.65em;
  opacity: 0.7;
  line-height: 1;
}

.cond-add-btn {
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: 700;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}
.cond-add-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--text-muted); }

/* Picker dropdown */
.cond-picker {
  width: 100%;
  margin-top: 4px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
}

.cond-picker-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.cond-picker-item {
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.5;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.cond-picker-item:hover { background: var(--surface-3); color: var(--text); }
.cond-picker-item.active { color: #fff; border-color: transparent; }
.cond-picker-item.active:hover { opacity: 0.8; }

.cond-picker-sep {
  display: block;
  width: 100%;
  height: 1px;
  background: var(--border);
  margin: 3px 0;
}

.cond-picker-footer {
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid var(--border);
}

.cond-new-custom {
  font-size: 0.68rem;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.cond-new-custom:hover { color: var(--text); }

.custom-cond-form {
  display: none;
  gap: 4px;
  align-items: center;
  margin-top: 5px;
  flex-wrap: wrap;
}
.custom-cond-form .custom-cond-name {
  flex: 1;
  min-width: 80px;
  font-size: 0.72rem;
  padding: 2px 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
}
.custom-cond-form .custom-cond-color {
  width: 26px;
  height: 22px;
  padding: 1px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface);
  cursor: pointer;
}
.custom-cond-form .custom-cond-save,
.custom-cond-form .custom-cond-cancel {
  padding: 2px 7px;
  font-size: 0.72rem;
  border-radius: 3px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
}
.custom-cond-form .custom-cond-save:hover { background: var(--gold); color: var(--on-gold); border-color: var(--gold); }
.custom-cond-form .custom-cond-cancel:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ── Notes tabs (DM and player panels) ── */
.dm-tab-content[data-tab="notes"],
.player-tab-content[data-ptab="notes"] {
  flex: 1;
  min-height: 0;
  gap: 0.35rem;
}

.notes-textarea {
  flex: 1;
  min-height: 0 !important;
  resize: none;
  line-height: 1.65;
  font-size: var(--text-sm);
}

.notes-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
}
.notes-toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}
.notes-toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

.notes-filename {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 80px;
}

.notes-preview {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.5rem 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.82rem;
  line-height: 1.65;
  color: var(--text);
}
.notes-preview h1, .notes-preview h2, .notes-preview h3,
.notes-preview h4, .notes-preview h5, .notes-preview h6 {
  margin: 0.8rem 0 0.35rem;
  color: var(--gold);
  line-height: 1.3;
  font-size: 0.9rem;
}
.notes-preview h1 { font-size: 1.05rem; }
.notes-preview h2 { font-size: 0.95rem; }
.notes-preview p  { margin: 0 0 0.45rem; }
.notes-preview ul, .notes-preview ol { margin: 0 0 0.45rem 1.2rem; }
.notes-preview li { margin-bottom: 0.15rem; }
.notes-preview code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1em 0.35em;
  font-size: 0.8em;
  font-family: var(--font-mono);
}
.notes-preview pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  overflow-x: auto;
  margin-bottom: 0.45rem;
}
.notes-preview pre code { background: none; border: none; padding: 0; }
.notes-preview blockquote {
  border-left: 3px solid var(--gold-dim);
  margin: 0 0 0.45rem;
  padding: 0.15rem 0.6rem;
  color: var(--text-muted);
}
.notes-preview hr { border: none; border-top: 1px solid var(--border); margin: 0.75rem 0; }
.notes-preview a  { color: var(--gold); }
.notes-preview strong { font-weight: 600; }

/* ── Panel tabs (shared by player + DM panels) ── */
.player-tabs,
.dm-tabs {
  position: relative;
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.player-tabs::after,
.dm-tabs::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: var(--tab-indicator-left, 0px);
  width: var(--tab-indicator-width, 0px);
  height: 2px;
  background: var(--gold);
  transition: left var(--transition-panel), width var(--transition-panel);
}

.player-tab-btn,
.dm-tab-btn {
  flex: 1;
  padding: var(--space-3) var(--space-2);
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}
.player-tab-btn:hover,
.dm-tab-btn:hover { color: var(--text); background: var(--surface-2); }

.player-tab-btn.active,
.dm-tab-btn.active {
  color: var(--gold);
  background: var(--gold-soft);
}

.player-tab-content,
.dm-tab-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  animation: tab-content-in 0.16s var(--ease-out);
}

@keyframes tab-content-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Dice footer (always visible, bottom of both panels) ── */
.dice-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 0.6rem 0.75rem 0.7rem;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* ── Settings window ── */
.settings-radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.settings-radio {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--text-sm);
  cursor: pointer;
}
.settings-radio input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 1rem;
  height: 1rem;
  min-width: 1rem;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition);
}
.settings-radio input[type="radio"]:checked {
  border-color: var(--gold);
  background: var(--gold);
}
.settings-radio input[type="radio"]:checked::after {
  content: '';
  display: block;
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 50%;
  background: var(--bg);
}

/* Custom checkbox to replace browser default */
.settings-radio input[type="checkbox"],
.combat-setup-row input[type="checkbox"],
.handout-recipient-check {
  appearance: none;
  -webkit-appearance: none;
  width: 1rem;
  height: 1rem;
  min-width: 1rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition);
}
.settings-radio input[type="checkbox"]:checked,
.combat-setup-row input[type="checkbox"]:checked,
.handout-recipient-check:checked {
  background: var(--gold);
  border-color: var(--gold);
}
.settings-radio input[type="checkbox"]:checked::after,
.combat-setup-row input[type="checkbox"]:checked::after,
.handout-recipient-check:checked::after {
  content: '';
  display: block;
  width: 0.28rem;
  height: 0.52rem;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* Party panel empty state */
.party-empty-state {
  flex: 1;
  padding: 1.5rem 0.75rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--text);
  text-align: center;
}
.party-empty-state .text-muted {
  font-size: 0.77rem;
}
.party-empty-icon {
  width: calc(100% + 3rem);
  margin-inline: -1.5rem;
  height: auto;
  margin-top: 0.6rem;
  filter: brightness(0) invert(1);
  opacity: 0.5;
}
body.light .party-empty-icon,
body.amber .party-empty-icon,
body.sage .party-empty-icon,
body.wisteria .party-empty-icon {
  filter: brightness(0) invert(1) sepia(1) saturate(4) brightness(0.5);
  opacity: 0.85;
}

/* ── Spell slot pips on party cards ── */
.card-spell-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.4rem;
  padding-top: 0.3rem;
  margin-bottom: 0.3rem;
}

.card-spell-row {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.card-spell-label {
  font-size: 0.64rem;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  margin-right: 1px;
  line-height: 1;
}

.card-spell-pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.1s, opacity 0.1s, transform 0.08s;
}
.card-spell-pip.avail { background: var(--gold); }
.card-spell-pip.used  { background: transparent; opacity: 0.35; }
.card-spell-pip.avail:not(.readonly):hover { background: var(--gold-dim); transform: scale(1.2); }
.card-spell-pip.used:not(.readonly):hover  { opacity: 0.8; transform: scale(1.2); }
.card-spell-pip.readonly { cursor: default; }

/* ── Spell slots (character sheet) ── */
.spell-slots-section {
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.spell-slots-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}

.spell-slot-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0;
  min-height: 26px;
}

.spell-level-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  width: 26px;
  flex-shrink: 0;
}

.spell-max-input {
  width: 38px !important;
  padding: 0.12rem 0.3rem !important;
  font-size: 0.78rem;
  text-align: center;
  flex-shrink: 0;
}

.spell-pips {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
  align-items: center;
}

.spell-pip {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.1s, opacity 0.1s, transform 0.08s;
}

.spell-pip.avail {
  background: var(--gold);
}

.spell-pip.used {
  background: transparent;
  opacity: 0.4;
}

.spell-pip.avail:not(.readonly):hover {
  background: var(--gold-dim);
  transform: scale(1.15);
}

.spell-pip.used:not(.readonly):hover {
  opacity: 0.9;
  transform: scale(1.15);
}

.spell-pip.readonly {
  cursor: default;
}

.spell-pip-none {
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.35;
}

.spell-count {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 26px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Stat grid (character sheet) ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}
.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}
.stat-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted); }
.stat-value { font-size: 1.2rem; font-weight: 700; color: var(--gold); }
.stat-mod   { font-size: 0.7rem; color: var(--text-muted); }

/* ── Connection badge ── */
.conn-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.conn-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--border);
}
.conn-dot.connected { background: var(--success); }
.conn-dot.error     { background: var(--danger); }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translate(-50%, 8px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 1.2rem;
  font-size: 0.85rem;
  z-index: var(--z-topmost);
  pointer-events: none;
  opacity: 0;
  box-shadow: var(--shadow-2);
  transition: opacity 0.2s ease, transform 0.2s var(--ease-out);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ── Invalid field flash ── */
.field-flash { animation: field-flash 1s var(--ease-out); }
@keyframes field-flash {
  0%, 100% { border-color: var(--border); }
  15%, 45% { border-color: var(--danger); }
}

/* ── Help panel ── */
.help-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.help-section summary {
  padding: 0.6rem 0.85rem;
  font-weight: 600;
  font-size: var(--text-md);
  cursor: pointer;
  background: var(--surface-2);
  list-style: none;
  transition: background var(--transition);
}
.help-section summary:hover { background: var(--surface-3); }

.help-section summary::-webkit-details-marker { display: none; }

.help-section summary::before {
  content: '▶';
  display: inline-block;
  margin-right: 0.5rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform var(--transition);
}

.help-section[open] summary::before { transform: rotate(90deg); }

.help-body {
  padding: 0.75rem 0.9rem;
  font-size: var(--text-sm);
  line-height: 1.55;
  color: var(--text);
}

.help-body p { margin: 0 0 0.6rem; }
.help-body p:last-child { margin-bottom: 0; }
.help-body ul { margin: 0 0 0.6rem 1.2rem; padding: 0; }
.help-body ul:last-child { margin-bottom: 0; }
.help-body li { margin-bottom: 0.3rem; }
.help-body li:last-child { margin-bottom: 0; }

.help-body kbd {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  font-size: 0.78rem;
  font-family: inherit;
}

.help-body code {
  background: var(--surface-2);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  font-size: 0.78rem;
}

/* ── Reveal image ── */
.reveal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-reveal);
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
}

.reveal-overlay img,
.reveal-overlay video {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  box-shadow: 0 8px 48px rgba(0,0,0,0.6);
  border-radius: var(--radius);
}

.reveal-overlay-controls {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  display: flex;
  gap: 0.5rem;
}

.reveal-overlay-controls #reveal-overlay-close {
  font-size: 1.2rem;
  color: #fff;
  background: rgba(0,0,0,0.4);
  border-color: rgba(255,255,255,0.2);
}

.reveal-overlay-controls #reveal-overlay-close:hover {
  background: rgba(0,0,0,0.6);
  color: #fff;
}

#reveal-current {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* ── Handout popup ── */
.handout-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-reveal);
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.handout-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  padding: 2.5rem 1.75rem 1.75rem;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.handout-card #handout-overlay-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
}

#handout-overlay-text {
  white-space: pre-wrap;
  line-height: 1.5;
}

#handout-overlay-img {
  max-width: 100%;
  max-height: 50vh;
  object-fit: contain;
  border-radius: var(--radius);
  align-self: center;
}

.reveal-actions {
  display: flex;
  gap: 0.5rem;
}

#reveal-current-thumb,
#reveal-current-thumb-video {
  width: 100%;
  max-height: 160px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

@media (max-width: 860px) {
  /* Touch target size, without changing any button's visible size or shape.
     A plain `min-height` here used to force every button — including compact
     pills/chips/toggles (tier/disposition buttons, tab buttons, per-row
     Edit/Delete/pin controls) — to a uniform tall box, squashing their
     authored proportions toward stubbier or near-circular shapes. Expanding
     the *tappable* area via an invisible pseudo-element instead (a standard
     technique, e.g. WCAG's target-size "invisible expanded hit area")
     guarantees the same 44px (38px for .btn-sm) touch target while every
     button keeps rendering at exactly its own designed size. */
  button, .btn {
    position: relative;
  }
  button::after, .btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: max(100%, 44px);
    height: max(100%, 44px);
  }
  .btn-sm::after {
    width: max(100%, 38px);
    height: max(100%, 38px);
  }
  /* Safari zooms the whole page on focus for any input under 16px — bumping
     just the mobile size avoids that without changing desktop density. */
  input[type="text"],
  input[type="email"],
  input[type="number"],
  textarea,
  select {
    font-size: 16px;
  }
}
