/* ─── Reset & Base ───────────────────────────────────────────── */

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

body {
	font-family: "Inter", system-ui, -apple-system, sans-serif;
	background: #f5f5f7;
	color: #1a1a2e;
	line-height: 1.5;
	min-height: 100vh;
}

/* ─── Controls Bar ───────────────────────────────────────────── */

.controls-bar {
	display: flex;
	align-items: center;
	gap: 16px;
	padding: 10px 24px;
	background: #eaeaef;
	border-bottom: 1px solid #d0d0d8;
	flex-wrap: wrap;
}

.status {
	font-family: "JetBrains Mono", "Fira Code", monospace;
	font-size: 0.75em;
	color: #5a5a7a;
	padding: 4px 10px;
	background: #e0e0e8;
	border-radius: 4px;
	white-space: nowrap;
}

.controls {
	display: flex;
	align-items: center;
	gap: 14px;
	flex-wrap: wrap;
	margin-left: auto;
}

.controls label {
	font-size: 0.8em;
	color: #5a5a7a;
	display: flex;
	align-items: center;
	gap: 6px;
}

.controls input[type="range"] { width: 100px; accent-color: #6366f1; }

.controls input[type="number"] {
	width: 60px;
	padding: 4px 6px;
	background: #ffffff;
	border: 1px solid #c0c0d0;
	border-radius: 4px;
	color: #1a1a2e;
	font-size: 0.85em;
}

button {
	padding: 6px 16px;
	font-size: 0.8em;
	font-weight: 600;
	border: none;
	border-radius: 5px;
	cursor: pointer;
	transition: all 0.15s;
}

button:disabled { opacity: 0.35; cursor: not-allowed; }

#generate-btn { background: #6366f1; color: white; position: relative; }
#generate-btn:hover:not(:disabled) { background: #5558e6; box-shadow: 0 0 12px rgba(99,102,241,0.3); }
#generate-btn.generating { color: transparent; pointer-events: none; }
#generate-btn.generating::after {
	content: "";
	position: absolute;
	inset: 0;
	margin: auto;
	width: 14px;
	height: 14px;
	border: 2px solid rgba(255,255,255,0.3);
	border-top-color: white;
	border-radius: 50%;
	animation: btn-spin 0.6s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }
#stop-btn { background: #ef4444; color: white; }
#stop-btn:hover:not(:disabled) { background: #dc2626; }

/* ─── Main Layout ────────────────────────────────────────────── */

.main-grid { padding: 16px 24px; }

.io-panel {
	display: grid;
	grid-template-columns: 1fr;
	gap: 16px;
	margin-bottom: 20px;
}

.io-section label {
	display: block;
	font-size: 0.7em;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: #6b7094;
	margin-bottom: 4px;
}

textarea {
	width: 100%;
	padding: 10px 12px;
	font-family: "JetBrains Mono", "Fira Code", monospace;
	font-size: 0.85em;
	background: #ffffff;
	border: 1px solid #c0c0d0;
	border-radius: 6px;
	color: #1a1a2e;
	resize: vertical;
	transition: border-color 0.15s;
}

textarea:focus { outline: none; border-color: #6366f1; }

.output {
	padding: 10px 12px;
	font-family: "JetBrains Mono", "Fira Code", monospace;
	font-size: 0.85em;
	background: #ffffff;
	border: 1px solid #c0c0d0;
	border-radius: 6px;
	white-space: pre-wrap;
	min-height: 60px;
	max-height: 200px;
	overflow-y: auto;
	color: #2a2a4e;
}

/* ─── Viz Container ──────────────────────────────────────────── */

.viz-container {
	--weights-width: 200px;
	background: #ffffff;
	border: 1px solid #d0d0d8;
	border-radius: 8px;
	padding: 16px;
}

.viz-placeholder {
	text-align: center;
	color: #8a8aaa;
	font-size: 0.85em;
	padding: 40px;
}

/* ─── Viz: Step Bar ──────────────────────────────────────────── */

.viz-step-bar {
	margin-bottom: 12px;
	padding: 6px 12px;
	background: #eeeef4;
	border-radius: 5px;
}

.viz-step-text {
	font-family: "JetBrains Mono", monospace;
	font-size: 0.75em;
	color: #5a5a7a;
}

/* ─── Viz: Scroll Container ─────────────────────────────────── */

.viz-scroll-container {
	overflow-x: auto;
	overflow-y: visible;
	position: relative;
}

/* ─── Viz: Sections (stacked vertically) ─────────────────────── */

.viz-section {
	margin-bottom: 14px;
	background: #f0f0f5;
	border: 1px solid #d0d0d8;
	border-radius: 6px;
	padding: 10px 12px;
}

.viz-section-header {
	display: flex;
	align-items: baseline;
	gap: 10px;
	margin-bottom: 8px;
}

.viz-section-title {
	font-size: 0.72em;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: #5a5a7a;
}

.viz-section-subtitle {
	font-size: 0.65em;
	color: #8a8aaa;
}

/* ─── Viz: Token Strip (horizontal, fixed-width) ─────────────── */

.viz-token-strip {
	display: flex;
	flex-wrap: nowrap;
	gap: 0;
}

.viz-token {
	display: inline-block;
	flex-shrink: 0;
	padding: 2px 0;
	background: #e8e8f0;
	font-family: "JetBrains Mono", monospace;
	font-size: 0.68em;
	color: #2a2a4e;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	text-align: center;
	cursor: default;
	transition: background 0.1s;
	border-right: 1px solid #f0f0f5;
}

.viz-token:hover { background: #d0d0e0; }

.viz-token-highlight {
	background: #b8b8ff !important;
	box-shadow: inset 0 -2px 0 #6366f1;
}

.viz-token-latest {
	background: #c0c0e8;
	color: #1a1a3e;
	box-shadow: 0 0 6px rgba(99,102,241,0.25);
}

/* ─── Viz: Layer Section ─────────────────────────────────────── */

.viz-layer-section {
	border-left: 3px solid #b0b0d0;
}

.viz-layer-title-row {
	margin-bottom: 8px;
}

.viz-col-label {
	font-size: 0.6em;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: #6b7094;
	margin-bottom: 4px;
	margin-top: 8px;
}

/* ─── Viz: Attention Area (combined + thumbs) ────────────────── */

.viz-attn-area {
	display: flex;
	align-items: flex-start;
	gap: 12px;
}

.viz-attn-canvas-wrap {
	position: relative;
	flex-shrink: 0;
}

.viz-attn-overlay {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	pointer-events: none;
	display: none;
}

.viz-attn-highlight-row {
	position: absolute;
	left: 0;
	background: rgba(34, 197, 94, 0.35);
	border-top: 1px solid rgba(34, 197, 94, 0.7);
	border-bottom: 1px solid rgba(34, 197, 94, 0.7);
}

.viz-attn-thumbs {
	position: sticky;
	right: 0;
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 4px;
	background: #f0f0f5;
	border-radius: 4px;
	z-index: 1;
	flex-shrink: 0;
}

.viz-thumb-wrap {
	text-align: center;
	cursor: pointer;
	border: 2px solid transparent;
	border-radius: 3px;
	padding: 2px;
	transition: border-color 0.15s;
}

.viz-thumb-wrap:hover {
	border-color: #6366f1;
}

.viz-thumb-selected {
	border-color: #6366f1;
	background: #e8e8ff;
}

.viz-thumb-label {
	font-size: 0.55em;
	font-weight: 700;
	margin-bottom: 1px;
}

.viz-thumb-canvas {
	image-rendering: pixelated;
}

/* ─── Viz: SAE Features ──────────────────────────────────────── */

.viz-sae-area {
	display: flex;
	align-items: flex-start;
	gap: 16px;
	flex-wrap: wrap;
}

.viz-sae-topk {
	display: flex;
	flex-direction: column;
	gap: 3px;
	min-width: 180px;
}

.topk-row {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 0.7em;
}

.topk-label {
	font-family: "JetBrains Mono", monospace;
	font-size: 0.9em;
	color: #2a2a4e;
	width: 70px;
	text-align: right;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	flex-shrink: 0;
}

.topk-bar-outer {
	flex: 1;
	height: 12px;
	background: #e0e0e8;
	border-radius: 3px;
	overflow: hidden;
}

.topk-bar-inner {
	height: 100%;
	border-radius: 3px;
	transition: width 0.15s ease;
}

.topk-value {
	font-family: "JetBrains Mono", monospace;
	font-size: 0.85em;
	color: #6b7094;
	width: 45px;
	text-align: right;
	flex-shrink: 0;
}

/* token strip shown directly above an SAE feature heatmap */
.viz-sae-tokens {
	margin-bottom: 3px;
}

/* ─── Viz: Canvas ────────────────────────────────────────────── */

.viz-canvas {
	display: block;
	border: 1px solid #d0d0d8;
	border-radius: 3px;
	image-rendering: pixelated;
	cursor: crosshair;
}

/* ─── Viz: Predictions Strip ─────────────────────────────────── */

.viz-pred-strip {
	display: flex;
	flex-wrap: nowrap;
	gap: 0;
}

.viz-pred-col {
	display: flex;
	flex-direction: column;
	flex-shrink: 0;
	gap: 0;
}

.viz-pred-cell {
	font-family: "JetBrains Mono", monospace;
	font-size: 0.5em;
	color: #1a1a2e;
	text-align: center;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	height: 14px;
	line-height: 14px;
	border-right: 1px solid rgba(255,255,255,0.3);
	border-bottom: 1px solid rgba(255,255,255,0.15);
}

/* ─── Viz: Section Row (weights + activations side by side) ──── */

.viz-section-row {
	display: flex;
	align-items: stretch;
}

.viz-section-weights {
	position: sticky;
	left: 0;
	z-index: 2;
	flex-shrink: 0;
	width: var(--weights-width);
	background: #f0f0f5;
	padding-right: 12px;
	border-right: 2px solid #d0d0d8;
	overflow: hidden;
	cursor: col-resize;
}

.viz-section-weights:hover {
	border-right-color: #6366f1;
}

.viz-section-activations {
	flex: 1;
	min-width: 0;
}


.viz-wp-block {
	margin-bottom: 6px;
}

.viz-wp-label {
	font-family: "JetBrains Mono", monospace;
	font-size: 0.55em;
	color: #6b7094;
	margin-bottom: 2px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 4px;
	white-space: nowrap;
}

/* ablation toggles in the weights panel */
.viz-wp-ablate,
.viz-wp-head {
	display: inline-flex;
	align-items: center;
	gap: 2px;
	font-size: 0.95em;
	color: #8089a8;
	cursor: pointer;
	user-select: none;
}

.viz-wp-ablate input,
.viz-wp-head input {
	margin: 0;
	cursor: pointer;
}

.viz-wp-heads {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
}

.viz-wp-ablated {
	color: #d23c3c;
}

/* dim the matrix preview when its weight is ablated */
.viz-wp-block.viz-wp-ablated .viz-wp-canvas-wrap {
	opacity: 0.35;
	filter: grayscale(0.6);
}

.viz-wp-canvas-wrap {
	position: relative;
	display: inline-block;
}

.viz-wp-overlay {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	pointer-events: none;
	display: none;
}

.viz-wp-highlight-band {
	position: absolute;
	top: 0;
	background: rgba(34, 197, 94, 0.35);
	border-left: 1px solid rgba(34, 197, 94, 0.7);
	border-right: 1px solid rgba(34, 197, 94, 0.7);
}

.viz-wp-highlight-row {
	position: absolute;
	left: 0;
	background: rgba(34, 197, 94, 0.35);
	border-top: 1px solid rgba(34, 197, 94, 0.7);
	border-bottom: 1px solid rgba(34, 197, 94, 0.7);
}

/* ─── Viz: Weights (legacy, kept for renderWeightsInto) ──────── */

.viz-weight-block { display: inline-block; }

.viz-weight-label {
	font-family: "JetBrains Mono", monospace;
	font-size: 0.6em;
	color: #6b7094;
	margin-bottom: 2px;
	max-width: 250px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* ─── Viz: Weight Axis Labels ────────────────────────────────── */

.viz-weight-row {
	display: flex;
	align-items: flex-start;
}

.viz-axis-labels {
	display: flex;
	flex-direction: column;
	flex-shrink: 0;
	overflow: hidden;
}

.viz-axis-label {
	font-family: "JetBrains Mono", monospace;
	font-size: 0.5em;
	color: #6b7094;
	text-align: right;
	padding-right: 3px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	line-height: 1;
}

.viz-weight-col-labels {
	display: flex;
	flex-direction: row;
	overflow: hidden;
}

.viz-axis-label-col {
	font-family: "JetBrains Mono", monospace;
	font-size: 0.5em;
	color: #6b7094;
	text-align: center;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	line-height: 1;
}

/* ─── Viz: Tooltip ───────────────────────────────────────────── */

.viz-tooltip {
	position: fixed;
	pointer-events: none;
	z-index: 100;
	background: #1a1a2e;
	color: #e0e0f0;
	font-family: "JetBrains Mono", monospace;
	font-size: 0.68em;
	padding: 6px 10px;
	border-radius: 5px;
	box-shadow: 0 2px 10px rgba(0,0,0,0.25);
	white-space: nowrap;
	display: none;
	line-height: 1.6;
}

.viz-tooltip-tokens {
	margin-bottom: 3px;
	border-bottom: 1px solid #3a3a5e;
	padding-bottom: 3px;
}

.viz-tooltip-pred-row {
	display: flex;
	align-items: center;
	gap: 6px;
	margin: 1px 0;
}

.viz-tooltip-pred-tok {
	display: inline-block;
	padding: 0 4px;
	border-radius: 2px;
	font-weight: 600;
	color: #1a1a2e;
}

.viz-tooltip-pred-pct {
	color: #b0b0c8;
	font-size: 0.9em;
}

.viz-tooltip-head {
	display: inline-block;
	width: 8px;
	height: 8px;
	border-radius: 2px;
	margin-right: 4px;
	vertical-align: middle;
}

/* ─── Superposition Demo ─────────────────────────────────────── */

.nav-link {
	font-size: 0.8em;
	font-weight: 600;
	color: #6366f1;
	text-decoration: none;
	padding: 4px 10px;
	border-radius: 4px;
	white-space: nowrap;
}

.nav-link:hover { background: #e0e0ff; }

.controls select {
	padding: 4px 6px;
	background: #ffffff;
	border: 1px solid #c0c0d0;
	border-radius: 4px;
	color: #1a1a2e;
	font-size: 0.85em;
}

#reset-btn { background: #e0e0e8; color: #3a3a5e; }
#reset-btn:hover:not(:disabled) { background: #d0d0dc; }
#train-btn { background: #6366f1; color: white; }
#train-btn:hover:not(:disabled) { background: #5558e6; }

.tms-intro {
	font-size: 0.85em;
	color: #5a5a7a;
	margin-bottom: 16px;
	max-width: 880px;
}

.tms-intro code {
	font-family: "JetBrains Mono", monospace;
	font-size: 0.92em;
	background: #eeeef4;
	padding: 1px 5px;
	border-radius: 3px;
}

.tms-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
	gap: 16px;
	align-items: start;
}

.tms-panel { margin-bottom: 0; }

.tms-panel canvas { background: #ffffff; }

.tms-geometry { cursor: grab; }
.tms-geometry:active { cursor: grabbing; }
.tms-loss { cursor: default; }

.tms-bars {
	display: flex;
	flex-direction: column;
	gap: 4px;
	max-height: 360px;
	overflow-y: auto;
}

.tms-bar-row {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 0.72em;
}

.tms-bar-dot {
	width: 9px;
	height: 9px;
	border-radius: 50%;
	flex-shrink: 0;
}

.tms-bar-label {
	font-family: "JetBrains Mono", monospace;
	color: #2a2a4e;
	width: 28px;
	flex-shrink: 0;
}

.tms-bar-val {
	font-family: "JetBrains Mono", monospace;
	color: #6b7094;
	width: 38px;
	text-align: right;
	flex-shrink: 0;
}

.tms-bar-bias {
	font-family: "JetBrains Mono", monospace;
	color: #8a8aaa;
	width: 64px;
	text-align: right;
	flex-shrink: 0;
}

/* ─── Scrollbar ──────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c0c0d0; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a0a0b0; }

/* ─── 2D Classifier + LIME Demo ──────────────────────────────── */

.clf-seg-group {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	font-size: 0.8em;
	color: #5a5a7a;
}

.clf-seg {
	padding: 5px 10px;
	font-size: 1em;
	font-weight: 600;
	background: #e0e0e8;
	color: #3a3a5e;
	border-radius: 4px;
}

.clf-seg:hover:not(.active) { background: #d0d0dc; }
.clf-seg.active { background: #6366f1; color: #ffffff; }

#reset-points-btn, #reset-network-btn { background: #e0e0e8; color: #3a3a5e; }
#reset-points-btn:hover:not(:disabled),
#reset-network-btn:hover:not(:disabled) { background: #d0d0dc; }

.clf-instructions {
	font-size: 0.82em;
	color: #5a5a7a;
	margin-bottom: 14px;
}

.clf-instructions code {
	font-family: "JetBrains Mono", monospace;
	font-size: 0.92em;
	background: #eeeef4;
	padding: 1px 4px;
	border-radius: 3px;
}

.clf-layout {
	display: flex;
	gap: 16px;
	align-items: flex-start;
	flex-wrap: wrap;
}

.clf-stage {
	position: relative;
	width: 560px;
	height: 560px;
	flex-shrink: 0;
	border: 1px solid #d0d0d8;
	border-radius: 6px;
	overflow: hidden;
}

.clf-canvas {
	position: absolute;
	top: 0;
	left: 0;
	width: 560px;
	height: 560px;
	display: block;
}

.clf-boundary { z-index: 1; }
.clf-overlay { z-index: 2; cursor: default; }

.clf-side {
	flex: 1;
	min-width: 240px;
	display: flex;
	flex-direction: column;
	gap: 14px;
}

.clf-side .viz-section { margin-bottom: 0; }

.clf-legend {
	display: flex;
	flex-direction: column;
	gap: 6px;
	font-size: 0.78em;
	color: #4a4a6a;
}

.clf-legend-row {
	display: flex;
	align-items: center;
	gap: 8px;
}

.clf-legend code {
	font-family: "JetBrains Mono", monospace;
	font-size: 0.9em;
	color: #6b7094;
}

.clf-swatch {
	width: 16px;
	height: 16px;
	border-radius: 4px;
	flex-shrink: 0;
}

.clf-swatch-a { background: rgb(40,90,200); }
.clf-swatch-b { background: rgb(210,50,80); }

.clf-cross {
	width: 16px;
	text-align: center;
	color: rgb(220,20,30);
	font-weight: 800;
	flex-shrink: 0;
}

.clf-dash {
	width: 16px;
	height: 0;
	border-top: 2.5px dashed rgb(70,70,80);
	flex-shrink: 0;
}

.clf-lime-readout {
	font-size: 0.8em;
	color: #3a3a5e;
	line-height: 1.7;
}

.clf-readout-dim {
	color: #8a8aaa;
	font-size: 0.92em;
}
