/* Console page styles. Tokens come from tokens.css; this file owns selectors
 * that used to live in per-template <style> blocks.
 *
 * Sections:
 *   1. Sortable tables (bestiary, llm)
 *   2. Spell effectiveness badges
 *   3. Map / dungeon / quest viz containers + legend
 *   4. SVG viz fills + strokes (driven by .viz-* classes on rects/circles)
 *   5. Death card + filmstrip
 *   6. LLM transcript modal
 *   7. Replay scrubber
 *   8. Timeline rows
 */

/* 1. Sortable tables --------------------------------------------------- */
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: " ⇅"; opacity: 0.4; }
th[data-sort].asc::after { content: " ↑"; opacity: 1; }
th[data-sort].desc::after { content: " ↓"; opacity: 1; }

/* 2. Spell effectiveness badges --------------------------------------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.8em;
  font-weight: bold;
  text-transform: uppercase;
}
.badge-high    { background: var(--color-status-in-progress); color: var(--color-on-accent); }
.badge-medium  { background: var(--color-warning); color: var(--color-on-accent); }
.badge-low     { background: var(--fg-secondary); color: var(--color-on-accent); }
.badge-broken  { background: var(--color-error); color: var(--color-white); }
.badge-unknown { background: var(--bg-elevated); color: var(--fg-muted); }

/* 3. Map / dungeon / quest viz containers ----------------------------- */
.map-container,
.quest-graph-container {
  overflow: hidden;
  border: 1px solid var(--border-default);
  cursor: grab;
  user-select: none;
  touch-action: none;
  width: 100%;
  position: relative;
  background: var(--bg-surface);
}
.map-container:active,
.quest-graph-container:active { cursor: grabbing; }

.map-inner,
.quest-graph-inner {
  position: absolute;
  transform-origin: 0 0;
}

/* Per-page sizing (each instance has a unique id). */
#floor-container        { max-width: 600px; height: 400px; }
#overworld-container    { max-width: 600px; height: 400px; }
#world-map-container    { max-width: 700px; height: 500px; }
#quest-graph-container  { max-width: 700px; height: 450px; }

/* Selectors / dropdowns above the viz. */
#dungeon-selector,
#floor-selector { margin: 0.5rem 0.5rem 0.5rem 0; }
.floor-view { margin-top: 0.5rem; }

/* Legend. */
.map-legend,
.quest-legend { font-size: 0.75rem; margin: 0.5rem 0; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 0.75rem;
}
.legend-swatch {
  width: 12px;
  height: 12px;
  display: inline-block;
  border: 1px solid var(--viz-swatch-border);
}
.quest-legend .legend-swatch { border: 0; border-radius: 50%; }

/* Per-swatch viz colors. Same tokens drive the inline SVG via the fill
 * rules in section 4. */
.legend-swatch.viz-wall            { background: var(--viz-wall); }
.legend-swatch.viz-chest           { background: var(--viz-chest); }
.legend-swatch.viz-stairs          { background: var(--viz-stairs); }
.legend-swatch.viz-damage          { background: var(--viz-damage); }
.legend-swatch.viz-blocker         { background: var(--viz-blocker); }
.legend-swatch.viz-tile-passable   { background: var(--viz-tile-passable); }
.legend-swatch.viz-marker          { background: var(--viz-marker); }
.legend-swatch.viz-path            { background: var(--viz-path); }
.legend-swatch.viz-quest-discovered { background: var(--viz-quest-discovered); }
.legend-swatch.viz-quest-active     { background: var(--viz-quest-active); }
.legend-swatch.viz-quest-completed  { background: var(--viz-quest-completed); }
.legend-swatch.viz-quest-failed     { background: var(--viz-quest-failed); }

/* 4. SVG viz fills + strokes ------------------------------------------ */
/* Apply via class= on the inline SVG elements; values come from tokens. */
.viz-bg              { fill: var(--viz-bg); }
.viz-wall            { fill: var(--viz-wall); }
.viz-chest           { fill: var(--viz-chest); }
.viz-stairs          { fill: var(--viz-stairs); }
.viz-damage          { fill: var(--viz-damage); }
.viz-blocker         { fill: var(--viz-blocker); }
.viz-tile-passable   { fill: var(--viz-tile-passable); }
.viz-tile-impassable { fill: var(--viz-tile-impassable); }
.viz-marker          { fill: var(--viz-marker); }
.viz-path            { fill: none; stroke: var(--viz-path); }
.viz-path-dot        { fill: var(--viz-path); }
.viz-edge            { stroke: var(--viz-edge); }
.viz-label           { fill: var(--viz-label); }
.viz-quest-discovered { fill: var(--viz-quest-discovered); }
.viz-quest-active     { fill: var(--viz-quest-active); }
.viz-quest-completed  { fill: var(--viz-quest-completed); }
.viz-quest-failed     { fill: var(--viz-quest-failed); }

/* 5. Death card + filmstrip ------------------------------------------- */
.death-card {
  border: 1px solid var(--border-default);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}
.death-card h3 { margin-top: 0; }
.filmstrip-img {
  max-width: 100%;
  image-rendering: pixelated;
  display: block;
  background: var(--bg-surface);
}
.filmstrip-controls {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-1);
}
.filmstrip-controls button { cursor: pointer; }
.filmstrip-indicator {
  color: var(--fg-secondary);
  font-family: var(--font-mono);
  font-size: 0.85em;
}
.death-analysis {
  font-style: italic;
  color: var(--fg-secondary);
  margin-top: var(--space-2);
}

/* 6. LLM transcript modal --------------------------------------------- */
#llm-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  justify-content: center;
  align-items: flex-start;
  padding-top: 5vh;
}
#llm-modal-overlay.open { display: flex; }
#llm-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  padding: var(--space-4);
  max-width: 90vw;
  width: 800px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}
#llm-modal-close {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  cursor: pointer;
}
#llm-modal-body pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 0.85em;
}
.llm-table-row { cursor: pointer; }
.llm-table-row:hover { background: var(--bg-hover); }

/* 7. Replay scrubber -------------------------------------------------- */
#replay-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
#replay-img {
  max-width: 100%;
  image-rendering: pixelated;
  background: var(--bg-surface);
}
#replay-controls {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
#replay-controls button {
  padding: var(--space-1) var(--space-2);
  cursor: pointer;
}
#replay-scrubber-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
#replay-scrubber { flex: 1; }
#replay-indicator {
  color: var(--fg-secondary);
  font-family: var(--font-mono);
  margin: 0;
}
#export-section { margin-top: var(--space-4); }
#export-status {
  color: var(--fg-secondary);
  font-family: var(--font-mono);
}

/* 8. Timeline rows ---------------------------------------------------- */
#timeline-filters {
  margin-bottom: var(--space-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: flex-end;
}
#timeline-filters label {
  display: flex;
  flex-direction: column;
  font-size: 0.85em;
  gap: 2px;
}
#timeline-filters input {
  padding: 2px 4px;
  font-family: var(--font-mono);
}
#timeline-list { list-style: none; padding: 0; margin: 0; }
.tl-row {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  border-bottom: 1px solid var(--border-default);
  padding: var(--space-2) 0;
  cursor: pointer;
}
.tl-row:hover { background: var(--bg-hover); }
.tl-thumb {
  width: 64px;
  height: 48px;
  object-fit: contain;
  background: var(--viz-bg);
  flex-shrink: 0;
}
.tl-thumb-placeholder {
  width: 64px;
  height: 48px;
  background: var(--bg-elevated);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-muted);
  font-size: 0.7em;
}
.tl-meta { flex: 1; min-width: 0; }
.tl-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.75em;
  font-family: var(--font-mono);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  margin-right: var(--space-2);
}
.tl-ts,
.tl-frame {
  font-size: 0.8em;
  color: var(--fg-muted);
}
.tl-payload {
  display: none;
  font-family: var(--font-mono);
  font-size: 0.8em;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  padding: var(--space-2);
  margin-top: var(--space-2);
}
.tl-row.expanded .tl-payload { display: block; }
#tl-load-more { margin-top: var(--space-4); }
