/**
 * ============================================================================
 * JOYFUL-FERMI D&D 3.5e — CANONICAL CSS DESIGN TOKENS & THEME SYSTEM (R2)
 * ============================================================================
 * Provides CSS Custom Properties for the dark Slate/Indigo/Emerald/Amber/
 * Purple/Rose/Sky palette, 4-tier button dimensions, domain tab theme tokens,
 * and Play vs. Build mode visibility rules.
 * ============================================================================
 */

:root {
  /* Core Surfaces & Backgrounds */
  --bg-page: #080e1e;
  --bg-page-wallpaper: #050811;
  --bg-card: #0f172a;
  --bg-card-translucent: rgba(15, 23, 42, 0.90);
  --bg-surface: #020617;
  --bg-elevated: #1e293b;
  --border-subtle: #1e293b;
  --border-default: #334155;
  --border-strong: #475569;

  /* Typography Palette */
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  /* Semantic Domain Accents */
  --accent-indigo: #6366f1;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-purple: #a855f7;
  --accent-rose: #f43f5e;
  --accent-sky: #0ea5e9;
  --accent-cyan: #06b6d4;

  /* Canonical 4-Tier Button & Input Dimensions */
  --btn-md-h: 2.25rem;
  --btn-sm-h: 1.75rem;
  --btn-xs-h: 1.5rem;
  --btn-icon-sm: 1.5rem;
  --input-md-h: 2rem;
  --input-sm-h: 1.75rem;

  /* Default Domain Theme Variables */
  --theme-accent: #6366f1;
  --theme-border: rgba(99, 102, 241, 0.40);
  --theme-badge-bg: #1e1b4b;
  --theme-badge-text: #a5b4fc;
}

/* Domain Theme Scopes */
[data-theme="combat"] {
  --theme-accent: #f43f5e;
  --theme-border: rgba(244, 63, 94, 0.40);
  --theme-badge-bg: #4c0519;
  --theme-badge-text: #fda4af;
}

[data-theme="spells"] {
  --theme-accent: #a855f7;
  --theme-border: rgba(168, 85, 247, 0.40);
  --theme-badge-bg: #3b0764;
  --theme-badge-text: #d8b4fe;
}

[data-theme="inventory"] {
  --theme-accent: #f59e0b;
  --theme-border: rgba(245, 158, 11, 0.40);
  --theme-badge-bg: #451a03;
  --theme-badge-text: #fcd34d;
}

[data-theme="char"] {
  --theme-accent: #0ea5e9;
  --theme-border: rgba(14, 165, 233, 0.40);
  --theme-badge-bg: #082f49;
  --theme-badge-text: #7dd3fc;
}

/* Sheet Mode Visibility Rules (Play vs. Build) */
[data-sheet-mode="play"] [data-mode-only="build"],
body[data-sheet-mode="play"] [data-mode-only="build"] {
  display: none !important;
}

[data-sheet-mode="build"] [data-mode-only="play"],
body[data-sheet-mode="build"] [data-mode-only="play"] {
  display: none !important;
}

/* Canonical 4-Tier UI Button & Input Utility Classes (1:1 parity with index.html) */
:where(.ui-btn-md, .ui-btn-sm, .ui-btn-xs, .ui-btn-icon, .ui-btn-icon-sm) { display: inline-flex; }
.ui-btn-md { height: 2.25rem; padding-left: 0.75rem; padding-right: 0.75rem; border-radius: 0.5rem; font-size: 0.75rem; font-weight: 700; align-items: center; justify-content: center; gap: 0.375rem; line-height: 1; white-space: nowrap; transition: all 0.15s ease; cursor: pointer; }
.ui-btn-sm { height: 1.75rem; padding-left: 0.625rem; padding-right: 0.625rem; border-radius: 0.375rem; font-size: 0.6875rem; font-weight: 700; align-items: center; justify-content: center; gap: 0.25rem; line-height: 1; white-space: nowrap; transition: all 0.15s ease; cursor: pointer; }
.ui-btn-xs { height: 1.5rem; padding-left: 0.5rem; padding-right: 0.5rem; border-radius: 0.25rem; font-size: 0.625rem; font-weight: 700; align-items: center; justify-content: center; gap: 0.25rem; line-height: 1; white-space: nowrap; transition: all 0.15s ease; cursor: pointer; }
.ui-btn-icon { width: 1.75rem; height: 1.75rem; padding: 0; border-radius: 0.375rem; font-size: 0.75rem; font-weight: 700; align-items: center; justify-content: center; flex-shrink: 0; line-height: 1; transition: all 0.15s ease; cursor: pointer; }
.ui-btn-icon-sm { width: 1.5rem; height: 1.5rem; padding: 0; border-radius: 0.375rem; font-size: 0.75rem; font-weight: 700; align-items: center; justify-content: center; flex-shrink: 0; line-height: 1; transition: all 0.15s ease; cursor: pointer; }
.ui-input-md { height: 2rem; border-radius: 0.5rem; font-size: 0.75rem; line-height: 1; }
.ui-input-sm { height: 1.75rem; border-radius: 0.375rem; font-size: 0.75rem; line-height: 1; }

/* Canonical Ability Score Grid Order:
 * Mobile (<640px, 1-col): STR, DEX, CON, INT, WIS, CHA top-to-bottom.
 * Desktop (>=640px, 2-col): Col 1 = STR/DEX/CON, Col 2 = INT/WIS/CHA via grid-auto-flow: column.
 */
#stat-picker-options-grid {
  grid-template-rows: repeat(3, minmax(0, 1fr));
  grid-auto-flow: column;
}
@media (min-width: 640px) {
  #manual-stats-container,
  #pointbuy-stats-container,
  #rolled-assign-container {
    grid-template-rows: repeat(3, minmax(0, 1fr));
    grid-auto-flow: column;
  }
}

/* Item description tooltip (Inventory rows): summary line is the trigger; the full text renders in one
 * viewport-fixed panel (char_inventory.js initItemDescTooltip) so overflow containers never clip it. */
.ui-desc-tip-trigger { cursor: help; text-decoration: underline dotted var(--border-strong); text-underline-offset: 2px; }
.ui-desc-tip-trigger:focus-visible, [data-desc-tip]:focus-visible { outline: 1px solid var(--accent-amber); outline-offset: 1px; border-radius: 0.125rem; }
.ui-desc-tooltip { position: fixed; z-index: 250; max-width: min(28rem, calc(100vw - 1rem)); max-height: 75vh; overflow: hidden; padding: 0.5rem 0.625rem; background: var(--bg-surface); border: 1px solid var(--border-strong); border-radius: 0.5rem; color: var(--text-secondary); font-size: 0.6875rem; line-height: 1.45; white-space: normal; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.55); pointer-events: none; }
.ui-desc-tooltip[hidden] { display: none; }

/* Sticky Live HUD Bar (Shown on scroll past top Vitals HUD) */
.calm-sticky-hud {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 42;
  background: rgba(8, 14, 30, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(51, 65, 85, 0.65);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.48);
  transform: translateY(-110%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.18s ease, opacity 0.16s ease;
}
.calm-sticky-hud.is-visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.calm-sticky-inner {
  max-width: 80rem;
  margin: 0 auto;
  padding: 6px 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
@media (min-width: 768px) {
  .calm-sticky-inner {
    padding: 6px 32px;
  }
}
.calm-sticky-inner::-webkit-scrollbar { display: none; }
.calm-sticky-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #131c2e;
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}
.calm-sticky-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  background: #162033;
  border: 1px solid rgba(148, 163, 184, 0.22);
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.calm-sticky-btn:hover {
  background: #1e293b;
  border-color: rgba(148, 163, 184, 0.4);
  color: #f8fafc;
}
