:root {
  color-scheme: dark;
  --bg: #111313;
  --panel: #191c1d;
  --panel-2: #202525;
  --line: #313838;
  --text: #eef1ef;
  --muted: #9ba6a4;
  --accent: #b1c301;
  --accent-2: #7fb6a6;
  --danger: #d66a5f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  min-height: 36px;
  padding: 0 12px;
}

button:hover {
  border-color: #52605e;
}

.start-screen {
  align-items: center;
  background: #06021c;
  display: flex;
  inset: 0;
  justify-content: center;
  opacity: 1;
  position: fixed;
  transition: opacity 0.45s ease;
  z-index: 100;
}

.start-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.start-inner {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 32px;
  text-align: center;
}

.start-logo {
  animation: start-rise 0.7s ease 0.1s both;
  height: auto;
  max-width: min(560px, 80vw);
  width: 100%;
}

.start-logo .lodestar-star {
  animation: start-glow 4s ease-in-out 0.8s infinite;
  transform-box: fill-box;
  transform-origin: center;
}

.start-tagline {
  animation: start-rise 0.7s ease 0.35s both;
  color: var(--muted);
  font-size: 1rem;
  letter-spacing: 0.02em;
  margin: 0;
}

.start-actions {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.start-enter {
  animation: start-rise 0.7s ease 0.55s both;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 10px;
  color: #1b1508;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  min-height: 52px;
  padding: 0 48px;
}

.start-enter:hover {
  border-color: transparent;
  filter: brightness(1.08);
}

/* Animated ellipsis while the demo bundle downloads ("Loading", "Loading.", …). */
.start-enter.is-loading {
  cursor: progress;
}

.start-enter.is-loading::after {
  animation: loading-dots 1.2s steps(4, jump-none) infinite;
  content: "...";
  display: inline-block;
  overflow: hidden;
  text-align: left;
  vertical-align: bottom;
  white-space: nowrap;
  width: 0;
}

@keyframes loading-dots {
  to {
    width: 1.05em;
  }
}

/* Demo button + the hand-drawn "Try it now" arrow pointing at its top-left corner. */
.start-demo-wrap {
  display: inline-flex;
  position: relative;
}

.start-demo-wrap .start-enter {
  animation-delay: 0.7s;
}

.start-demo-arrow {
  height: auto;
  pointer-events: none;
  position: absolute;
  width: 240px;
  /* The arrowhead tip sits ~92% across / ~66% down the SVG, i.e. ~222px right / ~92px down
     at this width; offsetting by that lands the tip on the button's top-left corner.
     Nudge `left`/`top` to fine-tune. */
  left: -222px;
  top: -92px;
  animation: start-rise 0.7s ease 0.9s both;
}

.start-credit {
  animation: start-fade 0.9s ease 0.9s both;
  bottom: 24px;
  color: var(--muted);
  font-size: 0.82rem;
  left: 0;
  letter-spacing: 0.03em;
  margin: 0;
  opacity: 0.7;
  position: absolute;
  right: 0;
  text-align: center;
}

.start-credits-btn {
  animation: start-fade 0.9s ease 0.9s both;
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  bottom: 18px;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 8px 16px;
  position: absolute;
  right: 24px;
}

.start-credits-btn:hover {
  border-color: var(--accent-2);
  color: var(--text);
}

@keyframes start-rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes start-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 0.7;
  }
}

@keyframes start-glow {
  0%,
  100% {
    filter: drop-shadow(0 0 2px rgba(177, 195, 1, 0.35));
  }
  50% {
    filter: drop-shadow(0 0 14px rgba(210, 230, 60, 1))
      drop-shadow(0 0 30px rgba(197, 215, 40, 0.85))
      drop-shadow(0 0 48px rgba(177, 195, 1, 0.55));
  }
}

.app-shell {
  display: grid;
  /* Three columns always: left controls, stage, right panels. The right track is 0 when no
     panel is active (or it's retracted), and the left track is 0 when collapsed, so panels
     animate open/shut by transitioning the track widths. Left and right tracks match width. */
  grid-template-columns: 300px minmax(0, 1fr) 0px;
  height: 100vh;
  transition: grid-template-columns 0.28s ease;
  width: 100vw;
}

.app-shell.has-initiative,
.app-shell.has-music {
  grid-template-columns: 300px minmax(0, 1fr) 300px;
}

.app-shell.panel-collapsed {
  grid-template-columns: 0px minmax(0, 1fr) 0px;
}

.app-shell.panel-collapsed.has-initiative,
.app-shell.panel-collapsed.has-music {
  grid-template-columns: 0px minmax(0, 1fr) 300px;
}

/* The right retract tab collapses the entire right column (music + initiative together),
   regardless of which panel is active. */
.app-shell.right-collapsed.has-initiative,
.app-shell.right-collapsed.has-music {
  grid-template-columns: 300px minmax(0, 1fr) 0px;
}

.app-shell.right-collapsed.panel-collapsed.has-initiative,
.app-shell.right-collapsed.panel-collapsed.has-music {
  grid-template-columns: 0px minmax(0, 1fr) 0px;
}

.app-shell[data-role="player"] {
  display: block;
  cursor: none;
}

.app-shell[data-role="player"].cursor-active {
  cursor: default;
}

.app-shell[data-role="player"] .gm-panel {
  display: none;
}

.app-shell[data-role="player"] .stage-controls {
  display: none;
}

.app-shell[data-role="player"] .stage-wrap {
  height: 100vh;
}

.gm-panel {
  background: #06021c;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 22px;
}

.brand {
  align-items: center;
  display: flex;
  justify-content: center;
}

.brand-logo {
  display: block;
  height: auto;
  max-width: 220px;
  width: 100%;
}

.eyebrow,
.hint {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
  margin: 0;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 1.65rem;
  font-weight: 700;
}

h2 {
  font-size: 0.95rem;
  font-weight: 650;
}

.status {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent-2);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 5px 9px;
}

.control-section {
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 18px;
}

/* Sections made collapsible carry their own spacing inside .section-body. */
.control-section:has(.section-body) {
  gap: 0;
}

.section-title {
  align-items: center;
  display: flex;
  gap: 10px;
}

.section-title h2 {
  flex: 1;
  margin: 0;
}

/* Collapsible body: animate grid rows from 1fr to 0fr for a smooth slide. */
.section-toggle {
  align-items: center;
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  justify-content: center;
  min-height: 0;
  padding: 0;
  transition: transform 0.25s ease;
  width: 20px;
}

.section-toggle:hover {
  background: none;
  border: 0;
  color: var(--text);
}

.section-toggle svg {
  fill: none;
  height: 18px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 18px;
}

.control-section.collapsed .section-toggle {
  transform: rotate(-90deg);
}

.section-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.3s ease;
}

.control-section.collapsed .section-body {
  grid-template-rows: 0fr;
}

.section-body-inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
  min-height: 0;
  overflow: hidden;
}

.control-section.collapsed .section-body-inner {
  margin-top: 0;
}

label {
  color: var(--muted);
  display: grid;
  gap: 7px;
  font-size: 0.83rem;
}

input[type="range"] {
  accent-color: var(--accent);
  width: 100%;
}

input[type="color"] {
  background: transparent;
  border: 0;
  height: 34px;
  padding: 0;
  width: 100%;
}

.file-loader input {
  display: none;
}

.file-loader span,
.primary-button,
.library-button {
  align-items: center;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 6px;
  color: #1b1508;
  cursor: pointer;
  display: flex;
  font-weight: 750;
  justify-content: center;
  min-height: 42px;
  padding: 0 12px;
}

.library-button.empty {
  background: #3a3f3f;
  border-color: #4a5151;
  color: #9aa3a1;
  cursor: default;
}

/* Top GM actions: four icon buttons in a 2x2 grid. */
.top-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.top-action {
  align-items: center;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 8px;
  color: #1b1508;
  cursor: pointer;
  display: flex;
  justify-content: center;
  min-height: 52px;
  padding: 0;
}

.top-action:hover:not(:disabled) {
  filter: brightness(1.08);
}

.top-action svg {
  fill: none;
  height: 24px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
  width: 24px;
}

.top-action.empty,
.top-action:disabled {
  background: #3a3f3f;
  border-color: #4a5151;
  color: #9aa3a1;
  cursor: default;
}

.secondary-loader span {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
}

.primary-button,
.library-button {
  width: 100%;
}

.ghost-button {
  min-height: 30px;
  padding: 0 10px;
}

.inline-fields {
  display: grid;
  gap: 12px;
  grid-template-columns: 74px minmax(0, 1fr);
}

.inline-buttons {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.inline-buttons button,
.inline-loader span {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 36px;
  width: 100%;
}

.inline-loader {
  cursor: pointer;
}

.inline-loader input {
  display: none;
}

.inline-loader span {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
}

.checkbox-row {
  align-items: center;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: row;
  gap: 8px;
}

.checkbox-row input {
  accent-color: var(--accent);
}

.switch input {
  display: none;
}

.switch.with-label {
  align-items: center;
  color: var(--text);
  display: inline-flex;
  font-size: 0.8rem;
  gap: 8px;
}

.switch span {
  background: #3a4241;
  border-radius: 999px;
  display: block;
  height: 24px;
  position: relative;
  width: 44px;
}

.switch span::after {
  background: white;
  border-radius: 50%;
  content: "";
  height: 18px;
  left: 3px;
  position: absolute;
  top: 3px;
  transition: transform 150ms ease;
  width: 18px;
}

.switch input:checked + span {
  background: var(--accent-2);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.segmented,
.fog-actions {
  display: grid;
  gap: 8px;
}

.segmented {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented:has(#brushMode),
.segmented:has(#roundShape) {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented button {
  padding: 0 7px;
}

.segmented .active {
  background: #263635;
  border-color: var(--accent-2);
  color: #c6fff1;
}

/* Segmented rows whose buttons are icons rather than text (e.g. the AoE shapes). */
.icon-segmented button {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 36px;
}

.icon-segmented svg {
  fill: none;
  height: 20px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 20px;
}

/* Controls disabled while players drive their own view. */
button:disabled,
input:disabled {
  cursor: default;
  opacity: 0.45;
}

.switch input:disabled + span {
  opacity: 0.45;
}

.fog-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.hidden {
  display: none !important;
}

.stage-wrap {
  background: #080909;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* A tab on the left edge of the stage that collapses/expands the GM control panel. */
.panel-toggle {
  align-items: center;
  background: rgba(25, 28, 29, 0.92);
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 8px 8px 0;
  color: var(--muted);
  display: flex;
  height: 46px;
  justify-content: center;
  left: 0;
  min-height: 0;
  padding: 0;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  z-index: 7;
}

.panel-toggle:hover {
  background: var(--panel-2);
  color: var(--text);
}

.panel-toggle svg {
  fill: none;
  height: 18px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  transition: transform 0.28s ease;
  width: 18px;
}

/* When the left panel is collapsed, flip the chevrons to point "open". */
.app-shell.panel-collapsed .panel-toggle:not(.panel-toggle-right) svg {
  transform: rotate(180deg);
}

/* Initiative panel retract tab: mirror of the left tab, on the right edge of the stage. */
.panel-toggle-right {
  border-left: 1px solid var(--line);
  border-radius: 8px 0 0 8px;
  border-right: 0;
  left: auto;
  right: 0;
}

/* Points "open" (left) while the right panels are closed or retracted; "closed" (right) when open. */
.app-shell.right-collapsed .panel-toggle-right svg,
.app-shell:not(.has-initiative):not(.has-music) .panel-toggle-right svg {
  transform: rotate(180deg);
}

.app-shell[data-role="player"] .panel-toggle {
  display: none;
}

.stage-controls {
  align-items: start;
  display: flex;
  flex-direction: column;
  gap: 10px;
  left: 30px;
  position: absolute;
  top: 14px;
  z-index: 6;
}

.mode-hint-bar {
  background: rgba(25, 28, 29, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  left: 50%;
  line-height: 1.35;
  margin: 0;
  max-width: calc(100% - 240px);
  padding: 7px 14px;
  position: absolute;
  text-align: center;
  top: 14px;
  transform: translateX(-50%);
  z-index: 6;
}

.app-shell[data-role="player"] .mode-hint-bar {
  display: none;
}

.tool-row {
  align-items: flex-start;
  display: flex;
  gap: 8px;
}

.map-tools {
  background: rgba(25, 28, 29, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr 1fr;
  padding: 7px;
  width: 96px;
}

/* Fog-of-war tools live in a ribbon that opens to the right of the toolbar. */
.fog-ribbon {
  background: rgba(25, 28, 29, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 6px;
  padding: 7px;
}

.fog-ribbon .tool-button {
  width: 38px;
}

.tool-button:disabled {
  cursor: default;
  opacity: 0.4;
}

.tool-button {
  align-items: center;
  aspect-ratio: 1;
  display: grid;
  justify-items: center;
  min-height: 0;
  padding: 0;
}

.tool-button svg {
  fill: none;
  height: 21px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 21px;
}

.tool-button.active {
  background: #263635;
  border-color: var(--accent-2);
  color: #c6fff1;
}

.player-toggles {
  background: rgba(25, 28, 29, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px;
  width: 96px;
}

.toggle-chip {
  align-items: center;
  color: var(--text);
  cursor: pointer;
  display: flex;
  font-size: 0.82rem;
  gap: 8px;
  padding: 3px 4px;
}

.toggle-chip input {
  accent-color: var(--accent);
}

.tool-popover {
  background: rgba(25, 28, 29, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  display: grid;
  gap: 12px;
  min-width: 230px;
  max-width: 260px;
  padding: 12px;
}

/* Keep long hint text from stretching the grid-auto-sized popover. */
.tool-popover .hint {
  max-width: 236px;
}

.tool-popover h2 {
  font-size: 0.9rem;
}

.tool-popover input[type="text"],
.tool-popover select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  min-height: 34px;
  padding: 0 10px;
}

#measureCalibrateRow {
  display: grid;
  gap: 8px;
}

/* A field (label/slider) paired with a small action button to its right. */
.field-with-action {
  align-items: end;
  display: flex;
  gap: 8px;
}

.field-with-action label {
  flex: 1;
}

.field-with-action .calib-label {
  color: var(--muted);
  flex: 1;
  font-size: 0.83rem;
}

.mini-btn {
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  flex: none;
  height: 34px;
  justify-content: center;
  min-height: 0;
  padding: 0;
  width: 34px;
}

.mini-btn:hover {
  border-color: #52605e;
}

.mini-btn svg {
  fill: none;
  height: 18px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 18px;
}

.mini-btn.active {
  background: #263635;
  border-color: var(--accent-2);
  color: #c6fff1;
}

.token-image-row {
  align-items: center;
  display: flex;
  gap: 8px;
}

.token-image-row .inline-loader {
  flex: 1;
}

.token-image-preview {
  border: 1px solid var(--line);
  border-radius: 50%;
  height: 36px;
  object-fit: cover;
  width: 36px;
}

.player-fullscreen {
  align-items: center;
  background: rgba(25, 28, 29, 0.6);
  border: 1px solid rgba(120, 130, 130, 0.4);
  border-radius: 8px;
  color: var(--text);
  display: none;
  height: 40px;
  justify-content: center;
  opacity: 0.35;
  position: absolute;
  right: 16px;
  top: 16px;
  transition: opacity 150ms ease;
  width: 40px;
  z-index: 7;
}

.player-fullscreen:hover {
  opacity: 1;
}

.player-fullscreen svg {
  fill: none;
  height: 20px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 20px;
}

.app-shell[data-role="player"] .player-fullscreen {
  display: flex;
  opacity: 0;
  pointer-events: none;
}

/* Reveal the fullscreen button alongside the cursor (on mouse movement). */
.app-shell[data-role="player"].cursor-active .player-fullscreen {
  opacity: 0.55;
  pointer-events: auto;
}

.app-shell[data-role="player"].cursor-active .player-fullscreen:hover {
  opacity: 1;
}

/* ---- Top-right stage widgets (initiative toggle + floor nav) ---- */
.stage-top-right {
  align-items: flex-end;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: absolute;
  right: 14px;
  top: 14px;
  z-index: 6;
}

.app-shell[data-role="player"] .stage-top-right {
  display: none;
}

.floor-widget {
  align-items: center;
  background: rgba(25, 28, 29, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 4px;
}

.floor-widget-btn {
  align-items: center;
  aspect-ratio: 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  display: flex;
  justify-content: center;
  min-height: 0;
  padding: 2px;
  width: 30px;
}

.floor-widget-btn:hover:not(:disabled) {
  border-color: var(--line);
  background: var(--panel-2);
}

.floor-widget-btn:disabled {
  cursor: default;
  opacity: 0.3;
}

.floor-widget-btn svg {
  fill: none;
  height: 18px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 18px;
}

.floor-widget-label {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0 2px;
  text-align: center;
  white-space: nowrap;
}

/* ---- Player floor badge ---- */
.player-floor-badge {
  background: rgba(6, 2, 28, 0.82);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  position: absolute;
  right: 14px;
  top: 14px;
  z-index: 6;
}

/* ---- Floor panel controls in sidebar ---- */
.floor-add-row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.floor-add-row .ghost-button {
  align-items: center;
  display: flex;
  gap: 6px;
  justify-content: center;
  padding: 0 8px;
}

.floor-add-row svg {
  fill: none;
  flex-shrink: 0;
  height: 16px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 16px;
}

.danger-button {
  background: transparent;
  border-color: rgba(214, 106, 95, 0.45);
  color: var(--danger);
}

.danger-button:hover:not(:disabled) {
  background: rgba(214, 106, 95, 0.1);
  border-color: var(--danger);
}

.danger-button:disabled {
  cursor: default;
  opacity: 0.35;
}

.hint-inline {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
}

.name-dialog select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  min-height: 38px;
  padding: 0 10px;
  width: 100%;
}

#floorName {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  min-height: 34px;
  padding: 0 10px;
  width: 100%;
}

#battlemap {
  display: block;
  height: 100%;
  width: 100%;
}

.empty-state {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 8px;
  inset: 0;
  justify-content: center;
  pointer-events: none;
  position: absolute;
  text-align: center;
}

.empty-state strong {
  color: var(--text);
  font-size: 1.1rem;
}

.empty-state.hidden {
  display: none;
}

.library-dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  max-width: 560px;
  padding: 0;
  width: min(92vw, 560px);
}

.library-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.name-dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 0;
  width: min(92vw, 360px);
}

.name-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.name-dialog form {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 18px;
}

.name-dialog h2 {
  font-size: 1rem;
}

.name-dialog input[type="text"] {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  min-height: 40px;
  padding: 0 12px;
  width: 100%;
}

.name-dialog-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
}

.name-dialog-actions .save-btn {
  background: var(--accent);
  border-color: transparent;
  color: #1b1508;
  font-weight: 750;
}

.library-dialog form {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 18px;
}

.dialog-head,
.saved-map-row {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.saved-map-list {
  display: grid;
  gap: 8px;
  max-height: 55vh;
  overflow-y: auto;
}

.saved-map-row {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.saved-map-row strong,
.saved-map-row span {
  display: block;
}

/* ----------------------------- shortcuts cheatsheet ----------------------------- */
.shortcuts-dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 0;
  width: min(94vw, 680px);
}

.shortcuts-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.shortcuts-dialog form {
  display: grid;
  gap: 16px;
  margin: 0;
  padding: 18px;
}

.shortcuts-grid {
  display: grid;
  gap: 18px 24px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.sc-group h3 {
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.sc-row {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 0.84rem;
  gap: 6px;
  min-height: 26px;
}

.sc-row span:last-child {
  margin-left: auto;
  text-align: right;
}

.sc-row kbd {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.72rem;
  line-height: 1;
  min-width: 18px;
  padding: 4px 6px;
  text-align: center;
}

.sc-mouse {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font-size: 0.72rem;
  padding: 3px 7px;
  white-space: nowrap;
}

/* ----------------------------- credits dialog ----------------------------- */
.credits-dialog {
  width: min(94vw, 560px);
}

.credits-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.credits-group h3 {
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  margin: 0 0 6px;
  text-transform: uppercase;
}

.credits-group p,
.credits-group ul {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
  margin: 0;
}

.credits-group ul {
  padding-left: 18px;
}

.credits-group li {
  margin: 3px 0;
}

.credits-group strong {
  color: var(--text);
  font-weight: 600;
}

.credits-group a {
  color: var(--accent);
  text-decoration: none;
}

.credits-group a:hover {
  text-decoration: underline;
}

.saved-map-row span {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 3px;
}

.saved-map-actions {
  display: flex;
  gap: 8px;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(280px, 45vh) 1fr;
  }

  .gm-panel {
    border-bottom: 1px solid var(--line);
    border-right: 0;
    order: 2;
    padding: 16px;
  }

  .stage-wrap {
    height: auto;
    min-height: 0;
    order: 1;
  }

  .app-shell.has-initiative,
  .app-shell.has-music {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(280px, 45vh) 1fr auto;
  }

  .right-panels {
    order: 3;
    flex-direction: column;
  }

  .app-shell.panel-collapsed .gm-panel {
    display: none;
  }

  .panel-toggle {
    display: none;
  }
}

/* ----------------------------- right panel column ----------------------------- */
.right-panels {
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* The player display never shows the GM's right panels. */
.app-shell[data-role="player"] .right-panels {
  display: none;
}

/* ----------------------------- initiative tracker ----------------------------- */
.initiative-panel {
  background: #06021c;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 12px;
  min-height: 0;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 22px;
  scrollbar-gutter: stable;
}

.app-shell:not(.has-initiative) .initiative-panel {
  display: none;
}

.init-head {
  align-items: center;
  display: flex;
  gap: 10px;
}

.init-head h2 {
  flex: 1;
  font-size: 1rem;
  margin: 0;
}

.init-round {
  align-items: center;
  display: flex;
  gap: 8px;
}

.init-round span {
  color: var(--accent);
  flex: 1;
  font-weight: 700;
  text-align: center;
}

.init-round button {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 34px;
  padding: 0 8px;
}

.init-round button svg {
  fill: none;
  height: 16px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 16px;
}

.init-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.init-row {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  padding: 8px;
}

.init-row.current {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.init-row-top {
  align-items: center;
  display: flex;
  gap: 8px;
}

.init-dot {
  border-radius: 50%;
  flex: none;
  height: 10px;
  width: 10px;
}

.init-dot.player {
  background: #6fb6f2;
}

.init-dot.npc {
  background: #c7b15a;
}

.init-dot.monster {
  background: #d66a5f;
}

.init-name {
  background: none;
  border: 0;
  color: var(--text);
  cursor: pointer;
  flex: 1;
  font-weight: 600;
  min-height: 0;
  overflow: hidden;
  padding: 2px 0;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.init-name:hover {
  background: none;
  border: 0;
  color: var(--accent);
}

.init-init {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--accent);
  font-weight: 700;
  min-height: 0;
  padding: 3px;
  text-align: center;
  width: 42px;
}

/* Locate/link button: ties a combatant to a map token. Dim when unlinked, accent when
   linked, and a pulsing accent while waiting for the token click. */
.init-link {
  align-items: center;
  background: none;
  border: 0;
  color: var(--muted);
  display: flex;
  flex-shrink: 0;
  justify-content: center;
  min-height: 0;
  padding: 0 2px;
}

.init-link svg {
  fill: none;
  height: 15px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 15px;
}

.init-link:hover {
  background: none;
  border: 0;
  color: var(--text);
}

.init-link.linked {
  color: var(--accent);
}

.init-link.linking {
  color: var(--accent);
  animation: init-link-pulse 1s ease-in-out infinite;
}

@keyframes init-link-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.init-remove {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  min-height: 0;
  padding: 0 4px;
}

.init-remove:hover {
  background: none;
  border: 0;
  color: var(--danger);
}

.init-conc {
  background: none;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  flex-shrink: 0;
  font-size: 0.78rem;
  font-weight: 700;
  min-height: 0;
  padding: 2px 6px;
}

.init-conc:hover {
  border-color: var(--accent);
  color: var(--text);
}

.init-conc.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1b1508;
}

.init-hp-line {
  align-items: center;
  display: flex;
  gap: 6px;
}

.init-hp-step {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  min-height: 0;
  padding: 2px 7px;
}

.init-hp-bar {
  background: rgba(214, 106, 95, 0.18);
  border-radius: 4px;
  flex: 1;
  height: 8px;
  overflow: hidden;
}

.init-hp-bar span {
  background: linear-gradient(90deg, #8bbf6a, #b1c301);
  display: block;
  height: 100%;
}

.init-hp-input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  min-height: 0;
  padding: 3px;
  text-align: center;
  width: 48px;
}

.init-hp-max {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.init-add {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding-top: 12px;
}

.init-add input,
.init-add select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  min-height: 36px;
  min-width: 0; /* let the grid columns shrink so the row never overflows the panel */
  padding: 0 10px;
  width: 100%;
}

.init-add-row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr 1.2fr;
}

.init-add button[type="submit"] {
  background: var(--accent);
  border-color: transparent;
  color: #1b1508;
  font-weight: 700;
}

/* ----------------------------- music panel ----------------------------- */
.music-panel {
  background: #06021c;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: 8px;
  max-height: 48vh;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px 14px;
}

.app-shell:not(.has-music) .music-panel {
  display: none;
}

.music-head {
  align-items: center;
  display: flex;
  gap: 8px;
}

.music-head h2 {
  flex: 1;
  font-size: 0.9rem;
  margin: 0;
}

/* Dimmed until a scene chip is selected, then lights up red so deletes are deliberate. */
.music-delete-scene {
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.74rem;
  min-height: 24px;
  padding: 0 10px;
}

.music-delete-scene:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.music-delete-scene:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
}

.music-delete-scene:not(:disabled):hover {
  background: color-mix(in srgb, var(--danger) 18%, transparent);
  border-color: var(--danger);
}

.music-scenes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.music-scene-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.music-scene-chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.8rem;
  min-height: 0;
  padding: 3px 10px;
  transition: border-color 0.15s, background 0.15s;
}

.music-scene-chip.active {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  border-color: var(--accent);
  color: var(--accent);
}

.music-scene-chip:hover:not(.active) {
  border-color: var(--muted);
}

.music-add-scene {
  background: none;
  border: 1px dashed var(--line);
  border-radius: 20px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 3px 10px;
}

.music-add-scene:hover {
  border-color: var(--muted);
  color: var(--text);
}

/* A bed (Music / Ambiance / SFX) is two tight rows: a control line + a slim volume slider. */
.music-bed {
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 6px;
}

.music-bed-row {
  align-items: center;
  display: flex;
  gap: 6px;
  min-width: 0;
}

/* Layer label + loaded track name, sharing one truncating line. */
.music-bed-info {
  align-items: baseline;
  display: flex;
  flex: 1;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

.music-bed-info strong {
  flex-shrink: 0;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

/* In the SFX row the label is short, so let the inline volume slider take the slack. */
.music-sfx .music-bed-info {
  flex: 0 0 auto;
}

.music-track-name {
  color: var(--muted);
  font-size: 0.78rem;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.music-track-name.loaded {
  color: var(--text);
}

/* Compact loop toggle: a checkbox with a tiny caption, no chrome. */
.music-loop {
  align-items: center;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-shrink: 0;
  font-size: 0.66rem;
  gap: 3px;
}

.music-loop input {
  height: 13px;
  margin: 0;
  width: 13px;
}

.mini-btn {
  align-items: center;
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  flex-shrink: 0;
  height: 24px;
  justify-content: center;
  padding: 0 5px;
  width: 24px;
}

.mini-btn svg {
  fill: none;
  height: 13px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 13px;
}

.mini-btn:hover {
  border-color: var(--muted);
  color: var(--text);
}

/* Slim volume slider — bare, no "Volume" label row. */
.music-vol {
  accent-color: var(--accent);
  height: 14px;
  width: 100%;
}

.music-vol-inline {
  flex: 1;
  min-width: 0;
}

.music-play-btn {
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  flex-shrink: 0;
  height: 26px;
  justify-content: center;
  min-height: 0;
  padding: 0;
  transition: border-color 0.15s;
  width: 26px;
}

.music-play-btn svg {
  fill: currentColor;
  height: 11px;
  stroke: none;
  width: 11px;
}

.music-play-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.music-play-btn:not(:disabled):hover {
  border-color: var(--accent);
  color: var(--accent);
}

.music-play-btn.playing {
  border-color: var(--accent);
  color: var(--accent);
}

/* Tight soundboard: pads wrap into a compact grid so many SFX fit at a glance. */
.music-sfx-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 96px;
  overflow-y: auto;
}

.music-sfx-list:empty {
  display: none;
}

.music-sfx-pad {
  position: relative;
}

.music-sfx-trigger {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.72rem;
  max-width: 120px;
  min-height: 24px;
  overflow: hidden;
  padding: 0 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.music-sfx-trigger:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.music-sfx-trigger:active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

/* × tucked into the pad's top-right corner, revealed only on hover. */
.music-sfx-remove {
  align-items: center;
  background: var(--danger);
  border: 1px solid #06021c;
  border-radius: 50%;
  color: #1b1508;
  cursor: pointer;
  display: none;
  font-size: 0.7rem;
  height: 16px;
  justify-content: center;
  line-height: 1;
  min-height: 0;
  padding: 0;
  position: absolute;
  right: -5px;
  top: -5px;
  width: 16px;
}

.music-sfx-pad:hover .music-sfx-remove {
  display: flex;
}

.music-sfx-remove:hover {
  filter: brightness(1.1);
}

/* Player display: one-time "enable audio" prompt shown when the browser blocks autoplay. */
.audio-unlock {
  background: rgba(6, 2, 28, 0.92);
  border: 1px solid var(--accent);
  border-radius: 12px;
  bottom: 24px;
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  left: 50%;
  padding: 14px 26px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 50;
}

.audio-unlock:hover {
  background: rgba(6, 2, 28, 1);
  border-color: var(--accent);
}

/* Floating turn-order overlay on the map (GM always; player when shared). */
.initiative-overlay {
  background: rgba(6, 2, 28, 0.86);
  border: 1px solid var(--line);
  border-radius: 10px;
  bottom: 16px;
  color: var(--text);
  left: 16px;
  max-height: 46vh;
  max-width: 240px;
  min-width: 170px;
  overflow-y: auto;
  padding: 10px 12px;
  position: absolute;
  z-index: 6;
}

/* On the GM screen the help button sits in the bottom-left corner, so lift the order
   overlay above it. (The button is hidden on the player display.) */
.app-shell[data-role="gm"] .initiative-overlay {
  bottom: 62px;
}

.init-ov-round {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
  text-transform: uppercase;
}

/* Overlay header with round label + turn arrows (GM only). */
.init-ov-head {
  align-items: center;
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.init-ov-head .init-ov-round {
  flex: 1;
  margin: 0;
}

.init-ov-btn {
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-size: 1rem;
  height: 22px;
  justify-content: center;
  line-height: 1;
  min-height: 0;
  padding: 0;
  width: 22px;
}

.init-ov-btn:hover {
  border-color: var(--accent-2);
  color: #c6fff1;
}

/* GM panel: the two order-overlay visibility switches. */
.init-visibility {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.initiative-overlay ol {
  display: flex;
  flex-direction: column;
  gap: 3px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.initiative-overlay li {
  align-items: center;
  border-radius: 6px;
  display: flex;
  gap: 8px;
  padding: 4px 8px;
}

.initiative-overlay li.current {
  background: rgba(177, 195, 1, 0.18);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.initiative-overlay .init-ov-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.init-conc-badge {
  background: var(--accent);
  border-radius: 4px;
  color: #1b1508;
  flex: none;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 5px;
}

.initiative-overlay em {
  color: var(--muted);
  font-size: 0.78rem;
  font-style: normal;
}

/* ----------------------------- panel subsection ----------------------------- */
.subsection-title {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-top: 4px;
  padding-top: 14px;
}

.subsection-title h3 {
  font-size: 0.9rem;
  font-weight: 650;
  margin: 0;
}

/* ----------------------------- floating help button ----------------------------- */
.shortcuts-fab {
  align-items: center;
  background: rgba(6, 2, 28, 0.82);
  border: 1px solid var(--line);
  border-radius: 50%;
  bottom: 16px;
  color: var(--text);
  display: flex;
  height: 38px;
  justify-content: center;
  left: 16px;
  padding: 0;
  position: absolute;
  width: 38px;
  z-index: 6;
}

.shortcuts-fab:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.shortcuts-fab svg {
  fill: none;
  height: 20px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 20px;
}

.app-shell[data-role="player"] .shortcuts-fab {
  display: none;
}

/* Demo-map credit + support link, bottom-center of the map. Only shown while the bundled
   demo map is loaded (`.is-demo`), never for the GM's own maps or on the player display. */
.map-credit-link {
  display: none;
}

.app-shell.is-demo .map-credit-link {
  background: rgba(6, 2, 28, 0.82);
  border: 1px solid var(--line);
  border-radius: 8px;
  bottom: 14px;
  color: var(--muted);
  display: block;
  font-size: 0.78rem;
  left: 50%;
  padding: 6px 12px;
  position: absolute;
  text-decoration: none;
  transform: translateX(-50%);
  white-space: nowrap;
  z-index: 6;
}

.map-credit-link:hover {
  border-color: var(--accent);
  color: var(--text);
}

.app-shell[data-role="player"] .map-credit-link {
  display: none;
}

.dialog-head-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.dialog-manual-link {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--accent);
  font-size: 0.82rem;
  padding: 6px 10px;
  text-decoration: none;
}

.dialog-manual-link:hover {
  border-color: var(--accent);
}

/* ----------------------------- GM rich-text notes ----------------------------- */
#noteLayer {
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  position: absolute;
  z-index: 4;
}

.app-shell[data-role="player"] #noteLayer,
.app-shell[data-role="player"] #imageHandles,
.app-shell[data-role="player"] #pdfLayer {
  display: none;
}

/* The note is sized in native px and the layer scales it with the map (transform set in JS). */
.map-note {
  background: #f4e8c1;
  border: 1px solid #b59f63;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  color: #14110a;
  font-family: Georgia, serif;
  pointer-events: auto;
  position: absolute;
  transform-origin: top left;
  top: 0;
  left: 0;
}

.map-note-grip {
  align-items: center;
  background: #e6d6a6;
  border-bottom: 1px solid #c8b576;
  border-radius: 4px 4px 0 0;
  cursor: move;
  display: flex;
  justify-content: space-between;
  padding: 1px 4px;
}

.map-note-dots {
  color: #8a7b4d;
  font-weight: 700;
  letter-spacing: 2px;
  line-height: 1;
}

.map-note-del {
  background: none;
  border: 0;
  color: #8a5a4d;
  cursor: pointer;
  font-size: 1.1em;
  line-height: 1;
  min-height: 0;
  padding: 0 2px;
}

.map-note-del:hover {
  color: #b3382b;
}

.map-note-body {
  min-height: 1.6em;
  outline: none;
  padding: 5px 7px;
  word-break: break-word;
}

.map-note-resize {
  bottom: 0;
  cursor: nwse-resize;
  height: 14px;
  position: absolute;
  right: 0;
  width: 14px;
}

.map-note-resize::after {
  border-right: 2px solid #9c8a55;
  border-bottom: 2px solid #9c8a55;
  bottom: 3px;
  content: "";
  height: 6px;
  position: absolute;
  right: 3px;
  width: 6px;
}

.note-format-bar {
  align-items: center;
  background: #06021c;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: flex;
  gap: 3px;
  padding: 4px;
  position: absolute;
  z-index: 7;
}

.note-format-bar select,
.note-format-bar button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.78rem;
  min-height: 26px;
  padding: 0 6px;
}

.note-format-bar button {
  min-width: 26px;
}

.note-format-bar button:hover,
.note-format-bar select:hover {
  border-color: var(--accent);
}

/* ----------------------------- selected-image handles ----------------------------- */
#imageHandles {
  inset: 0;
  pointer-events: none;
  position: absolute;
  z-index: 5;
}

.img-handle {
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 2px;
  height: 12px;
  margin: -7px 0 0 -7px;
  pointer-events: auto;
  position: absolute;
  width: 12px;
}

.img-handle[data-corner="nw"],
.img-handle[data-corner="se"] {
  cursor: nwse-resize;
}

.img-handle[data-corner="ne"],
.img-handle[data-corner="sw"] {
  cursor: nesw-resize;
}

.img-rot-stem {
  background: var(--accent);
  height: 26px;
  margin-left: -1px;
  pointer-events: none;
  position: absolute;
  transform-origin: top center;
  width: 2px;
}

.img-rot-ball {
  background: var(--accent);
  border: 2px solid #06021c;
  border-radius: 50%;
  cursor: grab;
  height: 16px;
  margin: -8px 0 0 -8px;
  min-height: 0;
  padding: 0;
  pointer-events: auto;
  position: absolute;
  width: 16px;
}

.img-show-players {
  align-items: center;
  background: rgba(6, 2, 28, 0.88);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  font-size: 0.76rem;
  gap: 5px;
  padding: 4px 8px;
  pointer-events: auto;
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

/* ----------------------------- DM PDF windows ----------------------------- */
#pdfLayer {
  inset: 0;
  pointer-events: none;
  position: absolute;
  z-index: 8;
}

.pdf-window {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  height: 540px;
  overflow: hidden;
  pointer-events: auto;
  position: absolute;
  width: 420px;
}

.pdf-head {
  align-items: center;
  background: #06021c;
  border-bottom: 1px solid var(--line);
  cursor: move;
  display: flex;
  gap: 8px;
  padding: 6px 8px;
}

.pdf-title {
  color: var(--text);
  flex: 1;
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-head button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.76rem;
  min-height: 26px;
  padding: 0 8px;
}

.pdf-head .pdf-close {
  font-size: 1rem;
  min-width: 28px;
  padding: 0;
}

.pdf-head button:hover {
  border-color: var(--accent);
}

.pdf-frame {
  background: #fff;
  border: 0;
  flex: 1;
  width: 100%;
}

.pdf-resize {
  bottom: 0;
  cursor: nwse-resize;
  height: 16px;
  position: absolute;
  right: 0;
  width: 16px;
}

.pdf-resize::after {
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  bottom: 4px;
  content: "";
  height: 7px;
  position: absolute;
  right: 4px;
  width: 7px;
}
