:root {
  --bg: #0e0e12;
  --panel: #16161e;
  --border: #2a2a38;
  --accent: #7ee8fa;
  --accent2: #f9a26c;
  --accent3: #a78bfa;
  --text: #e2e2f0;
  --muted: #6b6b85;
  --dot: #7ee8fa;
  --line: #f9a26c;
  --resid: #f472b6;
  --tss: #a78bfa;
  --good: #6ee7b7;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
header {
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 16px;
}
header h1 {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  color: var(--accent);
}
header span {
  font-size: 0.8rem;
  color: var(--muted);
}
.small-screen-warning {
  display: none;
}
.main {
  display: grid;
  grid-template-columns: 308px 1fr 260px;
  flex: 1;
  overflow: hidden;
}

/* ---- LEFT PANEL ---- */
.controls {
  border-right: 1px solid var(--border);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}
.left-credit {
  margin-top: auto;
  padding-top: 10px;
  font-size: 0.7rem;
  color: var(--muted);
  line-height: 1.4;
}
.center-credit {
  width: 100%;
  max-width: 700px;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.72;
  margin-top: 8px;
  margin-bottom: 2px;
  line-height: 1.4;
}
.right-credit {
  margin-top: auto;
  padding-top: 10px;
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.72;
  line-height: 1.4;
}
.start-hint {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #1c1c28;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--text);
  font-size: 0.84rem;
}
.start-hint-box {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--accent2);
  box-shadow: 0 0 0 2px rgba(249, 162, 108, 0.18);
  flex-shrink: 0;
}
.section-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.left-section-spaced {
  margin-top: 16px;
}
.control-group { display: flex; flex-direction: column; gap: 10px; }
.ctrl { display: flex; flex-direction: column; gap: 4px; }
.ctrl label {
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}
.ctrl label span { color: var(--accent); font-family: 'IBM Plex Mono', monospace; }
.ctrl select {
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  padding: 6px 8px;
  outline: none;
}
.ctrl select:focus { border-color: var(--accent); }
.ctrl select:disabled,
input[type=range]:disabled {
  opacity: 0.55;
}
input[type=range] {
  -webkit-appearance: none;
  width: 100%;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.dgp-input {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  color: var(--muted);
}
.dgp-input label {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}
.dgp-input .dgp-intercept-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  row-gap: 6px;
}
.dgp-input .coef-label {
  min-width: 40px;
  color: var(--muted);
}
.dgp-input .coef-term {
  min-width: 38px;
  color: var(--text);
}
.dgp-input input[type=number] {
  width: 72px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--accent);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  padding: 4px 6px;
  text-align: center;
  outline: none;
}
.dgp-input input[type=number]:focus { border-color: var(--accent); }
.dgp-eq {
  background: #1c1c28;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  margin-top: 4px;
}

btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
button {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  padding: 7px 14px;
  border-radius: 5px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.15s;
}
button:hover { background: var(--accent); color: var(--bg); }
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
button:disabled:hover {
  background: transparent;
  color: var(--accent);
}
button.secondary { border-color: var(--border); color: var(--muted); }
button.secondary:hover { border-color: var(--muted); color: var(--text); background: transparent; }
.floating-reset {
  position: fixed;
  left: 16px;
  bottom: 14px;
  z-index: 20;
  background: rgba(22, 22, 30, 0.88);
}

.toggle-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--muted);
}
.toggle input { display: none; }
.toggle-dot {
  width: 32px; height: 16px;
  background: var(--border);
  border-radius: 8px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-dot::after {
  content: '';
  position: absolute;
  width: 12px; height: 12px;
  background: var(--muted);
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: all 0.2s;
}
.toggle input:checked ~ .toggle-dot { background: var(--accent); }
.toggle input:checked ~ .toggle-dot::after { left: 18px; background: var(--bg); }
.toggle input:checked ~ span { color: var(--text); }

/* ---- CHART ---- */
.chart-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 24px;
  position: relative;
  overflow-y: auto;
}
.center-tabs {
  width: 100%;
  max-width: 700px;
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.center-tab {
  border-color: var(--border);
  color: var(--muted);
}
.center-tab.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(126, 232, 250, 0.09);
}
.center-tab:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  border-color: var(--border);
  color: var(--muted);
}
.center-view {
  width: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
}
.center-view.active {
  display: flex;
}
#chart { width: 100%; max-width: 700px; }
.chart-wrap {
  width: 100%;
  max-width: 700px;
  position: relative;
}
.zoom-home {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  width: 28px;
  height: 24px;
  padding: 0;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(14,14,18,0.85);
  font-size: 0.9rem;
  line-height: 1;
}
.zoom-home:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(14,14,18,0.95);
}
#residHist { width: 100%; max-width: 700px; }
svg { width: 100%; }
.axis text { font-family: 'IBM Plex Mono', monospace; font-size: 10px; fill: var(--muted); }
.axis path, .axis line { stroke: var(--border); }
.domain { display: none; }
.grid line { stroke: var(--border); stroke-opacity: 0.5; stroke-dasharray: 3,4; }
.grid path { display: none; }
.hist-wrap { width: 100%; max-width: 700px; }
.hist-wrap { margin-top: 24px; }
#mseBlock {
  width: 100%;
  max-width: 860px;
  margin-top: 20px;
}
.hist-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
}
.hist-bar {
  fill: var(--accent2);
  opacity: 0.55;
  stroke: var(--accent2);
  stroke-opacity: 0.8;
}
.hist-zero {
  stroke: var(--accent3);
  stroke-dasharray: 4,3;
  stroke-width: 1;
  opacity: 0.8;
}
.zoom-select {
  fill: rgba(126, 232, 250, 0.12);
  stroke: var(--accent);
  stroke-width: 1;
  stroke-dasharray: 4,3;
}
.hist-annot {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  fill: var(--muted);
}
.dot {
  cursor: pointer;
  transition: r 0.1s;
}
.dot:hover { r: 8; }
.ols-line-manual { cursor: ns-resize; }
.reg-handle {
  fill: var(--accent2);
  stroke: #fff;
  stroke-width: 1;
  cursor: ns-resize;
}

/* ---- RIGHT PANEL ---- */
.info-panel {
  border-left: 1px solid var(--border);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.stat-card .label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 4px;
}
.stat-card .value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1rem;
  font-weight: 600;
}
.stat-card .stat-formula {
  margin-top: 2px;
  margin-bottom: 4px;
  font-size: 0.62rem;
  color: var(--muted);
  font-family: 'IBM Plex Mono', monospace;
}
.stat-card.tss .value { color: var(--tss); }
.stat-card.rss .value { color: var(--resid); }
.stat-card.ess .value { color: var(--good); }
.stat-card.r2 .value { color: var(--accent); }

.obs-card {
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 14px;
  display: none;
}
.obs-card.visible { display: block; }
.obs-card .obs-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.65rem;
  color: var(--accent);
  letter-spacing: 0.1em;
  margin-bottom: 10px;
}
.obs-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.obs-row:last-child { border-bottom: none; }
.obs-row .k { color: var(--muted); }
.obs-row .v { font-family: 'IBM Plex Mono', monospace; }
.obs-row .v.pos { color: var(--good); }
.obs-row .v.neg { color: var(--resid); }
.mse-surface-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
}
#mseSurface {
  width: 100%;
  height: 200px;
  display: block;
}
.mse-meta {
  margin-top: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.67rem;
  line-height: 1.5;
  color: var(--muted);
  white-space: pre-line;
}

.formula-box {
  background: #1c1c28;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  line-height: 1.8;
  color: var(--muted);
}
.ci-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.68rem;
}
.ci-controls select {
  background: var(--border);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 0.68rem;
}
.coef-est-row {
  margin-top: 2px;
}
.coef-se-text {
  margin-left: 18px;
  margin-top: -2px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.66rem;
}
.coef-est-row .ci-text {
  color: var(--muted);
  font-size: 0.68rem;
}
.formula-box .highlight { color: var(--text); }
.formula-box .tss-c { color: var(--tss); }
.formula-box .rss-c { color: var(--resid); }
.formula-box .ess-c { color: var(--good); }
.formula-box .r2-c { color: var(--accent); }

.hint {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  font-style: italic;
}
.hypothesis-head {
  width: 100%;
  max-width: 700px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  margin-top: 6px;
  margin-bottom: 8px;
}
.hypothesis-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.hypothesis-list {
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 8px;
}
.hypothesis-area-note {
  width: 100%;
  max-width: 700px;
  margin-bottom: 8px;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: left;
}
.hypo-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 10px 8px;
}
.hypo-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.hypo-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.74rem;
  color: var(--muted);
}
.hypo-null-input {
  width: 72px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--accent);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.74rem;
  padding: 3px 5px;
}
.hypo-right {
  text-align: right;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  color: var(--muted);
}
.hypo-right .reject {
  color: var(--resid);
}
.hypo-right .keep {
  color: var(--good);
}
.hypo-plot {
  width: 100%;
}
.hypo-note {
  width: 100%;
  max-width: 700px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  padding: 26px 8px;
}

.r2-bar-wrap {
  background: var(--border);
  border-radius: 4px;
  height: 8px;
  overflow: hidden;
}
.r2-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--tss), var(--accent));
  border-radius: 4px;
  transition: width 0.4s;
}

@media (max-width: 900px) {
  header,
  .main {
    display: none !important;
  }
  .small-screen-warning {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    color: var(--text);
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 1rem;
    line-height: 1.5;
  }
  .floating-reset {
    display: none;
  }
}
