/* =============================================================================
   Sheet Renderer — Item & Condition Cards
   Matches the Mausritter book's card layout design.
   Mausritter item art by Isaac Williams, licensed CC-BY.
   ============================================================================= */

/* ---------------------------------------------------------------------------
   Item Card — base structure
   --------------------------------------------------------------------------- */
.sr-item-card {
  background: var(--sr-card-bg, #000);
  border: 1.5px solid var(--border-primary, #2a2a2a);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: default;
  transition: border-color 0.15s, box-shadow 0.15s;
  height: 100%;
}
.sr-item-card:hover {
  border-color: var(--border-secondary, #444);
}
.sr-item-card.draggable {
  cursor: grab;
}
.sr-item-card.draggable:active {
  cursor: grabbing;
}

/* Card header — name + stat box */
.sr-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 6px;
  min-height: 1.4em;
}
.sr-card-name {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-primary, #e8e8e8);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  text-transform: capitalize;
}

/* Stat box — damage die or armor def */
.sr-card-stat {
  font-size: 0.6rem;
  font-weight: 700;
  padding: 1px 4px;
  border: 1px solid var(--border-primary, #2a2a2a);
  border-radius: 2px;
  white-space: nowrap;
  margin-left: 4px;
  flex-shrink: 0;
}
.sr-stat-damage {
  color: var(--error, #f87171);
  border-color: var(--error, #f87171);
}
.sr-stat-armor {
  color: var(--info, #60a5fa);
  border-color: var(--info, #60a5fa);
}

/* Divider */
.sr-card-divider {
  margin: 0;
  border: none;
  border-top: 1px solid var(--border-primary, #2a2a2a);
}

/* Dots row — usage dots + stat box on same line */
.sr-card-dots-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 6px;
}

/* Usage dots */
.sr-usage-dots {
  display: flex;
  gap: 3px;
}
.sr-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid var(--text-muted, #808080);
  background: transparent;
  cursor: pointer;
  transition: background 0.1s;
}
.sr-dot.filled {
  background: var(--text-muted, #808080);
}
.sr-dot:hover {
  border-color: var(--text-primary, #e8e8e8);
}

/* Card body — icon fills the space, overlay content on top */
.sr-card-body {
  flex: 1;
  position: relative;
  display: flex;
  min-height: 60px;
}

/* Icon — fills the card body. Source PNGs are alpha-only (line shape on
   transparent); rendered via CSS mask-image so the line color comes from
   `background-color: var(--text-primary)` and theme-switches automatically.
   The element is a <span> with `--icon-mask: url("/path/icon.png")` set
   inline; per-icon CSS rules aren't needed. */
.sr-card-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  height: 80%;
  background-color: var(--text-primary);
  -webkit-mask: var(--icon-mask) center/contain no-repeat;
          mask: var(--icon-mask) center/contain no-repeat;
  pointer-events: none;
}

html[data-theme="light"] .sr-item-card {
  background: var(--sr-card-bg-light, #fff);
}
@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) .sr-item-card {
    background: var(--sr-card-bg-light, #fff);
  }
}

/* Overlay — dots, stat, footer sit on top of icon */
.sr-card-overlay {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.sr-card-spacer {
  flex: 1;
}

/* Footer — type label, left justified, no top border */
.sr-card-footer {
  font-size: 0.55rem;
  color: var(--text-muted, #808080);
  text-align: left;
  padding: 2px 6px 4px;
  text-transform: capitalize;
}

/* ---------------------------------------------------------------------------
   Condition Card
   --------------------------------------------------------------------------- */
.sr-condition-card {
  background: var(--bg-secondary, #0a0a0a);
  border: 1.5px solid var(--warning, #fbbf24);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  height: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.sr-condition-card:hover {
  border-color: var(--error, #f87171);
  box-shadow: 0 0 6px rgba(251, 191, 36, 0.2);
}

.sr-condition-card .sr-card-header {
  background: rgba(251, 191, 36, 0.1);
}
.sr-condition-card .sr-card-name {
  color: var(--warning, #fbbf24);
}
.sr-condition-card .sr-card-divider {
  border-color: var(--warning, #fbbf24);
  opacity: 0.3;
}

.sr-cond-effect {
  font-size: 0.55rem;
  font-style: italic;
  color: var(--text-secondary, #b0b0b0);
  padding: 4px 6px;
  flex: 1;
  line-height: 1.3;
}
.sr-cond-clear {
  font-size: 0.55rem;
  color: var(--text-muted, #808080);
  padding: 2px 6px 4px;
  border-top: 1px solid rgba(251, 191, 36, 0.15);
}
.sr-cond-clear strong {
  color: var(--text-secondary, #b0b0b0);
}
.sr-cond-remove {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 0.7rem;
  color: var(--text-muted, #808080);
  opacity: 0;
  transition: opacity 0.15s;
}
.sr-condition-card:hover .sr-cond-remove {
  opacity: 1;
}

/* Condition color variants */
.sr-cond-exhausted { border-color: #a78bfa; }
.sr-cond-exhausted .sr-card-header { background: rgba(167, 139, 250, 0.1); }
.sr-cond-exhausted .sr-card-name { color: #a78bfa; }

.sr-cond-frightened { border-color: #fbbf24; }

.sr-cond-hungry { border-color: var(--wound-orange); }
.sr-cond-hungry .sr-card-header { background: rgba(251, 146, 60, 0.1); }
.sr-cond-hungry .sr-card-name { color: var(--wound-orange); }

.sr-cond-injured { border-color: #f87171; }
.sr-cond-injured .sr-card-header { background: rgba(248, 113, 113, 0.1); }
.sr-cond-injured .sr-card-name { color: #f87171; }

.sr-cond-drained { border-color: #94a3b8; }
.sr-cond-drained .sr-card-header { background: rgba(148, 163, 184, 0.1); }
.sr-cond-drained .sr-card-name { color: #94a3b8; }

/* ---------------------------------------------------------------------------
   Empty Slot
   --------------------------------------------------------------------------- */
.sr-empty-slot {
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  height: 100%;
}
.sr-slot-label {
  font-size: 0.55rem;
  color: var(--text-disabled, #666);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------------------------------------------------------------------------
   Resource Pool Bar
   --------------------------------------------------------------------------- */
.sr-resource-pool {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
}
.sr-pool-name {
  font-size: 0.8rem;
  color: var(--text-secondary, #b0b0b0);
  min-width: 3em;
}
.sr-pool-value {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary, #e8e8e8);
}

/* ---------------------------------------------------------------------------
   Resolution Saves — spaced section + hint text
   --------------------------------------------------------------------------- */
.cs-saves-section-spaced {
  margin-top: 0.75rem;
}
.cs-saves-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ---------------------------------------------------------------------------
   Mode Toggle — Session / Downtime
   --------------------------------------------------------------------------- */
.cs-mode-toggle {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

/* ---------------------------------------------------------------------------
   Condition Management — Downtime Mode
   --------------------------------------------------------------------------- */
.cs-condition-manage {
  padding: 0.5rem 0;
}
.cs-condition-manage .cs-section-title {
  margin-bottom: 0.5rem;
}

/* Slot-based: grid of condition cards with remove */
.cs-condition-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.cs-condition-empty {
  font-size: 0.8rem;
  color: var(--text-muted, #808080);
  padding: 0.5rem 0;
  font-style: italic;
}

.cs-condition-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

/* Phase 4: compact-mode header for flag-based panels (5E SRD's 15-item list).
   Title row with optional active-count + Manage/Hide chevron button. */
.cs-condition-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.cs-condition-active-count {
  font-size: 0.85rem;
  font-weight: normal;
  color: var(--text-secondary, #b0b0b0);
}

/* Active-condition badges shown in collapsed state — quick "what's on" view
   with click-to-remove. */
.cs-condition-active-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}
.cs-condition-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: var(--warning, #fbbf24);
  cursor: pointer;
  transition: background 0.15s;
}
.cs-condition-badge:hover {
  background: rgba(251, 191, 36, 0.22);
}

/* Flag-based: checklist of togglable conditions */
.cs-condition-checklist {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.cs-condition-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
}
.cs-condition-item:hover {
  background: var(--bg-hover, #242424);
}
.cs-condition-item.cs-condition-active {
  background: rgba(251, 191, 36, 0.08);
  border-color: rgba(251, 191, 36, 0.25);
}

.cs-condition-checkbox {
  font-size: 1.1rem;
  color: var(--text-muted, #808080);
  flex-shrink: 0;
  width: 1.2em;
  text-align: center;
}
.cs-condition-active .cs-condition-checkbox {
  color: var(--warning, #fbbf24);
}

.cs-condition-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary, #e8e8e8);
  flex-shrink: 0;
}
.cs-condition-active .cs-condition-name {
  color: var(--warning, #fbbf24);
}

.cs-condition-effect {
  font-size: 0.7rem;
  color: var(--text-secondary, #b0b0b0);
  font-style: italic;
}

/* =============================================================================
   Mobile Responsive — Sheet Renderer
   ============================================================================= */

/* --- Tablet (768px) --- */
@media (max-width: 768px) {
  /* Mode toggle: full width buttons */
  .cs-mode-toggle {
    gap: 0.35rem;
  }
  .cs-mode-toggle .button {
    flex: 1;
    text-align: center;
  }

  /* Condition card grid: 2 columns */
  .cs-condition-card-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Condition checklist: ensure touch targets */
  .cs-condition-item {
    padding: 0.5rem;
    min-height: 44px;
  }

  /* Condition action buttons: wrap tightly */
  .cs-condition-actions .button {
    min-height: 44px;
  }

  /* Resource pool: items don't overflow */
  .sr-resource-pool {
    flex-wrap: wrap;
  }
}

/* --- Phone (480px) --- */
@media (max-width: 480px) {
  /* Mode toggle: full width, stacked */
  .cs-mode-toggle {
    flex-direction: column;
    gap: 0.35rem;
  }
  .cs-mode-toggle .button {
    width: 100%;
    min-height: 44px;
    font-size: 0.9rem;
  }

  /* Item cards: slightly larger text for readability */
  .sr-card-name {
    font-size: 0.7rem;
  }
  .sr-card-stat {
    font-size: 0.65rem;
  }

  /* Condition cards: single column */
  .cs-condition-card-grid {
    grid-template-columns: 1fr;
  }

  /* Condition actions: full width buttons */
  .cs-condition-actions {
    flex-direction: column;
  }
  .cs-condition-actions .button {
    width: 100%;
    min-height: 44px;
    text-align: center;
  }

  /* Condition checklist items: generous touch targets */
  .cs-condition-item {
    padding: 0.6rem 0.5rem;
    min-height: 48px;
  }
  .cs-condition-checkbox {
    font-size: 1.3rem;
  }
  .cs-condition-name {
    font-size: 0.85rem;
  }

  /* Condition manage section: full width clear button */
  .cs-condition-manage .button.danger {
    width: 100%;
    min-height: 44px;
    text-align: center;
    margin-top: 0.5rem;
  }

  /* Usage dots: larger touch targets */
  .sr-dot {
    width: 14px;
    height: 14px;
  }

  /* Condition card remove: always visible on mobile (no hover) */
  .sr-cond-remove {
    opacity: 1;
  }

  /* Attribute pool save button: ensure touch target */
  .attr-save-btn {
    min-height: 44px;
    min-width: 3.5rem;
    font-size: 0.75rem;
  }

  /* Attribute pool rows: allow wrapping on narrow screens */
  .attr-pool-row {
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  /* STR save prompt: stack vertically */
  .str-save-prompt {
    flex-wrap: wrap;
    gap: 0.35rem;
  }
  .str-save-prompt .button {
    min-height: 44px;
  }

  /* STR save result card: wrap on narrow screens */
  .str-save-result-card {
    flex-wrap: wrap;
    gap: 0.25rem;
  }
}
