/* Treatise-specific styles: layer toggle, part headers, equations */

/* Section dividers */
section + section {
  border-top: 1px solid var(--border);
}

/* Permalink headings */
h2 .section-link {
  color: inherit;
  text-decoration: none;
}

h2 .section-link:hover {
  color: var(--accent);
}


/* Progressive disclosure — inline collapsible blocks.
   Blocks start collapsed (CSS default); JS adds .layer-open to expand. */
.math,
.code-detail {
  height: 0;
  overflow: hidden;
  margin: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-left-color: transparent;
  opacity: 0;
  transition: height 0.3s ease, opacity 0.2s ease, margin 0.3s ease,
              padding 0.3s ease, border-left-color 0.3s ease;
}

.math.layer-open,
.code-detail.layer-open {
  opacity: 1;
  overflow: visible;
  transition: height 0.3s ease, opacity 0.2s ease 0.05s;
}

/* Full-width toggle bar */
.layer-toggle {
  display: flex;
  align-items: center;
  gap: 0.4em;
  width: 100%;
  font-family: var(--font-serif);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: none;
  border: none;
  border-left: 2px solid var(--border);
  padding: 0.3rem 0 0.3rem 1rem;
  cursor: pointer;
  margin: 0.25rem 0;
  transition: color 0.15s, border-left-color 0.15s;
}

.layer-toggle[data-layer="3"] {
  border-left-color: var(--text-muted);
}

.layer-toggle:hover {
  color: var(--accent);
  border-left-color: var(--accent);
}

.layer-toggle .toggle-arrow {
  display: inline-block;
  transition: transform 0.3s ease;
  font-size: 0.55rem;
}

.layer-toggle.expanded .toggle-arrow {
  transform: rotate(90deg);
}

.layer-toggle.expanded {
  border-left-color: var(--accent);
  margin-bottom: 0;
}

/* Part headers */
.part-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin: 4rem 0 0.5rem;
  padding-top: 2rem;
  border-top: 2px solid var(--accent);
  font-weight: 600;
}

.part-title + h2 {
  margin-top: 0.25rem;
}

/* Equations (KaTeX rendered at build time) */
.equation {
  padding: 0.85rem 1.2rem;
  margin: 0.75rem 0;
  background: var(--bg-alt);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
  overflow-x: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.equation .katex {
  font-size: 1.3em;
  color: var(--text);
}

.equation .katex-error {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* Layer content markers */
.math, .code-detail {
  border-left: 2px solid var(--border);
  padding-left: 1rem;
  margin: 0.75rem 0;
}

.code-detail {
  border-left-color: var(--text-muted);
}

/* Pre blocks for code layer */
.code-detail pre {
  background: var(--bg-alt);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  overflow: visible;
  font-size: 0.8rem;
  line-height: 1.5;
}

.code-detail pre code {
  background: none;
  padding: 0;
}

/* Reset code-detail pre styles inside code-cards (code-card owns its own layout) */
.code-detail .code-card pre {
  padding: 0.3rem 0;
  border-radius: 0;
  font-size: inherit;
  line-height: 1;
}

/* Key insight / info callout */
.insight,
.acknowledgment {
  background: var(--bg-alt);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
  border-left: 4px solid var(--accent);
  font-size: 0.92rem;
  line-height: 1.6;
}

.insight strong:first-child,
.acknowledgment strong:first-child {
  color: var(--accent);
}

.acknowledgment strong {
  display: block;
  margin-bottom: 0.4rem;
}

.acknowledgment a,
.insight a {
  color: var(--accent);
}

/* ===== Widget Solver Interactive ===== */
.widget-solver {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.widget-solver-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  gap: 0.75rem;
}

.widget-solver-state {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.widget-solver-state .ev-value {
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.widget-mode-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
  flex-shrink: 0;
}

.widget-mode-toggle button {
  font-family: var(--font-serif);
  font-size: 0.7rem;
  padding: 0.2rem 0.6rem;
  border: none;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.widget-mode-toggle button + button {
  border-left: 1px solid var(--border);
}

.widget-mode-toggle button.active {
  background: var(--accent-light);
  color: var(--text);
  font-weight: 600;
}

/* Flow: vertical stack of compact rows */
.widget-turn-flow {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

/* Each stage: single-line row with label + content + ev */
.widget-stage {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.3rem 0.6rem;
  border-left: 3px solid transparent;
  min-height: 44px;
  transition: border-left-color 0.3s, background 0.3s;
}

.widget-stage.chance {
  background: var(--bg-alt);
  border-left-color: var(--border);
}

.widget-stage.decision {
  background: var(--accent-light);
  border-left-color: var(--accent);
}

.widget-stage.highlighted {
  border-left-width: 4px;
  border-left-color: var(--accent);
  box-shadow: inset 4px 0 8px -4px rgba(243, 112, 33, 0.25);
}

/* Stage: categories get column layout */
.widget-stage.categories {
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0.4rem 0.6rem;
}

.widget-stage-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 5rem;
  flex-shrink: 0;
}

/* Thin separator between stages */
.widget-stage + .widget-stage {
  border-top: 1px solid var(--border);
}

/* Dice row: inline, 32px dice */
.widget-dice-row {
  display: flex;
  gap: 4px;
  align-items: center;
}

.widget-dice-row .die-svg {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}

.widget-dice-row .die-svg.rerolling {
  opacity: 0.35;
}

.widget-dice-row .die-svg.clickable {
  cursor: pointer;
}

.widget-dice-row .die-svg.clickable:hover {
  transform: scale(1.1);
}

.widget-dice-separator {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 2px;
  flex-shrink: 0;
}

.widget-ev-badge {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  margin-left: auto;
  white-space: nowrap;
  flex-shrink: 0;
}

.widget-ev-badge.optimal {
  color: var(--accent);
  font-weight: 600;
}

/* Category rows: compact */
.widget-category-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
}

.widget-category-row {
  display: flex;
  align-items: center;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  border-left: 2px solid transparent;
  font-size: 0.75rem;
  transition: background 0.12s;
}

.widget-category-row.interactive {
  cursor: pointer;
}

.widget-category-row.interactive:hover {
  background: rgba(128, 128, 128, 0.08);
}

.widget-category-row.optimal {
  background: rgba(243, 112, 33, 0.08);
  border-left-color: var(--accent);
}

.widget-category-row.selected {
  background: rgba(243, 112, 33, 0.08);
  border-left-color: var(--accent);
  font-weight: 600;
}

.widget-category-name {
  flex: 1;
  min-width: 0;
}

.widget-category-score {
  font-variant-numeric: tabular-nums;
  min-width: 3.5rem;
  text-align: right;
  color: var(--text-muted);
}

.widget-category-ev {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  min-width: 4rem;
  text-align: right;
}

.widget-optimal-star {
  color: var(--accent);
  margin-left: 0.25rem;
}

.widget-selected-marker {
  color: var(--text-muted);
  margin-left: 0.25rem;
  font-size: 0.65rem;
  font-style: italic;
}

/* Explain panel */
.widget-explain-panel {
  border-left: 3px solid var(--accent);
  padding: 0.5rem 0.75rem;
  margin-top: 0.4rem;
  font-size: 0.8rem;
  line-height: 1.45;
  background: var(--accent-light);
  border-radius: 0 6px 6px 0;
}

/* Action bar */
.widget-action-bar {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
  align-items: center;
}

.widget-action-bar button {
  font-family: var(--font-serif);
  font-size: 0.75rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.widget-action-bar button:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.widget-action-bar button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.widget-action-bar button.primary:hover {
  opacity: 0.9;
}

.widget-action-bar .ev-delta {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  margin-left: auto;
}

/* Fallback + loading */
.widget-api-fallback {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.75rem;
  text-align: center;
  background: var(--bg-alt);
  border-radius: 6px;
}

.widget-api-fallback code {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--bg);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
}

.widget-loading {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.4rem 0;
}

.widget-loading .spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: widget-spin 0.6s linear infinite;
}

@keyframes widget-spin {
  to { transform: rotate(360deg); }
}

/* Decision Anatomy */
.anatomy-dice-section {
  text-align: center;
  margin-bottom: 1rem;
}

.anatomy-dice-label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.anatomy-state-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.split-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.split-left,
.split-right {
  padding: 16px;
  border-radius: 8px;
  background: var(--bg-alt);
}

.anatomy-side-header {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  text-align: center;
}

.human-header {
  color: var(--text-muted);
}

.optimal-header {
  color: var(--accent);
}

.anatomy-action {
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.25rem;
}

.anatomy-score {
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.anatomy-why {
  font-size: 0.8rem;
  line-height: 1.4;
  margin-bottom: 0.5rem;
}

.anatomy-ev {
  font-size: 0.85rem;
}

.anatomy-detail {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

.anatomy-gap {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  margin: 16px 0;
}

.anatomy-breakdown {
  background: var(--bg-alt);
  border-radius: 8px;
  padding: 12px 16px;
  margin-top: 1rem;
}

.anatomy-breakdown-title {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.anatomy-breakdown-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  padding: 0.15rem 0;
}

/* Backward Wave */
.wave-dot {
  transition: opacity 0.3s;
}

.wave-dot.highlight {
  stroke: gold;
  stroke-width: 2;
}

/* Score Spray */
#chart-score-spray-wrap { position: relative; min-height: 400px; }
#chart-score-spray-wrap canvas { position: absolute; top: 0; left: 0; }
#chart-score-spray-wrap svg { position: absolute; top: 0; left: 0; pointer-events: none; }

.spray-legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.spray-legend-item { display: flex; align-items: center; gap: 4px; font-size: 0.75rem; cursor: pointer; user-select: none; }
.spray-legend-swatch { width: 12px; height: 12px; border-radius: 50%; }
.spray-legend-item.muted { opacity: 0.3; }

.spray-popup {
  position: absolute; z-index: 50;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  font-size: 0.75rem; min-width: 200px; max-width: 280px;
}
.spray-popup.hidden { display: none; }
.spray-popup-title { font-weight: 600; margin-bottom: 6px; font-size: 0.85rem; }
.spray-popup-row { display: flex; justify-content: space-between; padding: 1px 0; }
.spray-popup-row.zero { color: var(--text-muted); }
.spray-popup-divider { border-top: 1px solid var(--border); margin: 4px 0; }
.spray-popup-bonus { color: var(--accent); font-weight: 600; }
.spray-popup-total { font-weight: 700; font-size: 0.9rem; margin-top: 4px; }
.spray-popup-close { position: absolute; top: 4px; right: 8px; cursor: pointer; color: var(--text-muted); background: none; border: none; font-size: 1rem; }
.spray-popup-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 0.7rem; margin-top: 6px; }

/* Reduction Funnel */
.funnel-bar {
  transition: opacity 0.2s;
}

/* Reachability Grid */
#chart-reachability-grid rect {
  transition: opacity 0.15s;
}

/* ===== Backward Cascade ===== */
.backward-cascade {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  margin: 1.5rem 0;
}

.cascade-card {
  width: 100%;
  max-width: 540px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
}

.cascade-card-final {
  border-color: var(--accent);
  border-width: 2px;
}

.cascade-card-header {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.cascade-layer-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.cascade-card-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Scorecard strip: 15 small squares */
.cascade-scorecard {
  display: flex;
  gap: 4px;
  margin-bottom: 0.6rem;
}

.cascade-sq {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  flex-shrink: 0;
}

.cascade-sq.filled {
  background: var(--text-muted);
  opacity: 0.4;
  border: 2px solid var(--text-muted);
}

.cascade-sq.empty {
  background: none;
  border: 2px dashed var(--text-muted);
}

.cascade-desc {
  font-size: 0.85rem;
  line-height: 1.45;
  margin: 0 0 0.3rem;
}

.cascade-footnote {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0;
}

/* Bonus fork on Layer 15 */
.cascade-bonus-fork {
  display: flex;
  gap: 0.75rem;
  margin: 0.5rem 0;
}

.cascade-bonus-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.78rem;
}

.cascade-bonus-earned {
  border-color: var(--accent);
  background: var(--accent-light);
}

.cascade-bonus-label {
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.cascade-bonus-value {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.cascade-bonus-earned .cascade-bonus-value {
  color: var(--accent);
  font-weight: 700;
}

/* Dependency arrows between cards */
.cascade-arrow,
.cascade-ellipsis {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 0.15rem 0;
}

.cascade-arrow-line {
  width: 1.5px;
  height: 14px;
  background: var(--text-muted);
  opacity: 0.4;
}

.cascade-arrow-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-style: italic;
  padding: 0.1rem 0;
}

.cascade-ellipsis-dots {
  font-size: 1.1rem;
  color: var(--text-muted);
  letter-spacing: 0.3em;
  padding: 0.1rem 0;
}

@media (max-width: 720px) {
  .cascade-card {
    padding: 0.75rem 1rem;
  }
  .cascade-sq {
    width: 16px;
    height: 16px;
  }
  .cascade-bonus-fork {
    flex-direction: column;
    gap: 0.4rem;
  }
}

/* Memory Lifecycle */
#chart-memory-lifecycle path {
  transition: opacity 0.2s;
}

/* Responsive */
@media (max-width: 720px) {
  .part-title {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
  }
  .split-container {
    grid-template-columns: 1fr;
  }
  .widget-solver-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
  }
  .widget-stage {
    flex-wrap: wrap;
  }
  .widget-dice-row .die-svg {
    width: 28px;
    height: 28px;
  }
}

/* ===== Dice Symmetry Explorer ===== */

.dice-symmetry-explorer {
  position: relative;
}

.dice-tray {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-alt);
  border-radius: 8px;
}

.dice-tray-top {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.dice-tray-row {
  display: flex;
  gap: 6px;
}

.dice-roll-btn {
  font-weight: 600;
}

.dice-symmetry-legend {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: auto;
}

.dice-symmetry-legend > span {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

.legend-swatch-keep {
  background: var(--bg);
  border: 2px solid var(--accent);
}

.legend-swatch-reroll {
  background: none;
  border: 1.5px dashed var(--border);
}

/* Keeps Panel — floats outside content column on the right */
.dice-symmetry-explorer {
  position: relative;
}

.keeps-panel {
  position: absolute;
  left: 100%;
  top: 0;
  margin-left: 1rem;
  width: 160px;
  background: var(--bg-alt);
  border-radius: 8px;
  padding: 0.2rem 0;
}

.keeps-panel-header {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.25rem 0.4rem 0.15rem;
}

.keeps-panel:empty {
  display: none;
}

.keep-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.4rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.keep-row:last-child {
  border-bottom: none;
  border-radius: 0 0 8px 8px;
}

.keep-row:hover {
  background: rgba(128, 128, 128, 0.08);
}

.keep-row.active {
  background: var(--accent-light, rgba(243, 112, 33, 0.12));
}

.keep-row-dice {
  display: flex;
  gap: 2px;
}

.keep-die {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  line-height: 0;
}

.keep-die svg {
  width: 100%;
  height: 100%;
}

.keep-masks {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: auto;
  white-space: nowrap;
}

/* Pattern Table */
.pattern-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 0.5rem 0;
  table-layout: fixed;
}

.pattern-table colgroup .col-swatch  { width: 32px; }
.pattern-table colgroup .col-pattern { width: 24%; }
.pattern-table colgroup .col-num     { width: 24%; }

.pattern-table th.num {
  text-align: right;
}

.pattern-table th {
  text-align: left;
  padding: 0.2rem 0.5rem;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted, #666);
}

.pattern-table td {
  padding: 0.15rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.pattern-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.pattern-row {
  cursor: pointer;
  transition: background 0.15s;
}

.pattern-row:hover {
  background: var(--bg-alt);
}

.pattern-row.active {
  background: var(--accent-light, rgba(243, 112, 33, 0.12));
}

.pattern-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

.pattern-glyph {
  font-family: 'Courier New', monospace;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.pattern-total td {
  border-top: 2px solid var(--border);
  border-bottom: none;
}


/* 252 Grid */
.grid-252 {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.grid-family-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.grid-family-label {
  font-size: 0.8rem;
  font-weight: 600;
  padding-left: 6px;
  margin-bottom: 2px;
  border-left: 3px solid var(--family-color);
}

.grid-family-count {
  font-weight: 400;
  color: var(--text-muted, #666);
}

.grid-family-dice {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.grid-quintuplet {
  display: flex;
  gap: 1px;
  cursor: pointer;
  padding: 1px;
  border: 1px solid transparent;
  border-radius: 2px;
  transition: border-color 0.15s;
}

.grid-quintuplet:hover {
  border-color: var(--text);
}

.grid-quintuplet.active {
  border-color: var(--accent);
  border-width: 2px;
  padding: 0;
  background: rgba(243, 112, 33, 0.15);
  animation: pulse-border 1.2s ease-in-out infinite;
  z-index: 1;
  position: relative;
}

.grid-die {
  width: 8px;
  height: 8px;
  border-radius: 1px;
}

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 4px 2px rgba(243, 112, 33, 0.4); }
  50% { box-shadow: 0 0 8px 4px rgba(243, 112, 33, 0.7); }
}

/* Responsive */
@media (max-width: 720px) {
  .dice-tray {
    flex-direction: column;
    align-items: flex-start;
  }
  .grid-die {
    width: 6px;
    height: 6px;
  }
  .pattern-table {
    font-size: 0.8rem;
  }
  .keeps-panel {
    display: none;
  }
}

/* ===== Keep Funnel Chart ===== */

.keep-funnel {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.keep-funnel-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.keep-funnel-dice {
  display: flex;
  gap: 6px;
}

.keep-funnel-pattern {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: 'Courier New', monospace;
  font-weight: 600;
}

.keep-funnel-center {
  flex-shrink: 0;
}

.keep-funnel-center-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

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

.keep-funnel-cell {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  transition: opacity 0.12s, transform 0.12s;
  border: 2px solid transparent;
}

.keep-funnel-cell:hover {
  transform: scale(1.15);
  z-index: 1;
}

.keep-funnel-cell.highlight {
  border-color: var(--text);
  transform: scale(1.15);
  z-index: 1;
}

.keep-funnel-cell.dimmed {
  opacity: 0.25;
}

.keep-funnel-right {
  flex: 1;
  min-width: 0;
}

.keep-funnel-right-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

.keep-funnel-keeps {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  align-content: start;
}

.keep-funnel-keep-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s;
  border-left: 3px solid transparent;
}

.keep-funnel-keep-row:hover {
  background: rgba(128, 128, 128, 0.08);
}

.keep-funnel-keep-row.highlight {
  background: rgba(128, 128, 128, 0.12);
}

.keep-funnel-keep-row .keep-row-dice {
  display: flex;
  gap: 2px;
}

.keep-funnel-keep-row .keep-masks {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: auto;
  white-space: nowrap;
}

.keep-funnel-summary {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
  text-align: center;
}

.keep-funnel-summary strong {
  color: var(--text);
}

/* Keep equivalence illustration (static) */
.keep-equiv {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin: 1.25rem 0;
}

.keep-equiv-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.keep-equiv .keep-die {
  width: 26px;
  height: 26px;
}

.keep-equiv-dice {
  display: flex;
  gap: 4px;
}

.keep-equiv-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  width: 3.5rem;
  text-align: right;
  flex-shrink: 0;
}

.keep-equiv-arrow {
  font-size: 1.3rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.keep-equiv-result {
  display: flex;
  gap: 4px;
  padding: 0.25rem 0.4rem;
  background: var(--accent-light);
  border-radius: 6px;
}

.keep-equiv-result-label {
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 600;
  text-align: center;
  margin-top: -0.1rem;
}

@media (max-width: 720px) {
  .keep-funnel {
    flex-direction: column;
    align-items: stretch;
    min-height: auto;
  }
  .keep-funnel-cell {
    width: 22px;
    height: 22px;
  }
}

/* ===== PMF Grid ===== */
.pmf-grid {
  margin: 0.5rem 0;
}

/* ===== Position Explorer ===== */
.position-explorer {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.explorer-controls {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.explorer-section-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.explorer-dice-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.explorer-dice-row .die-svg {
  cursor: pointer;
  transition: transform 0.12s;
}

.explorer-dice-row .die-svg:hover {
  transform: scale(1.1);
}

.explorer-reroll-row {
  display: flex;
  gap: 4px;
}

.explorer-reroll-btn {
  font-family: var(--font-serif);
  font-size: 0.8rem;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.explorer-reroll-btn:hover {
  border-color: var(--accent);
}

.explorer-reroll-btn.active {
  background: var(--accent-light);
  border-color: var(--accent);
  font-weight: 600;
}

.explorer-scorecard {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.8rem;
}

.explorer-cat-toggle {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--text);
}

.explorer-cat-toggle input {
  margin: 0;
  accent-color: var(--accent);
}

.explorer-upper-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.explorer-upper-row input[type="range"] {
  flex: 1;
  max-width: 200px;
  accent-color: var(--accent);
}

.explorer-upper-row .slider-value {
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  min-width: 1.5rem;
}

.explorer-random-btn {
  font-family: var(--font-serif);
  font-size: 0.78rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  align-self: flex-start;
  transition: background 0.15s, border-color 0.15s;
}

.explorer-random-btn:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.explorer-results {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.explorer-summary {
  padding: 0.6rem 0.75rem;
  background: var(--accent-light);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}

.explorer-action {
  font-size: 0.85rem;
  margin-bottom: 0.2rem;
}

.explorer-ev {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.explorer-ev .ev-value {
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.explorer-cat-table,
.explorer-mask-table {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  font-size: 0.8rem;
}

.explorer-cat-header,
.explorer-mask-header {
  display: flex;
  gap: 0.5rem;
  padding: 0.3rem 0.5rem;
  background: var(--bg-alt);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.explorer-cat-header span:first-child,
.explorer-mask-header span:first-child {
  flex: 1;
}

.explorer-cat-header span:not(:first-child),
.explorer-mask-header span:not(:first-child) {
  min-width: 5rem;
  text-align: right;
}

.explorer-cat-row,
.explorer-mask-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.2rem 0.5rem;
  border-top: 1px solid var(--border);
  transition: background 0.12s;
}

.explorer-cat-row.optimal,
.explorer-mask-row.optimal {
  background: rgba(243, 112, 33, 0.08);
  border-left: 3px solid var(--accent);
}

.explorer-cat-name,
.explorer-mask-keep {
  flex: 1;
}

.explorer-cat-score,
.explorer-cat-ev,
.explorer-mask-ev {
  min-width: 5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
  .explorer-scorecard {
    gap: 0.3rem 0.5rem;
  }
  .explorer-cat-toggle {
    font-size: 0.7rem;
  }
}

/* ===== Reference Markers ===== */

.ref-marker {
  font-size: 0.75em;
  vertical-align: super;
  line-height: 0;
  text-decoration: none;
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
}

.ref-marker:hover {
  text-decoration: underline;
}

/* References section */
.references-section {
  padding-bottom: 3rem;
}

.references-list {
  font-size: 0.88rem;
  color: var(--text-muted);
  padding-left: 1.5rem;
}

.references-list li {
  margin-bottom: 0.5rem;
  line-height: 1.55;
}

.references-list a {
  color: var(--accent);
}

/* Tooltip */
.annotation-tooltip {
  position: absolute;
  z-index: 10000;
  max-width: 380px;
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  pointer-events: auto;
  font-family: var(--font-serif);
}

.dark .annotation-tooltip {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.annotation-tooltip a {
  color: var(--accent);
}

.annotation-tooltip p {
  margin: 0;
}

