/* ==========================================================================
   Mapwright Design System — Base, Reset, Typography & Layout
   ========================================================================== */

:root {
  color-scheme: dark;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);

  /* Obsidian & Eldritch Brass Unified Palette */
  --bg: #090d14;
  --canvas: #06090e;
  --panel: rgba(13, 19, 28, 0.90);
  --panel2: rgba(20, 29, 42, 0.95);
  --panel-solid: #0f1622;
  --panel2-solid: #151f2e;
  --line: rgba(200, 166, 104, 0.22);
  --line-subtle: rgba(255, 255, 255, 0.07);
  --fg: #e8eef5;
  --muted: #8b9bb0;
  --brass: #c8a668;
  --brass-bright: #e2c084;
  --brass-glow: rgba(200, 166, 104, 0.32);
  --accent: #2dd4bf;
  --accent-fg: #061116;
  --danger: #ef4444;
  --hp-ok: #10b981;

  /* Unified Architectural Geometry */
  --r-lg: 12px;     /* Модальные окна и крупные панели (#side, .sheet-modal-card, .lobby-box) */
  --r-panel: 10px;  /* Все плавающие HUD-блоки (.top, .tools, .right-dock, .init-strip, .hud-hero-pill, .hud-hotbar, .dicetray, .dice-input-capsule, .zoom-stack, .hud-pill) */
  --r-item: 7px;    /* Внутренние карточки, кнопки, чипы инициативы (.init-chip, .init-round, .btn, .tool, .dock-btn, .actor-card, .combat-row, .map-card) */
  --r-sm: 5px;      /* Инпуты, мелкие кнопки .btn.xs, теги и бейджи */

  /* Unified Glass & Shadow */
  --hud-shadow: 0 10px 28px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.06);

  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}

/* Base Reset & Typography */
* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  padding-inline: 0;
  overflow: hidden;
}

img {
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body, .app, .stage, #cv {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}
#cv::selection, .stage::selection {
  background: transparent;
}

input, textarea, [contenteditable="true"], .compendium-card-desc, .ttg-spell-desc {
  -webkit-user-select: text;
  user-select: text;
}

/* App Canvas & Layout */
.app {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  min-width: 0;
  min-height: 0;
  background: var(--canvas);
  overflow: hidden;
}

#cv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  display: block;
  cursor: grab;
}

#cv:active {
  cursor: grabbing;
}

/* Screen Reader Utility */
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Glassmorphism Floating Panels */
.tools, .side, .dicebar, .dicetray, .sidetoggle {
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--line);
  box-shadow: var(--hud-shadow);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .tools, .side, .dicebar, .dicetray, .sidetoggle {
    background: var(--panel);
  }
}

/* Floating Panels Glare & Elevation */
.top, .tools, .right-dock, .side, .hud-hero-pill, .hud-hotbar, .init-strip, .dicetray, .dice-input-capsule, .zoom-stack, .hud-pill {
  box-shadow: var(--hud-shadow);
}

/* Sections & Form Elements */
.sec h3 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sec h3.dm {
  color: var(--brass);
}

.sec h3 .end {
  margin-left: auto;
  text-transform: none;
  letter-spacing: 0;
}

.tgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.hint {
  font-size: 12.5px;
  color: var(--muted);
  margin: 8px 0 0;
}

.row2 {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.field label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

.inp {
  width: 100%;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm, 5px);
  padding: 6px 8px;
}

.inp:focus {
  border-color: var(--accent);
}

textarea.inp {
  min-height: 84px;
  resize: vertical;
}

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

.fgrid .wide {
  grid-column: 1 / -1;
}

.fgrid .two {
  grid-column: span 2;
}

.chk {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
}

.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 6px 2px;
}

/* Collapsible Section Toggles */
.fold {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  font-weight: inherit;
  text-align: left;
  cursor: pointer;
}

.fold .car {
  font-style: normal;
  display: inline-block;
  font-size: 12px;
  transition: transform .15s;
}

.fold[aria-expanded="false"] .car {
  transform: rotate(-90deg);
}

.sec h3 .fold {
  flex: 1;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
