/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-muted: #718096;
  --accent: #3b5bdb;
  --accent-light: #e8edff;
  --danger: #e53e3e;
  --success: #38a169;
  --warning: #d69e2e;
  --radius: 12px;
  --shadow: 0 1px 4px rgba(0,0,0,.07), 0 4px 16px rgba(0,0,0,.05);

  --c0: #3b5bdb;  --c0l: #e8edff;
  --c1: #2b9348;  --c1l: #e6f4ea;
  --c2: #e67700;  --c2l: #fff3e0;
  --c3: #862e9c;  --c3l: #f3e5f5;
  --c4: #0b7285;  --c4l: #e0f7fa;
  --c5: #c0392b;  --c5l: #fdecea;
  --c6: #1565c0;  --c6l: #e3f2fd;
  --c7: #558b2f;  --c7l: #f1f8e9;
  --c8: #4a148c;  --c8l: #f3e5f5;
  --c9: #bf360c;  --c9l: #fbe9e7;
}

html { font-family: 'Inter', system-ui, -apple-system, sans-serif; font-size: 15px; }
body { background: var(--bg); color: var(--text); min-height: 100vh; display: flex; flex-direction: column; }

/* ===== Header ===== */
header {
  background: var(--accent);
  color: #fff;
  padding: 20px 32px;
}
.header-inner { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.header-title h1 { font-size: 1.8rem; font-weight: 800; letter-spacing: -0.5px; }
.header-title .subtitle { font-size: 0.85rem; opacity: 0.85; display: block; margin-top: 2px; }
.header-badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.3); border-radius: 20px; padding: 3px 10px; font-size: 0.75rem; white-space: nowrap; }

/* ===== Main ===== */
main { max-width: 1200px; margin: 0 auto; padding: 28px 20px; flex: 1; width: 100%; }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 1rem; font-weight: 700; color: var(--text); margin-bottom: 16px; }
.chart-subtitle { font-size: 0.78rem; font-weight: 400; color: var(--text-muted); }

/* ===== Input Section ===== */
.input-section { display: grid; grid-template-columns: 1fr; gap: 20px; margin-bottom: 24px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group label { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }

input[type="text"],
input[type="password"],
select,
textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.92rem;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,91,219,.12); }
textarea { resize: vertical; }

/* ===== Example pills ===== */
.example-pills, .param-presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; }
.pill-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.pill, .preset-pill {
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid #c5d0f5;
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background .15s;
  font-family: inherit;
}
.pill:hover, .preset-pill:hover { background: #d0d9ff; }

/* ===== Sliders ===== */
.slider-group { margin-bottom: 18px; }
.slider-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.slider-header label { font-size: 0.88rem; font-weight: 600; }
.slider-val { font-size: 0.88rem; font-weight: 700; color: var(--accent); background: var(--accent-light); padding: 2px 8px; border-radius: 6px; min-width: 44px; text-align: center; }
input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }
.param-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; line-height: 1.4; }
.field-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 3px; }
.n-slider-row { display: flex; align-items: center; gap: 16px; margin-top: 14px; }
.n-slider-row label { font-size: 0.88rem; font-weight: 600; white-space: nowrap; color: var(--text-muted); }
.n-slider-row label span { color: var(--accent); font-weight: 700; }
.n-slider-row input[type="range"] { flex: 1; accent-color: var(--accent); cursor: pointer; }

/* ===== Analyze button ===== */
#analyze-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 16px;
  transition: background .15s, transform .1s;
  font-family: inherit;
}
#analyze-btn:hover { background: #2f4ac9; }
#analyze-btn:active { transform: scale(.98); }
#analyze-btn:disabled { background: #a0aec0; cursor: not-allowed; transform: none; }

.param-presets { margin-top: 0; }

/* ===== Loading ===== */
.loading-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 32px;
  text-align: center;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-msg { font-weight: 600; font-size: 1rem; margin-bottom: 16px; color: var(--text); }
.loading-sub { font-size: 0.82rem; color: var(--text-muted); margin-top: 8px; }
.progress-track { background: var(--border); border-radius: 4px; height: 6px; width: 300px; max-width: 100%; margin: 0 auto; overflow: hidden; }
.progress-fill { background: var(--accent); height: 100%; border-radius: 4px; transition: width .4s ease; width: 0%; }

/* ===== Error ===== */
.error-card {
  background: #fff5f5;
  border: 1px solid #feb2b2;
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}
.error-icon { font-size: 1.4rem; }
#error-msg { flex: 1; font-size: 0.92rem; color: #c53030; }
#dismiss-error { background: none; border: 1px solid #c53030; color: #c53030; border-radius: 6px; padding: 6px 14px; cursor: pointer; font-family: inherit; font-size: 0.82rem; }

/* ===== Entropy Card ===== */
.entropy-card {
  display: flex;
  gap: 32px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.entropy-left { display: flex; flex-direction: column; align-items: center; min-width: 120px; }
.entropy-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 4px; }
.entropy-value { font-size: 3rem; font-weight: 800; color: var(--accent); line-height: 1; }
.entropy-unit { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }
.entropy-badge { margin-top: 8px; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; padding: 3px 10px; border-radius: 20px; background: var(--accent-light); color: var(--accent); }
.entropy-right { flex: 1; min-width: 260px; }
.gauge-row { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.gauge-anchor { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.certain { color: var(--success); }
.uncertain { color: var(--danger); }
.gauge-track { flex: 1; height: 14px; background: linear-gradient(to right, #38a169, #d69e2e, #e53e3e); border-radius: 8px; position: relative; }
.gauge-fill { height: 100%; border-radius: 8px; background: transparent; }
.gauge-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 20px; height: 20px;
  background: #fff;
  border: 3px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  transition: left .6s cubic-bezier(.34,1.56,.64,1);
}
.entropy-meta { font-size: 0.85rem; color: var(--text-muted); line-height: 1.7; }
.entropy-meta strong { color: var(--text); }

/* ===== Charts ===== */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
@media (max-width: 800px) { .charts-row { grid-template-columns: 1fr; } }
.chart-card { }
.chart-wrap { position: relative; height: 320px; }

/* ===== Cluster Summary ===== */
.cluster-summary { display: flex; flex-wrap: wrap; gap: 12px; }
.cluster-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
}
.cluster-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

/* ===== Response Cards ===== */
.responses-hint { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 14px; }
.responses-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.response-card {
  border-radius: 10px;
  padding: 14px;
  border: 2px solid transparent;
  transition: transform .15s, box-shadow .15s;
}
.response-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,.1); }
.response-num { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; opacity: .7; margin-bottom: 6px; }
.response-text { font-size: 0.92rem; font-weight: 600; line-height: 1.4; margin-bottom: 8px; word-break: break-word; }
.response-footer { display: flex; justify-content: space-between; align-items: center; font-size: 0.75rem; opacity: .75; }
.response-cluster { font-weight: 700; }
.response-ll { font-family: 'Courier New', monospace; }

/* ===== Cluster colors ===== */
.cl-0 { background: var(--c0l); border-color: var(--c0); color: var(--c0); }
.cl-1 { background: var(--c1l); border-color: var(--c1); color: var(--c1); }
.cl-2 { background: var(--c2l); border-color: var(--c2); color: var(--c2); }
.cl-3 { background: var(--c3l); border-color: var(--c3); color: var(--c3); }
.cl-4 { background: var(--c4l); border-color: var(--c4); color: var(--c4); }
.cl-5 { background: var(--c5l); border-color: var(--c5); color: var(--c5); }
.cl-6 { background: var(--c6l); border-color: var(--c6); color: var(--c6); }
.cl-7 { background: var(--c7l); border-color: var(--c7); color: var(--c7); }
.cl-8 { background: var(--c8l); border-color: var(--c8); color: var(--c8); }
.cl-9 { background: var(--c9l); border-color: var(--c9); color: var(--c9); }

/* ===== Calculation Walkthrough ===== */
.calc-step {
  margin-bottom: 28px;
}
.calc-step:last-child { margin-bottom: 0; }

.step-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.step-num {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.step-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
}
.step-formula {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

.calc-table-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.calc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}
.calc-table th {
  background: var(--bg);
  padding: 8px 12px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.calc-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.calc-table tr:last-child td { border-bottom: none; }
.calc-table tr:hover td { background: #f7f9ff; }

.mono { font-family: 'Courier New', monospace; font-size: 0.82rem; }
.resp-cell { max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cl-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.pbar-wrap {
  width: 100px;
  height: 10px;
  background: var(--border);
  border-radius: 5px;
  overflow: hidden;
}
.pbar {
  height: 100%;
  border-radius: 5px;
  transition: width .4s ease;
  min-width: 2px;
}

.entropy-sum-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding: 12px 16px;
  background: var(--accent-light);
  border-radius: 8px;
  border: 1px solid #c5d0f5;
}
.esum-label { font-size: 1.05rem; font-weight: 800; color: var(--accent); font-style: italic; }
.esum-op { font-size: 1rem; color: var(--text-muted); }
.esum-terms { font-family: 'Courier New', monospace; font-size: 0.82rem; color: var(--text); flex-wrap: wrap; word-break: break-word; }
.esum-result { font-size: 1rem; font-weight: 800; color: var(--accent); }

/* ===== Footer ===== */
footer { text-align: center; padding: 20px; font-size: 0.78rem; color: var(--text-muted); border-top: 1px solid var(--border); }

/* ===== Utilities ===== */
.hidden { display: none !important; }
