/* Calculator-specific variables (shared vars set in page <style>) */
:root {
  --accent-light: #dbeafe;
  --text-muted: #64748b;
  --bg-subtle: #f9fafb;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Tuneable font sizes */
  --fs-heading: 20px;
  --fs-subheading: 13px;
  --fs-body: 13px;
  --fs-label: 13px;
  --fs-input: 14px;
  --fs-button: 14px;
  --fs-result: 13px;
  --fs-small: 11px;
}

/* Main content area */
#app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 24px;
  overflow-x: hidden;
}

/* Home page */
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.home-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s;
}

.home-card:hover {
  border-color: var(--accent);
}

.home-card h3 {
  font-size: calc(var(--fs-subheading) + 2px);
  font-weight: 600;
  margin-bottom: 6px;
}

.home-card p {
  font-size: var(--fs-body);
  color: var(--text-muted);
  line-height: 1.5;
}

.home-category {
  font-size: var(--fs-small);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 4px;
}

/* Calculator layout */
.calc-header {
  margin-bottom: 16px;
}

.calc-header h2 {
  font-size: calc(var(--fs-heading) * 1.1);
  font-weight: 700;
  margin-bottom: 4px;
}

.calc-header p {
  font-size: var(--fs-body);
  color: var(--text-muted);
  line-height: 1.4;
}

.calc-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Input form */
.input-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.input-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}


/* Binomial two-column layout */
.binom-2col {
  display: flex;
  gap: 16px;
}
.binom-col-params {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.binom-col-mode {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.binom-col-params h3,
.binom-col-mode h3 {
  margin: 0 0 2px 0;
  font-size: var(--fs-subheading);
  font-weight: 600;
  color: var(--text);
}

/* Binomial mode options */
.binom-mode-opt {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: .15s;
  font-size: var(--fs-small);
  line-height: 1.3;
}
.binom-mode-opt:hover {
  background: #f1f5f9;
}
.binom-mode-opt:has(input:checked) {
  border-color: var(--accent);
  background: #eff6ff;
}
.binom-mode-opt input[type="radio"] {
  margin: 0;
  flex-shrink: 0;
}
.binom-mode-opt strong {
  color: var(--text);
  font-size: var(--fs-small);
}
.binom-mode-desc {
  color: var(--text-muted);
  font-size: var(--fs-small);
  margin-left: 4px;
}

.input-row:last-child {
  margin-bottom: 0;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 120px;
}

.input-group label {
  font-size: var(--fs-label);
  font-weight: 500;
  color: var(--text-muted);
}

.input-group input, .input-group select, .input-group textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--fs-input);
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.input-group input:focus, .input-group select:focus, .input-group textarea:focus {
  border-color: var(--accent);
}

.input-group textarea {
  resize: vertical;
  min-height: 60px;
}

.input-group .input-hint {
  font-size: var(--fs-small);
  color: var(--text-muted);
}

/* Radio/toggle groups */
.radio-group {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.radio-group label {
  font-size: var(--fs-label);
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: var(--text);
  font-weight: 400;
}

.radio-group-label {
  font-size: var(--fs-label);
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* Collapsible settings */
.settings-collapse {
  margin-bottom: 0;
}

.settings-toggle {
  font-size: var(--fs-label);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 0;
  list-style: none;
  user-select: none;
}

.settings-toggle::-webkit-details-marker {
  display: none;
}

.settings-toggle::before {
  content: '\25B6';
  display: inline-block;
  margin-right: 6px;
  font-size: 10px;
  transition: transform 0.15s;
}

.settings-collapse[open] > .settings-toggle::before {
  transform: rotate(90deg);
}

.settings-body {
  padding-top: 12px;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 8px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: var(--fs-button);
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn:hover {
  opacity: 0.9;
}

.btn-row {
  margin-top: 16px;
}

/* Results */
.results-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: none;
}

.results-section.visible {
  display: block;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
}

.results-table td {
  padding: 6px 0;
  font-size: var(--fs-result);
  border-bottom: 1px solid var(--border);
}

.results-table tr:last-child td {
  border-bottom: none;
}

.results-table td:first-child {
  color: var(--text-muted);
  font-weight: 500;
  padding-right: 16px;
  white-space: nowrap;
}

.results-table td:last-child {
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-size: var(--fs-result);
  text-align: right;
}

.results-table tr.clickable { cursor: pointer; transition: background 0.15s; }
.results-table tr.clickable:hover { background: rgba(37, 99, 235, 0.06); }
.results-table tr.clickable.active { background: rgba(37, 99, 235, 0.10); }
.results-table tr.clickable.active td:first-child { color: #2563eb; }

/* Chart */
.chart-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: none;
}

.chart-section.visible {
  display: block;
}

.chart-container {
  position: relative;
  width: 100%;
  max-height: 280px;
}

/* Step-by-step explanation */
.steps-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: none;
}

.steps-section.visible {
  display: block;
}

.steps-section h3 {
  font-size: calc(var(--fs-subheading) + 2px);
  font-weight: 600;
  margin-bottom: 12px;
}

.steps-section ol {
  padding-left: 20px;
}

.steps-section li {
  font-size: var(--fs-body);
  margin-bottom: 8px;
  line-height: 1.5;
}

/* Dynamic groups (for multinomial, bartlett, etc) */
.dynamic-groups {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dynamic-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.dynamic-row label {
  font-size: var(--fs-label);
  font-weight: 500;
  color: var(--text-muted);
  min-width: 70px;
}

.dynamic-row input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--fs-input);
  font-family: var(--font);
  outline: none;
  width: 100px;
  transition: border-color 0.15s;
}

.dynamic-row input:focus {
  border-color: var(--accent);
}

/* Data output (for random number generator) */
.data-output {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-size: var(--fs-result);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Venn diagram */
.venn-container {
  position: relative;
  width: 300px;
  height: 200px;
  margin: 20px auto;
}

.venn-circle {
  position: absolute;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-body);
  font-weight: 600;
}

.venn-circle.circle-a {
  left: 20px;
  top: 20px;
  background: rgba(37, 99, 235, 0.1);
}

.venn-circle.circle-b {
  left: 120px;
  top: 20px;
  background: rgba(37, 99, 235, 0.1);
}

/* Probability tree */
.tree-container {
  padding: 20px;
}

.tree-level {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: 20px;
}

.tree-node {
  text-align: center;
  font-size: var(--fs-body);
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  position: relative;
}

.tree-node.highlight {
  border-color: var(--accent);
  background: var(--accent-light);
}

/* Error messages */
.error-msg {
  color: #dc2626;
  font-size: var(--fs-body);
  margin-top: 8px;
}

/* Simulator */
.sim-mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

.sim-mode-toggle button {
  padding: 8px 20px;
  font-size: var(--fs-button);
  font-weight: 500;
  font-family: var(--font);
  border: none;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sim-mode-toggle button.active {
  background: var(--accent);
  color: #fff;
}

.sim-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.sim-controls select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--fs-input);
  font-family: var(--font);
  outline: none;
}

.btn-secondary {
  display: inline-block;
  padding: 8px 20px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--fs-button);
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: border-color 0.15s;
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--text);
}

.sim-die {
  width: 64px;
  height: 64px;
  border: 2px solid var(--text);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 6px;
  gap: 2px;
}

.sim-pip {
  width: 100%;
  aspect-ratio: 1;
  background: var(--text);
  border-radius: 50%;
}

.sim-pip.hidden {
  visibility: hidden;
}

.sim-die-number {
  width: 64px;
  height: 64px;
  border: 2px solid var(--text);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
}

/* 3D Dice — line-art style */
.dice-3d-wrapper {
  width: 64px;
  height: 64px;
  position: relative;
  isolation: isolate;
}

.dice-3d-scene {
  width: 64px;
  height: 64px;
  perspective: 250px;
  perspective-origin: 50% 40%;
}

.dice-3d-shadow {
  position: absolute;
  bottom: -12px;
  left: -2%;
  width: 104%;
  height: 14px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.12) 0%, transparent 75%);
  border-radius: 50%;
  pointer-events: none;
  z-index: -1;
}

.dice-3d {
  width: 64px;
  height: 64px;
  position: relative;
  transform-style: preserve-3d;
}

.dice-face {
  position: absolute;
  width: 64px;
  height: 64px;
  background: #fff;
  border: 2.5px solid var(--text);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 8px;
  gap: 2px;
  backface-visibility: hidden;
}

.dice-face .sim-pip {
  background: #111;
  box-shadow: inset 0.5px 0.5px 1px rgba(0,0,0,0.3);
}

.dice-face .sim-pip.hidden {
  background: none;
  box-shadow: none;
}

.dice-face.front  { transform: translateZ(32px); }
.dice-face.back   { transform: rotateY(180deg) translateZ(32px); }
.dice-face.right  { transform: rotateY(90deg) translateZ(32px); }
.dice-face.left   { transform: rotateY(-90deg) translateZ(32px); }
.dice-face.top    { transform: rotateX(90deg) translateZ(32px); }
.dice-face.bottom { transform: rotateX(-90deg) translateZ(32px); }

.coin-wrapper {
  width: 64px;
  height: 64px;
  position: relative;
  isolation: isolate;
}

.coin-3d-scene {
  width: 64px;
  height: 64px;
  perspective: 2000px;
  perspective-origin: 50% 50%;
}

.coin-shadow {
  position: absolute;
  bottom: -12px;
  left: 0%;
  width: 100%;
  height: 14px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.10) 0%, transparent 75%);
  border-radius: 50%;
  pointer-events: none;
  z-index: -1;
}

.coin-3d {
  width: 64px;
  height: 64px;
  position: relative;
  transform-style: preserve-3d;
}

.coin-face {
  position: absolute;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2.5px solid var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 800;
  backface-visibility: hidden;
}

.coin-face::after {
  content: '';
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  opacity: 0.5;
  pointer-events: none;
}

.coin-heads {
  background: var(--text);
  color: var(--bg);
  transform: translateZ(4px);
}

.coin-tails {
  background: var(--bg);
  color: var(--text);
  transform: rotateX(180deg) translateZ(4px);
}

.coin-edge-seg {
  position: absolute;
  left: 50%;
  top: 50%;
  background: repeating-linear-gradient(to right, #444 0px, #aaa 1.5px, #444 3px);
  border-top: 0.5px solid #333;
  border-bottom: 0.5px solid #333;
}

.sim-stats {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  font-size: var(--fs-body);
  padding: 8px 0;
}

.sim-stats span {
  color: var(--text-muted);
}

.sim-stats strong {
  color: var(--text);
}

.sim-freq-table {
  max-height: 260px;
  overflow-y: auto;
  margin-top: 12px;
}

.sim-freq-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-result);
}

.sim-freq-table th, .sim-freq-table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}

.sim-freq-table th {
  text-align: right;
  font-weight: 600;
  color: var(--text-muted);
  font-size: var(--fs-small);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
  background: var(--bg);
}

.sim-freq-table th:first-child, .sim-freq-table td:first-child {
  text-align: left;
}

/* Shared tool layout — banner, two-column, panels */
.calc-banner {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 20px;
  margin-bottom: 16px;
}

.calc-banner h2 {
  font-size: var(--fs-heading);
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}

.calc-banner p {
  font-size: var(--fs-body);
  color: var(--text-muted);
  line-height: 1.4;
}

.badge-tip {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: var(--fs-small);
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  cursor: help;
  position: relative;
}

/* Examples widget */
.examples-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}

.examples-counter {
  font-size: var(--fs-small);
  color: var(--text-muted);
  font-weight: 500;
  min-width: 90px;
  text-align: center;
}

.examples-arrow {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 28px;
  height: 28px;
  font-size: 16px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.examples-arrow:hover:not(:disabled) {
  background: var(--accent-light);
}

.examples-arrow:disabled {
  opacity: 0.3;
  cursor: default;
}

.examples-title {
  font-size: var(--fs-body);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.examples-notes {
  font-size: var(--fs-small);
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 2px;
}

.examples-try {
  font-size: var(--fs-small) !important;
  padding: 4px 10px !important;
}

.tool-layout {
  display: flex;
  gap: 20px;
  align-items: stretch;
}

.tool-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.tool-sidebar {
  width: 420px;
  flex-shrink: 1;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tool-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--bg);
}

.tool-panel h3 {
  margin: 0 0 6px 0;
  font-size: var(--fs-subheading);
  font-weight: 600;
  color: var(--text);
}

.tool-slider-row {
  margin-bottom: 4px;
}

.tool-slider-row label {
  display: block;
  font-size: var(--fs-small);
  color: var(--text-muted);
  margin-bottom: 2px;
}

.tool-slider-row input[type="range"] {
  width: 100%;
}

.tool-stats-table {
  width: 100%;
  font-size: var(--fs-small);
}

.tool-stats-table td {
  padding: 2px 0;
}

.tool-stats-table td:last-child {
  text-align: right;
}

/* Simulator two-column layout */
.sim-2col {
  display: flex;
  gap: 16px;
}
.sim-col-params {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sim-col-controls {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sim-col-params h3,
.sim-col-controls h3 {
  margin: 0 0 2px 0;
  font-size: var(--fs-subheading);
  font-weight: 600;
  color: var(--text);
}

/* Simulator visual frame */
.sim-frame {
  width: 100%;
  flex: 1;
  min-height: 200px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 0;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
}

/* Sim stats overlay (on sim frame) */
.sim-stats-overlay {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.sim-stats-toggle {
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 20px;
  font-size: var(--fs-button);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: .15s;
  backdrop-filter: blur(4px);
}
.sim-stats-toggle:hover {
  border-color: var(--accent);
  color: var(--text);
}
.sim-stats-body {
  margin-top: 4px;
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  backdrop-filter: blur(6px);
  min-width: 180px;
}
.sim-stats-body h3 {
  font-size: var(--fs-small);
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.sim-stats-body .tool-stats-table {
  font-size: var(--fs-small);
}
.sim-stats-body .tool-stats-table td {
  padding: 1px 0;
}

.sim-frame.dice-3d-active {
  min-height: 200px;
  padding-top: 24px;
}

/* Flat dice/coin for fast mode */
.sim-die-flat {
  width: 64px;
  height: 64px;
  border: 2.5px solid var(--text);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  background: var(--bg);
}

.sim-coin-flat {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2.5px solid var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 800;
  background: var(--bg);
}
.sim-coin-flat.heads { color: var(--accent); }
.sim-coin-flat.tails { color: var(--text-muted); }

.sim-visual-grid {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  gap: 64px;
  justify-content: center;
}
/* For 1-2 items, shrink to fewer columns */
.sim-visual-grid:has(> :nth-child(2):last-child) { grid-template-columns: repeat(2, 64px); }
.sim-visual-grid:has(> :first-child:last-child) { grid-template-columns: 64px; }

.sim-chart-wrap {
  width: 100%;
  height: 360px;
  position: relative;
}

.sim-chart-wrap canvas {
  display: block;
}

.tool-main > #simChartPanel {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.tool-main > #simChartPanel .sim-chart-wrap {
  flex: 1;
  height: auto;
  min-height: 300px;
}

.tool-sidebar > .sim-frame {
  min-height: 200px;
  max-height: 400px;
}

/* Galton-specific */

.galton-frame {
  width: 100%;
  flex: 1;
  min-height: 560px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
  position: relative;
}

.galton-canvas {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  will-change: transform;
}

.galton-stats-overlay {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.galton-stats-toggle {
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 20px;
  font-size: var(--fs-button);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: .15s;
  backdrop-filter: blur(4px);
}
.galton-stats-toggle:hover {
  border-color: var(--accent);
  color: var(--text);
}

.galton-stats-body {
  margin-top: 4px;
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  backdrop-filter: blur(6px);
  min-width: 180px;
}
.galton-stats-body h3 {
  font-size: var(--fs-small);
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.galton-stats-body .tool-stats-table {
  font-size: var(--fs-small);
}
.galton-stats-body .tool-stats-table td {
  padding: 1px 0;
}

.galton-chart-wrap {
  width: 100%;
  height: 360px;
  position: relative;
}

/* Chart expand overlay */
.chart-expand-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 5;
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: var(--fs-body);
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  transition: .15s;
  backdrop-filter: blur(4px);
}
.chart-expand-btn:hover {
  color: var(--text);
  background: rgba(255,255,255,1);
  border-color: var(--accent);
}

.chart-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.chart-overlay.open {
  display: flex;
}
.chart-overlay-inner {
  background: var(--bg);
  border-radius: 8px;
  padding: 20px;
  width: 100%;
  max-width: 900px;
  height: 70vh;
  position: relative;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.chart-overlay-inner canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}
.chart-overlay-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  z-index: 1;
  line-height: 1;
}
.chart-overlay-close:hover {
  color: var(--text);
}

/* Font size settings overlay */
.fs-settings-btn {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 900;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: .15s;
}
.fs-settings-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.fs-settings-panel {
  display: none;
  position: fixed;
  bottom: 60px;
  right: 16px;
  z-index: 900;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  width: 260px;
}
.fs-settings-panel.open {
  display: block;
}
.fs-settings-panel h4 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 10px;
  color: var(--text);
}
.fs-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.fs-slider-row label {
  font-size: 11px;
  color: var(--text-muted);
  width: 80px;
  flex-shrink: 0;
}
.fs-slider-row input[type="range"] {
  flex: 1;
  min-width: 0;
}
.fs-slider-row .fs-val {
  font-size: 11px;
  color: var(--text);
  width: 30px;
  text-align: right;
  flex-shrink: 0;
}
.fs-reset-btn {
  margin-top: 8px;
  font-size: 11px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  width: 100%;
}
.fs-reset-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* Responsive — matches sitenav 900px breakpoint */
@media (max-width: 900px) {
  #app {
    padding: 20px;
  }

  .tool-layout {
    flex-direction: column;
  }

  .tool-sidebar {
    width: 100%;
    min-width: 0;
  }

  .tool-main {
    min-height: 300px;
  }
}

/* Tighter layout for small screens */
@media (max-width: 800px) {
  #app {
    padding: 12px;
  }

  .calc-header {
    margin-bottom: 10px;
  }

  .calc-header h2 {
    font-size: var(--fs-heading);
  }

  .calc-body {
    gap: 10px;
  }

  .input-section {
    padding: 12px;
  }

  .input-row {
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
  }

  .btn, .btn-secondary {
    padding: 6px 14px;
    font-size: var(--fs-body);
  }

  .sim-controls {
    margin-top: 8px;
  }

  .chart-container {
    max-height: 200px;
  }

  .home-grid {
    grid-template-columns: 1fr;
  }

  .results-table td {
    padding: 4px 0;
    font-size: var(--fs-small);
  }

}
