/* ── Design tokens ── */
:root {
  /* BACKGROUNDS (Darker/Muted) */
  --bg:           #F6D6DA;         
  --surface:      #FFFFFF;         /* Use white or near-white for high contrast */
  --surface-2:    #F9F4FE;         /* Very light tint for subtle depth */

  /* BORDERS & UI (Darker/More saturated for definition) */
  --border:       #E6A2F5;         
  --border-light: #DFEFFD;         

  /* TEXT (Ensuring WCAG contrast) */
  --text:         #1a3a52;         
  --muted:        #4A6B85;         /* Darkened for readability */
  --sub:          #1a3a52;         

  /* ACCENTS (High visibility) */
  --accent:       #2B88DA;         /* Shifted to a more legible blue */
  --active:       #2B88DA;
  --active-glow:  rgba(43,136,218,.18);
  --inactive:     #CBE6F4;
  
  /* TARGETS/HIGHLIGHTS (Using yellow carefully) */
  --target:       #F9EB77;         
  --target-glow:  rgba(249,235,119,.35);
  --label-fg:     #1a3a52;
  
  /* TOOLS */
  --mono:         'IBM Plex Mono', monospace;
  --sans:         'IBM Plex Sans', sans-serif;
  --radius:       8px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 20px 60px;
}

/* ── Header ── */
header {
  text-align: center;
  margin-bottom: 36px;
}
header h1 {
  font-family: var(--mono);
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--text);
}
header h1 span { color: var(--accent); }
header p {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 300;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 860px;
  padding: 28px 32px;
  box-shadow: 0 2px 16px rgba(43,136,218,.08);
}

/* ── Section label ── */
.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 14px;
}

.divider { border: none; border-top: 1px solid var(--border-light); margin: 22px 0; }

/* ── Controls grid ── */
.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px 32px;
  margin-bottom: 24px;
}
@media (max-width: 580px) { .controls-grid { grid-template-columns: 1fr; } }

.control-group > .ctrl-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

/* ── Slider + number input combo ── */
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  transition: background 0.2s;
}
input[type="range"]:hover { background: #91C5DF; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 17px; height: 17px;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 3px var(--active-glow);
  transition: box-shadow 0.2s;
}
input[type="range"]::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 5px rgba(43,136,218,.28);
}
input[type="range"]::-moz-range-thumb {
  width: 17px; height: 17px;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid var(--surface);
}

.num-input {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 6px;
  width: 64px;
  text-align: center;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -moz-appearance: textfield;
}
.num-input::-webkit-inner-spin-button,
.num-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.num-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--active-glow);
}
.num-input.invalid {
  border-color: #e07070;
  box-shadow: 0 0 0 3px rgba(224,112,112,.2);
  color: #c0392b;
}

.p-suffix {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  margin-left: -4px;
}

/* ── Mode selector ── */
.mode-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.mode-btn {
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.mode-btn:hover { border-color: var(--accent); color: var(--accent); }
.mode-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.stepper-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.step-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-family: var(--mono);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.step-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #edf6fd;
}

/* ── Result ── */
.result-row {
  display: flex;
  align-items: center;
  gap: 28px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.result-pill {
  font-family: var(--mono);
  font-size: 2.2rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -1px;
  line-height: 1;
}
.result-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-top: 4px;
}
.result-desc {
  font-size: 13px;
  color: var(--muted);
}
.result-desc strong { color: var(--text); font-weight: 500; }

/* ── Absurdity comparisons ── */
#absurd-box { margin: 0; }

.absurd-section { margin-bottom: 4px; }

.absurd-list {
  display: flex;
  flex-direction: column;
  margin-top: 8px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
  background: #f0f8fd;
}

.absurd-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.12s;
}
.absurd-item:last-child { border-bottom: none; }
.absurd-item:hover { background: var(--surface-2); }

.absurd-icon {
  font-size: 20px;
  flex-shrink: 0;
  line-height: 1.4;
}

.absurd-body {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
}

.absurd-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
  flex: 1;
  min-width: 0;
}
.absurd-text strong {
  color: var(--text);
  font-weight: 500;
}

.absurd-pill {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Histogram ── */
.histogram-wrap {
  position: relative;
  width: 100%;
  overflow: hidden;
}
#histogram {
  width: 100%;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 220px;
  padding-bottom: 28px;
}
.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  position: relative;
  min-width: 0;
}
.bar-label {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--label-fg);
  position: absolute;
  top: 0;
  transform: translateY(-100%) translateY(-2px);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.bar-label.show { opacity: 1; }
.bar {
  width: 100%;
  border-radius: 3px 3px 0 0;
  transition: height 0.22s cubic-bezier(.4,0,.2,1), background 0.18s;
}
.bar.is-active   { background: var(--active); }
.bar.is-inactive { background: var(--inactive); }
.bar.is-target   { background: var(--target); box-shadow: 0 0 0 1px var(--target); }
.x-label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}

/* grid lines */
.grid-lines {
  position: absolute;
  inset: 0;
  bottom: 28px;
  pointer-events: none;
}
.grid-line {
  position: absolute;
  left: 0; right: 0;
  border-top: 1px dashed var(--border-light);
}
.grid-line span {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--muted);
  position: absolute;
  right: 0;
  top: -8px;
}

/* ── Math footer ── */
.math-footer {
  border-top: 1px solid var(--border-light);
  background: var(--surface-2);
  border-radius: 0 0 14px 14px;
  padding: 20px 32px;
  width: 100%;
  max-width: 860px;
  font-size: 13px;
  color: var(--muted);
  margin-top: -1px;
  border: 1px solid var(--border);
  border-top: none;
  box-shadow: 0 2px 16px rgba(43,136,218,.06);
}
.math-footer .eq-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  margin-bottom: 10px;
}
#latex-display { color: var(--text); line-height: 2; }

/* ── Misc additions ── */
header em { font-style: italic; color: var(--accent); }

.param-tag {
  font-style: normal;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  margin-left: 4px;
  vertical-align: middle;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  font-weight: 300;
  line-height: 1.5;
  margin-bottom: 9px;
}

.mode-hint {
  font-size: 12px;
  color: var(--muted);
  font-weight: 300;
  margin-top: 8px;
  line-height: 1.5;
}
.mode-hint strong { color: var(--text); font-weight: 500; }

.result-plain {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  margin-top: 6px;
  max-width: 520px;
}
.result-plain strong { color: var(--text); font-weight: 500; }

.section-sub {
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  font-weight: 300;
  margin-left: 4px;
}

/* histogram legend */
.hist-legend {
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.legend-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  margin-right: 3px;
}
.active-dot   { background: var(--active); }
.target-dot   { background: var(--target); }
.inactive-dot { background: var(--inactive); border: 1px solid var(--border); }

.eq-sublabel {
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  font-weight: 300;
  margin-left: 4px;
}