/* This file is for your main application CSS.
 *
 * Dungeon Master's "handbook page" theme: a parchment/serif look inspired by
 * https://github.com/fatters/dnd-css (palette and approach only -- this is
 * original CSS, no code copied from that repo).
 *
 * These rules are deliberately NOT wrapped in an `@layer`. Per the CSS
 * Cascade Layers spec, unlayered rules always win over rules declared inside
 * an `@layer` (which is everything in default.css), regardless of selector
 * specificity or `<link>` order. That means the handful of overrides below
 * can reskin the existing daisyUI-flavored classes used throughout the
 * templates (`.btn`, `.card`, `.input`, `.list`, ...) without having to
 * rewrite every template or fight specificity.
 */

@import url("https://fonts.googleapis.com/css2?family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&display=swap");

/* ---- Palette ------------------------------------------------------- */

:root {
  --color-base-100: #fdf6e3; /* box / card background -- warm off-white "page" */
  --color-base-200: #f7ebcb; /* parchment background */
  --color-base-300: #e4d2a0; /* borders / dividers */
  --color-base-content: #2b1a0e; /* ink */

  --color-primary: #7a2b17; /* dark red-brown headers */
  --color-primary-content: #f7ebcb;
  --color-secondary: #4a3722;
  --color-secondary-content: #f7ebcb;
  --color-neutral: #4a3722;
  --color-neutral-content: #f7ebcb;
  --color-accent: #7a2b17;
  --color-accent-content: #f7ebcb;

  --color-info: #2f5d62;
  --color-info-content: #f2ede0;
  --color-success: #3f6b2b;
  --color-success-content: #f2ede0;
  --color-warning: #8a5a12;
  --color-warning-content: #f2ede0;
  --color-error: #8c1f1f;
  --color-error-content: #f2ede0;

  --dm-header-border: tan;
  --dm-ink-border: #1a120a;

  --radius-box: 2px;
  --radius-field: 2px;
  --radius-selector: 2px;
}

/* ---- Base -----------------------------------------------------------
 * A cheap "noise" texture: a few faint radial gradients layered over the
 * flat parchment color. If a browser can't be bothered with gradients for
 * some reason, the flat --color-base-200 background is a perfectly fine
 * fallback.
 */

body {
  /* `.tabletop-layout`'s full-bleed break-out targets 100% of the viewport
     width, but `vw` units include the scrollbar's own width in this
     browser (matching `window.innerWidth`, not the narrower
     scrollbar-excluded `clientWidth`) -- so a full-bleed element sized off
     `vw` is always a few px wider than the actual scrollable area,
     producing a spurious horizontal scrollbar. Nothing in this app is
     meant to scroll horizontally, so guarding it here is simpler and more
     robust than chasing exact scrollbar-width arithmetic in the layout
     rule itself. */
  overflow-x: hidden;
  background-color: var(--color-base-200);
  background-image: radial-gradient(circle at 15% 20%, rgba(70, 45, 15, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 85% 8%, rgba(70, 45, 15, 0.04) 0%, transparent 35%),
    radial-gradient(circle at 70% 85%, rgba(70, 45, 15, 0.05) 0%, transparent 45%),
    radial-gradient(circle at 8% 90%, rgba(70, 45, 15, 0.04) 0%, transparent 40%),
    radial-gradient(circle at 50% 50%, rgba(70, 45, 15, 0.03) 0%, transparent 60%);
  background-attachment: fixed;
  font-family: "Libre Baskerville", Georgia, "Times New Roman", serif;
  font-size: 16px;
  color: var(--color-base-content);
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: "Libre Baskerville", Georgia, serif;
  color: var(--color-primary);
  text-transform: uppercase;
  line-height: 1.1;
  margin: 24px 0 12px 0;
  letter-spacing: 0.02em;
}

h1::first-letter,
h2::first-letter,
h3::first-letter,
h4::first-letter,
h5::first-letter,
h6::first-letter {
  font-size: 150%;
}

h1 {
  font-size: 24px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--dm-header-border);
}

h2 {
  font-size: 19px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--dm-header-border);
}

p {
  line-height: 1.4;
}

a:not(.btn),
.link {
  color: var(--color-primary);
}

/* ---- "Handbook page" boxes -------------------------------------------
 * Every panel in the DM console / player table already uses the same
 * `card bg-base-200` combination, so a single rule here re-skins the
 * roster, tokens, dice, chat, voice, and character-sheet panels at once
 * instead of touching each one individually.
 */

.box,
.card.bg-base-200 {
  background-color: var(--color-base-100);
  border-left: 2px solid var(--dm-ink-border);
  border-right: 2px solid var(--dm-ink-border);
  border-top: 1px solid var(--dm-header-border);
  border-bottom: 1px solid var(--dm-header-border);
  border-radius: 2px;
  box-shadow: none;
  padding: 16px;
  margin: 16px 0 24px;
  overflow: hidden;
}

/* Lists/join-code readouts nested inside a box should blend into the page
 * rather than reading as a second, darker box. */
.list.bg-base-200 {
  background: transparent;
}

.list-row {
  border-bottom: 1px dashed var(--color-base-300);
}

.list-row:last-child {
  border-bottom: none;
}

/* ---- Missing layout utilities ------------------------------------------
 * This app's Tailwind-flavored utility CSS (`default.css`) doesn't actually
 * define `.flex-wrap` or `.items-end`, even though several forms here use
 * them (token placement, grid calibration, presentation presets) expecting
 * wrapping flex rows. Without `.flex-wrap`, a flex row's items never drop
 * to a new line when they don't fit -- they just keep going in a single
 * `nowrap` row -- and since every one of those forms lives inside a `.card`
 * with `overflow: hidden`, the overflow silently disappears instead of
 * spilling out visibly: on the token form specifically, this clips the
 * "Place token" submit button (and sometimes the Kind/Label fields) off
 * the edge of the card entirely, with no scrollbar or visual hint that
 * anything is missing. That -- not just unstyled inputs -- is a big part
 * of why the token form reads as broken. Defining the two missing classes
 * here fixes every affected form at once.
 *
 * `.flex-col` and `.max-w-md` are the same story, hitting the character
 * sheet forms (`class="flex flex-col gap-2 max-w-md"`, both the DM's
 * editing_character form and the player's own sheet/creation forms):
 * without `.flex-col`, a `display: flex` form's fields lay out in a single
 * horizontal `row` (flex's initial direction) instead of stacking, so
 * every label/input pair -- Name, Class, HP, Max HP, Portrait, Attributes --
 * ends up squeezed side by side across the card instead of one per line.
 */

.flex-wrap {
  flex-wrap: wrap;
}

.items-end {
  align-items: flex-end;
}

.flex-col {
  flex-direction: column;
}

.max-w-md {
  max-width: 28rem;
}

/* ---- Form controls ----------------------------------------------------
 * Most forms in this app (token placement, map upload, character sheet,
 * grid calibration, presentation presets, grant-control) use plain,
 * unclassed <input>/<select>/<textarea>/<label> tags rather than daisyUI's
 * `.input`/`.select`/`.textarea` utility classes, so the re-theme pass
 * above (which only reskins those daisyUI classes) never touched them --
 * they still rendered as bare default browser widgets on the parchment
 * background. Tag selectors here give every one of those elements the
 * same handbook-page treatment in a single place, and (being unlayered,
 * same as the rest of this file) also win over any daisyUI `.input`/
 * `.select` styling already applied to the handful of elements that do
 * carry those classes, so the whole app's forms end up visually
 * consistent regardless of which classes an individual template used.
 */

label {
  display: block;
  margin-bottom: 2px;
  font-family: Georgia, serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-secondary);
  letter-spacing: 0.01em;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]),
select,
textarea {
  display: inline-block;
  width: auto;
  max-width: 100%;
  padding: 5px 8px;
  margin-bottom: 8px;
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 0.95rem;
  color: var(--color-base-content);
  background-color: var(--color-base-100);
  border: 1px solid var(--color-base-300);
  border-radius: 2px;
  box-shadow: inset 0 1px 2px rgba(43, 26, 14, 0.1);
}

select {
  cursor: pointer;
}

textarea {
  display: block;
  width: 100%;
  max-width: 32rem;
  resize: vertical;
  font-size: 0.9rem;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
  vertical-align: middle;
}

/* File pickers (map upload) get a themed "choose file" button instead of
 * the browser's stock grey one, so the upload control reads as part of
 * this UI rather than an unstyled leftover. */
input[type="file"] {
  display: inline-block;
  margin-bottom: 8px;
  font-family: Georgia, serif;
  font-size: 0.85rem;
  color: var(--color-base-content);
}

input[type="file"]::file-selector-button {
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 0.85rem;
  padding: 5px 10px;
  margin-right: 10px;
  border: 1px solid var(--dm-ink-border);
  border-radius: 2px;
  background-color: var(--color-secondary);
  color: var(--color-secondary-content);
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  background-color: var(--color-primary);
}

/* An unmissable boxed prompt, used in place of a muted throwaway line
 * whenever a section needs the DM to take a specific action first (e.g.
 * upload a map before tokens can be placed). */
.callout {
  border: 2px solid var(--dm-ink-border);
  border-left: 6px solid var(--color-primary);
  background-color: var(--color-base-200);
  padding: 12px 16px;
  margin-bottom: 16px;
  border-radius: 2px;
}

.callout h3 {
  margin: 0 0 4px;
  padding-bottom: 0;
  border-bottom: none;
  font-size: 1rem;
}

.callout p {
  margin: 0;
  color: var(--color-base-content);
}

/* ---- Header / nav ---------------------------------------------------- */

.navbar {
  border-bottom: 2px solid var(--dm-header-border);
  background-color: var(--color-base-100);
  margin-bottom: 8px;
}

.navbar .brand {
  font-family: "Libre Baskerville", Georgia, serif;
  text-transform: uppercase;
  color: var(--color-primary);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
}

/* ---- Home page --------------------------------------------------------- */

.home-hero {
  max-width: 40rem;
  margin: 40px auto;
  padding: 0 16px;
}

.home-hero .lede {
  font-size: 1.05rem;
}

.home-hero .actions {
  margin-top: 24px;
}

/* ---- Portraits (presentation presets, character sheets) --------------- */

.portrait {
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--dm-ink-border);
}

.portrait-sm {
  width: 32px;
  height: 32px;
}

.portrait-md {
  width: 40px;
  height: 40px;
}

/* ---- Map gallery (dm-4lr: multiple maps per session) -------------------
 * The "Map tools" dropdown's list of a session's maps -- reuses `.list`/
 * `.list-row` (daisyUI, same as the creature library and presentation
 * preset lists elsewhere in this panel) for the row layout, plus these two
 * rules: a small thumbnail (deliberately NOT a real generated thumbnail --
 * just `image_url` displayed small, per dm-4lr's "no thumbnail-generation
 * pipeline" scope) and a highlight for whichever row is the session's
 * currently active map.
 */

.map-gallery-thumb {
  width: 48px;
  height: 32px;
  object-fit: cover;
  border-radius: 2px;
  border: 1px solid var(--dm-ink-border);
}

.map-gallery-active {
  background-color: var(--color-base-100);
  outline: 1px solid var(--color-primary);
}

/* ---- Tabletop layout (docked sidebar, reverted from dm-ig2's top menu bar) -
 * The DM console and player table both render a `.tabletop-layout` row with
 * two children: `.tabletop-menubar` (now a docked LEFT column, despite its
 * name -- still one `.menubar-item` per tool group, unchanged from dm-ig2,
 * see below for why the class name stayed) and `.tabletop-main` (just the
 * map -- see `.map-panel` further down).
 *
 * WHY (back to a sidebar): dm-ig2 traded this docked column for an overlay
 * top menu bar specifically to stop any permanently-reserved width from
 * competing with the map -- but subsequent user feedback asked for tools
 * back on the side regardless of that trade-off. Two things soften it
 * compared to dm-759's original docked sidebar:
 *   1. The column auto-narrows to just its button labels (`width: 150px`)
 *      whenever nothing is open, and only widens (`340px`) while a panel
 *      actually has content on screen -- the `:has()` rule below -- instead
 *      of always reserving full width like dm-759 did.
 *   2. `MapFit` (`assets/js/hooks/map_fit.js`) now actively grows the map
 *      image to fill whatever width `.map-panel` ends up with (see "Map &
 *      tokens" below), rather than only ever shrinking to fit -- so
 *      whatever space the sidebar leaves behind, the map actually uses.
 *
 * The DOM shape dm-ig2 introduced -- each `.menubar-item` wraps its own
 * `.menubar-btn` (the always-visible button) directly above its own
 * `.menubar-dropdown` (that group's content, `:if={@open_menu == ...}`,
 * unchanged `handle_event("toggle_menu", ...)` state in SessionLive/
 * TableLive) -- turns out to work as a docked sidebar with NO template
 * changes at all: switching `.menubar-dropdown` from an absolutely
 * positioned overlay back to normal document flow makes each open panel's
 * content simply appear right below its own button, pushing whatever's
 * below it down the column -- a plain accordion list, not a floating
 * overlay. Only the CSS below changed; `session_live.ex`/`table_live.ex`
 * keep the exact same `@open_menu` state and template.
 *
 * `Layouts.app` (see `layouts.ex`) wraps every page's content in a
 * `mx-auto max-w-2xl` column -- fine for the rest of the app, far too
 * narrow for a map that's supposed to dominate the screen. `.tabletop-layout`
 * breaks out of that shell via the same margin-based full-bleed trick as
 * before (sized to the viewport, capped by `max-width` on very wide
 * screens) so only these two views claim the extra width.
 *
 * The viewport lock (`html`/`body` `overflow: hidden` while a
 * `.tabletop-layout` is mounted) is unchanged from dm-ig2 -- the sidebar
 * scrolls internally (`overflow-y: auto` below) rather than the page.
 * No narrow-viewport fallback is reintroduced here (dm-759/dm-d98 had an
 * `@media (max-width: 900px)` escape hatch back to a normal scrolling
 * page) -- not asked for, and the auto-narrow column costs far less width
 * than dm-759's always-280px one did, so it's left out until someone
 * actually needs it on a narrow screen.
 *
 * `:has()` is supported in every current major browser engine.
 */

html:has(.tabletop-layout) {
  height: 100%;
}

body:has(.tabletop-layout) {
  display: flex;
  flex-direction: column;
  height: 100vh; /* fallback for browsers without `dvh` support */
  height: 100dvh;
  overflow: hidden;
}

/* `Layouts.app`'s `<main>` and its `mx-auto max-w-2xl` inner wrapper both
 * just flow to content height normally on every other page; here they're
 * stretched to fill the remaining flex space below the navbar instead, so
 * `.tabletop-layout` (further stretched below) has a real, non-zero height
 * to fill without this file needing to know the navbar's actual rendered
 * height. */
body:has(.tabletop-layout) main {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding-top: 8px;
  padding-bottom: 8px;
}

body:has(.tabletop-layout) main > div {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* With tool panels living in the sidebar instead of a full page of their
 * own, the per-page `<.header>` title/subtitle ("DM Console" / "Table", see
 * `CoreComponents.header/1`) is still real, measured fixed chrome sitting
 * above the map (~121px at its default size) -- shrunk here the same way
 * dm-ig2 left it, scoped so no other page's header is affected. */
body:has(.tabletop-layout) main > div > header {
  padding-bottom: 4px;
}

body:has(.tabletop-layout) main > div > header h1 {
  font-size: 1rem;
  line-height: 1.3;
  margin: 0;
  padding-bottom: 0;
  border-bottom: none;
}

body:has(.tabletop-layout) main > div > header p {
  font-size: 0.75rem;
  margin: 2px 0 0;
}

.tabletop-layout {
  display: flex;
  flex-direction: row;
  flex: 1 1 auto;
  min-height: 0;
  gap: 12px;
  /* Margin-based full-bleed: sized by the (scrollbar-excluded) containing
     block rather than a `100vw` unit, which would include the scrollbar's
     own width on non-overlay-scrollbar platforms and force a spurious
     horizontal scrollbar. */
  width: auto;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  max-width: 1600px;
  box-sizing: border-box;
  padding: 0 16px;
}

.tabletop-main {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ---- Docked sidebar (class name kept as `.tabletop-menubar` from dm-ig2,
 * see the big comment above for why no template rename was needed) --------
 * A vertical, scrollable column of `.menubar-item`s -- each one a button
 * plus (while open) its own content, stacked directly beneath it, forming a
 * plain accordion rather than a floating overlay. `width` auto-narrows to
 * just the button labels when nothing is open (`:has()` below), so an idle
 * sidebar costs the map far less than a permanently-wide one would.
 */
.tabletop-menubar {
  flex-shrink: 0;
  width: 150px;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 8px 6px;
  background-color: var(--color-base-100);
  border-right: 2px solid var(--dm-header-border);
}

/* Widens the moment any panel actually has content on screen (excludes the
 * Voice dropdown while it's merely `display: none`-hidden, see
 * `.menubar-dropdown-hidden` below -- that one stays mounted at all times
 * for its `WebRTCMedia` hook, so `:not(.menubar-dropdown-hidden)` is what
 * keeps an idle sidebar narrow even though Voice's dropdown div is always
 * in the DOM). */
.tabletop-menubar:has(.menubar-dropdown:not(.menubar-dropdown-hidden)) {
  width: 340px;
}

.menubar-item {
  display: flex;
  flex-direction: column;
}

.menubar-btn {
  width: 100%;
  padding: 6px 10px;
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 0.8rem;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--color-primary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 2px;
  cursor: pointer;
}

.menubar-btn:hover {
  background-color: var(--color-base-200);
}

.menubar-btn-active {
  background-color: var(--color-secondary);
  color: var(--color-secondary-content);
  border-color: var(--dm-ink-border);
}

.menubar-btn-active:hover {
  background-color: var(--color-secondary);
}

/* A panel's content, docked in normal flow right below its own button --
 * no `position`/`z-index`/size caps needed any more since the whole
 * sidebar scrolls as one column (`overflow-y: auto` above) rather than
 * each panel capping its own height as a floating overlay would need to. */
.menubar-dropdown {
  margin-top: 4px;
  margin-bottom: 6px;
  padding: 10px 10px 12px;
  background-color: var(--color-base-100);
  border: 1px solid var(--dm-header-border);
  border-radius: 2px;
}

/* Tighter panel headers inside a docked panel -- the default `.header` h1
 * (see the base styles above) is sized for a full-width page title; at
 * sidebar width that's disproportionate, so each panel's own title is
 * scaled down without touching the shared `.header` component. */
.menubar-dropdown header h1 {
  font-size: 15px;
  padding-bottom: 4px;
  margin: 0 0 8px;
}

.menubar-dropdown header p {
  font-size: 0.8rem;
}

.menubar-dropdown .card.bg-base-200 {
  margin-top: 0;
}

/* ---- Voice / Party HUD panel -------------------------------------------
 * Voice/Party HUD is a sidebar panel like every other tool group, via its
 * own `.menubar-item`/"voice" key -- kept this way (rather than an
 * always-visible strip of its own) since real headless-Chrome measurement
 * during dm-ig2 showed party-hud's own chunky EOB-style boxes costing
 * ~120px whether or not Voice was actually in use, which meaningfully
 * shrank the map versus not having that strip at all.
 *
 * One real wrinkle: `#voice` (the `WebRTCMedia` hook's `phx-update=
 * "ignore"` container, holding any live peer connections) must stay
 * mounted in the DOM at ALL times -- unmounting it (which `:if` would do
 * the moment the panel closes) would tear down every active call just from
 * closing it. `.menubar-dropdown-hidden` below solves this with a plain
 * CSS `display: none` instead: the Voice panel always renders, `#voice`
 * and its hook never unmount, and the class toggles on and off exactly the
 * way every other panel's presence does -- zero footprint while closed.
 * `phx-update="ignore"` only protects `#voice`'s own children from being
 * patched; the class on its ancestor `.menubar-dropdown` is ordinary
 * tracked LiveView state, so this re-renders on every `@open_menu` change
 * same as anything else -- and, per the `:has()` rule above, is
 * specifically excluded from counting as "a panel is open" so it alone
 * doesn't keep the sidebar permanently widened.
 */
.menubar-dropdown-hidden {
  display: none;
}

/* ---- Map & tokens ------------------------------------------------------ */

/* `.map-panel` carries `card bg-base-200` in the template (see the DM
 * console/player table templates) purely so it picks up this app's dark-
 * red-brown border/background language via the generic `.card.bg-base-200`
 * rule near the top of this file -- but that rule's 16px padding + 16-24px
 * margin is sized for TEXT-content cards (Dice, Chat, character sheet),
 * where breathing room around prose actually helps. A map is a canvas, not
 * prose: every one of those pixels is space Roll20/Foundry would hand
 * straight to the map image instead (dm-759). This selector combines all
 * three classes the template applies (`.card.bg-base-200.map-panel`) so its
 * specificity ties the generic rule's and, being declared later in this
 * same unlayered file, wins the cascade -- no need to touch the generic
 * rule other cards still rely on. */
.card.bg-base-200.map-panel {
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  border-radius: 0;
  /* Centers `.map-surface` on both axes instead of leaving flexbox's
   * `align-items`/`justify-content` defaults (stretch / flex-start) in
   * place, which packed the map into the panel's top-left corner whenever
   * the image was narrower or shorter than the available space -- exactly
   * the "small and not centered" complaint, since most of the panel then
   * sat empty to the map's right/below instead of framing it evenly. */
  display: flex;
  align-items: center;
  justify-content: center;
}

.map-surface {
  position: relative;
  display: inline-block;
  /* `.map-surface` lives inside `.card` (`.map-panel`), now a centering
   * flex container (see above) rather than the default `align-items:
   * stretch`, which would otherwise still stretch this to the full
   * cross-axis (width) of the card, well past the actual map image once
   * the image is narrower than the card. `display: inline-block` here is
   * what actually keeps it hugging its content (the <img>) instead of
   * stretching, which keeps every absolutely-positioned overlay that
   * fills `.map-surface` (grid, token layer) flush with
   * the image's real rendered bounds. Token `left`/`top` (see
   * `token_style/1`) are raw pixel offsets from THIS element's own origin,
   * so keeping `.map-surface` sized flush to the image -- never bigger --
   * is what keeps a token's rendered position matching where it was
   * placed/dragged, at any width or height this box ends up at. */
  max-width: 100%;
}

.map-surface img {
  max-width: 100%;
  display: block;
  border: 2px solid var(--dm-ink-border);
}

/* `.map-panel` fills whatever height `.tabletop-main` has left (see the
 * "Tabletop layout" rules above) instead of sizing to its own content --
 * `flex: 1 1 auto` on a flex item of a definite-height flex container
 * (`.tabletop-main`) resolves to a definite used height, which is what
 * lets `.map-surface img`'s `max-height: 100%` below resolve to
 * something real instead of being ignored as an unresolvable percentage.
 * `min-height: 0` overrides flexbox's default `min-height: auto`, which
 * would otherwise refuse to let this shrink below its content's natural
 * (potentially much taller) height.
 *
 * dm-ig2: previously gated behind `@media (min-width: 901px)`, because
 * below that width the viewport lock itself used to be disabled (see the
 * removed dm-d98/dm-759 mobile fallback, above) and the map just flowed
 * normally on a scrolling page instead. Since the menu-bar redesign removed
 * that fallback -- there's no longer a docked column that stops fitting at
 * narrow widths -- the viewport lock now holds at every width, so the map
 * fills the available height at every width too, unconditionally. */
.map-panel {
  flex: 1 1 auto;
  min-height: 0;
}

/* Same reasoning one level down: `.map-surface` becomes a flex item of
 * `.map-panel` (also a flex column, from `.card`) so it too gets a
 * definite used height to hand down to the `<img>`'s `max-height: 100%`.
 * It only ever shrinks to fit (`flex-grow` stays at its `0` initial
 * value) rather than stretching -- a landscape map narrower than the
 * available height already renders at its natural size via `max-width:
 * 100%` on the <img> with room to spare, so there's nothing to grow
 * into; a portrait map or a short viewport is the case this actually
 * bounds. */
.map-surface {
  min-height: 0;
}

/* `object-fit: contain` with no explicit `width`/`height` on the <img>
 * itself is a deliberate belt-and-braces pairing with the `max-width`/
 * `max-height` above, not a second, competing sizing mechanism: with no
 * explicit box size forced onto the <img>, the browser's normal
 * replaced-element auto-sizing already shrinks it to fit both
 * constraints while preserving its aspect ratio -- `.map-surface` (see
 * above) then hugs that exact rendered size, so there's never a
 * letterboxed gap between `.map-surface`'s own box and the visible
 * picture inside it, which is what keeps token positions correct. */
.map-surface img {
  max-height: 100%;
  object-fit: contain;
}

.map-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  /* Purely visual -- tokens (and the map image itself) must still
   * receive every click/drag. */
  pointer-events: none;
}

/* A token is a compact portrait-plus-label stack -- the character's
 * portrait (see `Character.display_portrait_url/2`) so a token reads at a
 * glance instead of forcing a click to identify it, with the kind-based
 * accent color that used to fill the whole box now living on the
 * portrait's border, so kind stays a quick-glance cue alongside the
 * portrait rather than being replaced by it. Deliberately small (see
 * `.token-portrait`'s fixed size) so many tokens can share a map without
 * overwhelming it. */
.token {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: default;
}

.token-draggable {
  cursor: grab;
  touch-action: none;
}

.token-portrait {
  display: block;
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
  border: 2px solid rgba(0, 0, 0, 0.4);
  background: var(--color-base-200);
}

.token-player .token-portrait {
  border-color: #2563eb;
}

.token-monster .token-portrait {
  border-color: #7a2b17;
}

.token-npc .token-portrait {
  border-color: #3f6b2b;
}

.token-object .token-portrait {
  border-color: #78716c;
}

/* Groups the label with the DM-only hidden badge/hide/remove controls in
 * one row below the portrait, so those controls don't each fall onto
 * their own line under `.token`'s column layout. `TableLive`'s tokens
 * have no controls to group, so they render `.token-label` directly
 * without this wrapper. */
.token-controls {
  display: flex;
  align-items: center;
  gap: 3px;
}

.token-label {
  max-width: 72px;
  color: #f7ebcb;
  background: rgba(20, 14, 8, 0.85);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 11px;
  font-family: Georgia, serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid rgba(0, 0, 0, 0.4);
}

.token-remove-btn {
  margin-left: 4px;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
}

/* DM-only "hidden from players" indicator (see `Sessions.set_token_visibility/4`)
 * -- only ever rendered in `SessionLive`, never `TableLive`, since hidden
 * tokens are filtered out of a player's assigns server-side before they'd
 * ever reach this CSS. */
.token-hidden {
  /* Strongly transparent (not just dimmed) so a hidden token reads as
     "ghosted" at a glance on the DM's own map -- players never see this at
     all, since hidden tokens are filtered server-side before reaching
     TableLive; this is purely a DM-side visibility cue. */
  opacity: 0.25;
}

.token-hidden .token-portrait {
  border-style: dashed;
}

.token-hidden-badge {
  margin-left: 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 3px;
  padding: 1px 4px;
}

.token-visibility-btn {
  margin-left: 4px;
  background: none;
  border: none;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  font-size: 11px;
}

/* Transient "Goblin moved 15 ft" label the `MapDrag` hook drops onto
 * `.map-surface` right after a token's position is patched in (see its
 * `beforeUpdate`/`updated` lifecycle) -- purely informational, never
 * blocking pointer events, and removed by the hook itself a few seconds
 * later (or replaced immediately by the next one). `pointer-events: none`
 * keeps it from ever intercepting the next drag. */
.token-distance-label {
  position: absolute;
  transform: translate(-50%, -150%);
  background: rgba(20, 14, 8, 0.85);
  color: #f7ebcb;
  border: 1px solid var(--dm-ink-border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-family: Georgia, serif;
  white-space: nowrap;
  pointer-events: none;
  animation: token-distance-fade 3s ease-out forwards;
}

@keyframes token-distance-fade {
  0% {
    opacity: 0;
    transform: translate(-50%, -150%);
  }
  10% {
    opacity: 1;
  }
  75% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -220%);
  }
}

/* ---- Party HUD (EOB-style portrait strip) -------------------------------
 * A horizontal strip of chunky, beveled portrait boxes -- one per
 * currently-relevant participant (the DM, then each connected player) --
 * meant to evoke Eye of the Beholder's bottom-of-screen party frame rather
 * than a corporate video-conferencing tile grid, per the design spec's
 * "Voice and video" section. Translated into this app's own parchment/
 * dark-red-brown/serif theme instead of EOB's blue-metal pixel art. Sits
 * above the Slice 9 `#voice` `phx-update="ignore"` container (untouched --
 * the `WebRTCMedia` hook still owns that div) inside the same Voice card.
 * Each box's portrait doubles as an (opt-in) video tile -- see
 * `.party-hud-portrait-wrap`/`.party-hud-video` below.
 */

.party-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px;
  margin: 0 0 16px;
  background: var(--color-secondary);
  border: 2px solid var(--dm-ink-border);
  border-radius: 3px;
}

.party-hud-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 78px;
  padding: 6px 4px;
  background: var(--color-base-100);
  border-style: solid;
  border-width: 2px;
  border-color: #a9825a #241609 #241609 #a9825a;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px var(--color-base-300);
}

/*
 * Wraps a box's portrait `<img>` and its sibling `<video>` (see
 * `CoreComponents.party_hud/1`) so the video can sit absolutely positioned
 * directly on top of the portrait, same size, and simply be shown/hidden by
 * the `WebRTCMedia` hook as that participant's camera goes on/off -- the
 * portrait underneath never has to be touched (hidden, removed, swapped)
 * for this to work, so it keeps updating live (presentation/character
 * changes) exactly as it did before video tiles existed.
 */
.party-hud-portrait-wrap {
  position: relative;
  width: 48px;
  height: 48px;
}

.party-hud-video {
  position: absolute;
  inset: 0;
}

.party-hud-portrait {
  width: 48px;
  height: 48px;
  object-fit: cover;
  background: var(--color-base-200);
  border: 2px solid var(--dm-ink-border);
  border-radius: 2px;
}

.party-hud-name {
  margin-top: 4px;
  max-width: 100%;
  font-family: Georgia, serif;
  font-size: 11px;
  text-align: center;
  color: var(--color-base-content);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.party-hud-hp {
  width: 100%;
  margin-top: 3px;
}

.party-hud-hp-bar {
  width: 100%;
  height: 6px;
  background: #2b1a0e;
  border: 1px solid var(--dm-ink-border);
  border-radius: 1px;
  overflow: hidden;
}

.party-hud-hp-fill {
  height: 100%;
  background: var(--color-success);
}

.party-hud-hp-fill--mid {
  background: var(--color-warning);
}

.party-hud-hp-fill--low {
  background: var(--color-error);
}

.party-hud-hp-text {
  margin-top: 2px;
  font-size: 10px;
  text-align: center;
  color: var(--color-secondary);
}

/* Last roll shown beneath the DM's HUD portrait (dm-hhq, part 3). Keyed by
 * the roll's own id in the template (`party-hud-last-roll-dm-<roll id>`),
 * so a new roll is a genuinely new DOM node, not a patched one -- which is
 * what makes `dice-pop` below actually replay on every new roll instead of
 * firing once and never again. */
.party-hud-last-roll {
  margin-top: 4px;
  font-family: Georgia, serif;
  font-size: 10px;
  text-align: center;
  color: var(--color-primary);
  animation: dice-pop 0.4s ease-out;
}

/* ---- Dice icons and roll animation (dm-hhq) ------------------------------
 * `CoreComponents.dice_icon/1` inlines each die's SVG (already
 * `fill="currentColor"`) so it tints with whatever `color` is in scope --
 * the roll button's text color here, the log row's here. One shared, brief
 * `@keyframes` (a quick "pop" -- no shake/spin variety per die type, per the
 * spec's "one consistent effect reused everywhere") is reused for a new
 * dice-log row AND the HUD's last-roll box above, so the same visual
 * language means "something just happened" everywhere it appears.
 */
.dice-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.dice-icon svg {
  width: 1em;
  height: 1em;
  display: block;
}

.dice-icon-btn {
  font-size: 18px;
}

.dice-icon-log {
  font-size: 16px;
  color: var(--color-primary);
}

/* Marks only the newest row in the dice-roll log (see `dice_roll_row_class/2`
 * in `SessionLive`/`TableLive`) -- deliberately NOT applied to the whole
 * `:for` list, so re-rendering the log on an unrelated broadcast never
 * replays this on rows that already played it. */
.roll-latest {
  animation: dice-pop 0.4s ease-out;
}

@keyframes dice-pop {
  0% {
    transform: scale(0.7);
    opacity: 0;
  }
  60% {
    transform: scale(1.08);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* dm-8t2: map zoom/pan + fullscreen (see assets/js/hooks/map_fit.js).
 * The view is a transform on `.map-surface`; the panel clips it. Controls
 * sit small and faded in the panel's corner so they don't cover the map. */
.card.bg-base-200.map-panel {
  position: relative;
  overflow: hidden;
}

.map-surface {
  transform-origin: 0 0;
}

.map-controls {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 20;
  display: flex;
  gap: 4px;
  opacity: 0.45;
  transition: opacity 0.15s;
}

.map-controls:hover,
.map-controls:focus-within {
  opacity: 1;
}

/* Players' table is always "immersive": the fullscreen layout, but as a
 * fixed overlay of the window (real fullscreen needs a user gesture). */
.tabletop-layout.immersive {
  position: fixed;
  inset: 0;
  z-index: 30;
}

/* Fullscreen takes the whole tabletop (sidebar + map), not just the map,
 * so the tools stay docked beside it instead of overlaying it. */
:is(.tabletop-layout:fullscreen, .tabletop-layout.immersive) {
  margin: 0;
  max-width: none;
  width: 100%;
  height: 100%;
  padding: 0;
  background-color: var(--color-base-100);
}

/* dm-vng: Hand / Magnifier map tools (state classes live on the
 * phx-update="ignore" `.map-controls`, set by map_fit.js). */
.map-panel:has(.map-controls.tool-hand) .map-surface,
.map-panel:has(.map-controls.tool-hand) .map-surface * {
  cursor: grab;
}

.map-panel:has(.map-controls.tool-zoom) .map-surface,
.map-panel:has(.map-controls.tool-zoom) .map-surface * {
  cursor: none;
}

.map-lens {
  display: none;
  position: fixed;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  border: 3px solid var(--dm-ink-border);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  background-color: var(--color-base-200);
  pointer-events: none;
  z-index: 40;
}

/* The lens holds a copy of the map; nothing inside it may catch the
 * pointer (tokens/drawing layer set pointer-events themselves). */
.map-lens * {
  pointer-events: none !important;
}

.map-panel.map-panning .map-surface,
.map-panel.map-panning .map-surface * {
  cursor: grabbing;
}

/* Keep the controls fully visible while a tool is on, so it's obvious. */
.map-controls.tool-hand,
.map-controls.tool-zoom,
.map-controls.tool-ruler {
  opacity: 1;
}

/* dm-c50: custom voice toolbox sliders. */
.voice-slider {
  display: block;
  font-size: 0.75rem;
  margin-top: 4px;
}

.voice-slider span {
  display: flex;
  justify-content: space-between;
}

/* dm-hws: the map lives in its own image-pixel coordinate space. The
 * <img> renders at natural size; map_fit.js places and scales the whole
 * surface with one transform, so tokens/drawings/grid stored in image
 * pixels line up identically on every screen. Overrides the older
 * fit-by-CSS rules above. `max-content` keeps the surface (and the grid,
 * fog and areas filling it) as wide as the image: an absolute box would
 * otherwise shrink to the panel's width and the image would overflow it. */
.map-surface {
  position: absolute;
  top: 0;
  left: 0;
  width: max-content;
  max-width: none;
}

/* `>` so only the map image matches, not token portraits (also <img>s
 * inside `.map-surface`), which keep their fixed `.token-portrait` size. */
.map-surface > img {
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  object-fit: fill;
}

/* Tokens and their move label keep a constant on-screen size at the fitted
 * view (counter-scaled by 1/fit) and grow with the DM's zoom. Origin 0 0
 * keeps the token centred on its x/y anchor under the extra scale. */
.token,
.token-distance-label {
  transform-origin: 0 0;
  scale: var(--token-scale, 1);
}

/* The map never moves when a sidebar menu opens: the sidebar is out of
 * flow at its narrow width with the map beside it, and an opened panel
 * (340px) floats over the map's left edge instead of pushing it. */
.tabletop-layout {
  position: relative;
}

.tabletop-menubar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 16px;
  height: auto;
  z-index: 30;
}

.tabletop-menubar:has(.menubar-dropdown:not(.menubar-dropdown-hidden)) {
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.35);
}

.tabletop-main {
  margin-left: 162px; /* 150px sidebar + 12px gap */
}

/* Fullscreen (DM screen shown to players): the map takes the whole screen
 * and the sidebar auto-hides like a dock -- it waits just off the left
 * edge (an 8px invisible strip catches the pointer) and slides in while
 * hovered. */
:is(.tabletop-layout:fullscreen, .tabletop-layout.immersive) .tabletop-main {
  margin-left: 0;
}

:is(.tabletop-layout:fullscreen, .tabletop-layout.immersive) .tabletop-menubar {
  top: 0;
  bottom: 0;
  left: 0;
  transform: translateX(calc(-100% + 8px));
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

:is(.tabletop-layout:fullscreen, .tabletop-layout.immersive) .tabletop-menubar:hover {
  transform: none;
  opacity: 1;
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.35);
}

@media (prefers-reduced-motion: reduce) {
  :is(.tabletop-layout:fullscreen, .tabletop-layout.immersive) .tabletop-menubar {
    transition: none;
  }
}

/* Fullscreen: the map controls hide like the sidebar dock and slide down
 * when the pointer reaches the top-right corner (a thin strip stays on
 * screen, invisible, to catch it). */
:is(.tabletop-layout:fullscreen, .tabletop-layout.immersive) .map-controls {
  top: 0;
  right: 0;
  padding: 8px;
  opacity: 0;
  transform: translateY(calc(-100% + 8px));
  transition: transform 0.2s ease, opacity 0.2s ease;
}

:is(.tabletop-layout:fullscreen, .tabletop-layout.immersive) .map-controls:hover,
:is(.tabletop-layout:fullscreen, .tabletop-layout.immersive) .map-controls:focus-within {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  :is(.tabletop-layout:fullscreen, .tabletop-layout.immersive) .map-controls {
    transition: none;
  }
}

/* dm-xlk: party HUD over the bottom of the map (both views). It auto-
 * hides like a dock: the tray slides down until only an invisible strip
 * is left at the bottom edge, and slides up on hover -- unless "Pin" is
 * checked. Only the tray moves (transform); the DM's spotlit box is in
 * the untransformed `.party-hud-stage`, so its `position: fixed` stays
 * relative to the screen. */
.tabletop-main {
  position: relative;
  overflow: hidden;
}

.party-hud-dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  z-index: 15;
  pointer-events: none;
}

.party-hud-tray {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 0 0 6px;
  max-width: calc(100% - 16px);
  pointer-events: auto;
}

/* dm-pkx: hidden with `visibility`, not a transform/opacity -- a spotlit
 * player's box lives in this tray and is `position: fixed`, which a
 * transformed ancestor would break and opacity would hide. `visibility`
 * lets that one box opt back in. The hotzone strip catches the pointer
 * while the tray is hidden (hidden elements get no pointer events). */
.party-hud-hotzone {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 10px;
  pointer-events: auto;
}

.party-hud-dock:not(:has(.hud-pin input:checked)):not(:hover) .party-hud-tray {
  visibility: hidden;
}

.party-hud-tray .party-hud-spotlight {
  visibility: visible;
}

@media (prefers-reduced-motion: reduce) {
  .party-hud-tray {
    transition: none;
  }
}

.party-hud-dock .party-hud {
  margin: 0;
  gap: 6px;
  padding: 4px 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

.party-hud-dock .party-hud:empty {
  display: none;
}

.party-hud-dock .party-hud-box {
  width: 68px;
  padding: 4px 3px;
}

.party-hud-dock .party-hud-portrait-wrap,
.party-hud-dock .party-hud-portrait {
  width: 48px;
  height: 48px;
}

.hud-pin {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  font-size: 0.75rem;
  background: var(--color-base-100);
  border: 1px solid var(--dm-header-border);
  border-radius: 2px;
  cursor: pointer;
  white-space: nowrap;
}

/* DM center stage: only visible while spotlit; then big, mid-screen. */
.party-hud-stage .party-hud-box:not(.party-hud-spotlight) {
  display: none;
}

.party-hud-stage .party-hud-box.party-hud-spotlight {
  position: fixed;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  width: min(44vw, 520px);
  padding: 10px;
  z-index: 25;
  pointer-events: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.party-hud-spotlight .party-hud-portrait-wrap {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
}

.party-hud-spotlight .party-hud-portrait {
  width: 100%;
  height: 100%;
}

.party-hud-spotlight .party-hud-name {
  font-size: 1.1rem;
  margin-top: 8px;
}

/* dm-8c7: Ruler tool overlay (screen space, over the map) and button. */
.map-ruler {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  overflow: visible;
}

.map-ruler-line {
  stroke: #f7ebcb;
  stroke-width: 3;
  stroke-dasharray: 8 5;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.9));
}

.map-ruler-end {
  fill: #f7ebcb;
  stroke: #241609;
  stroke-width: 1.5;
}

.map-ruler-text {
  fill: #f7ebcb;
  stroke: rgba(20, 14, 8, 0.9);
  stroke-width: 4px;
  paint-order: stroke;
  font: bold 15px Georgia, serif;
}

.map-panel:has(.map-controls.tool-ruler) .map-surface,
.map-panel:has(.map-controls.tool-ruler) .map-surface * {
  cursor: crosshair;
}

body:has(.map-controls.tool-ruler) .map-ruler-btn {
  background-color: var(--color-secondary);
  color: var(--color-secondary-content);
}

/* Live drag label: no fade-out while the token is still moving. */
.token-distance-live {
  animation: none;
}

/* dm-3po: quick mic/camera toggles, bottom-right of the map, auto-hiding
 * like the other docks (an invisible strip catches the pointer). The mic
 * stays visible while muted so you always know. */
.media-quick {
  position: absolute;
  right: 8px;
  bottom: 0;
  z-index: 16;
  display: flex;
  gap: 6px;
  padding: 0 0 8px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.media-quick:not(:hover):not(:focus-within):not(:has(.is-muted)) {
  transform: translateY(calc(100% - 10px));
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .media-quick {
    transition: none;
  }
}

.media-quick-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--dm-ink-border);
  background: var(--color-base-100);
  color: var(--color-base-content);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

.media-quick-btn svg {
  width: 20px;
  height: 20px;
}

/* Slash = off: mic when muted, camera unless on. */
.media-quick-btn .media-slash {
  display: none;
}

.media-quick-btn.is-muted,
.media-quick-btn[data-media-toggle="camera"]:not(.is-on) {
  color: #b42318;
}

.media-quick-btn.is-muted .media-slash,
.media-quick-btn[data-media-toggle="camera"]:not(.is-on) .media-slash {
  display: inline;
}

/* While muted, only the mic button shows when the dock is tucked away. */
.media-quick:not(:hover):not(:focus-within):has(.is-muted) [data-media-toggle="camera"] {
  visibility: hidden;
}

/* dm-rco: music volume in the quick-controls dock (0-200%). */
.media-quick-volume {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 10px;
  border-radius: 20px;
  border: 2px solid var(--dm-ink-border);
  background: var(--color-base-100);
  color: var(--color-base-content);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
}

.media-quick-volume svg {
  width: 20px;
  height: 20px;
  flex: none;
}

.media-quick-volume input {
  width: 96px;
}

.media-quick:not(:hover):not(:focus-within):has(.is-muted) .media-quick-volume {
  visibility: hidden;
}

/* dm-pkx: center-screen dice roll, seen by everyone. Sits lower when
 * someone is center stage so it doesn't cover them. */
.dice-spotlight {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 30;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

body:has(.party-hud-spotlight) .dice-spotlight {
  top: 82%;
}

.dice-spotlight.is-visible {
  opacity: 1;
}

.dice-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 28px 14px;
  background: rgba(20, 14, 8, 0.88);
  color: #f7ebcb;
  border: 2px solid var(--dm-ink-border);
  border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  font-family: Georgia, serif;
}

.dice-die {
  width: 132px;
  height: 132px;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.7));
}

.dice-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.dice-face-number {
  fill: #fff;
  stroke: #241609;
  stroke-width: 3px;
  paint-order: stroke;
  font-family: Georgia, serif;
  font-weight: bold;
}

.dice-tumbling {
  animation: dice-tumble 0.35s linear infinite;
}

@keyframes dice-tumble {
  from { transform: rotate(0deg) scale(0.9); }
  50% { transform: rotate(180deg) scale(1.1); }
  to { transform: rotate(360deg) scale(0.9); }
}

.dice-landed {
  animation: dice-land 0.35s ease-out;
}

@keyframes dice-land {
  from { transform: scale(1.8); }
  to { transform: scale(1); }
}

.dice-caption {
  font-size: 1rem;
}

.dice-crit .dice-die {
  filter: drop-shadow(0 0 14px #f5c542) drop-shadow(0 4px 6px rgba(0, 0, 0, 0.7));
}

.dice-fumble .dice-die {
  filter: drop-shadow(0 0 14px #e5533d) drop-shadow(0 4px 6px rgba(0, 0, 0, 0.7));
}

/* dm-8vl: token card (DM), top-right over the map. */
.token-card {
  position: absolute;
  top: 48px;
  right: 12px;
  z-index: 26;
  width: 230px;
  font-size: 12px;
  line-height: 1.35;
  max-height: calc(100% - 140px);
  overflow-y: auto;
  padding: 14px;
  background: var(--color-base-100);
  border: 2px solid var(--dm-ink-border);
  border-radius: 4px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.token-card-close {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 1.25rem;
  line-height: 1;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-base-content);
}

.token-card-portrait {
  display: block;
  width: 100%;
  max-height: 170px;
  aspect-ratio: 1;
  object-fit: cover;
  border: 2px solid var(--dm-ink-border);
  border-radius: 3px;
  background: var(--color-base-200);
}

.token-card-name {
  margin: 6px 0 3px;
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 14px;
  line-height: 1.25;
  padding: 0;
  border: none;
}

.token-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11px;
  margin-bottom: 8px;
}

.token-card-kind {
  text-transform: capitalize;
  padding: 0 6px;
  border-radius: 3px;
  color: #fff;
  background: #78716c;
}

.token-card-kind-player { background: #2563eb; }
.token-card-kind-monster { background: #7a2b17; }
.token-card-kind-npc { background: #3f6b2b; }

.token-card-hp {
  font-size: 11px;
  margin-bottom: 8px;
}

.token-card-hp-bar {
  height: 8px;
  margin-bottom: 2px;
  background: #2b1a0e;
  border: 1px solid var(--dm-ink-border);
  border-radius: 2px;
  overflow: hidden;
}

.token-card-hp-fill {
  height: 100%;
  background: #3f9b45;
}

.token-card-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin: 0 0 8px;
}

.token-card-stats > div {
  text-align: center;
  padding: 3px 2px;
  border: 1px solid var(--dm-header-border);
  border-radius: 3px;
}

.token-card-stats dt {
  font-size: 9px;
  text-transform: uppercase;
  opacity: 0.7;
}

.token-card-stats dd {
  margin: 0;
  font-size: 12px;
  font-weight: bold;
}

.token-card-notes {
  font-size: 11px;
  white-space: pre-line;
  margin: 0;
}

/* dm-8vl: tokens a player can't drag are still clickable (opens the card). */
.token[data-draggable="false"] {
  cursor: pointer;
}

/* dm-o95: DM-only ambient sound sources. The element sits at the source's
 * x/y (zero-size); the range circle is in map pixels (scales with the
 * map), the pin keeps a readable size like tokens. */
.sound-emitter {
  position: absolute;
  width: 0;
  height: 0;
  touch-action: none;
}

.sound-emitter-range {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px dashed rgba(126, 200, 255, 0.75);
  background: radial-gradient(rgba(126, 200, 255, 0.22), rgba(126, 200, 255, 0.04) 70%);
  pointer-events: none;
}

.sound-emitter-pin {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  transform-origin: 0 0;
  scale: var(--token-scale, 1);
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  font-size: 12px;
  white-space: nowrap;
  color: #f7ebcb;
  background: rgba(20, 50, 80, 0.85);
  border: 1px solid rgba(126, 200, 255, 0.9);
  border-radius: 12px;
  cursor: grab;
}

.sound-emitter-label {
  font-family: Georgia, serif;
  font-size: 11px;
}

.map-panel:has(.map-controls.tool-sound) .map-surface,
.map-panel:has(.map-controls.tool-sound) .map-surface * {
  cursor: copy;
}

body:has(.map-controls.tool-sound) .map-sound-btn {
  background-color: var(--color-secondary);
  color: var(--color-secondary-content);
}

/* Join screen: bundled portrait picker. */
.portrait-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
}

.portrait-choice {
  position: relative;
  cursor: pointer;
  border-radius: 6px;
  overflow: hidden;
  outline: 2px solid transparent;
}

.portrait-choice input {
  position: absolute;
  opacity: 0;
}

.portrait-choice img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}

.portrait-choice span {
  position: absolute;
  inset: auto 0 0;
  padding: 1px 4px;
  font-size: 0.7rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
}

.portrait-choice:has(input:checked) {
  outline-color: var(--color-primary, #e0a040);
}

.portrait-choice:has(input:focus-visible) {
  outline-color: currentColor;
}

/* Your own party-HUD box: token/camera switch in its corner. */
.party-hud-portrait-wrap {
  position: relative;
}

.hud-self-camera {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 20px;
  height: 20px;
  padding: 3px;
  border-radius: 50%;
  border: 0;
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

.hud-self-camera.is-on {
  background: var(--color-primary, #c0392b);
}

.hud-self-camera svg {
  width: 100%;
  height: 100%;
}

/* Turn tracker: banner over the map, glow on the acting token / HUD box. */
.turn-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  padding: 4px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  color: #fff;
  background: rgba(20, 16, 12, 0.75);
  pointer-events: none;
  white-space: nowrap;
}

.turn-banner-mine {
  background: #b8860b;
  box-shadow: 0 0 12px rgba(255, 200, 60, 0.8);
}

/* Whose turn it is: a gold ring that pulses, easy to spot on a busy map. */
.token.token-turn {
  filter: drop-shadow(0 0 6px #ffcc33) drop-shadow(0 0 3px #ffcc33);
  z-index: 5;
}

.token.token-turn .token-portrait {
  border-color: #ffcc33;
  animation: token-turn-pulse 1.4s ease-in-out infinite;
}

@keyframes token-turn-pulse {
  0%, 100% { box-shadow: 0 0 0 3px #ffcc33, 0 0 10px 4px rgba(255, 204, 51, 0.7); }
  50% { box-shadow: 0 0 0 5px #ffcc33, 0 0 22px 10px rgba(255, 204, 51, 0.9); }
}

@media (prefers-reduced-motion: reduce) {
  .token.token-turn .token-portrait {
    animation: none;
    box-shadow: 0 0 0 4px #ffcc33, 0 0 16px 6px rgba(255, 204, 51, 0.8);
  }
}

.party-hud-box.party-hud-turn {
  box-shadow: 0 0 0 2px #ffcc33, 0 0 14px rgba(255, 204, 51, 0.8);
}

.turn-order {
  list-style: decimal inside;
  margin: 0;
  padding: 0;
}

.turn-order li {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  border-radius: 4px;
}

.turn-order .turn-name {
  flex: 1;
}

.turn-order li.turn-current {
  background: rgba(255, 204, 51, 0.3);
  font-weight: 600;
}

.token-card-hp-form {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-top: 6px;
}

.token-card-hp-form input {
  width: 4.5em;
}

/* The DM's token card grows with an inventory; keep it scrollable. */
.token-card {
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

/* Token conditions: badges on the map token, toggles on the token card. */
.token-conditions {
  position: absolute;
  top: -0.6rem;
  right: -0.9rem;
  display: flex;
  flex-wrap: wrap;
  max-width: 3.4rem;
  gap: 1px;
  pointer-events: none;
}
.token-condition {
  font-size: 0.8rem;
  line-height: 1;
  background: rgba(20, 16, 12, 0.85);
  border: 1px solid #d9a441;
  border-radius: 999px;
  padding: 0.12rem;
}
.token-card-conditions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0.5rem 0;
}
.token-card-conditions .btn {
  text-transform: capitalize;
}

/* Fog of war: opaque above tokens for players, a see-through shade
 * under the tokens for the DM. */
.map-fog {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
.map-fog-fill {
  fill: #0b0a09;
}
.map-fog-dm {
  z-index: auto;
}
.map-fog-dm .map-fog-fill {
  fill: #1b2a4a;
  opacity: 0.55;
}
.map-ruler .map-fog-rect {
  fill: rgba(217, 164, 65, 0.15);
  stroke: #d9a441;
  stroke-width: 2;
  stroke-dasharray: 6 4;
}

/* DM handouts: a parchment card over everything. */
.handout-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 8, 6, 0.6);
}
.handout-card {
  position: relative;
  max-width: min(720px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 1.5rem 1.75rem;
  border-radius: 10px;
  background: #f1e3c3;
  color: #2b1d0e;
  border: 3px solid #8a6a3a;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.handout-title {
  font-family: Georgia, serif;
  font-size: 1.5rem;
  margin: 0 0 0.75rem;
}
.handout-image {
  max-width: 100%;
  max-height: 60vh;
  margin: 0 auto 0.75rem;
  display: block;
  border-radius: 6px;
}
.handout-body {
  font-family: Georgia, serif;
  white-space: pre-wrap;
  line-height: 1.5;
}

/* Spell area templates. */
.map-areas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}
.map-area {
  fill: rgba(255, 122, 0, 0.22);
  stroke: #ff7a00;
  stroke-width: 3;
}
.map-area-label {
  fill: #fff;
  stroke: #000;
  stroke-width: 3px;
  paint-order: stroke;
  font: 700 22px system-ui, sans-serif;
}

/* D&D stats on the character sheet: score, then a check button. */
.character-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.5rem, 1fr));
  gap: 0.4rem;
}
.character-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

/* Every token is one size, big enough that a camera shown on a player's
 * token is a recognisable face; creatures match them. */
.token .token-portrait {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  border-width: 3px;
}

/* A running camera covers the portrait; hidden = camera off. */
.token-video[hidden] {
  display: none;
}

.token-video:not([hidden]) + .token-portrait-img {
  display: none;
}

/* DM talk control on each party box; players see the 🔇 when silenced. */
:where(.party-hud-box) {
  position: relative;
}

.party-hud-silence {
  position: absolute;
  top: 2px;
  left: 2px;
  padding: 0 2px;
  border: 0;
  border-radius: 4px;
  font-size: 12px;
  line-height: 18px;
  background: rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

span.party-hud-silence {
  cursor: default;
}

.party-hud-silence.is-silenced {
  background: #b42318;
}

.media-quick-btn.is-silenced {
  color: #b42318;
  opacity: 0.6;
  cursor: not-allowed;
}

/* Player's read-only character sheet. */
.character-sheet {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  font-size: 0.875rem;
}

.character-sheet > div {
  display: contents;
}

.character-sheet dt {
  color: color-mix(in oklab, currentColor 60%, transparent);
}

/* ---- Character sheet (C) and pack (I): compact stone panels in the token
 * card's spot, after the old Eye of the Beholder character screens. ---- */
.menubar-kbd {
  margin-left: 4px;
  padding: 0 4px;
  border: 1px solid currentColor;
  border-radius: 3px;
  font-size: 0.65rem;
  opacity: 0.6;
}

.eob-panel {
  --eob-hi: #9a9aa6;
  --eob-lo: #2a2a33;
  --eob-ink: #f0e2b6;
  position: absolute;
  top: 48px;
  right: 12px;
  z-index: 26;
  /* Long words wrap; a tall sheet scrolls instead of running off screen. */
  width: 256px;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px;
  overflow-wrap: anywhere;
  color: var(--eob-ink);
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 11px;
  line-height: 1.3;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.06), transparent 40%),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.06) 0 2px, transparent 2px 5px),
    #4b4b57;
  /* Bevelled stone frame: light top-left, dark bottom-right. */
  border: 3px solid;
  border-color: var(--eob-hi) var(--eob-lo) var(--eob-lo) var(--eob-hi);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}

.eob-close {
  position: absolute;
  top: 2px;
  right: 6px;
  border: 0;
  background: none;
  color: var(--eob-ink);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.eob-head {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.eob-portrait {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border: 2px solid;
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
}

.eob-id {
  flex: 1;
  min-width: 0;
}

.eob-name {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 13px;
  color: #ffd76a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.eob-class {
  font-style: italic;
  opacity: 0.8;
}

.eob-hp {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.eob-hp-bar {
  flex: 1;
  height: 6px;
  background: #1c1c22;
  border: 1px solid var(--eob-lo);
}

.eob-hp-bar > div {
  height: 100%;
  background: #3fae3f;
}

.eob-stats {
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid;
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
}

.eob-row {
  display: grid;
  grid-template-columns: 1fr 28px 30px;
  align-items: center;
  min-height: 18px;
}

.eob-row-sep {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid rgba(240, 226, 182, 0.2);
}

.eob-key {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 10px;
}

.eob-val {
  text-align: right;
  font-weight: bold;
  color: #fff;
}

.eob-mod {
  justify-self: end;
  padding: 0 3px;
  border: 1px solid transparent;
  background: none;
  color: #ffd76a;
  font: inherit;
  font-weight: bold;
  cursor: pointer;
}

.eob-mod:hover {
  border-color: #ffd76a;
}

.eob-traits {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1px 8px;
  margin: 8px 0 0;
}

.eob-traits > div {
  display: contents;
}

.eob-traits dt {
  opacity: 0.75;
  text-transform: capitalize;
}

.eob-notes {
  margin: 8px 0 0;
  white-space: pre-line;
  font-style: italic;
  opacity: 0.85;
}

.eob-label {
  margin: 6px 0 3px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.7;
}

.eob-slots {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.eob-slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  padding: 2px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.35);
  /* Sunken slot. */
  border: 2px solid;
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
}

.eob-slot-worn {
  box-shadow: inset 0 0 0 1px #ffd76a;
}

.eob-slot-empty {
  opacity: 0.45;
}

.eob-slot-icon {
  font-size: 20px;
  line-height: 1;
}

.eob-slot-name {
  max-width: 100%;
  font-size: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.eob-slot-qty {
  position: absolute;
  right: 2px;
  bottom: 0;
  font-size: 9px;
  font-weight: bold;
  color: #fff;
}

.eob-foot {
  margin-top: 8px;
  font-size: 9px;
  font-style: italic;
  opacity: 0.6;
  text-align: center;
}

/* ---- Chat: see-through box, bottom-left over the map. Lines fade a while
 * after arriving; hover or typing brings the whole log back. ---- */
.chat-box {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 17;
  display: flex;
  flex-direction: column;
  width: min(260px, calc(100% - 24px));
  padding: 4px;
  border-radius: 6px;
  background: transparent;
  transition: background 0.2s ease;
}

/* Click-through until in use (Enter, or the 💬): tokens and anything else
 * under the corner stay clickable. Typing makes the whole box live. */
.chat-box {
  pointer-events: none;
}

.chat-box:focus-within {
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.45);
}

.chat-box-toggle {
  position: absolute;
  left: 2px;
  bottom: 4px;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  background: none;
  font-size: 12px;
  line-height: 20px;
  opacity: 0.55;
  cursor: pointer;
  pointer-events: auto;
}

.chat-box-toggle:hover {
  opacity: 1;
}

.chat-box-log {
  display: flex;
  flex-direction: column-reverse;
  max-height: 16vh;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  scrollbar-width: none;
}

.chat-box:focus-within .chat-box-log {
  scrollbar-width: thin;
}

.chat-line {
  padding: 0 2px;
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  text-shadow: 0 0 3px #000, 0 1px 2px #000;
  animation: chat-fade 1s ease 8s forwards;
}

.chat-box:hover .chat-line,
.chat-box:focus-within .chat-line {
  animation: none;
  opacity: 1;
}

@keyframes chat-fade {
  to {
    opacity: 0;
  }
}

.chat-box-input {
  width: 100%;
  margin-top: 4px;
  padding: 2px 6px 2px 24px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  background: transparent;
  color: #fff;
  font-size: 11px;
  /* Hidden until the corner is hovered or Enter is pressed. */
  opacity: 0;
  transition: opacity 0.2s ease;
}

.chat-box-input:focus {
  opacity: 1;
  outline: none;
  background: rgba(0, 0, 0, 0.5);
}

.chat-box-input::placeholder {
  color: rgba(255, 255, 255, 0.7);
}

@media (prefers-reduced-motion: reduce) {
  .chat-line {
    animation-duration: 0s;
  }
}

/* ---- Default tabletop skin: Eye of the Beholder stone ----------------
 * The whole table (sidebar, menus, token card, party bar, forms) reuses
 * the C/I panels' look: grey stone, bevelled frames, gold lettering. The
 * daisyUI palette is re-pointed here so every themed class follows; the
 * frames below add the bevel. Handouts keep their parchment on purpose. */
.tabletop-layout {
  --eob-hi: #9a9aa6;
  --eob-lo: #2a2a33;
  --eob-stone: #4b4b57;
  --eob-ink: #f0e2b6;
  --eob-gold: #ffd76a;

  --color-base-100: var(--eob-stone);
  --color-base-200: #3c3c46;
  --color-base-300: var(--eob-lo);
  --color-base-content: var(--eob-ink);
  --color-primary: var(--eob-gold);
  --color-primary-content: #2a2a33;
  --color-secondary: #6b6b78;
  --color-secondary-content: var(--eob-ink);
  --color-neutral: #6b6b78;
  --color-neutral-content: var(--eob-ink);
  --color-accent: #c8a24a;
  --color-accent-content: #2a2a33;
  --dm-header-border: var(--eob-hi);
  --dm-ink-border: var(--eob-lo);
  color: var(--eob-ink);
}

/* Raised stone frame. */
.tabletop-layout :is(.tabletop-menubar, .menubar-dropdown, .token-card, .party-hud-box, .turn-banner, .sound-emitter-panel) {
  color: var(--eob-ink);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.06), transparent 40%),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.06) 0 2px, transparent 2px 5px),
    var(--eob-stone);
  border: 3px solid;
  border-color: var(--eob-hi) var(--eob-lo) var(--eob-lo) var(--eob-hi);
  border-radius: 0;
}

.tabletop-layout :is(.menubar-dropdown, .token-card) {
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}

/* Sunken inner wells: cards, lists, and the token card's portrait. */
.tabletop-layout :is(.card, .list, .token-card-portrait, .party-hud-portrait-wrap) {
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid;
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
  border-radius: 0;
  box-shadow: none;
}

.tabletop-layout :is(h1, h2, h3, h4, .token-card-name, .party-hud-name) {
  color: var(--eob-gold);
}

/* Stone buttons: raised, pressed when active. */
.tabletop-layout .btn {
  color: var(--eob-ink);
  background: #5a5a67;
  border: 2px solid;
  border-color: var(--eob-hi) var(--eob-lo) var(--eob-lo) var(--eob-hi);
  border-radius: 0;
  box-shadow: none;
  font-family: "Libre Baskerville", Georgia, serif;
}

.tabletop-layout .btn:hover {
  background: #66667a;
  color: var(--eob-gold);
}

.tabletop-layout :is(.btn:active, .btn-active, .btn[aria-pressed="true"]) {
  background: #3c3c46;
  color: var(--eob-gold);
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
}

.tabletop-layout :is(.btn-error, .btn-success) {
  color: #fff;
}

.tabletop-layout .btn-error {
  background: #7a2b2b;
}

.tabletop-layout .btn-success {
  background: #2f5d2f;
}

/* Sunken fields. */
.tabletop-layout :is(.input, .select, .textarea, input[type="text"], input[type="number"], textarea, select):not(.chat-box-input):not(.range) {
  color: #fff;
  background: #24242b;
  border: 2px solid;
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
  border-radius: 0;
}

.tabletop-layout .menubar-btn {
  color: var(--eob-ink);
}

.tabletop-layout :is(.menubar-btn:hover, .menubar-btn-active) {
  color: var(--eob-gold);
  background: rgba(0, 0, 0, 0.3);
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
}

.tabletop-layout .party-hud-hp-bar {
  background: #1c1c22;
}

/* Keep the highlights and the paper handout readable over the stone skin. */
.tabletop-layout .turn-banner-mine {
  background: #b8860b;
  color: #2a1a05;
}

.tabletop-layout .handout-card :is(h1, h2, h3, h4) {
  color: #2b1d0e;
}

/* DM token card (stone): tags, tabs, HP form, condition grid, managed slots. */
.eob-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  font-size: 10px;
}

.eob-link {
  border: 0;
  background: none;
  color: var(--eob-gold, #ffd76a);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.eob-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 6px;
}

.eob-tab {
  flex: 1;
  padding: 2px 0;
  color: var(--eob-ink, #f0e2b6);
  background: #5a5a67;
  border: 2px solid;
  border-color: var(--eob-hi, #9a9aa6) var(--eob-lo, #2a2a33) var(--eob-lo, #2a2a33) var(--eob-hi, #9a9aa6);
  font: inherit;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
  cursor: pointer;
}

.eob-tab-on {
  color: var(--eob-gold, #ffd76a);
  background: #3c3c46;
  border-color: var(--eob-lo, #2a2a33) var(--eob-hi, #9a9aa6) var(--eob-hi, #9a9aa6) var(--eob-lo, #2a2a33);
}

.eob-hp-form {
  display: grid;
  grid-template-columns: 44px 1fr 1fr;
  gap: 4px;
  margin-bottom: 6px;
}

.eob-hp-form input {
  min-width: 0;
  padding: 0 4px;
}

.eob-hp-form .btn {
  min-width: 0;
  padding: 0 4px;
}

.eob-conditions {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}

.eob-cond {
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid;
  border-color: var(--eob-lo, #2a2a33) var(--eob-hi, #9a9aa6) var(--eob-hi, #9a9aa6) var(--eob-lo, #2a2a33);
  background: rgba(0, 0, 0, 0.35);
  font-size: 13px;
  filter: grayscale(1);
  opacity: 0.55;
  cursor: pointer;
}

.eob-cond-on {
  filter: none;
  opacity: 1;
  box-shadow: inset 0 0 0 1px var(--eob-gold, #ffd76a);
}

.eob-slot-manage {
  padding: 0;
}

.eob-slot-act {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 2px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.eob-slot-act:hover {
  background: rgba(255, 215, 106, 0.12);
}

.eob-slot-x {
  position: absolute;
  top: 0;
  right: 1px;
  padding: 0 2px;
  border: 0;
  background: none;
  color: #ff9b8a;
  font-size: 11px;
  line-height: 1;
  opacity: 0;
  cursor: pointer;
}

.eob-slot:hover .eob-slot-x,
.eob-slot-x:focus {
  opacity: 1;
}

.eob-add {
  display: grid;
  grid-template-columns: 1fr 64px 40px;
  gap: 3px;
  margin-top: 8px;
}

.eob-add input[name="item[notes]"] {
  grid-column: 1 / 3;
}

.eob-add :is(input, select) {
  min-width: 0;
  padding: 1px 4px;
  font-size: 11px;
}

/* Damage: the token shakes and its portrait flashes red. `translate` (the
 * individual property) stacks with the token's centring transform. */
.token.token-hit {
  animation: token-shake 0.45s ease-in-out;
}

.token.token-hit .token-portrait {
  animation: token-flash 0.45s ease-out;
}

@keyframes token-shake {
  0%, 100% { translate: 0 0; }
  15% { translate: -6px 0; }
  30% { translate: 5px -1px; }
  45% { translate: -4px 1px; }
  60% { translate: 3px 0; }
  75% { translate: -2px 0; }
}

@keyframes token-flash {
  0% { filter: none; }
  20% { filter: brightness(1.3) sepia(1) saturate(6) hue-rotate(-30deg) drop-shadow(0 0 6px #e11); }
  100% { filter: none; }
}

@media (prefers-reduced-motion: reduce) {
  .token.token-hit {
    animation: none;
  }
}

/* Your turn: the banner takes clicks (End turn), shows movement left, and
 * pulses so it's hard to miss. */
.tabletop-layout .turn-banner-mine {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
  animation: turn-pulse 1.6s ease-in-out infinite;
}

.turn-move {
  font-weight: normal;
  font-size: 0.8rem;
}

@keyframes turn-pulse {
  50% {
    box-shadow: 0 0 22px rgba(255, 200, 60, 1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tabletop-layout .turn-banner-mine {
    animation: none;
  }
}

.eob-unit {
  justify-self: end;
  font-size: 9px;
  opacity: 0.7;
}

.turn-used {
  font-size: 0.8rem;
  font-weight: normal;
}


/* Hands on player tokens (main / off), Eye of the Beholder style. */
.token-hands {
  position: absolute;
  top: 40px;
  left: -10px;
  right: -10px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.token-hand {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  background: #3c3c46;
  border: 2px solid;
  border-color: #2a2a33 #9a9aa6 #9a9aa6 #2a2a33;
  pointer-events: auto;
}

.token-hand-empty {
  opacity: 0.55;
  filter: grayscale(1);
}

/* The owner's main hand on their turn: click to aim. */
.token-hand-aim {
  cursor: crosshair;
  border-color: #ffd76a;
  box-shadow: 0 0 8px rgba(255, 215, 106, 0.9);
}

/* Aim: the weapon's reach square and the creatures inside it. */
.aim-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.aim-square {
  position: absolute;
  border: 2px solid rgba(255, 215, 106, 0.95);
  background: rgba(255, 215, 106, 0.12);
  box-shadow: inset 0 0 18px rgba(255, 215, 106, 0.35);
}

.aim-square-empty {
  border-color: rgba(255, 120, 100, 0.9);
  background: rgba(255, 80, 60, 0.1);
}

.aim-square::after {
  content: attr(data-label);
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  margin-bottom: 4px;
  padding: 1px 8px;
  white-space: nowrap;
  font-size: 12px;
  color: #ffd76a;
  background: rgba(20, 16, 12, 0.8);
}

.token.aim-target {
  cursor: crosshair;
}

.token.aim-target .token-portrait {
  outline: 3px solid #e5533d;
  outline-offset: 2px;
  animation: aim-pulse 0.9s ease-in-out infinite;
}

.token.aim-dim {
  opacity: 0.45;
}

@keyframes aim-pulse {
  50% {
    outline-color: rgba(229, 83, 61, 0.35);
  }
}

/* The DM's hit/miss call on a player's attack: top-left of the map, so it
 * doesn't cover the token card. */
.eob-panel.pending-attack {
  right: auto;
  left: 12px;
  width: 240px;
  border-color: #ffd76a #2a2a33 #2a2a33 #ffd76a;
}

.pending-attack p {
  margin: 4px 0 0;
}

/* Death: a creature's token becomes a loot bag; a player at 0 HP is
 * unconscious -- black and white with a skull, Eye of the Beholder style. */
.token-bag {
  display: grid;
  place-items: center;
  font-size: 32px;
  background: #4a3722;
  border-color: #c8a24a;
  cursor: pointer;
}

.token-loot .token-label {
  opacity: 0.7;
  font-style: italic;
}

.token-down .token-portrait {
  filter: grayscale(1) brightness(0.7);
}

.token-down::after {
  content: "💀";
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 22px;
  pointer-events: none;
  text-shadow: 0 0 4px #000;
}

/* A usable potion in the pack: click it, then pick who drinks. */
.eob-slot-use {
  cursor: crosshair;
  box-shadow: inset 0 0 0 1px #6fdc8c;
}

/* ---- Menus as sidebar + inspector (Apple HIG) ----------------------------
 * The menu list stays a narrow column and the open menu shows as a wider
 * panel beside it with its own scroll, instead of an accordion squeezed
 * into the column. Panels keep everyday controls on top; setup sections
 * (uploads, scenes, create forms) are collapsed `.panel-section`s. */
.tabletop-menubar,
.tabletop-menubar:has(.menubar-dropdown:not(.menubar-dropdown-hidden)) {
  width: 150px;
  overflow: visible;
}

.tabletop-menubar .menubar-dropdown:not(.menubar-dropdown-hidden) {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 100%;
  width: min(440px, calc(100vw - 170px));
  margin: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 0;
  box-shadow: 6px 0 18px rgba(0, 0, 0, 0.35);
}

.menubar-dropdown > .card {
  padding: 10px;
  margin-bottom: 0;
}

.menubar-dropdown .list-row {
  padding: 4px 8px;
  gap: 8px;
}

.menubar-dropdown .list-row .btn {
  white-space: nowrap;
}

.panel-section {
  margin: 8px 0;
  border-top: 1px solid var(--dm-header-border);
}

.panel-section > summary {
  padding: 6px 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-primary);
  cursor: pointer;
  list-style: none;
}

.panel-section > summary::before {
  content: "▸ ";
  display: inline-block;
  width: 1em;
}

.panel-section[open] > summary::before {
  content: "▾ ";
}

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

#grid-calibration-form {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 8px;
}

#grid-calibration-form > div:first-child {
  grid-column: 1 / -1;
}

#grid-calibration-form :is(input[type="number"], input[type="text"], select) {
  width: 100%;
}

/* Home page: the DM's saved and running sessions. */
.home-sessions {
  margin-top: 2rem;
  text-align: left;
}

.home-sessions ul {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.home-sessions li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--dm-header-border);
  background-color: var(--color-base-100);
}

/* Leave session sits at the bottom of the menu column, apart from the
 * everyday menus. */
.menubar-item-end {
  margin-top: auto;
}

.leave-session-btn {
  color: var(--color-error);
}

/* Player screen while the DM has the session saved (paused). */
.session-paused {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.7);
}

.session-paused > div {
  max-width: 24rem;
  padding: 20px 24px;
  text-align: center;
  background-color: var(--color-base-100);
  border: 2px solid var(--dm-header-border);
}

.session-paused h2 {
  margin-bottom: 8px;
  font-size: 1.2rem;
  color: var(--color-primary);
}

.session-paused .leave-session-btn {
  width: auto;
  margin-top: 12px;
  text-align: center;
}

/* ---- Character creation, stone style -------------------------------------
 * Full screen over a dark stone backdrop (no parchment, no page scroll).
 * A bevelled stone frame like the C / I panels with two tabs: Pick a hero
 * (portrait slots + that hero's sheet) and Create new (face with ◀ ▶,
 * race / sex / class, scores). Sized to fit a laptop screen. */
.hero-screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: auto;
  background:
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 40%, rgba(0, 0, 0, 0.6)),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.25) 0 2px, transparent 2px 34px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.2) 0 2px, transparent 2px 68px),
    #2c2c34;
}

.hero-creation {
  --eob-hi: #9a9aa6;
  --eob-lo: #2a2a33;
  --eob-ink: #f0e2b6;
  box-sizing: border-box;
  width: min(760px, 100%);
  padding: 12px 14px 14px;
  color: var(--eob-ink);
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 12px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.06), transparent 40%),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.06) 0 2px, transparent 2px 5px),
    #4b4b57;
  border: 4px solid;
  border-color: var(--eob-hi) var(--eob-lo) var(--eob-lo) var(--eob-hi);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
}

.hero-creation h1 {
  margin: 0 0 8px;
  padding: 0;
  border: 0;
  font-size: 16px;
  color: #ffd76a;
  text-align: center;
  font-variant: small-caps;
  letter-spacing: 0.08em;
}

/* Inset well, like a slot cut in the stone. */
#hero-creation :is(.hero-premades, .hero-stats, .hero-kit, .hero-title, input, select) {
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid;
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
}

.hero-tabs {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 10px;
}

/* Raised stone buttons; the selected tab and pressed buttons sink in. */
.hero-creation :is(.hero-tabs button, .hero-face-arrows button, .btn) {
  min-height: 0;
  height: auto;
  padding: 4px 14px;
  color: var(--eob-ink);
  font: inherit;
  font-weight: bold;
  background: #5c5c69;
  border: 2px solid;
  border-color: var(--eob-hi) var(--eob-lo) var(--eob-lo) var(--eob-hi);
  border-radius: 0;
  box-shadow: none;
  cursor: pointer;
}

.hero-creation :is(.hero-face-arrows button, .btn):active,
.hero-creation .hero-tabs button[aria-selected="true"] {
  color: #ffd76a;
  background: #3d3d47;
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
}

.hero-creation .btn.btn-primary {
  color: #2a1d05;
  background: #c9a34a;
}

.hero-sheet {
  display: grid;
  gap: 12px;
  align-items: start;
}

.hero-sheet-premade {
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
}

.hero-sheet-new {
  grid-template-columns: 150px minmax(0, 1fr);
}

.hero-premades {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
}

.hero-premade {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 3px 2px;
  color: var(--eob-ink);
  font: inherit;
  font-size: 10px;
  line-height: 1.2;
  text-align: center;
  background: none;
  border: 2px solid transparent;
  cursor: pointer;
}

.hero-premade img {
  width: 100%;
  max-height: 150px;
  aspect-ratio: 210 / 330;
  object-fit: cover;
  object-position: top;
  border: 2px solid;
  border-color: var(--eob-hi) var(--eob-lo) var(--eob-lo) var(--eob-hi);
}

.hero-premade strong {
  color: #ffd76a;
  font-size: 11px;
}

.hero-premade:hover,
.hero-premade-active {
  border-color: #ffd76a;
}

.hero-face img {
  display: block;
  width: 150px;
  aspect-ratio: 210 / 330;
  object-fit: cover;
  border: 3px solid;
  border-color: var(--eob-hi) var(--eob-lo) var(--eob-lo) var(--eob-hi);
}

.hero-face-arrows {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  font-variant: small-caps;
}

.hero-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hero-title {
  display: flex;
  flex-direction: column;
  padding: 4px 8px;
}

.hero-title strong {
  color: #ffd76a;
  font-size: 15px;
}

.hero-creation .hero-fields label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  color: var(--eob-ink);
  font-size: 11px;
  font-variant: small-caps;
  letter-spacing: 0.05em;
}

#hero-creation .hero-fields :is(input, select) {
  width: 100%;
  height: auto;
  margin: 0;
  padding: 3px 6px;
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-variant: normal;
  letter-spacing: normal;
  background-color: rgba(0, 0, 0, 0.3);
  border-radius: 0;
}

.hero-creation select option {
  color: #000;
}

.hero-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hero-row > label {
  flex: 1;
  min-width: 0;
}

.hero-numbers {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.hero-stats {
  flex: 1;
  max-width: 200px;
  border-collapse: separate;
  padding: 3px 8px;
}

.hero-stats th {
  text-align: left;
  font-weight: normal;
  letter-spacing: 0.08em;
}

.hero-stats td {
  text-align: right;
  font-weight: bold;
  color: #fff;
}

.hero-stats .hero-mod {
  width: 3em;
  color: #ffd76a;
}

.hero-derived {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
}

.hero-derived dt {
  font-variant: small-caps;
  opacity: 0.8;
}

.hero-derived dd {
  margin: 0;
  font-size: 16px;
  font-weight: bold;
  color: #fff;
}

.hero-kit {
  margin: 0;
  padding: 4px 8px;
  font-style: italic;
}

@media (max-width: 600px) {
  .hero-screen {
    place-items: start center;
  }

  .hero-sheet-premade,
  .hero-sheet-new {
    grid-template-columns: minmax(0, 1fr);
  }

  .hero-face {
    width: 150px;
    margin: 0 auto;
  }
}

/* EN · ES language links. */
.locale-switch {
  display: flex;
  gap: 2px;
  font-size: 11px;
}

.locale-switch a {
  padding: 2px 6px;
  color: inherit;
  text-decoration: none;
  opacity: 0.6;
  border: 1px solid transparent;
}

.locale-switch a[aria-current="true"] {
  opacity: 1;
  font-weight: bold;
  border-color: currentColor;
}

.hero-creation {
  position: relative;
}

.hero-locale {
  position: absolute;
  top: 8px;
  right: 10px;
}

.menubar-locale {
  justify-content: center;
  margin-bottom: 4px;
  color: var(--color-primary);
}

/* The hidden sidebar opens only from its strip at the screen edge: while
 * it's tucked away, an open menu's (invisible) flyout panel mustn't catch
 * the pointer over the map. */
:is(.tabletop-layout:fullscreen, .tabletop-layout.immersive) .tabletop-menubar:not(:hover) .menubar-dropdown {
  pointer-events: none;
}

/* ---- Grid tokens -----------------------------------------------------------
 * A token stands on one grid square (the server snaps it to the centre and
 * allows one per square), and its portrait fills that square: --cell is the
 * square in map pixels, and dividing by --token-scale undoes the token's
 * counter-scaling, so portraits grow and shrink with the map and
 * neighbours never overlap. The label, controls and hands hang outside the
 * portrait and keep a readable size. */
.token .token-portrait {
  width: calc(var(--cell, 50px) * 0.92 / var(--token-scale, 1));
  height: calc(var(--cell, 50px) * 0.92 / var(--token-scale, 1));
  border-radius: 18%;
  border-width: 2px;
}

.token .token-bag {
  font-size: calc(var(--cell, 50px) * 0.5 / var(--token-scale, 1));
}

.token > :is(.token-label, .token-controls) {
  position: absolute;
  top: 100%;
  left: 50%;
  translate: -50% 2px;
  white-space: nowrap;
}

.token .token-hands {
  top: auto;
  bottom: -8px;
}

/* Names and the DM's Hide / x are wider than a square, so they show on
 * hover (and for the token whose turn it is) instead of covering the
 * neighbours. The hand slots stay within the token's own square. */
.token > :is(.token-label, .token-controls) {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

.token:hover,
.token:focus-within {
  z-index: 6;
}

.token:is(:hover, :focus-within, .token-turn) > :is(.token-label, .token-controls) {
  opacity: 1;
  pointer-events: auto;
}

.token .token-hands {
  left: 0;
  right: 0;
}

/* Closed with the 💬: no messages, not even on hover, until reopened. */
.chat-box.chat-hidden .chat-box-log {
  visibility: hidden;
}

/* ---- Player dice panel ------------------------------------------------------
 * Common rolls first (initiative; checks / saves / skills with the sheet's
 * modifier already in), one roll mode for all of them, then plain dice and
 * a formula, then the last few rolls. */
.dice-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dice-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.dice-top .dice-visibility {
  margin-left: auto;
}

.dice-quick span {
  opacity: 0.75;
}

/* Advantage / disadvantage: small one-roll toggles at the tabs' end. */
.dice-modes {
  display: flex;
  gap: 4px;
}

.dice-mode {
  padding: 2px 6px;
  font: inherit;
  font-size: 11px;
  color: inherit;
  background: none;
  border: 1px solid var(--dm-header-border);
  border-radius: 3px;
  opacity: 0.7;
  cursor: pointer;
}

.dice-mode-on {
  opacity: 1;
  color: #2a1d05;
  background: #c9a34a;
  border-color: #c9a34a;
}

/* The DM's "roll as" picker. */
.dice-subject {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.dice-subject label {
  margin: 0;
  white-space: nowrap;
  color: inherit;
  font-size: 12px;
}

.dice-subject select {
  flex: 1;
  margin: 0;
}

.dice-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--dm-header-border);
}

.dice-tabs > button {
  flex: 1;
  padding: 4px 0;
  font: inherit;
  font-size: 12px;
  color: inherit;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  opacity: 0.7;
  cursor: pointer;
}

.dice-tabs > button[aria-selected="true"] {
  opacity: 1;
  font-weight: bold;
  border-bottom-color: currentColor;
}

.dice-chips {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.dice-chip {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px;
  padding: 6px 8px;
  font: inherit;
  font-size: 12px;
  color: inherit;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--dm-header-border);
  border-radius: 3px;
  cursor: pointer;
  overflow: hidden;
}

.dice-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dice-chip:hover {
  background: rgba(0, 0, 0, 0.3);
}

.dice-plain {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.dice-plain .dice-roll-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 4px 0;
  font: inherit;
  font-size: 10px;
  color: inherit;
  background: none;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
}

.dice-plain .dice-roll-btn:hover {
  border-color: var(--dm-header-border);
}

.dice-panel #dice-formula {
  margin-bottom: 0;
}

.dice-log {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
}

.dice-log li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dice-modes {
  align-items: center;
  font-size: 12px;
}

.dice-modes > span {
  opacity: 0.75;
}

/* ---- EOB2-style compact menus ---------------------------------------------
 * The menu column is a narrow strip of square stone buttons (icon over a
 * small label), and an open panel is only as tall as what it holds, with
 * no subtitle prose and one frame instead of a card inside a frame. */
.tabletop-menubar,
.tabletop-menubar:has(.menubar-dropdown:not(.menubar-dropdown-hidden)) {
  width: 70px;
  padding: 4px;
  gap: 4px;
}

.tabletop-main {
  margin-left: 82px;
}

.tabletop-menubar .menubar-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 5px 2px 4px;
  font-size: 9px;
  line-height: 1.1;
  text-align: center;
  white-space: normal;
  overflow-wrap: normal;
  border: 2px solid;
  border-color: var(--eob-hi) var(--eob-lo) var(--eob-lo) var(--eob-hi);
  background: rgba(255, 255, 255, 0.04);
}

.tabletop-menubar .menubar-btn-active {
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
  background: rgba(0, 0, 0, 0.3);
  color: var(--color-accent);
}

.tabletop-menubar .menubar-btn::before {
  font-size: 20px;
  line-height: 1;
}

.menubar-btn[phx-value-menu="session"]::before { content: "🏰"; }
.menubar-btn[phx-value-menu="voice"]::before { content: "🎙️"; }
.menubar-btn[phx-value-menu="handout"]::before { content: "📜"; }
.menubar-btn[phx-value-menu="combat"]::before { content: "⚔️"; }
.menubar-btn[phx-value-menu="dice"]::before { content: "🎲"; }
.menubar-btn[phx-value-menu="map_tools"]::before { content: "🗺️"; }
.menubar-btn[phx-value-menu="creatures"]::before { content: "🐉"; }
.menubar-btn[phx-value-menu="items"]::before { content: "💰"; }
.menubar-btn[phx-value-menu="music"]::before { content: "🎵"; }
.menubar-btn[phx-value-menu="character"]::before { content: "🛡️"; }
.menubar-btn[phx-value-menu="inventory"]::before { content: "🎒"; }
.menubar-btn[phx-value-menu="players"]::before { content: "👥"; }

.tabletop-menubar .menubar-dropdown:not(.menubar-dropdown-hidden) {
  bottom: auto;
  max-height: 100%;
  width: min(320px, calc(100vw - 90px));
  padding: 8px;
}

.menubar-dropdown header {
  padding-bottom: 0;
}

.menubar-dropdown header h1 {
  font-size: 13px;
  margin: 0 0 6px;
}

.menubar-dropdown header p {
  display: none;
}

.tabletop-layout .menubar-dropdown > .card {
  padding: 0;
  margin: 0;
  background: none;
  border: 0;
}

.menubar-dropdown .btn {
  min-height: 0;
  height: auto;
  padding: 3px 8px;
  font-size: 0.72rem;
}

.menubar-dropdown .list-row {
  padding: 3px 6px;
}

.menubar-dropdown .panel-section {
  margin: 4px 0;
}

.menubar-dropdown .panel-section > summary {
  padding: 4px 0;
}

/* Creature library: a grid of portraits; click one to place it. */
.creature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  gap: 4px;
  margin-bottom: 6px;
}

.creature-tile {
  position: relative;
}

.creature-tile > button:first-child {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 3px;
  font-size: 9px;
  line-height: 1.1;
  text-align: center;
  color: var(--eob-ink);
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid;
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
  cursor: pointer;
}

.creature-tile > button:first-child:hover:not(:disabled) {
  border-color: var(--color-accent);
}

.creature-tile > button:first-child:disabled {
  cursor: default;
  opacity: 0.6;
}

.creature-tile img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  margin-bottom: 2px;
}

.creature-tile-delete {
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: 13px;
  line-height: 1;
  color: var(--color-error);
  background: none;
  border: 0;
  cursor: pointer;
}

/* Panel contents at a compact EOB-like size: text, inputs and spacing
 * shrink with the panel instead of keeping page-sized defaults. */
.menubar-dropdown {
  font-size: 12px;
  line-height: 1.35;
}

.menubar-dropdown :is(.text-sm, label, p, li, summary) {
  font-size: 12px;
}

.menubar-dropdown .text-xs {
  font-size: 11px;
}

.menubar-dropdown .text-4xl {
  font-size: 24px;
  line-height: 1.2;
}

.menubar-dropdown :is(.mb-6, .mb-4) {
  margin-bottom: 6px;
}

.menubar-dropdown .mb-2 {
  margin-bottom: 4px;
}

.menubar-dropdown :is(.gap-4, .gap-2) {
  gap: 4px;
}

.menubar-dropdown :is(input:not([type="checkbox"]):not([type="range"]):not([type="file"]), select, textarea) {
  font-size: 12px;
  height: auto;
  min-height: 0;
  padding: 2px 6px;
}

.menubar-dropdown input[type="file"] {
  font-size: 11px;
  max-width: 100%;
}

.menubar-dropdown input[type="checkbox"] {
  width: 14px;
  height: 14px;
}

.menubar-dropdown .portrait-md {
  width: 40px;
  height: 40px;
}

/* Map tools: ruler and spell areas as one row of icon buttons. */
#area-tools .btn {
  min-width: 26px;
  justify-content: center;
}

/* Music + ambient muted on this screen: red with a slash, like the mic. */
.media-quick-btn[data-sound-mute][aria-pressed="true"] {
  color: #b42318;
}

.media-quick-btn[data-sound-mute][aria-pressed="true"] .media-slash {
  display: inline;
}

/* EN/ES at the foot of the narrow menu strip. */
.tabletop-menubar .menubar-locale {
  justify-content: center;
  gap: 0;
  font-size: 10px;
}

.tabletop-menubar .menubar-locale a {
  padding: 2px 4px;
}

.camera-device {
  display: block;
  max-width: 100%;
  margin-top: 4px;
}

/* Talking portraits: --talk (0..1, set by talk_meter.js) bobs and lights
 * up whoever is speaking -- the creature the DM speaks as included. */
.party-hud-box .party-hud-portrait-wrap {
  transform: translateY(calc(var(--talk, 0) * -5px)) scale(calc(1 + var(--talk, 0) * 0.07)) rotate(calc(var(--talk, 0) * -1.5deg));
  box-shadow: 0 0 calc(var(--talk, 0) * 22px) rgba(255, 204, 51, calc(var(--talk, 0) * 0.9));
  transition: transform 60ms linear, box-shadow 60ms linear;
}

@media (prefers-reduced-motion: reduce) {
  .party-hud-box .party-hud-portrait-wrap {
    transform: none;
  }
}

/* Voice panel: Character / Camera / Players' mics groups. */
.menubar-dropdown .voice-section {
  margin: 8px 0 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-accent);
}

.menubar-dropdown .voice-section:first-child {
  margin-top: 0;
}

.speak-as {
  display: flex;
  align-items: center;
  gap: 6px;
}

.speak-as-portrait {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border: 2px solid;
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
}

.speak-as select {
  flex: 1;
  min-width: 0;
}

.voice-effects,
.voice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 4px;
}

.voice-effects .btn {
  flex: 1;
}

/* Center stage: big enough to read a face, but up top and click-through so
 * the tokens in the middle of the map stay usable. */
.party-hud-stage .party-hud-box.party-hud-spotlight {
  top: 12px;
  transform: translateX(-50%);
  width: min(30vw, 360px);
  pointer-events: none;
}

.party-hud-stage .party-hud-box.party-hud-spotlight button {
  pointer-events: auto;
}

.voice-effects {
  flex-wrap: nowrap;
}

.voice-effects .btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 3px 2px;
}

/* Talking portraits, stronger: easy to see at a glance across the table. */
.party-hud-box .party-hud-portrait-wrap {
  transform: translateY(calc(var(--talk, 0) * -10px)) scale(calc(1 + var(--talk, 0) * 0.12)) rotate(calc(var(--talk, 0) * -2deg));
  box-shadow:
    0 0 0 calc(var(--talk, 0) * 4px) rgba(255, 204, 51, calc(var(--talk, 0) * 1.2)),
    0 0 calc(var(--talk, 0) * 40px) rgba(255, 204, 51, calc(var(--talk, 0) * 1.1));
  filter: brightness(calc(1 + var(--talk, 0) * 0.3));
}

/* The DM's own talk lights: "Speak as" portrait and the mic button. */
[data-talk-id] {
  box-shadow: 0 0 0 calc(var(--talk, 0) * 3px) rgba(255, 204, 51, calc(var(--talk, 0) * 1.2)),
    0 0 calc(var(--talk, 0) * 16px) rgba(255, 204, 51, calc(var(--talk, 0) * 1.1));
  transition: box-shadow 60ms linear;
}

/* Key hints in the narrow menu strip: a small corner badge. */
.tabletop-menubar .menubar-btn {
  position: relative;
}

.tabletop-menubar .menubar-kbd {
  position: absolute;
  top: 1px;
  right: 2px;
  margin: 0;
  padding: 0 2px;
  font-size: 8px;
  line-height: 1.2;
}

.menubar-dropdown .btn .menubar-kbd {
  font-size: 9px;
  padding: 0 3px;
}

.menubar-keys-btn {
  width: 100%;
  margin-bottom: 4px;
  font-size: 10px;
  color: var(--color-primary);
  background: none;
  border: 0;
  cursor: pointer;
}

/* "?" key list: a stone card over the map; click or ?/Esc closes it. */
.dm-keys {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 40;
  width: min(420px, calc(100% - 32px));
  padding: 12px 14px;
  font-size: 12px;
  color: var(--eob-ink, #f0e2b6);
  background: var(--eob-stone, #3b3a40);
  border: 3px solid;
  border-color: var(--eob-hi, #9a9aa6) var(--eob-lo, #2a2a33) var(--eob-lo, #2a2a33) var(--eob-hi, #9a9aa6);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

.dm-keys h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--color-accent, #c8a24a);
}

.dm-keys dl > div {
  display: flex;
  gap: 10px;
  padding: 2px 0;
}

.dm-keys dt {
  flex: 0 0 84px;
  text-align: right;
}

.dm-keys kbd {
  padding: 0 4px;
  border: 1px solid currentColor;
  border-radius: 3px;
  font-size: 11px;
  white-space: nowrap;
}

/* Labels on the stone panels: light ink (the base label colour is meant
 * for light backgrounds and nearly vanished here). */
.tabletop-layout .menubar-dropdown label {
  color: var(--eob-ink);
  opacity: 0.9;
}

/* Checkboxes on the stone panels: a sunken, light-edged well that shows
 * clearly when empty, with a gold tick when on. */
.tabletop-layout input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  display: inline-grid;
  place-content: center;
  width: 15px;
  height: 15px;
  margin: 0;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid;
  border-color: var(--eob-lo, #2a2a33) var(--eob-hi, #9a9aa6) var(--eob-hi, #9a9aa6) var(--eob-lo, #2a2a33);
  border-radius: 0;
  outline: 1px solid rgba(240, 226, 182, 0.55);
  cursor: pointer;
}

.tabletop-layout input[type="checkbox"]::after {
  content: "";
  width: 8px;
  height: 5px;
  margin-top: -2px;
  border: solid var(--color-accent, #c8a24a);
  border-width: 0 0 2px 2px;
  transform: rotate(-45deg) scale(0);
  transition: transform 80ms ease-out;
}

.tabletop-layout input[type="checkbox"]:checked {
  outline-color: var(--color-accent, #c8a24a);
}

.tabletop-layout input[type="checkbox"]:checked::after {
  transform: rotate(-45deg) scale(1);
}

.tabletop-layout input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--color-accent, #c8a24a);
  outline-offset: 1px;
}

.tabletop-layout input[type="checkbox"]:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Creature palette (NWN toolset style): a type -> group -> name tree. */
.creature-tree,
.creature-tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.creature-tree {
  max-height: 60vh;
  overflow-y: auto;
  margin-bottom: 6px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid;
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
}

.creature-tree ul {
  margin-left: 12px;
  border-left: 1px dotted rgba(240, 226, 182, 0.25);
  padding-left: 4px;
}

.creature-tree summary {
  padding: 1px 2px;
  cursor: pointer;
  color: var(--color-accent);
  font-weight: 700;
  list-style: none;
  user-select: none;
}

.creature-tree summary::-webkit-details-marker {
  display: none;
}

.creature-tree summary::before {
  content: "▸ ";
  display: inline-block;
  width: 1em;
}

.creature-tree details[open] > summary::before {
  content: "▾ ";
}

.creature-tree details details > summary {
  font-weight: 600;
  color: var(--eob-ink);
}

.creature-tree-count {
  margin-left: 4px;
  font-weight: 400;
  font-size: 10px;
  opacity: 0.6;
}

.creature-leaves li {
  display: flex;
  align-items: center;
}

.creature-leaves button:first-child {
  flex: 1;
  padding: 1px 4px;
  text-align: left;
  color: var(--eob-ink);
  background: none;
  border: 0;
  cursor: pointer;
}

.creature-leaves button:first-child:hover:not(:disabled),
.creature-leaves button:first-child:focus-visible {
  color: var(--color-accent-content, #2a2a33);
  background: var(--color-accent);
}

.creature-leaves button:first-child:disabled {
  cursor: default;
  opacity: 0.6;
}

.creature-leaf-delete {
  padding: 0 4px;
  color: var(--color-error);
  background: none;
  border: 0;
  cursor: pointer;
}

#creature-search input {
  width: 100%;
}

/* Dungeon Crawl sprites (32x32 pixel art): scale up crisp, not blurred,
 * on a dark backing so the transparent edges read on any map. */
img[src*="/images/sprites/"] {
  image-rendering: pixelated;
  background-color: #1d1c21;
}

/* An open panel keeps the tucked-away strip out, so a panel opened from the
 * keyboard (V D A C T) shows without moving the mouse to the edge. Closing it
 * (same key, Esc, or its button) tucks the strip away again. */
:is(.tabletop-layout:fullscreen, .tabletop-layout.immersive) .tabletop-menubar:has(.menubar-dropdown:not(.menubar-dropdown-hidden)) {
  transform: none;
  opacity: 1;
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.35);
}
:is(.tabletop-layout:fullscreen, .tabletop-layout.immersive) .tabletop-menubar:has(.menubar-dropdown:not(.menubar-dropdown-hidden)) .menubar-dropdown {
  pointer-events: auto;
}

/* ---- Hands on the party HUD (Eye of the Beholder) --------------------------
 * The two hand slots sit under each party member's portrait; on your turn
 * your main hand glows and is the attack button. */
.party-hud-box .token-hands {
  position: static;
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 3px;
  pointer-events: auto;
}
.party-hud-box .token-hand {
  width: 26px;
  height: 26px;
  font-size: 15px;
}
.party-hud-box .token-hand-aim {
  animation: hand-ready 1.2s ease-in-out infinite alternate;
}
@keyframes hand-ready {
  to { box-shadow: 0 0 14px rgba(255, 215, 106, 1); }
}

/* Damage / healing numbers floating over a portrait. */
.party-hud-portrait-wrap { position: relative; }
.hp-flash {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 900 28px/1 var(--font-display, serif);
  pointer-events: none;
  text-shadow: 0 0 4px #000, 2px 2px 0 #000;
  animation: hp-flash 1.4s ease-out forwards;
  z-index: 3;
}
.hp-flash-hit { color: #ff4d3d; }
.hp-flash-heal { color: #5dff7a; }
@keyframes hp-flash {
  0% { opacity: 0; transform: scale(0.6); }
  15% { opacity: 1; transform: scale(1.25); }
  100% { opacity: 0; transform: translateY(-24px) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .hp-flash { animation: hp-flash-still 1.4s forwards; }
  .party-hud-box .token-hand-aim { animation: none; }
  @keyframes hp-flash-still { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
}

/* The creature the DM possesses: a purple ring, and the sheet's link lit. */
.token.token-possessed {
  outline: 3px solid #b77bff;
  outline-offset: 2px;
  box-shadow: 0 0 14px rgba(183, 123, 255, 0.85);
}
.eob-link.eob-link-on {
  color: #b77bff;
  font-weight: 700;
}

/* ---- Camp (party rest) ---------------------------------------------------- */
.rest-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
}
.rest-title { font-weight: 700; }
.rest-check { display: flex; align-items: center; gap: 4px; font-size: 11px; }
.rest-fade {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: #000;
  pointer-events: none;
  animation: rest-fade 4s ease-in-out forwards;
}
.rest-fade p {
  color: #f3e3b5;
  font: 700 28px/1.3 var(--font-display, serif);
  text-shadow: 0 0 12px rgba(255, 170, 60, 0.6);
  padding: 0 16px;
  text-align: center;
}
.rest-fade.rest-interrupted p { color: #ff6a4d; }
@keyframes rest-fade {
  0% { opacity: 0; }
  25%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---- DM quick-access bar (keys 1-9) -----------------------------------------
 * Stone slots in the map's bottom-left corner, Neverwinter Nights style. */
/* Above the bottom-right strip where the audio controls (volume, mute,
   mic, camera) slide up on hover, so the two never overlap. */
.quickbar {
  position: absolute;
  right: 16px;
  bottom: 62px;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  gap: 3px;
}
.quickbar-slots { display: flex; gap: 3px; }
.quickbar-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  color: #f3e3b5;
  background: #3c3c46;
  border: 2px solid;
  border-color: #9a9aa6 #2a2a33 #2a2a33 #9a9aa6;
  cursor: pointer;
}
.quickbar-btn:active { border-color: #2a2a33 #9a9aa6 #9a9aa6 #2a2a33; }
.quickbar-btn img { width: 32px; height: 32px; object-fit: cover; image-rendering: pixelated; }
.quickbar-empty { opacity: 0.45; cursor: default; }
.quickbar-num {
  position: absolute;
  top: 0;
  left: 2px;
  font: 700 10px/1 sans-serif;
  color: #ffd76a;
  text-shadow: 1px 1px 0 #000;
}
.quickbar-edit-btn { width: 26px; height: 26px; font-size: 14px; }
.quickbar-edit {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 150px));
  gap: 4px;
  padding: 6px;
  background: #2b2b33;
  border: 2px solid #9a9aa6;
}
.quickbar-pick { position: relative; display: flex; align-items: center; gap: 4px; }
.quickbar-pick .quickbar-num { position: static; }
.quickbar-pick select { min-width: 0; flex: 1; }
@media (max-width: 640px) {
  .quickbar-btn { width: 30px; height: 30px; font-size: 16px; }
  .quickbar-edit { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---- Map triggers (DM only) ------------------------------------------------ */
.trigger-zone {
  position: absolute;
  border: 2px dashed #ffb13b;
  background: rgba(255, 177, 59, 0.1);
  pointer-events: none;
  z-index: 2;
}
.trigger-zone span {
  position: absolute;
  top: 2px;
  left: 4px;
  font: 700 calc(14px * var(--token-scale, 1)) / 1 sans-serif;
  color: #ffb13b;
  text-shadow: 1px 1px 0 #000;
}
.trigger-zone-fired { border-color: #77777f; background: rgba(120, 120, 128, 0.08); }
.trigger-zone-fired span { color: #9a9aa6; }
.trigger-form {
  display: grid;
  gap: 4px;
  padding: 6px 0;
  border-top: 1px solid rgba(0, 0, 0, 0.2);
}
.trigger-num { font-weight: 700; color: #b06a00; }
.map-controls.tool-trigger ~ * , .map-panel:has(.map-controls.tool-trigger) .map-surface { cursor: crosshair; }

/* A trigger's message: a gentler banner than the rest fade. */
.rest-fade.rest-narrate {
  background: rgba(0, 0, 0, 0.55);
  animation-duration: 6s;
}

/* Conditions over a party portrait; a character at 0 HP greys out. */
.party-hud-portrait-wrap .token-conditions {
  position: absolute;
  top: 2px;
  left: 2px;
  right: 2px;
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  z-index: 2;
  pointer-events: auto;
}
.party-hud-portrait-wrap .token-condition {
  font-size: 13px;
  line-height: 1;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 3px;
  padding: 1px;
}
.party-hud-down .party-hud-portrait { filter: grayscale(1) brightness(0.55); }
.party-hud-down .party-hud-portrait-wrap::after {
  content: "💀";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 26px;
  pointer-events: none;
}

/* Whispers (only the two of them and the DM see them) and /me actions. */
.chat-line.chat-whisper { font-style: italic; opacity: 0.9; }
.chat-line.chat-whisper strong { color: #c9a0ff; }
.chat-line.chat-emote { font-style: italic; }

/* ---- Quest journal ----------------------------------------------------------- */
.menubar-btn[phx-value-menu="journal"]::before { content: "📓"; }
.menubar-btn.has-new::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ff5a3c;
  box-shadow: 0 0 6px #ff5a3c;
}
.menubar-btn { position: relative; }
.journal { display: grid; gap: 8px; }
.journal-add { display: grid; gap: 4px; }
.journal-empty { opacity: 0.7; font-style: italic; }
.journal-entry header { display: flex; align-items: center; gap: 6px; }
.journal-entry header strong { flex: 1; }
.journal-entry p { margin: 2px 0 0 20px; white-space: pre-wrap; }
.journal-entry details { margin-left: 20px; font-size: 11px; }
.journal-done { opacity: 0.6; }
.journal-done strong { text-decoration: line-through; }
.journal-notes { display: grid; gap: 4px; border-top: 1px solid rgba(0, 0, 0, 0.25); padding-top: 6px; }

/* ---- Spells from the hand (party HUD) ---------------------------------------- */
.party-hud-hands { display: flex; justify-content: center; align-items: flex-start; gap: 4px; }
.party-hud-hands .token-hands { margin-top: 3px; }
.spell-menu { position: relative; margin-top: 3px; }
.spell-menu > summary {
  list-style: none;
  width: 26px;
  height: 26px;
  font-size: 15px;
  cursor: pointer;
}
.spell-menu > summary::-webkit-details-marker { display: none; }
.spell-menu[open] > summary { border-color: #b77bff; box-shadow: 0 0 8px rgba(183, 123, 255, 0.9); }
.spell-list {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  translate: -50% 0;
  z-index: 40;
  display: grid;
  gap: 3px;
  width: 190px;
  padding: 6px;
  background: #2b2b33;
  border: 2px solid;
  border-color: #9a9aa6 #2a2a33 #2a2a33 #9a9aa6;
  color: #f3e3b5;
  font-size: 12px;
}
.spell-slots { margin: 0 0 2px; color: #c9a0ff; }
.spell-btn {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 3px 6px;
  text-align: left;
  background: #3c3c46;
  color: inherit;
  border: 1px solid #55555f;
  cursor: crosshair;
}
.spell-btn small { opacity: 0.75; white-space: nowrap; }
.spell-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.spell-btn:not(:disabled):hover { border-color: #b77bff; }
.quickbar-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.quickbar-roll small {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font: 700 8px/1 sans-serif;
  color: #f3e3b5;
  text-shadow: 1px 1px 0 #000;
}
/* The party strip scrolls sideways, which would clip the spell list. */
.party-hud-dock .party-hud:has(.spell-menu[open]) { overflow: visible; }

/* Spell menu, explained for new players. */
.spell-list { width: 270px; max-height: 60vh; overflow-y: auto; gap: 4px; }
.spell-help { margin: 0; font-style: italic; color: #f3e3b5; }
.spell-slots small { display: block; opacity: 0.7; font-size: 10px; }
.spell-pips { letter-spacing: 2px; }
.spell-list h4 {
  margin: 4px 0 2px;
  font: 700 10px/1.2 sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #ffd76a;
}
.spell-list section { display: grid; gap: 3px; }
.spell-btn { display: grid; justify-content: stretch; gap: 2px; }
.spell-name { font-weight: 700; }
.spell-tags { display: flex; flex-wrap: wrap; gap: 3px; }
.spell-tag {
  font-size: 10px;
  padding: 0 4px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.35);
}
.spell-tag-attack { color: #ffb36b; }
.spell-tag-save { color: #8fd0ff; }
.spell-tag-auto { color: #c9a0ff; }
.spell-tag-heal { color: #7dff9a; }
.spell-desc { opacity: 0.85; white-space: normal; }
.spell-why { color: #ff9b8a; white-space: normal; }
@media (max-width: 640px) { .spell-list { width: min(270px, calc(100vw - 32px)); } }
.spell-btn .spell-desc, .spell-btn .spell-why { white-space: normal; opacity: 1; }
.spell-list { overflow-x: hidden; }
.spell-btn:disabled { opacity: 0.6; }

/* Eye of the Beholder spell panel: a stone box, names in gold, grouped by
 * level; a spell's details show on hover / focus only. */
.spell-list.eob-spells {
  width: 190px;
  gap: 6px;
  padding: 6px 8px;
  background: #4a4a55;
  border: 3px solid;
  border-color: #a8a8b4 #26262e #26262e #a8a8b4;
  font-family: var(--font-display, serif);
}
.eob-spells h4 {
  display: flex;
  justify-content: space-between;
  margin: 0 0 2px;
  padding-bottom: 2px;
  border-bottom: 1px solid #26262e;
  font: 700 11px/1.2 var(--font-display, serif);
  text-transform: none;
  letter-spacing: 0;
  color: #ffd76a;
}
.eob-spells .spell-pips { color: #c9a0ff; letter-spacing: 1px; }
.eob-spells .spell-btn {
  display: block;
  padding: 1px 4px;
  background: none;
  border: 0;
  color: #f3e3b5;
  font-size: 13px;
  text-align: left;
}
.eob-spells .spell-btn:not(:disabled):hover,
.eob-spells .spell-btn:not(:disabled):focus-visible {
  background: #26262e;
  color: #ffd76a;
  outline: none;
}
.eob-spells .spell-btn:disabled { color: #8a8a96; opacity: 1; }
.eob-spells .spell-desc { display: none; font: 10px/1.3 sans-serif; color: #d8cfa8; }
.eob-spells .spell-btn:hover .spell-desc,
.eob-spells .spell-btn:focus-visible .spell-desc { display: block; }

/* ---- The creature the DM plays: its own little action bar -------------------- */
.possess-bar {
  position: absolute;
  right: 16px;
  bottom: 64px;
  z-index: 31;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px 3px 3px;
  background: #3c3c46;
  border: 2px solid;
  border-color: #b77bff #2a2a33 #2a2a33 #b77bff;
  color: #f3e3b5;
}
.possess-face { width: 34px; height: 34px; object-fit: cover; image-rendering: pixelated; }
.possess-name { font: 700 12px/1 var(--font-display, serif); margin-right: 4px; white-space: nowrap; }
.possess-bar .token-hand { width: 28px; height: 28px; font-size: 15px; cursor: pointer; }
.possess-bar .token-hand:disabled { opacity: 0.45; cursor: not-allowed; }
.possess-bar .spell-list { left: auto; right: -6px; translate: none; }
/* Slots left, on the spellbook / holy symbol itself. */
.spell-menu > summary { position: relative; }
.spell-count {
  position: absolute;
  right: -4px;
  bottom: -4px;
  min-width: 13px;
  height: 13px;
  padding: 0 2px;
  border-radius: 7px;
  background: #6b3fb0;
  border: 1px solid #c9a0ff;
  font: 700 9px/11px sans-serif;
  color: #fff;
  text-align: center;
}

/* ---- Spell effects on the map (assets/js/spell_fx.js) ---------------------- */
.spell-fx {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.fx-ball {
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0 18%, var(--fx) 40%, transparent 72%);
  box-shadow: 0 0 18px 6px var(--fx);
}
.fx-orb { animation: fx-hue 0.4s linear infinite; }
@keyframes fx-hue { to { filter: hue-rotate(360deg); } }
.fx-dart {
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0 25%, var(--fx) 60%);
  box-shadow: 0 0 10px 4px var(--fx);
}
.fx-burst {
  border-radius: 50%;
  border: 3px solid var(--fx);
  background: radial-gradient(circle, color-mix(in srgb, var(--fx) 60%, transparent), transparent 70%);
  box-shadow: 0 0 20px 6px var(--fx);
}
.fx-ray {
  transform-origin: 0 50%;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--fx) 15%, #fff 50%, var(--fx) 85%);
  box-shadow: 0 0 12px 4px var(--fx);
}
.fx-column {
  transform-origin: 50% 100%;
  border-radius: 40% 40% 8px 8px;
  background: linear-gradient(to top, #fff, var(--fx) 30%, transparent);
  box-shadow: 0 0 22px 8px var(--fx);
}
.fx-spark {
  border-radius: 50%;
  background: var(--fx);
  box-shadow: 0 0 8px 3px var(--fx);
}
.eob-link:disabled { opacity: 0.5; cursor: default; }

/* Kids mode: the DM's roll request, one big button mid-screen. */
.roll-request {
  position: fixed;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  z-index: 60;
  max-width: min(28rem, calc(100vw - 2rem));
  padding: 1.25rem 1.5rem;
  border-radius: 1rem;
  border: 3px solid #f5c542;
  background: color-mix(in oklab, var(--color-base-100, #1d1d1d) 92%, transparent);
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.5);
  text-align: center;
  animation: roll-request-pop 0.35s ease-out;
}
.roll-request-ask { font-size: 1.35rem; font-weight: 700; }
.roll-request-need { font-size: 1.1rem; margin-top: 0.35rem; opacity: 0.9; }
.roll-request-buttons { display: flex; gap: 0.75rem; justify-content: center; margin-top: 1rem; flex-wrap: wrap; }
@keyframes roll-request-pop { from { transform: translate(-50%, -50%) scale(0.8); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .roll-request { animation: none; } }
.request-roll { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin: 0.4rem 0; font-size: 0.8rem; }
.request-roll-dc { width: 3.5rem; }
.request-roll-waiting { opacity: 0.75; font-style: italic; }
.party-hud-stars { font-size: 0.75rem; line-height: 1; text-align: center; }
.party-hud-ko { font-size: 0.7rem; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 0.2rem; }
.kids-party-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin: -0.25rem 0 0.75rem 1.5rem; }
.table-safety { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; align-items: center; margin-bottom: 0.75rem; }
.party-hud-kick { position: absolute; top: 2px; right: 2px; border: 0; font-size: 0.7rem; line-height: 1; padding: 2px; border-radius: 4px; background: rgb(0 0 0 / 0.55); opacity: 0; transition: opacity 0.15s; }
.party-hud-box:hover .party-hud-kick, .party-hud-kick:focus-visible { opacity: 1; }
@media (pointer: coarse) { .party-hud-kick { opacity: 0.8; } }
/* A stat's plain-words meaning: a little popup on hover / tap. */
.eob-row[data-hint] { position: relative; cursor: help; }
.eob-row[data-hint]:hover::after,
.eob-row[data-hint]:focus-visible::after,
.eob-row[data-hint]:focus::after {
  content: attr(data-hint);
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 5;
  padding: 4px 6px;
  font-size: 0.72rem;
  line-height: 1.25;
  color: #1f1a10;
  background: #f0e2b6;
  border: 1px solid #2a2a33;
  border-radius: 4px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.eob-row[data-hint]:focus { outline: none; }
.hero-blurb { font-size: 1rem; line-height: 1.35; margin: 0.5rem 0 0.75rem; }
.hero-title label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; }

/* Kids mode: the turn panel, everything you can do as big buttons. */
.kids-turn-panel {
  position: fixed;
  left: 50%;
  top: 4.25rem;
  transform: translateX(-50%);
  z-index: 45;
  width: max-content;
  max-width: calc(100vw - 2rem);
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  border: 2px solid #f5c542;
  background: color-mix(in oklab, var(--color-base-100, #1d1d1d) 90%, transparent);
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.45);
  text-align: center;
}
.ktp-title { font-size: 1.15rem; font-weight: 700; }
.ktp-walk, .ktp-hint { font-size: 0.9rem; opacity: 0.85; margin-top: 0.25rem; }
.ktp-buttons { display: flex; flex-wrap: wrap; gap: 0.6rem; justify-content: center; margin-top: 0.6rem; }
.ktp-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 5.5rem;
  min-height: 4.5rem;
  padding: 0.4rem 0.6rem;
  border-radius: 0.75rem;
  border: 2px solid color-mix(in oklab, currentColor 30%, transparent);
  background: color-mix(in oklab, var(--color-base-200, #2a2a2a) 90%, transparent);
  font-weight: 700;
  cursor: pointer;
}
.ktp-btn > span { font-size: 1.6rem; line-height: 1.1; }
.ktp-btn small { font-weight: 400; font-size: 0.7rem; opacity: 0.75; }
.ktp-btn:hover:not(:disabled) { border-color: #f5c542; }
.ktp-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ktp-done { border-color: #5fbf4a; }
.ktp-magic .spell-menu { position: absolute; inset: 0; }
.ktp-magic .spell-menu > summary { position: absolute; inset: 0; opacity: 0; }
/* The turn panel sits at the top: its spell list opens downward. */
.ktp-magic .spell-list { bottom: auto; top: calc(100% + 6px); text-align: left; }
/* Kids mode celebrations (celebrate.js). */
.celebrate-layer { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.celebrate-layer i { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: confetti-fall linear forwards; }
@keyframes confetti-fall { to { transform: translate(var(--drift), 105vh) rotate(720deg); } }
.celebrate-word { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); font-size: clamp(3rem, 10vw, 6rem); font-weight: 800; color: #f5c542; text-shadow: 0 4px 18px rgb(0 0 0 / 0.6); animation: celebrate-pop 2.6s ease-out forwards; }
@keyframes celebrate-pop { 0% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; } 15% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; } 75% { opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1); opacity: 0; } }

/* Tablets and phones (touch): nothing hides behind hover, and fingers get
   bigger targets. */
@media (pointer: coarse) {
  .party-hud-dock .party-hud-tray { visibility: visible; }
  .eob-spells .spell-desc { display: block; }
  .eob-slot-x { opacity: 1; }
  .quickbar-btn { width: 46px; height: 46px; }
  .token-hand { min-width: 40px; min-height: 40px; }
  .dice-chip, .dice-plain .dice-roll-btn { min-height: 44px; }
  .tabletop-layout .btn-xs { min-height: 36px; padding-inline: 0.6rem; }
  .eob-link { padding: 6px 8px; }
  .roll-request .btn-lg { min-height: 3.5rem; font-size: 1.25rem; }
}
/* The party's start point (DM only). */
.start-point { position: absolute; z-index: 3; transform: translate(-50%, -100%); font-size: 48px; line-height: 1; pointer-events: none; filter: drop-shadow(0 2px 3px rgb(0 0 0 / 0.6)); }
.map-panel:has(.map-controls.tool-start) .map-surface,
.map-panel:has(.map-controls.tool-start) .map-surface * { cursor: crosshair; }

/* The printable hero card: hidden on screen, the only thing on paper. */
.hero-print { display: none; }
@media print {
  body * { visibility: hidden !important; }
  body { background: #fff !important; }
  .hero-print, .hero-print * { visibility: visible !important; }
  .hero-print {
    display: block; position: absolute; inset: 0; padding: 12mm;
    color: #111; background: #fff; font: 12pt/1.4 Georgia, serif;
  }
  .hero-print header { display: flex; gap: 8mm; align-items: center; }
  .hero-print header img { width: 38mm; height: 48mm; object-fit: cover; border: 1mm solid #333; border-radius: 3mm; }
  .hero-print h1 { font-size: 26pt; margin: 0; }
  .hero-print h2 { font-size: 14pt; margin: 6mm 0 2mm; border-bottom: 0.4mm solid #999; }
  .hero-print-blurb { font-style: italic; }
  .hero-print-big { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5mm; margin-top: 6mm; text-align: center; }
  .hero-print-big div { border: 0.6mm solid #333; border-radius: 4mm; padding: 3mm; font-size: 10pt; display: flex; flex-direction: column; align-items: center; }
  .hero-print-big span { font-size: 18pt; }
  .hero-print-big strong { font-size: 28pt; line-height: 1.1; }
  .hero-print ul { margin: 0; padding-left: 5mm; }
  .hero-print table { width: 100%; border-collapse: collapse; }
  .hero-print th, .hero-print td { text-align: left; padding: 1mm 2mm; border-bottom: 0.2mm solid #ddd; font-size: 11pt; }
  .hero-print-stars { margin-top: 6mm; font-size: 16pt; }
  .hero-print-lines { height: 30mm; background: repeating-linear-gradient(#fff 0 7mm, #bbb 7mm 7.3mm); }
}
@media print {
  .hero-print h1, .hero-print h2 { color: #111 !important; text-shadow: none !important; }
  .hero-print { padding: 8mm 12mm; font-size: 11pt; }
  .hero-print h2 { margin: 4mm 0 1.5mm; }
  .hero-print-big { margin-top: 4mm; }
  .hero-print-lines { height: 22mm; }
  @page { margin: 8mm; }
}
/* Players' dice colours. */
.dice-colors { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 6px 0; font-size: 0.75rem; }
.dice-color { width: 20px; height: 20px; border-radius: 50%; border: 2px solid rgb(0 0 0 / 0.4); cursor: pointer; }
.dice-color-on { outline: 2px solid currentColor; outline-offset: 2px; }
@media (pointer: coarse) { .dice-color { width: 30px; height: 30px; } }
/* Encounter builder (DM creature library). */
.creature-leaf-add { padding: 0 5px; margin-left: 2px; border-radius: 4px; opacity: 0.55; font-weight: 700; }
.creature-leaves li:hover .creature-leaf-add, .creature-leaf-add:focus-visible { opacity: 1; }
.encounter { border: 1px solid color-mix(in oklab, currentColor 25%, transparent); border-radius: 8px; padding: 6px 8px; margin-bottom: 8px; font-size: 0.8rem; }
.encounter-head { display: flex; justify-content: space-between; align-items: center; }
.encounter ul { margin: 4px 0; }
.encounter li button { padding: 0 6px; border-radius: 4px; margin-right: 4px; }
.encounter li small { opacity: 0.6; margin-left: 4px; }
.encounter-xp { font-size: 0.7rem; opacity: 0.75; margin: 2px 0; }
.encounter-rating { font-weight: 700; padding: 1px 8px; border-radius: 999px; color: #111; }
.encounter-trivial { background: #9a9aa6; }
.encounter-easy { background: #6fd17a; }
.encounter-medium { background: #f5c542; }
.encounter-hard { background: #f2883a; }
.encounter-deadly { background: #e5533d; color: #fff; }
@media (pointer: coarse) { .creature-leaf-add { opacity: 1; padding: 4px 10px; } }
/* Kids mode: where your hero can walk this turn. */
.walk-range {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  border: 3px dashed #5dff7a;
  border-radius: 6px;
  background-color: rgb(93 255 122 / 0.12);
  background-image: linear-gradient(rgb(93 255 122 / 0.35) 1px, transparent 1px), linear-gradient(90deg, rgb(93 255 122 / 0.35) 1px, transparent 1px);
  animation: walk-glow 2.4s ease-in-out infinite;
}
@keyframes walk-glow { 50% { background-color: rgb(93 255 122 / 0.22); } }
.walk-range-pulse { animation: walk-pulse 0.5s ease-out 3, walk-glow 2.4s ease-in-out 1.5s infinite; }
@keyframes walk-pulse { 50% { background-color: rgb(93 255 122 / 0.5); box-shadow: 0 0 30px #5dff7a; } }
@media (prefers-reduced-motion: reduce) { .walk-range, .walk-range-pulse { animation: none; } }
.ktp-walk-btn { border-color: #5dff7a; }
/* Walls and doors. */
.map-walls { position: absolute; inset: 0; overflow: visible; pointer-events: none; z-index: 2; }
.map-wall { stroke: #ff4d4d; stroke-width: 6; stroke-linecap: round; opacity: 0.85; }
.map-door { stroke: #b0743c; stroke-width: 9; }
.map-door-open { stroke: #6fd17a; stroke-dasharray: 10 8; }
.map-door-btn { position: absolute; z-index: 4; transform: translate(-50%, -50%); font-size: 22px; line-height: 1; padding: 3px; border-radius: 8px; background: rgb(60 35 15 / 0.85); border: 2px solid #b0743c; cursor: pointer; }
.map-door-btn-open { background: rgb(20 60 25 / 0.85); border-color: #6fd17a; opacity: 0.8; }
.map-panel:has(.map-controls:is(.tool-wall, .tool-door)) .map-surface,
.map-panel:has(.map-controls:is(.tool-wall, .tool-door)) .map-surface * { cursor: crosshair; }
/* Line of sight: what the hero can't see is dark. */
.map-sight { position: absolute; inset: 0; overflow: visible; pointer-events: none; z-index: 3; }
.map-sight path { fill: rgb(8 8 14 / 0.88); }

/* Aiming a weapon attack: a sword pointer everywhere until it's done. */
body[data-aim="attack"],
body[data-aim="attack"] * {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cg stroke='%23111' stroke-width='1.5' stroke-linejoin='round'%3E%3Cpath d='M3 3 L8 3 L22 17 L17 22 L3 8 Z' fill='%23e5e7eb'/%3E%3Cpath d='M15 24 L24 15 L26 17 L17 26 Z' fill='%23b45309'/%3E%3Cpath d='M21 23 L23 21 L29 27 L27 29 Z' fill='%2378350f'/%3E%3C/g%3E%3C/svg%3E") 3 3, crosshair !important;
}

/* Right-click on another hero: choices in a ring around the pointer. */
.token-menu {
  position: fixed;
  z-index: 60;
  width: 0;
  height: 0;
}
.token-menu-item {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  color: #f0e2b6;
  background: #4b4b57;
  border: 3px solid;
  border-color: #9a9aa6 #2a2a33 #2a2a33 #9a9aa6;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.55);
  cursor: pointer;
  animation: token-menu-in 0.15s ease-out;
}
.token-menu-item span { font-size: 10px; margin-top: 3px; font-family: "Libre Baskerville", Georgia, serif; }
.token-menu-item:hover:not(:disabled), .token-menu-item:focus-visible { background: #5d5d6b; outline: 2px solid #ffcc33; }
.token-menu-item:disabled { opacity: 0.45; cursor: not-allowed; }
.token-menu-n { transform: translate(0, -70px); }
.token-menu-e { transform: translate(70px, 0); }
.token-menu-center { width: 34px; height: 34px; margin: -17px 0 0 -17px; font-size: 14px; }
.token-menu-name {
  position: absolute;
  transform: translate(-50%, 34px);
  white-space: nowrap;
  padding: 2px 8px;
  font-size: 12px;
  color: #1f1a10;
  background: #f0e2b6;
  border-radius: 4px;
}
@keyframes token-menu-in { from { opacity: 0; scale: 0.6; } }
@media (prefers-reduced-motion: reduce) { .token-menu-item { animation: none; } }

/* The trade window: what you give on the left, what they give on the right. */
.trade-panel { right: auto; left: 12px; width: 360px; z-index: 40; }
.trade-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0; }
.trade-col { min-width: 0; }
.trade-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px;
  margin-bottom: 2px;
  border-radius: 3px;
  color: var(--eob-ink);
  font-size: 11px;
  font-family: inherit;
  background: rgba(0, 0, 0, 0.22);
  cursor: pointer;
}
.trade-item > span:first-child { flex: 1; min-width: 0; }
.trade-item-on { color: #ffe9a8; background: rgba(120, 90, 10, 0.55); outline: 1px solid rgba(255, 204, 51, 0.7); }
.trade-item input[type="number"] { width: 44px; color: #1f1a10; background: #f0e2b6; border-radius: 3px; padding: 0 2px; }
.trade-of { opacity: 0.7; }
.trade-empty { opacity: 0.7; font-style: italic; }
.trade-status { margin-top: 6px; opacity: 0.8; }
.trade-status-ok { color: #86efac; opacity: 1; }
.trade-actions { display: flex; gap: 6px; justify-content: flex-end; }
@media (max-width: 480px) { .trade-panel { left: 8px; right: 8px; width: auto; } }

/* The paper doll: a body with a slot for each kind of gear (EOB style). */
.paperdoll {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-areas:
    "head  .    neck"
    "main  body off"
    "ring1  .    ring2"
    "quiver feet .";
  gap: 4px;
  padding: 6px;
  margin-bottom: 6px;
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid;
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
}
.paperdoll-figure {
  grid-column: 2;
  grid-row: 1 / -1;
  align-self: stretch;
  opacity: 0.22;
  background: no-repeat center / contain
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 120'%3E%3Cg fill='%23f0e2b6'%3E%3Ccircle cx='30' cy='12' r='9'/%3E%3Cpath d='M18 24h24l6 34-6 2-4-22v28l4 48h-9l-3-40-3 40h-9l4-48V38l-4 22-6-2z'/%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
}
.doll-slot {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 2px;
  text-align: center;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid;
  border-color: var(--eob-lo) var(--eob-hi) var(--eob-hi) var(--eob-lo);
}
.doll-head { grid-area: head; }
.doll-neck { grid-area: neck; }
.doll-main { grid-area: main; }
.doll-body { grid-area: body; }
.doll-off { grid-area: off; }
.doll-ring1 { grid-area: ring1; }
.doll-ring2 { grid-area: ring2; }
.doll-feet { grid-area: feet; }
.doll-quiver { grid-area: quiver; }
.doll-slot-item { position: relative; }
/* An arrow in flight: sized by font-size (set from the grid) in em. */
.fx-arrow {
  position: absolute;
  height: 1em;
  transform-origin: 100% 50%;
  background: linear-gradient(90deg, #8a6a3a 0 75%, #d8d8d8 75% 100%);
  border-radius: 0.5em;
  box-shadow: 0 0 0.6em rgba(0, 0, 0, 0.6);
  pointer-events: none;
  z-index: 6;
}
.fx-arrow::before {
  content: "";
  position: absolute;
  left: -0.4em;
  top: -0.9em;
  width: 2.2em;
  height: 2.8em;
  background: linear-gradient(90deg, #f3eee0, #c0392b);
  clip-path: polygon(0 0, 100% 38%, 100% 62%, 0 100%);
}
.fx-arrow::after {
  content: "";
  position: absolute;
  right: -2.2em;
  top: -1.1em;
  border-left: 2.4em solid #e6e6e6;
  border-top: 1.6em solid transparent;
  border-bottom: 1.6em solid transparent;
}
.doll-slot-full { background: rgba(120, 90, 10, 0.35); }
.doll-slot-both { opacity: 0.55; }
.doll-slot-over { outline: 2px solid #ffcc33; background: rgba(255, 204, 51, 0.25); }
.doll-slot-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}
button.doll-slot-item:hover { color: #ffe9a8; }
.doll-slot-icon, .doll-slot-empty-icon { font-size: 16px; line-height: 1.1; }
.doll-slot-empty-icon { opacity: 0.35; }
.doll-slot-name { font-size: 9px; line-height: 1.1; }
.doll-slot-label { font-size: 8px; opacity: 0.5; text-transform: uppercase; letter-spacing: 0.04em; }
[data-pack].doll-slot-over { outline: 2px dashed #ffcc33; }
.eob-slot-act[draggable="true"] { cursor: grab; }

/* The DM's bag: in the Items menu, and under an inventory to give from. */
.dm-bag-row, .dm-bag-entry {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px;
  margin-bottom: 2px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.12);
}
.dm-bag-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-bag-give { margin-top: 6px; }
.dm-bag-entry { background: rgba(0, 0, 0, 0.25); cursor: grab; }
.dm-bag-entry .btn { min-height: 1.25rem; height: 1.25rem; padding: 0 6px; font-size: 10px; }
.dm-bag-qty { opacity: 0.8; }
.dm-bag-empty { opacity: 0.7; font-style: italic; }
.doll-slot-item .eob-slot-qty { position: absolute; top: -2px; right: 0; bottom: auto; left: auto; font-size: 9px; line-height: 1; }

/* Kids mode, while walking: a way back to the turn's choices. */
.kids-back {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  padding: 8px 18px;
  font-size: 16px;
  font-weight: 700;
  color: #1f1a10;
  background: #ffd76a;
  border: 3px solid #8a6a1a;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

/* The DM's own journal entries (read-aloud, tips, notes): marked, never shown to players. */
.journal-dm { border-left: 3px solid #b8860b; background: rgba(184, 134, 11, 0.08); }
.journal-dm-only { display: flex; align-items: center; gap: 6px; font-size: 11px; margin: 4px 0; }

/* Item pictures (game-icons.net, parchment on transparent). */
.item-art { display: inline-block; width: 1.25em; height: 1.25em; vertical-align: middle; object-fit: contain; pointer-events: none; }
.eob-slot .item-art { width: 26px; height: 26px; }
.doll-slot .item-art { width: 22px; height: 22px; }
.doll-slot-both .item-art { opacity: 0.6; }
.token-hand .item-art, .party-hud-hand .item-art { width: 20px; height: 20px; }
.dm-bag-row .item-art, .dm-bag-entry .item-art, .creature-leaves .item-art { width: 16px; height: 16px; }
/* On light panels the parchment icons need a dark outline to show. */
[data-theme="light"] .item-art { filter: drop-shadow(0 0 1px #2a2a33) drop-shadow(0 0 1px #2a2a33); }

/* After a hero's first turn the box is gone (it took too much room). */
.kids-turn.ktp-quiet .kids-turn-panel { display: none; }

/* Touch: a long press on a token opens its menu, not the browser's
   copy/save callout or a text selection. */
@media (pointer: coarse) {
  .token, .token * { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
}

/* Touch: the picked piece of gear, and the body slots (and pack) lit up
   to say "tap where it goes". */
.doll-picked { outline: 2px solid #ffcc33; outline-offset: 1px; background: rgba(255, 204, 51, 0.25) !important; }
.doll-picking .doll-slot,
.doll-picking [data-pack] { outline: 2px dashed rgba(255, 204, 51, 0.7); outline-offset: -2px; }

/* Touch: no hover to slide the audio controls out, so they stay out. */
@media (pointer: coarse) {
  .media-quick:not(:hover):not(:focus-within):not(:has(.is-muted)) { transform: none; opacity: 1; }
}

/* Touch on the map is ours (one finger pans or drags a token, two pinch
   to zoom): the browser mustn't scroll or zoom the page instead. */
.map-panel { touch-action: none; }

/* ==== Players' framed table (Baldur's Gate 2 / Eye of the Beholder) ====
   The map sits inside a stone frame: the party in a column on the right,
   the quick bar and the sound controls along the bottom. Nothing of the
   HUD covers the map any more. */
.framed {
  --frame-right: 58px;
  --frame-bottom: 62px;
}
.framed .tabletop-main {
  padding: 0 var(--frame-right) var(--frame-bottom) 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.06), transparent 40%),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.08) 0 2px, transparent 2px 5px),
    #3c3c46;
}
.framed .map-panel {
  border: 3px solid;
  border-color: #2a2a33 #9a9aa6 #9a9aa6 #2a2a33;
  border-radius: 0;
}

/* Right column: the party, portraits and hit points, always shown. */
.framed .party-hud-dock {
  top: 0;
  right: 0;
  bottom: var(--frame-bottom);
  left: auto;
  width: var(--frame-right);
  display: block;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
}
.framed .party-hud-hotzone,
.framed .hud-pin { display: none; }
.framed .party-hud-dock .party-hud-tray,
.framed .party-hud-dock:not(:has(.hud-pin input:checked)):not(:hover) .party-hud-tray {
  visibility: visible;
  flex-direction: column;
  align-items: center;
  max-width: none;
  padding: 6px 0;
}
.framed .party-hud-dock .party-hud {
  flex-direction: column;
  flex-wrap: nowrap;
  overflow: visible;
  gap: 6px;
  padding: 0;
  background: none;
  border: 0;
  box-shadow: none;
}
.framed .party-hud-dock .party-hud-box { width: 50px; padding: 2px; }
.framed .party-hud-dock .party-hud-portrait-wrap,
.framed .party-hud-dock .party-hud-portrait { width: 44px; height: 44px; }
/* Just the hit points as a number: no name, no bar (the portrait says who). */
.framed .party-hud-dock .party-hud-name,
.framed .party-hud-dock .party-hud-hp-bar { display: none; }
.framed .party-hud-dock .party-hud-hp { margin-top: 2px; }
.framed .party-hud-dock .party-hud-name {
  font-size: 10px;
  max-width: 66px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.framed .party-hud-dock .party-hud-hp-text { font-size: 12px; font-weight: 700; }
/* The quick bar has the actions: no hands in the column. */
.framed .party-hud-dock .party-hud-hands,
.framed .party-hud-dock .party-hud-last-roll { display: none; }
/* Knocked out: just the 💤 and the Help up button fit the column. */
.framed .party-hud-dock .party-hud-ko { font-size: 0; line-height: 1; }
.framed .party-hud-dock .party-hud-ko::before { content: "💤"; font-size: 16px; }
.framed .party-hud-dock .party-hud-ko .btn { font-size: 10px; margin-top: 2px; }

/* Bottom strip: quick bar on the left, sound and voice on the right. */
.framed .quickbar {
  left: 12px;
  right: auto;
  bottom: 10px;
}
.framed .media-quick,
.framed .media-quick:not(:hover):not(:focus-within):not(:has(.is-muted)) {
  right: calc(var(--frame-right) + 8px);
  bottom: 0;
  padding-bottom: 10px;
  transform: none;
  opacity: 1;
}

/* Floating things move off the frame. */
.framed .chat-box { bottom: calc(var(--frame-bottom) + 10px); }
.framed .eob-panel:not(.trade-panel) { right: calc(var(--frame-right) + 12px); }
.framed .token-card { right: calc(var(--frame-right) + 12px); }

@media (max-width: 640px) {
  .framed { --frame-right: 50px; }
  .framed .party-hud-dock .party-hud-box { width: 44px; }
  .framed .party-hud-dock .party-hud-portrait-wrap,
  .framed .party-hud-dock .party-hud-portrait { width: 38px; height: 38px; }
}
.framed .party-hud-dock .party-hud-hp-text { color: #f0e2b6; }
.party-hud-own { cursor: pointer; }

/* Framed table: under your own portrait, just your spellbook (casters);
   the list opens to the left of the column. */
.framed .party-hud-dock { overflow: visible; }
.framed .party-hud-dock .party-hud-self .party-hud-hands { display: flex; justify-content: center; }
.framed .party-hud-dock .party-hud-self .party-hud-hands .token-hands { display: none; }
.framed .party-hud-dock .spell-list {
  bottom: auto;
  top: 0;
  left: auto;
  right: calc(100% + 8px);
  translate: none;
}

/* Spell pictures (game-icons.net, each in its spell's colour). */
.spell-art { display: inline-block; width: 1.3em; height: 1.3em; vertical-align: middle; object-fit: contain; pointer-events: none; filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.8)); }
.quickbar-btn .spell-art { width: 26px; height: 26px; }
.spell-menu > summary .spell-art { width: 20px; height: 20px; }
.spell-btn .spell-art { width: 18px; height: 18px; margin-right: 2px; }

/* Spell effects with particle textures (Kenney, CC0): a white texture,
   tinted by the background colour through a luminance mask, added onto
   the map with a glow. */
.fx-sprite {
  -webkit-mask-image: var(--tex);
  mask-image: var(--tex);
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  mask-mode: luminance;
  -webkit-mask-source-type: luminance;
  /* Additive light: bright on any map. */
  mix-blend-mode: plus-lighter;
  pointer-events: none;
  z-index: 21;
}

/* Quick bar pictures: weapons and potions (items), spells, rolls. */
.ui-art { display: inline-block; width: 1.3em; height: 1.3em; vertical-align: middle; object-fit: contain; pointer-events: none; }
.quickbar-btn .item-art, .quickbar-btn .ui-art { width: 26px; height: 26px; }
.quickbar-roll .ui-art { width: 22px; height: 22px; }
.quickbar-save { position: absolute; left: 2px; bottom: 2px; }
.quickbar-save .ui-art { width: 12px; height: 12px; }
.quickbar-btn:disabled .item-art, .quickbar-btn:disabled .ui-art, .quickbar-btn:disabled .spell-art { opacity: 0.45; }
/* The DM's creature bar (playing a creature) sits in the bottom strip,
   between the quick bar and the sound controls. */
.framed .possess-bar { right: auto; left: 50%; transform: translateX(-50%); bottom: 10px; }

/* The frame is rock, like Eye of the Beholder 2: grey stone blocks with
   light and dark bevels and a little grain, drawn in SVG (no image file). */
.framed {
  --stone: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='128' height='64'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.45 0'/%3E%3C/filter%3E%3Crect width='128' height='64' fill='%231f1f24'/%3E%3Crect x='1' y='1' width='62' height='30' fill='%235d5d66'/%3E%3Cpath d='M1 31V1H63' stroke='%238d8d97' stroke-width='2' fill='none'/%3E%3Cpath d='M1 31H63V1' stroke='%232b2b31' stroke-width='2' fill='none'/%3E%3Crect x='65' y='1' width='62' height='30' fill='%235d5d66'/%3E%3Cpath d='M65 31V1H127' stroke='%238d8d97' stroke-width='2' fill='none'/%3E%3Cpath d='M65 31H127V1' stroke='%232b2b31' stroke-width='2' fill='none'/%3E%3Crect x='-31' y='33' width='62' height='30' fill='%235d5d66'/%3E%3Cpath d='M-31 63V33H31' stroke='%238d8d97' stroke-width='2' fill='none'/%3E%3Cpath d='M-31 63H31V33' stroke='%232b2b31' stroke-width='2' fill='none'/%3E%3Crect x='33' y='33' width='62' height='30' fill='%235d5d66'/%3E%3Cpath d='M33 63V33H95' stroke='%238d8d97' stroke-width='2' fill='none'/%3E%3Cpath d='M33 63H95V33' stroke='%232b2b31' stroke-width='2' fill='none'/%3E%3Crect x='97' y='33' width='62' height='30' fill='%235d5d66'/%3E%3Cpath d='M97 63V33H159' stroke='%238d8d97' stroke-width='2' fill='none'/%3E%3Cpath d='M97 63H159V33' stroke='%232b2b31' stroke-width='2' fill='none'/%3E%3Crect width='128' height='64' filter='url(%23n)'/%3E%3C/svg%3E");
}
.framed .tabletop-main {
  background: var(--stone) 0 0 / 128px 64px, #3c3c46;
}
.framed .map-panel {
  border: 4px solid;
  border-color: #1a1a1f #8d8d97 #8d8d97 #1a1a1f;
  box-shadow: inset 0 0 0 1px #000, 0 0 0 2px #2b2b31;
}

/* The menu lives in the frame too, in a column on the left, always there
   (its panels open to the right over the map); the party stays on the
   right. Both side columns are the same width: the map sits centred in
   its stone frame. */
.framed { --frame-menu: 70px; --frame-right: 70px; }
.framed .tabletop-main { padding-left: var(--frame-menu); }
.tabletop-layout.immersive.framed .tabletop-menubar,
.tabletop-layout.immersive.framed .tabletop-menubar:hover {
  left: 0;
  right: auto;
  width: var(--frame-menu);
  bottom: var(--frame-bottom);
  transform: none;
  opacity: 1;
  background: var(--stone) 0 0 / 128px 64px, #3c3c46;
  border-right: 2px solid #1a1a1f;
  box-shadow: none;
}
.tabletop-layout.immersive.framed .tabletop-menubar .menubar-dropdown { pointer-events: auto; }
.tabletop-layout.immersive.framed .tabletop-menubar .menubar-dropdown:not(.menubar-dropdown-hidden) {
  left: 100%;
  right: auto;
  box-shadow: 6px 0 18px rgba(0, 0, 0, 0.45);
}
.framed .tabletop-menubar .menubar-btn { background: rgba(40, 40, 46, 0.85); color: #f0e2b6; }
/* Things floating over the map's left side clear the menu column. */
.framed .chat-box { left: calc(var(--frame-menu) + 12px); }
.framed .quickbar { left: 12px; }
.framed .trade-panel { left: calc(var(--frame-menu) + 12px); }
@media (max-width: 640px) { .framed { --frame-menu: 56px; --frame-right: 56px; } }
