/* Basic Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    background-color: #2c2f33; /* Dark grey background */
    color: #ffffff;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* Disable page scrolling */
}

/* Let #main-container fill the whole screen */
#main-container {
    display: flex;
    width: 100%;
    height: calc(100vh - 50px); /* The 50px from your navbar */
    flex-direction: row;
    overflow: hidden; /* Hide any overflow, so no scroll here */
}

/* LEFT SIDEBAR */

#left-sidebar {
    flex: none;
    width: 20%;
    background-color: #2c2f33;
    padding: 15px;
    max-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    position: absolute;
    left: 0;
    top: 50px; /* Below the navbar */
    z-index: 10;
    border-right: 1px solid #99aab5;
}

/* MAP AREA */

#map-area {
    flex: 2;
    background-color: #23272a;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #99aab5;
    overflow: hidden;
    position: relative;
}

/* ---- Map Toolbar ---- */

#map-toolbar {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    background-color: var(--bg-tertiary, #36393f);
    border-bottom: 1px solid var(--border, #40444b);
    z-index: 10;
}

.map-toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.map-toolbar-sep {
    width: 1px;
    height: 22px;
    background-color: var(--border, #40444b);
    margin: 0 4px;
    flex-shrink: 0;
}

.map-tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 5px 10px;
    background-color: transparent;
    color: var(--text-secondary, #b9bbbe);
    border: 1px solid transparent;
    border-radius: var(--radius-sm, 4px);
    font-family: var(--font, 'Inter', Arial, sans-serif);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--transition, 0.15s ease), color var(--transition, 0.15s ease), border-color var(--transition, 0.15s ease);
    white-space: nowrap;
    user-select: none;
}

.map-tool-btn:hover {
    background-color: var(--bg-hover, #3e4147);
    color: var(--text-primary, #ffffff);
}

.map-tool-btn.active {
    background-color: var(--accent, #7289da);
    color: #ffffff;
}

.map-tool-btn.grid-active {
    background-color: var(--success, #43b581);
    color: #ffffff;
}

/* ─── Map tool help (ⓘ popovers, MAP-015) ─────────────────────────────────── */

.map-tool-slot {
    display: inline-flex;
    align-items: stretch;
    gap: 0;
}

.map-tool-help-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    padding: 2px 5px;
    margin: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-sm, 4px);
    background: transparent;
    color: var(--text-muted, #72767d);
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    transition: color var(--transition, 0.15s ease), background-color var(--transition, 0.15s ease);
}

.map-tool-help-btn:hover,
.map-tool-help-btn:focus-visible {
    color: var(--text-primary, #fff);
    background-color: var(--bg-hover, #3e4147);
    outline: none;
}

.map-tool-help-popover {
    position: fixed;
    z-index: 10050;
    display: none;
    max-width: min(380px, calc(100vw - 24px));
    max-height: min(72vh, 440px);
    overflow: auto;
    padding: 0;
    margin: 0;
    border: 1px solid var(--border, #40444b);
    border-radius: var(--radius, 8px);
    background: var(--bg-secondary, #2f3136);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    font-family: var(--font, 'Inter', Arial, sans-serif);
    font-size: 13px;
    color: var(--text-secondary, #b9bbbe);
}

.map-tool-help-popover.is-open {
    display: block;
}

.map-tool-help-popover:focus {
    outline: 2px solid var(--accent, #7289da);
    outline-offset: 2px;
}

.map-tool-help-popover-inner {
    padding: 12px 14px 14px;
}

.map-tool-help-title {
    margin: 0 0 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #fff);
}

.map-tool-help-body {
    margin: 0 0 12px;
    line-height: 1.45;
}

.map-tool-help-body strong {
    color: var(--text-primary, #e8eaed);
    font-weight: 600;
}

.map-tool-help-shortcuts {
    margin: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 12px;
    align-items: baseline;
}

.map-tool-help-shortcuts dt {
    margin: 0;
    font-weight: 600;
    color: var(--text-primary, #dcddde);
    font-size: 12px;
    white-space: nowrap;
}

.map-tool-help-shortcuts dd {
    margin: 0;
    font-size: 12px;
    line-height: 1.4;
}

/* ─── Stamp Tool ─────────────────────────────────────────────────────────── */

.stamp-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.65);
}

.stamp-modal-content {
    background: var(--bg-secondary, #2f3136);
    border: 1px solid var(--border, #40444b);
    border-radius: var(--radius, 8px);
    padding: 20px 24px;
    min-width: 320px;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.stamp-modal-content h3 {
    margin: 0;
    font-size: 16px;
    color: var(--text-primary, #fff);
}

.stamp-preview-wrapper {
    position: relative;
    background-image:
        linear-gradient(45deg, #3a3d41 25%, transparent 25%),
        linear-gradient(-45deg, #3a3d41 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #3a3d41 75%),
        linear-gradient(-45deg, transparent 75%, #3a3d41 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    border-radius: var(--radius-sm, 4px);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px;
    max-height: 300px;
}

#stamp-preview-canvas {
    max-width: 100%;
    max-height: 300px;
    display: block;
}

.stamp-modal-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stamp-modal-controls .input {
    background: var(--bg-tertiary, #36393f);
    border: 1px solid var(--border, #40444b);
    color: var(--text-primary, #fff);
    padding: 6px 10px;
    border-radius: var(--radius-sm, 4px);
    font-size: 13px;
    outline: none;
}

.stamp-transparent-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary, #b9bbbe);
    font-size: 13px;
    cursor: pointer;
}

.stamp-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

#stamp-picker {
    max-width: 160px;
    text-overflow: ellipsis;
}

#stamp-picker option[data-stamp-id] {
    padding: 2px 6px;
}

#draw-color-picker {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border, #40444b);
    border-radius: var(--radius-sm, 4px);
    padding: 2px;
    background: none;
    cursor: pointer;
}

#draw-size-slider {
    width: 80px;
    accent-color: var(--accent, #7289da);
    cursor: pointer;
}

.map-number-input {
    width: 52px;
    padding: 4px 6px;
    background-color: var(--bg-primary, #1e2124);
    color: var(--text-primary, #ffffff);
    border: 1px solid var(--border, #40444b);
    border-radius: var(--radius-sm, 4px);
    font-size: 12px;
    font-family: var(--font, 'Inter', Arial, sans-serif);
    text-align: center;
}

.map-size-label {
    font-size: 11px;
    color: var(--text-muted, #72767d);
    min-width: 24px;
}

#zoom-level-display {
    min-width: 38px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* ---- Map Stage (canvas container) ---- */

#map-stage {
    position: relative;
    flex: 1;
    overflow: hidden;
}

#bg-canvas,
#grid-canvas,
#draw-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#bg-canvas    { z-index: 1; }
#token-layer  { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 2; }
#grid-canvas  { z-index: 3; pointer-events: none; }
#draw-canvas  { z-index: 4; cursor: crosshair; }

/* Brush size ring (MAP-002): DOM overlay, not drawn on #draw-canvas — excluded from snapshots */
.brush-size-preview {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
    overflow: hidden;
}

.brush-size-preview-circle {
    position: absolute;
    box-sizing: border-box;
    border: 2px solid rgba(255, 255, 255, 0.92);
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
    transform: translate(-50%, -50%);
    pointer-events: none;
    background: rgba(255, 255, 255, 0.06);
}

.brush-size-preview-circle--erase {
    border-color: rgba(255, 160, 150, 0.95);
    background: rgba(255, 90, 80, 0.07);
}

/* Center-anchor dot — marks the exact brush origin inside the preview ring */
.brush-size-preview-dot {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

.brush-size-preview-circle--erase .brush-size-preview-dot {
    background: rgba(255, 160, 150, 0.95);
}

#draw-canvas.inactive { pointer-events: none; }

/* ---- Tokens ---- */

.map-token {
    position: absolute;
    cursor: move;
    user-select: none;
    touch-action: none;
    box-sizing: border-box;
}

.map-token img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 3px;
    pointer-events: none;
}

.map-token .token-controls {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
}

.map-token:hover .token-controls,
.map-token.selected .token-controls {
    opacity: 1;
    pointer-events: auto;
}

.token-resize-handle {
    position: absolute;
    bottom: -6px;
    right: -6px;
    width: 14px;
    height: 14px;
    background-color: var(--accent, #7289da);
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: nwse-resize;
    z-index: 5;
}

.token-rotate-handle {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 14px;
    height: 14px;
    background-color: var(--warning, #faa61a);
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: grab;
    z-index: 5;
}

.token-rotate-handle:active { cursor: grabbing; }

.token-delete-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 18px;
    height: 18px;
    background-color: var(--danger, #f04747);
    color: #fff;
    border: 2px solid #fff;
    border-radius: 50%;
    font-size: 10px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 6;
    padding: 0;
}

.token-delete-btn:hover {
    background-color: #c0392b;
}

.map-token.selected {
    outline: 2px solid var(--accent, #7289da);
    outline-offset: 2px;
}

/* RIGHT SIDEBAR */

#right-sidebar h3 {
    color: #7289da;
    margin-bottom: 10px;
}

.player-profile-box {
    border: 1px solid #ccc;
    padding: 10px;
    margin-bottom: 10px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-content {
    text-align: center;
}

.player-profile-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    margin: 0 auto 6px;
}

#player-profiles:not(.hidden) {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Character list + editor embedded in Player Profiles (session view) */
.session-character-host {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-top: 1px solid #40444b;
    margin-top: 8px;
    padding-top: 8px;
}

#player-profiles #character-sheet-area {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: auto;
    overflow-y: auto;
    padding: 8px;
}

#player-profiles #session-character-scroll #edit-character-button,
#player-profiles #edit-character-button {
    flex-shrink: 0;
    padding: 0 8px 8px;
}

/* Creation wizard overlay in session panel: see character_creation.css #session-character-host .modal.modal-inline */

#player-profiles-container {
    /* Base overflow; grid + compact cards live in character_preview.css (CHAR-014) */
    overflow-y: auto;
    flex: 0 1 auto;
    min-height: 0;
    max-height: min(48vh, 460px);
}

/* Dice / roll UI: see #dice-area under “Dice Area Container” below + dice_area.css (loaded after). */

/* LETTERHEAD */

#letterhead-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;           /* or any fixed height that suits your design */
    background-color: #2c2f33; /* confirm color if needed */
    z-index: 2;
    display: flex;
    gap: 10px;
    padding: 10px;
    border-bottom: 1px solid #99aab5;
}

/* The letterhead tabs inside #letterhead-bar */
.letterhead-tab {
    background-color: #23272a;
    color: #99aab5;
    border: none;
    padding: 10px;
    border-radius: 10px 10px 0 0;
    cursor: pointer;
    transition: background-color 0.3s, color 0.3s;
    flex: 1;
    text-align: center;
}

.letterhead-tab:hover {
    background-color: #7289da;
    color: #ffffff;
}

.letterhead-tab.active {
    background-color: #99aab5;
    color: #2c2f33;
}

#letterhead-contents {
    position: absolute;
    top: 50px;       /* same as #letterhead-bar height */
    left: 0;
    right: 0;
    bottom: 40%;     /* space for the dice area at bottom */
    overflow-y: auto;
    padding: 10px;
    box-sizing: border-box;
    z-index: 1;
}

.letterhead-content {
    display: none;
}

.letterhead-content:not(.hidden) {
    display: block;
}

/* INITIATIVE TRACKER STYLES */

#initiative-container {
    background-color: #23272a;
    border: 1px solid #99aab5;
    padding: 10px;
    border-radius: 5px;
    max-height: 400px; /* Adjust if needed */
    overflow-y: auto;
    margin-bottom: 10px;
  }
  
  #initiative-container h2 {
    margin-bottom: 10px;
    color: #7289da;
  }
  
  /* Participant List */
  #initiative-list {
    list-style: none;
    margin: 0;
    padding: 0;
  }
  
  .initiative-item {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
  }

  /* Highlight the active combatant */
  .initiative-item.active-turn {
    background-color: rgba(114, 137, 218, 0.25);
    border-left: 3px solid #7289da;
    border-radius: 3px;
  }

  /* Delete button per initiative entry */
  .delete-initiative-btn {
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
    line-height: 1;
  }

  .delete-initiative-btn:hover {
    color: #ff6b6b;
  }

  .reroll-initiative-btn {
    background: none;
    border: none;
    color: #7289da;
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
    line-height: 1;
  }

  .reroll-initiative-btn:hover {
    color: #99b3f0;
  }

  /* Modifier input next to Roll button */
  #initiative-buttons label[for="init-modifier"] {
    margin-right: 4px;
    font-size: 13px;
    color: var(--text-primary, #ffffff);
    white-space: nowrap;
  }
  #init-modifier {
    width: 50px;
    text-align: center;
    background-color: #2c2f33;
    color: #ffffff;
    border: 1px solid #99aab5;
    border-radius: 3px;
    padding: 3px;
    margin-right: 5px;
  }

  /* Add combatant form (DM only) */
  #add-combatant-section {
    display: flex;
    gap: 5px;
    margin-top: 8px;
  }

  #add-combatant-section input {
    background-color: #2c2f33;
    color: #ffffff;
    border: 1px solid #99aab5;
    border-radius: 3px;
    padding: 3px;
    flex: 1;
  }

  #add-combatant-btn {
    background-color: #7289da;
    color: #ffffff;
    border: none;
    padding: 4px 10px;
    cursor: pointer;
    border-radius: 3px;
  }

  #add-combatant-btn:hover {
    background-color: #5b6eae;
  }
  
  .initiative-item input[type="text"] {
    flex: 1;
    margin-right: 5px;
    background-color: #2c2f33;
    color: #ffffff;
    border: 1px solid #99aab5;
    border-radius: 3px;
    padding: 3px;
  }
  
  .initiative-item input[type="number"] {
    width: 60px;
    text-align: center;
    background-color: #2c2f33;
    color: #ffffff;
    border: 1px solid #99aab5;
    border-radius: 3px;
    margin-right: 5px;
  }
  
  /* Round and Turn Display */
  #round-turn-display {
    margin: 10px 0;
    font-size: 14px;
  }
  
  /* Buttons */
  #initiative-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: center;
    gap: 6px 10px;
    margin-bottom: 10px;
  }
  
  #initiative-buttons button {
    background-color: #7289da;
    color: #ffffff;
    border: none;
    padding: 5px 10px;
    cursor: pointer;
    margin-right: 5px;
    border-radius: 3px;
  }
  
  #initiative-buttons button:hover {
    background-color: #5b6eae;
  }
  
  /* Minimal Letterhead Overlay */

#letterhead-overlay {
    position: absolute;
    top: 60px;       /* Adjust as needed so it's below your navbar */
    left: 0;
    width: 70px;     /* Narrow column for letterheads */
    z-index: 999;    /* Ensure it's on top of map/other elements */
    display: none;   /* Hidden until toggled */
    pointer-events: none; 
    /* 
      pointer-events: none ensures clicks pass through to the map,
      but we’ll re-enable pointer-events on the letterheads themselves 
    */
  }

  #letterhead-overlay .letterhead {
    pointer-events: auto;  /* So we can click them even though parent is none */
    background-color: #7289da;
    color: #fff;
    text-align: center;
    margin: 5px 0;
    padding: 10px;
    border-radius: 3px;
    font-weight: bold;
    cursor: pointer;
    width: 60px;    /* Slightly narrower than container width for margin */
    margin-left: 5px;
  }
  
  /* Active turn highlight in minimal overlay */
  .letterhead.active-turn-letterhead {
    background-color: #5b6eae;
    border: 2px solid #ffffff;
  }

  .bottom-letterhead {
    background-color: #e74c3c;
    margin-top: 10px;
  }


  /* ============================================================
     Asset Library
     ============================================================ */

  /* Filter bar */
  .asset-filter-bar {
      padding: 8px 10px;
      background: var(--bg-primary, #1e2124);
      border: 1px solid var(--border, #40444b);
      border-radius: var(--radius, 8px);
      margin-bottom: 8px;
  }
  .asset-filter-row {
      display: flex;
      gap: 8px;
      align-items: center;
      flex-wrap: wrap;
  }
  .asset-filter-select {
      font-size: 12px;
      padding: 5px 8px;
      border-radius: var(--radius-sm, 4px);
      border: 1px solid var(--border, #40444b);
      background: var(--bg-secondary, #2c2f33);
      color: var(--text-primary, #fff);
      min-width: 0;
      flex: 1 1 100px;
      max-width: 180px;
  }
  .asset-clear-btn {
      font-size: 11px;
      padding: 4px 10px;
      border-radius: var(--radius-sm, 4px);
      border: 1px solid var(--border, #40444b);
      background: transparent;
      color: var(--text-secondary, #b9bbbe);
      cursor: pointer;
      white-space: nowrap;
  }
  .asset-clear-btn:hover { color: var(--text-primary, #fff); border-color: var(--text-secondary, #b9bbbe); }

  /* Tag chips */
  .asset-tag-chips {
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
      margin-top: 6px;
  }
  .asset-tag-chips:empty { display: none; }
  .asset-tag-chip {
      font-size: 11px;
      padding: 2px 8px;
      border-radius: 12px;
      border: 1px solid var(--border, #40444b);
      background: var(--bg-secondary, #2c2f33);
      color: var(--text-secondary, #b9bbbe);
      cursor: pointer;
      transition: all 0.15s ease;
      line-height: 1.4;
  }
  .asset-tag-chip:hover { border-color: var(--accent, #7289da); color: var(--text-primary, #fff); }
  .asset-tag-chip--active {
      background: var(--accent, #7289da);
      border-color: var(--accent, #7289da);
      color: #fff;
  }
  .asset-tag-chip--active:hover { background: #5b6eae; }
  .asset-tag-chip .tag-x { margin-left: 4px; font-weight: 700; }

  /* Upload progress area */
  .asset-upload-progress {
      display: flex;
      flex-direction: column;
      gap: 4px;
      margin-bottom: 8px;
  }
  .asset-upload-row {
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 11px;
      color: var(--text-secondary, #b9bbbe);
      padding: 4px 8px;
      background: var(--bg-primary, #1e2124);
      border-radius: var(--radius-sm, 4px);
  }
  .asset-upload-row .upload-filename {
      flex: 1;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      min-width: 0;
  }
  .asset-upload-bar {
      width: 80px;
      height: 4px;
      background: var(--bg-tertiary, #36393f);
      border-radius: 2px;
      overflow: hidden;
      flex-shrink: 0;
  }
  .asset-upload-bar-fill {
      height: 100%;
      background: var(--accent, #7289da);
      border-radius: 2px;
      transition: width 0.2s ease;
      width: 0%;
  }
  .asset-upload-row--done .asset-upload-bar-fill { background: #43b581; width: 100%; }
  .asset-upload-row--error .asset-upload-bar-fill { background: #f04747; width: 100%; }
  .asset-upload-status { font-size: 10px; flex-shrink: 0; }

  /* Full-panel drop zone */
  .asset-drop-panel {
      position: relative;
      min-height: 200px;
      border-radius: var(--radius, 8px);
      flex: 1;
  }
  .asset-drop-overlay {
      display: none;
      position: absolute;
      inset: 0;
      z-index: 20;
      background: rgba(114, 137, 218, 0.12);
      border: 2px dashed var(--accent, #7289da);
      border-radius: var(--radius, 8px);
      align-items: center;
      justify-content: center;
  }
  .asset-drop-panel--dragover .asset-drop-overlay {
      display: flex;
  }
  .asset-drop-overlay-content {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;
      color: var(--accent, #7289da);
      font-size: 14px;
      font-weight: 500;
      pointer-events: none;
  }

  /* Asset grid */
  .asset-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
      gap: 8px;
  }

  /* Asset card */
  .asset-card {
      position: relative;
      background: var(--bg-secondary, #2c2f33);
      border: 1px solid var(--border, #40444b);
      border-radius: var(--radius, 8px);
      overflow: hidden;
      cursor: pointer;
      transition: border-color 0.15s, box-shadow 0.15s;
  }
  .asset-card:hover {
      border-color: var(--accent, #7289da);
      box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  }
  .asset-card-img {
      width: 100%;
      height: 100px;
      object-fit: cover;
      display: block;
      background: var(--bg-primary, #1e2124);
  }
  .asset-card-body {
      padding: 6px 8px;
  }
  .asset-card-name {
      font-size: 11px;
      color: var(--text-primary, #fff);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      line-height: 1.4;
  }
  .asset-card-tags {
      font-size: 10px;
      color: var(--text-muted, #72767d);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin-top: 2px;
  }
  .asset-card--hidden { display: none !important; }

  /* Badge stack for player/preview indicators on cards */
  .asset-card .map-thumb-badge-stack {
      position: absolute;
      top: 4px;
      left: 4px;
      display: flex;
      flex-direction: column;
      gap: 2px;
      z-index: 5;
  }

  /* Overflow (three-dot) menu button */
  .asset-card-menu-btn {
      position: absolute;
      top: 4px;
      right: 4px;
      width: 24px;
      height: 24px;
      border: none;
      border-radius: var(--radius-sm, 4px);
      background: rgba(0,0,0,0.6);
      color: #fff;
      font-size: 14px;
      line-height: 24px;
      text-align: center;
      cursor: pointer;
      opacity: 0;
      transition: opacity 0.15s;
      z-index: 5;
      padding: 0;
  }
  .asset-card:hover .asset-card-menu-btn { opacity: 1; }

  /* Dropdown menu */
  .asset-menu {
      position: absolute;
      z-index: 100;
      background: var(--bg-primary, #1e2124);
      border: 1px solid var(--border, #40444b);
      border-radius: var(--radius, 8px);
      box-shadow: 0 4px 16px rgba(0,0,0,0.5);
      padding: 4px;
      min-width: 160px;
      display: none;
  }
  .asset-menu--open { display: block; }
  .asset-menu-item {
      display: block;
      width: 100%;
      padding: 6px 10px;
      font-size: 12px;
      color: var(--text-secondary, #b9bbbe);
      background: none;
      border: none;
      border-radius: var(--radius-sm, 4px);
      text-align: left;
      cursor: pointer;
  }
  .asset-menu-item:hover {
      background: var(--bg-secondary, #2c2f33);
      color: var(--text-primary, #fff);
  }
  .asset-menu-item--danger { color: #f04747; }
  .asset-menu-item--danger:hover { background: rgba(240,71,71,0.15); color: #f04747; }
  .asset-menu-sep {
      height: 1px;
      background: var(--border, #40444b);
      margin: 4px 0;
  }

  /* Edit modal (tag editor / move folder) */
  .asset-edit-modal {
      position: fixed;
      inset: 0;
      z-index: 200;
      display: flex;
      align-items: center;
      justify-content: center;
      background: rgba(0,0,0,0.6);
  }
  .asset-edit-panel {
      background: var(--bg-secondary, #2c2f33);
      border: 1px solid var(--border, #40444b);
      border-radius: var(--radius, 8px);
      padding: 16px;
      width: 320px;
      max-width: 90vw;
      max-height: 80vh;
      overflow-y: auto;
  }
  .asset-edit-panel h4 {
      margin: 0 0 12px;
      font-size: 14px;
      color: var(--text-primary, #fff);
  }
  .asset-edit-panel label {
      display: block;
      font-size: 11px;
      color: var(--text-muted, #72767d);
      text-transform: uppercase;
      letter-spacing: 0.03em;
      margin-bottom: 4px;
      margin-top: 10px;
  }
  .asset-edit-panel select,
  .asset-edit-panel input[type="text"] {
      width: 100%;
      box-sizing: border-box;
      font-size: 13px;
      padding: 6px 8px;
      border-radius: var(--radius-sm, 4px);
      border: 1px solid var(--border, #40444b);
      background: var(--bg-primary, #1e2124);
      color: var(--text-primary, #fff);
  }
  .asset-edit-tags-wrap {
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
      padding: 6px;
      min-height: 32px;
      border-radius: var(--radius-sm, 4px);
      border: 1px solid var(--border, #40444b);
      background: var(--bg-primary, #1e2124);
      cursor: text;
  }
  .asset-edit-tag {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      font-size: 11px;
      padding: 2px 6px;
      border-radius: 10px;
      background: var(--accent, #7289da);
      color: #fff;
  }
  .asset-edit-tag-remove {
      cursor: pointer;
      font-weight: 700;
      font-size: 12px;
      line-height: 1;
  }
  .asset-edit-tag-input {
      border: none !important;
      background: transparent !important;
      color: var(--text-primary, #fff) !important;
      font-size: 12px !important;
      padding: 2px 4px !important;
      min-width: 60px;
      flex: 1;
      outline: none;
  }
  .asset-edit-actions {
      display: flex;
      gap: 8px;
      margin-top: 14px;
      justify-content: flex-end;
  }
  .asset-edit-actions button {
      padding: 6px 16px;
      font-size: 12px;
      border-radius: var(--radius-sm, 4px);
      border: 1px solid var(--border, #40444b);
      cursor: pointer;
  }
  .asset-edit-save {
      background: var(--accent, #7289da);
      color: #fff;
      border-color: var(--accent, #7289da);
  }
  .asset-edit-save:hover { background: #5b6eae; }
  .asset-edit-cancel {
      background: transparent;
      color: var(--text-secondary, #b9bbbe);
  }

  /* Empty state */
  .asset-empty-state {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 40px 20px;
      color: var(--text-muted, #72767d);
      text-align: center;
      cursor: pointer;
  }
  .asset-empty-state p { margin: 4px 0; font-size: 14px; }
  .asset-empty-hint { font-size: 12px; color: var(--text-muted, #72767d); }
  .asset-empty-state svg { margin-bottom: 8px; opacity: 0.5; }

  /* Snapshot gallery (Maps tab) re-uses asset-thumbnail class */
  .asset-thumbnail {
      width: 80px;
      height: auto;
      border: 1px solid var(--border, #40444b);
      background-color: var(--bg-primary, #1e2124);
      cursor: pointer;
      overflow: visible;
      display: flex;
      flex-direction: column;
      align-items: center;
      position: relative;
      border-radius: var(--radius-sm, 4px);
  }
  .asset-thumbnail img {
      width: 100%;
      display: block;
  }

/* ============================================================
   Design & Responsiveness Improvements
   ============================================================ */

/* Update base font and background to use design tokens */
body {
    font-family: var(--font, 'Inter', Arial, sans-serif);
    background-color: var(--bg-primary, #1e2124);
}

/* Adjust main container height to 56px navbar */
#main-container {
    height: calc(100vh - 56px);
}

/* ---- Left Panel (initiative tracker + dice tray) ---- */

#left-panel {
    display: flex;
    flex-direction: column;
    flex: 0 0 var(--left-panel-width);
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-secondary, #2c2f33);
    border-right: 1px solid var(--border, #40444b);
    /* Keep picker/action above the fixed L-shaped roll stage */
    padding-bottom: var(--dice-l-stage-height);
    box-sizing: border-box;
}

/* ---- Initiative Container Improvements ---- */

#initiative-container {
    background-color: var(--bg-secondary, #2c2f33);
    border-color: var(--border, #40444b);
    flex: 0 0 auto;
    overflow-y: auto;
    position: relative;
    top: auto;
    left: auto;
}

#initiative-container h2 {
    color: var(--accent, #7289da);
    font-family: var(--font, 'Inter', Arial, sans-serif);
}

#initiative-buttons button {
    font-family: var(--font, 'Inter', Arial, sans-serif);
    border-radius: var(--radius-sm, 4px);
    transition: background-color 0.15s ease;
    font-size: 13px;
    padding: 5px 8px;
}

#initiative-buttons button:hover {
    background-color: var(--accent-hover, #677bc4);
}

.initiative-item.active-turn {
    background-color: rgba(114, 137, 218, 0.2);
    border-left: 3px solid var(--accent, #7289da);
}

.initiative-item--nat20 {
    background-color: rgba(212, 168, 0, 0.35);
    border-left: 4px solid #e6b800;
    box-shadow: inset 0 0 0 1px rgba(255, 224, 102, 0.35);
}

.initiative-item--nat20 input {
    color: var(--text-primary, #ffffff);
}

.initiative-item--nat1 {
    background-color: rgba(185, 45, 45, 0.38);
    border-left: 4px solid #ff6b6b;
    box-shadow: inset 0 0 0 1px rgba(255, 120, 120, 0.25);
}

.initiative-item--nat1 input {
    color: var(--text-primary, #ffffff);
}

.letterhead--nat20 {
    background-color: rgba(212, 168, 0, 0.45);
    border: 2px solid #ffd54a;
    color: #1a1a1a;
    font-weight: 600;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.letterhead--nat1 {
    background-color: rgba(200, 60, 60, 0.5);
    border: 2px solid #ff8a8a;
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

/* ---- Map Area ---- */

#map-area {
    background-color: var(--bg-secondary, #23272a);
    border-color: var(--border, #40444b);
    flex-direction: column;
}

/* ---- Right Sidebar ---- */

#right-sidebar {
    position: relative;
    flex: var(--right-sidebar-flex, 0 0 clamp(260px, 28%, 440px));
    background-color: var(--bg-secondary, #2c2f33);
    border-left: 1px solid var(--border, #40444b);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Tabs + scrollable content only; vertical strip toggles this, not the dice tray (DICE-004). */
#right-sidebar-main {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    transition: flex 0.3s ease, opacity 0.2s ease;
}

#right-sidebar-main.panel-collapsed {
    flex: 0 0 0;
    min-height: 0;
    max-height: 0;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
    border: none !important;
}

/* Dice tray stack — lives in #left-panel, takes remaining vertical space. */
#dice-tray-stack {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 180px;
    overflow: hidden;
}

/* ---- Letterhead Tab Bar ---- */

#letterhead-bar {
    position: relative;
    z-index: 3;
    top: auto;
    left: auto;
    right: auto;
    flex-shrink: 0;
    background-color: var(--bg-tertiary, #36393f);
    border-color: var(--border, #40444b);
    padding: 6px 8px;
    gap: 4px;
    /* UI-010: allow tab tooltips (::after) to paint below the row without clipping */
    overflow: visible;
    flex-wrap: wrap;
    row-gap: 4px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}

.letterhead-tab {
    font-family: var(--font, 'Inter', Arial, sans-serif);
    font-size: 13px;
    font-weight: 500;
    background-color: transparent;
    color: var(--text-secondary, #b9bbbe);
    border-radius: 999px;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    flex: 0 0 auto;
    width: 2.25rem;
    height: 2.25rem;
    min-width: 2.25rem;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    position: relative;
}

/* UI-010: section name on hover and keyboard focus (aria-label = SR name + tooltip text; below tab avoids sidebar overflow clip) */
.letterhead-tab::after {
    content: attr(aria-label);
    position: absolute;
    left: 50%;
    top: calc(100% + 6px);
    transform: translateX(-50%);
    padding: 5px 9px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    color: var(--text-primary, #ffffff);
    background: var(--bg-tertiary, #36393f);
    border: 1px solid var(--border, #40444b);
    border-radius: var(--radius-sm, 4px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    pointer-events: none;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.12s ease, visibility 0.12s ease;
}

.letterhead-tab:hover::after,
.letterhead-tab:focus-visible::after {
    opacity: 1;
    visibility: visible;
}

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

.letterhead-tab-icon {
    display: inline-flex;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    color: inherit;
    opacity: 0.92;
}

.letterhead-tab-icon svg {
    display: block;
    width: 100%;
    height: 100%;
}

.letterhead-tab:hover {
    background-color: var(--bg-hover, #3e4147);
    color: var(--text-primary, #ffffff);
}

.letterhead-tab:hover .letterhead-tab-icon {
    opacity: 1;
}

.letterhead-tab.active {
    background-color: var(--accent, #7289da);
    color: #ffffff;
}

.letterhead-tab.active .letterhead-tab-icon {
    opacity: 1;
}

.letterhead-tab:focus-visible {
    outline: 2px solid var(--accent, #5865f2);
    outline-offset: 2px;
}

@media (max-height: 760px) {
    #letterhead-bar {
        padding: 4px 6px;
        gap: 3px;
    }

    .letterhead-tab-icon {
        width: 17px;
        height: 17px;
    }
}

/* ---- Letterhead Contents ---- */

#letterhead-contents {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    flex: 1;
    min-height: 150px; /* floor so tabs content is always usable */
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
}

/* Active tab fills the letterhead stack so notebook / compendium get a real height (NB-005) */
#letterhead-contents > .letterhead-content:not(.hidden) {
    height: 100%;
    min-height: 0;
    box-sizing: border-box;
}

/* ---- Chat Panel (Roll Log) ---- */

#chat-panel-header {
    flex-shrink: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 10px;
    background: var(--bg-tertiary, #36393f);
    border: none;
    border-top: 1px solid var(--border, #40444b);
    cursor: pointer;
    color: var(--text-secondary, #b9bbbe);
    font-family: var(--font, 'Inter', Arial, sans-serif);
    font-size: 12px;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}
#chat-panel-header:hover {
    background: var(--bg-hover, #3e4147);
    color: var(--text-primary, #ffffff);
}
#chat-panel-header:focus-visible {
    outline: 2px solid var(--accent, #5865f2);
    outline-offset: -2px;
    z-index: 1;
}
#chat-panel-header .panel-collapse-icon .panel-chevron {
    width: 14px;
    height: 14px;
}

#chat-panel-container {
    flex: 1 1 auto;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-primary, #1e2124);
    transition: max-height 0.3s ease, opacity 0.2s ease, flex 0.3s ease, min-height 0.3s ease;
}
#chat-panel-container.panel-collapsed {
    flex: 0 0 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

#chat-log {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border, #99aab5);
    padding: 8px 10px;
    background-color: var(--bg-secondary, #2c2f33);
    margin: 8px 10px;
    color: #ffffff;
    font-size: 13px;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    border-radius: var(--radius-sm, 4px);
    box-sizing: border-box;
}

/* ---- Dice Area Container ---- */
/* Picker + action controls only; 3D roll stage is the L-overlay #dice-bar. */

#dice-area-container {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    min-height: 0;
    max-height: 280px; /* finite value needed for collapse transition */
    overflow: visible; /* allow #dice-bar fixed L-stage to escape */
    border-top: none;
    container-type: inline-size;
    container-name: dice-shell;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    background-color: var(--bg-primary, #1e2124);
}

#dice-area {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    flex: 0 0 auto;
    min-height: 0;
    height: auto;
    width: 100%;
    border: none;
    border-top: none;
    background-color: var(--bg-primary, #1e2124);
    box-sizing: border-box;
}

/*
 * L-shaped 3D roll stage (game table only): sits bottom-left, wider than
 * the left sidebar, so DiceBox keeps a usable aspect ratio.
 */
#main-container:has(#left-panel) #dice-bar {
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 40;
    flex: none;
    /* Prefer a stable aspect ratio; width grows a bit past the sidebar */
    height: var(--dice-l-stage-height);
    aspect-ratio: 16 / 10;
    width: auto;
    min-width: calc(var(--left-panel-width) + 140px);
    max-width: min(560px, 48vw);
    min-height: 0;
    max-height: none;
    overflow: hidden;
    border: 1px solid var(--border, #40444b);
    border-left: none;
    border-bottom: none;
    border-radius: 0 10px 0 0;
    background-color: var(--bg-secondary, #2c2f33);
    box-shadow: 4px -4px 18px rgba(0, 0, 0, 0.45);
}

#main-container:has(#left-panel) #dice-bar canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* When dice panel is collapsed, reclaim the L-stage footprint */
#main-container:has(#dice-area-container.panel-collapsed) #left-panel {
    padding-bottom: 0;
}

#main-container:has(#dice-area-container.panel-collapsed) #dice-bar {
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
}

/* ---- Roll Log Entries ---- */

.roll-log-entry {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border, #40444b);
    border-radius: var(--radius-sm, 4px);
    font-size: 13px;
    margin-bottom: 2px;
    line-height: 1.4;
}

.roll-log-entry:last-child {
    border-bottom: none;
}

.roll-nat20 {
    background: linear-gradient(
        90deg,
        rgba(212, 168, 0, 0.42) 0%,
        rgba(212, 168, 0, 0.22) 100%
    );
    border-left: 4px solid #e6b800;
    color: var(--text-primary, #ffffff);
    box-shadow: inset 0 0 0 1px rgba(255, 224, 102, 0.2);
}

.roll-nat1 {
    background: linear-gradient(
        90deg,
        rgba(185, 45, 45, 0.45) 0%,
        rgba(185, 45, 45, 0.22) 100%
    );
    border-left: 4px solid #ff6b6b;
    color: var(--text-primary, #ffffff);
    box-shadow: inset 0 0 0 1px rgba(255, 150, 150, 0.2);
}

/* Map / asset thumbnails: who sees this map */
.map-thumb-badge-stack {
    position: absolute;
    top: 4px;
    right: 4px;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    max-width: calc(100% - 8px);
    pointer-events: none;
}

.player-map-indicator,
.dm-preview-indicator {
    position: relative;
    top: auto;
    right: auto;
    font-size: 10px;
    font-weight: 600;
    line-height: 1.2;
    padding: 3px 7px;
    border-radius: 999px;
    display: none;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.player-map-indicator {
    background: #c0392b;
    color: #fff;
}

.dm-preview-indicator {
    background: #3d5a80;
    color: #e8f1ff;
}

/* ---- Dice Notation Input ---- */

#dice-notation {
    background-color: var(--bg-secondary, #2c2f33);
    color: var(--text-primary, #ffffff);
    border: 1px solid var(--border, #40444b);
    border-radius: var(--radius-sm, 4px);
    padding: 6px 10px;
    font-family: var(--font, 'Inter', Arial, sans-serif);
    font-size: 14px;
    transition: border-color 0.15s ease;
}

#dice-notation:focus {
    outline: 2px solid var(--accent, #7289da);
    outline-offset: 1px;
    border-color: var(--accent, #7289da);
    box-shadow: 0 0 0 2px rgba(114, 137, 218, 0.5);
}

#roll-button,
#clear-button {
    font-family: var(--font, 'Inter', Arial, sans-serif);
    border-radius: var(--radius-sm, 4px);
    transition: background-color 0.15s ease;
}

/* ---- Init form inputs ---- */

#init-modifier,
#add-combatant-section input {
    background-color: var(--bg-primary, #1e2124);
    color: var(--text-primary, #ffffff);
    border-color: var(--border, #40444b);
    border-radius: var(--radius-sm, 4px);
    font-family: var(--font, 'Inter', Arial, sans-serif);
}

#add-combatant-btn {
    background-color: var(--accent, #7289da);
    border-radius: var(--radius-sm, 4px);
    font-family: var(--font, 'Inter', Arial, sans-serif);
    transition: background-color 0.15s ease;
}

#add-combatant-btn:hover {
    background-color: var(--accent-hover, #677bc4);
}

/* ============================================================
   Responsive Layout
   ============================================================ */

/* ---- Tablet (768px - 1200px) ---- */

@media (max-width: 1200px) {
    #left-panel {
        flex: 0 0 var(--left-panel-width-narrow);
    }

    #right-sidebar {
        flex: var(--right-sidebar-flex-narrow, 0 0 clamp(240px, 26%, 380px));
    }

    .letterhead-tab {
        font-size: 11px;
        padding: 6px 6px;
    }
}

/* ---- Mobile (< 768px) ---- */

@media (max-width: 768px) {
    html, body {
        overflow-x: hidden;
        overflow-y: auto;
    }

    #main-container {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 56px);
        overflow-x: hidden;
        overflow-y: auto;
        max-width: 100vw;
    }

    /* Left panel: stacks full-width on mobile */
    #left-panel {
        flex: none;
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border, #40444b);
        padding-bottom: 0; /* L-stage becomes in-flow on mobile */
    }

    /* Initiative tracker: collapsible top bar on mobile */
    #initiative-container {
        width: 100%;
        max-height: none;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border, #40444b);
        overflow: visible;
    }

    /* Collapse long initiative list on mobile */
    #initiative-list {
        max-height: 200px;
        overflow-y: auto;
    }

    /* Map area: fixed height on mobile */
    #map-area {
        flex: none;
        height: 300px;
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border, #40444b);
    }

    #map-toolbar {
        flex-wrap: wrap;
        gap: 3px;
        padding: 4px 6px;
        max-width: 100%;
    }

    .map-toolbar-group {
        flex-wrap: wrap;
    }

    .map-tool-btn {
        padding: 4px 7px;
        font-size: 11px;
    }

    #draw-size-slider {
        width: 60px;
    }

    /* Right sidebar: full width below map */
    #right-sidebar {
        flex: none;
        width: 100%;
        height: auto;
        min-height: 400px;
        border-left: none;
        border-top: 1px solid var(--border, #40444b);
    }

    #letterhead-contents {
        min-height: min(200px, 35vh);
        max-height: none;
    }

    #dice-area {
        min-height: 120px;
        max-height: min(42vh, 280px);
    }

    #chat-log {
        min-height: 3rem;
    }

    /* Initiative buttons: wrap on small screens */
    #initiative-buttons {
        flex-wrap: wrap;
        gap: 4px;
    }

    #initiative-buttons button {
        flex: 1;
        min-width: 80px;
    }

    /* Mobile-only "More tools" toggle button */
    #toolbar-more-btn {
        display: inline-flex;
        font-size: 11px;
        padding: 4px 7px;
    }

    /* Secondary toolbar panel (DM-only tools) */
    #toolbar-secondary-panel {
        display: none;
        width: 100%;
        flex-wrap: wrap;
        gap: 3px;
        padding: 4px 0 0;
        border-top: 1px solid var(--border, #40444b);
    }

    #toolbar-secondary-panel.open {
        display: flex;
    }
}

/* Toolbar more-btn hidden on desktop; secondary panel inlined via display:contents */
@media (min-width: 769px) {
    #toolbar-more-btn { display: none; }
    #toolbar-secondary-panel { display: contents; }
}

/* ============================================================
   Compendium
   ============================================================ */

#compendium-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 8px;
    gap: 8px;
}

.compendium-search-bar {
    display: flex;
    gap: 6px;
}

.compendium-search-bar .input {
    font-size: var(--font-size-sm, 13px);
    padding: 7px 10px;
}

.compendium-search-bar input[type="text"] {
    flex: 1;
    min-width: 0;
}

.compendium-search-bar select {
    flex: 0 0 auto;
    width: 110px;
    cursor: pointer;
    appearance: auto;
}

#compendium-results {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.compendium-result-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color var(--transition);
}

.compendium-result-item:hover {
    background-color: var(--bg-hover);
}

.compendium-type-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    flex-shrink: 0;
}

.compendium-type-badge.race { background-color: #43b581; color: #fff; }
.compendium-type-badge.class { background-color: #f04747; color: #fff; }
.compendium-type-badge.skill { background-color: #faa61a; color: #fff; }
.compendium-type-badge.background { background-color: #7289da; color: #fff; }
.compendium-type-badge.feat { background-color: #b968e0; color: #fff; }
.compendium-type-badge.feature { background-color: #e67e22; color: #fff; }
.compendium-type-badge.monster { background-color: #992d22; color: #fff; }

.compendium-result-name {
    flex: 1;
    font-size: var(--font-size-sm, 13px);
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.compendium-result-snippet {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

#compendium-detail {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.compendium-detail-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.compendium-back-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: background-color var(--transition);
}

.compendium-back-btn:hover {
    background-color: var(--bg-hover);
}

.compendium-detail-title {
    font-size: var(--font-size-lg, 18px);
    font-weight: 600;
}

.compendium-detail-body {
    font-size: var(--font-size-sm, 13px);
    color: var(--text-secondary);
    line-height: 1.6;
}

.compendium-detail-body h4 {
    color: var(--text-primary);
    font-size: var(--font-size-sm, 13px);
    margin-top: 10px;
    margin-bottom: 4px;
}

.compendium-detail-body p {
    margin-bottom: 6px;
}

.compendium-detail-body .detail-field {
    margin-bottom: 8px;
}

.compendium-detail-body .detail-label {
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.compendium-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 30px 10px;
    font-size: var(--font-size-sm, 13px);
}

.compendium-loading {
    text-align: center;
    color: var(--text-muted);
    padding: 20px;
    font-size: var(--font-size-sm, 13px);
}

/* ============================================================
   Monsters & stat blocks (DM-only, Compendium)
   ============================================================ */

#compendium-enemy-section {
    border-bottom: 2px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 8px;
}

.enemy-panel {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#enemy-random-btn {
    flex-shrink: 0;
    align-self: flex-start;
}

.enemy-filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

.enemy-filters select {
    font-size: 12px;
    padding: 5px 6px;
    cursor: pointer;
    appearance: auto;
}

#enemy-browse-results {
    max-height: 200px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 4px;
}

/* ── Stat Block (D&D-style card) ── */

.stat-block {
    background: linear-gradient(135deg, #fdf1dc 0%, #f5e6c8 100%);
    border: 2px solid #7a200d;
    border-radius: 4px;
    padding: 12px;
    font-family: 'Georgia', serif;
    color: #1a1a1a;
    font-size: 12px;
    line-height: 1.5;
    margin-top: 8px;
}

.stat-block-header {
    border-bottom: 2px solid #7a200d;
    padding-bottom: 6px;
    margin-bottom: 6px;
}

.stat-block-name {
    font-size: 18px;
    font-weight: 700;
    color: #7a200d;
    line-height: 1.2;
}

.stat-block-meta {
    font-size: 11px;
    font-style: italic;
    color: #4a3520;
}

.stat-block-divider {
    height: 2px;
    background: linear-gradient(90deg, transparent, #7a200d, transparent);
    margin: 6px 0;
}

.stat-block-props {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    font-size: 12px;
}

.stat-block-props div {
    white-space: nowrap;
}

.stat-block-abilities {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    text-align: center;
    font-size: 12px;
}

.stat-block-abilities .ability {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-block-abilities .ability-label {
    font-weight: 700;
    font-size: 11px;
    color: #7a200d;
    text-transform: uppercase;
}

.stat-block-section {
    margin-top: 4px;
}

.stat-block-section .detail-label {
    font-weight: 700;
    color: #7a200d;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.stat-block-section p {
    margin: 0;
    font-size: 12px;
    white-space: pre-wrap;
}

/* Action buttons below stat block */
.enemy-stat-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.enemy-action-btn {
    flex: 1;
    font-size: 12px;
    padding: 6px 10px;
}

.btn-secondary {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

/* ---- Notebook (Old Book Theme) ---- */

/* Column + stretch so the book frame gets real height; center row layout left pages ~half width (NB-005) */
#notebook.letterhead-content {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    min-height: 0;
    height: 100%;
    padding: 8px;
    overflow: hidden;
    box-sizing: border-box;
}

/* NB-004: Pages vs session notes inside one Notebook letterhead */
.notebook-mode-bar {
    display: flex;
    flex-shrink: 0;
    gap: 6px;
    margin-bottom: 8px;
    padding: 4px;
    background: var(--bg-tertiary, #36393f);
    border-radius: var(--radius-sm, 6px);
    border: 1px solid var(--border, #40444b);
}

.notebook-mode-btn {
    flex: 1;
    padding: 8px 10px;
    font-family: var(--font, 'Inter', Arial, sans-serif);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary, #b9bbbe);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm, 4px);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.notebook-mode-btn:hover {
    color: var(--text-primary, #ffffff);
    background: var(--bg-hover, #3e4147);
}

.notebook-mode-btn.active {
    color: var(--text-primary, #ffffff);
    background: var(--accent, #7289da);
}

.notebook-mode-pane {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.notebook-mode-pane.hidden {
    display: none !important;
}

#notebook-session-notes-pane {
    padding-top: 4px;
    gap: 8px;
}

#notebook-session-notes-pane .session-notes-textarea {
    flex: 1;
    min-height: 140px;
    resize: vertical;
}

/* NB-003: #notebook alone beats .letterhead-content { display:none } — must hide when tab inactive */
#notebook.letterhead-content.hidden {
    display: none;
}

#notebook-book-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-width: none;
}

/* Leather book frame */
#notebook-book-frame {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1;
    width: 100%;
    min-height: 0;
    background: linear-gradient(135deg, #3b1f0e 0%, #5c3a1e 40%, #4a2c14 60%, #3b1f0e 100%);
    border-radius: 6px 14px 14px 6px;
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.6),
        0 2px 8px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.05),
        inset 0 -1px 0 rgba(0, 0, 0, 0.3);
    padding: 10px;
    overflow: hidden;
    box-sizing: border-box;
}

/* Book spine shadow */
#notebook-book-frame::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 10px;
    bottom: 10px;
    width: 28px;
    transform: translateX(-50%);
    background: linear-gradient(to right,
        rgba(0, 0, 0, 0.25) 0%,
        rgba(0, 0, 0, 0.08) 25%,
        transparent 45%,
        transparent 55%,
        rgba(0, 0, 0, 0.08) 75%,
        rgba(0, 0, 0, 0.25) 100%);
    pointer-events: none;
    z-index: 10;
}

/* StPageFlip container — flex child fills frame content box (NB-007) */
#notebook-flipbook {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    position: relative;
}

/* Individual book pages */
.notebook-page {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    box-sizing: border-box;
    background:
        linear-gradient(135deg, rgba(139, 109, 71, 0.1) 0%, transparent 50%),
        linear-gradient(225deg, rgba(139, 109, 71, 0.07) 0%, transparent 50%),
        linear-gradient(to bottom, #f4e4c1, #ecdbb0, #f0debb);
    box-shadow: inset 0 0 40px rgba(139, 109, 71, 0.12);
    font-family: 'IM Fell English', 'Crimson Text', Georgia, serif;
    color: #3b2a1a;
    overflow: hidden;
    position: relative;
}

/* Page number at bottom */
.notebook-page-number {
    position: absolute;
    bottom: 8px;
    z-index: 2;
    font-family: 'IM Fell English', Georgia, serif;
    font-size: 12px;
    color: rgba(59, 42, 26, 0.5);
    pointer-events: none;
    user-select: none;
}

.notebook-page-number.left {
    left: 16px;
}

.notebook-page-number.right {
    right: 16px;
}

/* Page title header */
.notebook-page-title {
    flex-shrink: 0;
    text-align: center;
    font-family: 'IM Fell English', Georgia, serif;
    font-size: 16px;
    font-weight: normal;
    font-style: italic;
    color: rgba(59, 42, 26, 0.7);
    padding: 8px 12px 4px;
    border-bottom: 1px solid rgba(139, 109, 71, 0.2);
    margin: 0 8px;
    pointer-events: none;
    user-select: none;
}

/* Fabric canvas: fills paper below title; matches PageFlip page bounds (NB-007) */
.notebook-page-canvas-wrap {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    box-sizing: border-box;
}

.notebook-page-canvas-wrap canvas {
    display: block;
}

/* ── Navigation buttons ── */

.notebook-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 56px;
    background: linear-gradient(to bottom, #5c3a1e, #4a2c14);
    color: #d4b896;
    border: 1px solid rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
    z-index: 20;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.notebook-nav-btn:hover {
    background: linear-gradient(to bottom, #7a5030, #5c3a1e);
    color: #f4e4c1;
}

.notebook-nav-btn:active {
    transform: translateY(-50%) scale(0.95);
}

#notebook-prev-page {
    left: -6px;
    border-radius: 4px 2px 2px 4px;
}

#notebook-next-page {
    right: -6px;
    border-radius: 2px 4px 4px 2px;
}

/* ── Floating toolbar ── */

#notebook-floating-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    margin-top: 8px;
    background: linear-gradient(to bottom, #e8d5a3, #d4b896);
    border: 1px solid rgba(139, 109, 71, 0.4);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
    flex-wrap: wrap;
    justify-content: center;
}

.nb-tool-btn {
    width: 32px;
    height: 30px;
    background: rgba(255, 255, 255, 0.3);
    color: #3b2a1a;
    border: 1px solid rgba(139, 109, 71, 0.3);
    border-radius: 4px;
    cursor: pointer;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
    padding: 0;
}

.nb-tool-btn .nb-tool-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    pointer-events: none;
}

.nb-tool-btn:focus-visible {
    outline: 2px solid #7a5030;
    outline-offset: 2px;
}

.nb-tool-btn--book {
    width: 34px;
}

.nb-tool-btn:hover {
    background: rgba(255, 255, 255, 0.55);
    border-color: rgba(139, 109, 71, 0.5);
}

.nb-tool-btn.active {
    background: rgba(90, 60, 30, 0.2);
    border-color: #7a5030;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
}

.nb-tool-btn.nb-tool-danger {
    color: #8b2500;
}

.nb-tool-btn.nb-tool-danger:hover {
    background: rgba(139, 37, 0, 0.15);
}

.nb-tool-separator {
    width: 1px;
    height: 22px;
    background: rgba(139, 109, 71, 0.35);
    margin: 0 2px;
}

#nb-tool-color {
    width: 28px;
    height: 28px;
    padding: 1px;
    border: 1px solid rgba(139, 109, 71, 0.4);
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
}

#nb-tool-size {
    width: 60px;
    accent-color: #7a5030;
}

/* ── Page indicator ── */

#notebook-page-indicator {
    margin-top: 6px;
    font-family: 'IM Fell English', Georgia, serif;
    font-size: 13px;
    color: var(--text-secondary, #b9bbbe);
    text-align: center;
    user-select: none;
    min-height: 18px;
}

/* ── Empty state ── */

.notebook-empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'IM Fell English', Georgia, serif;
    font-size: 16px;
    font-style: italic;
    color: #d4b896;
    text-align: center;
    pointer-events: none;
}

/* ── Snapshot picker overlay (reused) ── */

#notebook-snapshot-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

#notebook-snapshot-overlay .snapshot-panel {
    background: linear-gradient(to bottom, #f4e4c1, #e8d5a3);
    border: 2px solid #7a5030;
    border-radius: 8px;
    padding: 20px;
    max-width: 500px;
    width: 90%;
    max-height: 60vh;
    overflow-y: auto;
    color: #3b2a1a;
    font-family: 'Crimson Text', Georgia, serif;
}

#notebook-snapshot-overlay .snapshot-panel h3 {
    margin: 0 0 12px;
    font-family: 'IM Fell English', Georgia, serif;
    font-size: 18px;
}

#notebook-snapshot-overlay .snapshot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}

#notebook-snapshot-overlay .snapshot-thumb {
    cursor: pointer;
    border: 2px solid rgba(139, 109, 71, 0.4);
    border-radius: 4px;
    overflow: hidden;
    transition: border-color 0.15s;
}

#notebook-snapshot-overlay .snapshot-thumb:hover {
    border-color: #7a5030;
}

#notebook-snapshot-overlay .snapshot-thumb img {
    width: 100%;
    display: block;
}

#notebook-snapshot-overlay .snapshot-cancel {
    margin-top: 12px;
    padding: 6px 16px;
    background: #5c3a1e;
    color: #f4e4c1;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
    font-family: 'Crimson Text', Georgia, serif;
    font-size: 14px;
}

#notebook-snapshot-overlay .snapshot-cancel:hover {
    background: #7a5030;
}

/* ── Reduced motion ── */

@media (prefers-reduced-motion: reduce) {
    #notebook-flipbook,
    .notebook-page {
        transition: none !important;
        animation: none !important;
    }
}

/* ---- Call Panel (Voice/Video) ---- */

#call-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#call-panel.hidden {
    display: none;
}

.call-panel-heading {
    font-size: 14px;
    font-weight: 600;
    color: #dcddde;
    margin: 0 0 12px 0;
}

.call-action-btn {
    font-family: 'Inter', Arial, sans-serif;
    font-size: 13px;
    font-weight: 500;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    background-color: #43b581;
    color: #ffffff;
}

.call-action-btn:hover {
    background-color: #3ca374;
}

.call-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.call-join-btn-full {
    width: 100%;
    padding: 10px 16px;
    font-size: 14px;
}

.call-leave-btn {
    background-color: #f04747;
}

.call-leave-btn:hover {
    background-color: #d84040;
}

.call-connected-info {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
}

.call-connected-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #43b581;
}

.call-connected-label {
    font-size: 12px;
    font-weight: 500;
    color: #43b581;
}

.call-leave-sidebar-btn {
    width: 100%;
    padding: 10px 16px;
    font-size: 14px;
}

#video-strip {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 150px;
    z-index: 10;
    flex-direction: row;
    background: rgba(30, 33, 36, 0.88);
    border-top: 1px solid #40444b;
    overflow: hidden;
}

#jitsi-container {
    flex: 1;
    height: 100%;
    background-color: #1e2124;
    overflow: hidden;
}

#jitsi-container iframe {
    border: none;
    width: 100%;
    height: 100%;
}

.video-strip-leave-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    padding: 6px 12px;
    font-size: 12px;
}

.call-status-text {
    font-size: 12px;
    color: #72767d;
    margin-top: 6px;
    flex-shrink: 0;
}

.call-error-text {
    font-size: 12px;
    color: #f04747;
    line-height: 1.45;
    margin: 0 0 10px 0;
}

/* ---- Session notes (sidebar) ---- */
.session-notes-intro {
    font-size: 12px;
    color: #b9bbbe;
    margin: 0 0 10px 0;
    line-height: 1.4;
}

.session-notes-textarea {
    width: 100%;
    min-height: 200px;
    box-sizing: border-box;
    resize: vertical;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.45;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #40444b;
    background-color: #2f3136;
    color: #dcddde;
}

.session-notes-textarea:read-only {
    cursor: default;
}

.session-notes-status {
    font-size: 11px;
    color: #72767d;
    min-height: 1.2em;
    margin-top: 8px;
}

/* ---- Token Source Chooser Modal ---- */

.token-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.token-modal {
    background: var(--bg-secondary, #2c2f33);
    border: 1px solid var(--border, #40444b);
    border-radius: var(--radius, 8px);
    width: 560px;
    max-width: 95vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.token-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border, #40444b);
    flex-shrink: 0;
}

.token-modal-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #ffffff);
}

.token-modal-close {
    background: none;
    border: none;
    color: var(--text-muted, #72767d);
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 2px 6px;
    border-radius: var(--radius-sm, 4px);
}

.token-modal-close:hover {
    color: var(--text-primary, #ffffff);
    background: var(--bg-hover, #3e4147);
}

.token-modal-tabs {
    display: flex;
    gap: 2px;
    padding: 8px 12px 0;
    border-bottom: 1px solid var(--border, #40444b);
    flex-shrink: 0;
}

.token-modal-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    padding: 6px 14px;
    color: var(--text-muted, #72767d);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm, 4px) var(--radius-sm, 4px) 0 0;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.token-modal-tab:hover {
    color: var(--text-primary, #ffffff);
}

.token-modal-tab.active {
    color: var(--accent, #7289da);
    border-bottom-color: var(--accent, #7289da);
}

.token-modal-body {
    flex: 1;
    overflow: hidden;
    position: relative;
    min-height: 0;
}

.token-tab-panel {
    display: none;
    height: 100%;
    overflow-y: auto;
    padding: 16px;
    flex-direction: column;
    gap: 12px;
}

.token-tab-panel.active {
    display: flex;
}

/* Upload tab */
.token-upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 2px dashed var(--border, #40444b);
    border-radius: var(--radius, 8px);
    padding: 40px 20px;
    cursor: pointer;
    color: var(--text-muted, #72767d);
    font-size: 13px;
    transition: border-color 0.15s ease, color 0.15s ease;
    text-align: center;
    flex: 1;
}

.token-upload-area:hover {
    border-color: var(--accent, #7289da);
    color: var(--text-primary, #ffffff);
}

.token-upload-icon {
    font-size: 32px;
    line-height: 1;
}

.token-upload-hint {
    font-size: 11px;
    color: var(--text-muted, #72767d);
    margin-top: 4px;
}

/* Assets tab */
.token-asset-controls {
    flex-shrink: 0;
}

.token-filter-select {
    padding: 5px 8px;
    background: var(--bg-primary, #1e2124);
    color: var(--text-primary, #ffffff);
    border: 1px solid var(--border, #40444b);
    border-radius: var(--radius-sm, 4px);
    font-size: 12px;
    cursor: pointer;
    font-family: var(--font, 'Inter', Arial, sans-serif);
}

.token-asset-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
    align-content: start;
}

.token-asset-item {
    aspect-ratio: 1;
    border-radius: var(--radius-sm, 4px);
    border: 2px solid transparent;
    overflow: hidden;
    cursor: pointer;
    background: var(--bg-tertiary, #36393f);
    transition: border-color 0.15s ease, transform 0.1s ease;
}

.token-asset-item:hover {
    border-color: var(--accent, #7289da);
    transform: scale(1.04);
}

.token-asset-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Character tab */
.token-character-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.token-character-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-tertiary, #36393f);
    border-radius: var(--radius-sm, 4px);
    border: 1px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.token-character-item:hover {
    border-color: var(--accent, #7289da);
    background: var(--bg-hover, #3e4147);
}

.token-character-item img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border, #40444b);
    flex-shrink: 0;
}

.token-character-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.token-character-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary, #ffffff);
}

.token-character-note {
    font-size: 11px;
    color: var(--text-muted, #72767d);
}

.token-empty-state {
    color: var(--text-muted, #72767d);
    font-size: 13px;
    text-align: center;
    padding: 24px 0;
    width: 100%;
}

/* ============================================================
   Collapsible Panels
   ============================================================ */

/* --- Initiative Tracker — collapse up (max-height → 0) inside #left-panel --- */
#initiative-container {
    max-height: 45vh; /* keeps dice tray visible; finite value needed for collapse transition */
    transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.2s ease, margin 0.2s ease;
}
#initiative-container.panel-collapsed {
    max-height: 0 !important;
    opacity: 0;
    overflow: hidden !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* --- Map Toolbar — collapse up (max-height → 0) --- */
#map-toolbar {
    max-height: 200px;
    overflow: hidden;
    transition: max-height 0.3s ease, padding-top 0.2s ease,
                padding-bottom 0.2s ease, opacity 0.2s ease;
}
#map-toolbar.panel-collapsed {
    max-height: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    opacity: 0;
    pointer-events: none;
}

/* --- Dice Area — collapse down (max-height → 0) --- */
#dice-area-container.panel-collapsed {
    flex: 0 0 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

/* --- Shared collapse control icons (PanelManager in main.js) --- */
.panel-collapse-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}
.panel-collapse-icon .panel-chevron {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
}
#dice-area-header .panel-collapse-icon .panel-chevron {
    width: 14px;
    height: 14px;
}
#toolbar-collapse-btn .panel-collapse-icon .panel-chevron {
    width: 11px;
    height: 11px;
}

/* --- Vertical strip toggles (initiative / sidebar): chevron left/right --- */
.panel-collapse-vstrip {
    flex-shrink: 0;
    width: 14px;
    align-self: stretch;
    background: var(--bg-secondary, #2c2f33);
    border: none;
    border-left: 1px solid var(--border, #40444b);
    border-right: 1px solid var(--border, #40444b);
    cursor: pointer;
    color: var(--text-muted, #72767d);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
    padding: 0;
}
.panel-collapse-vstrip:hover {
    background: var(--bg-hover, #3e4147);
    color: var(--text-secondary, #b9bbbe);
}
.panel-collapse-vstrip:focus-visible {
    outline: 2px solid var(--accent, #5865f2);
    outline-offset: -2px;
    z-index: 1;
}

/* --- Horizontal strip toggle (map toolbar): chevron up/down --- */
#toolbar-collapse-btn {
    flex-shrink: 0;
    height: 13px;
    width: 100%;
    background: var(--bg-secondary, #2c2f33);
    border: none;
    border-bottom: 1px solid var(--border, #40444b);
    cursor: pointer;
    color: var(--text-muted, #72767d);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
    padding: 0;
}
#toolbar-collapse-btn:hover {
    background: var(--bg-hover, #3e4147);
    color: var(--text-secondary, #b9bbbe);
}
#toolbar-collapse-btn:focus-visible {
    outline: 2px solid var(--accent, #5865f2);
    outline-offset: -2px;
    z-index: 1;
}

/* --- Dice area header / toggle --- */
#dice-area-header {
    flex-shrink: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 10px;
    background: var(--bg-tertiary, #36393f);
    border: none;
    border-top: 1px solid var(--border, #40444b);
    cursor: pointer;
    color: var(--text-secondary, #b9bbbe);
    font-family: var(--font, 'Inter', Arial, sans-serif);
    font-size: 12px;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}
#dice-area-header:hover {
    background: var(--bg-hover, #3e4147);
    color: var(--text-primary, #ffffff);
}
#dice-area-header:focus-visible {
    outline: 2px solid var(--accent, #5865f2);
    outline-offset: -2px;
    z-index: 1;
}

/* --- Mobile: disable collapse behaviour on stacked layout --- */
@media (max-width: 768px) {
    .panel-collapse-vstrip,
    #toolbar-collapse-btn,
    #chat-panel-header,
    #dice-area-header {
        display: none;
    }
    #initiative-container.panel-collapsed {
        max-height: none !important;
        opacity: 1 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        flex: none !important;
        border-bottom: 1px solid var(--border, #40444b) !important;
    }
    #right-sidebar-main.panel-collapsed {
        width: auto !important;
        min-width: auto !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        flex: none !important;
        border-bottom: 1px solid var(--border, #40444b) !important;
        max-height: none !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }
    #map-toolbar.panel-collapsed,
    #dice-area-container.panel-collapsed,
    #chat-panel-container.panel-collapsed {
        max-height: none !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        padding: 5px 8px !important;
    }
}
