/* ──────────────────────────────────────────────────────────────────────────
   style.css — Noisy Connect
   White background, mathematical minimal aesthetic.
   No keyframe animations. Only transition on interactive elements.
   ────────────────────────────────────────────────────────────────────────── */

/* ── Tokens ───────────────────────────────────────────────────────────────── */
:root {
  --bg:          #ffffff;
  --text:        #111111;
  --text-muted:  #666666;
  --border:      #e5e7eb;
  --accent:      #2563eb;
  --accent-hover:#1d4ed8;
  --dot-noisy:   #aaaaaa;
  --dot-true:    #2563eb;
  --win-color:   #16a34a;
  --lose-color:  #dc2626;

  --font-ui:     'Inter', system-ui, sans-serif;
  --font-mono:   'JetBrains Mono', 'Fira Mono', monospace;

  --radius:      4px;
  --gap:         12px;

  /* Rule page compatibility mappings */
  --color-background-primary: var(--bg);
  --color-background-secondary: #f9fafb;
  --color-text-primary: var(--text);
  --color-text-secondary: var(--text-muted);
  --color-border-tertiary: var(--border);
  --border-radius-lg: 8px;
  --border-radius-md: 4px;
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.mono { font-family: var(--font-mono); }
.hidden { display: none !important; }

/* ── Header ───────────────────────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gap) 20px;
  border-bottom: 1px solid var(--border);
  gap: var(--gap);
}

#header-left {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}

#title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

#formula {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Info bar ─────────────────────────────────────────────────────────────── */
#info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  gap: var(--gap);
}

#moves-value { color: var(--text); }

#status-msg {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Main graph area ──────────────────────────────────────────────────────── */
#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 20px 8px;
  min-height: 0;
}

#graph {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

#canvas-container {
  flex: 1;
  width: 100%;
  min-height: 200px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
}

/* ── Range Slider ─────────────────────────────────────────────────────────── */
#range-container {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.range-slider {
  position: relative;
  width: 100%;
  height: 24px;
  display: flex;
  align-items: center;
}

#range-track {
  position: absolute;
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
}

#range-selection {
  position: absolute;
  height: 4px;
  background: var(--accent);
  opacity: 0.3;
  border-radius: 2px;
  z-index: 1;
}

.range-slider input[type="range"] {
  position: absolute;
  width: 100%;
  height: 24px;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
  background: none;
  outline: none;
  margin: 0;
  z-index: 2;
}

.range-slider input[type="range"]::-webkit-slider-thumb {
  pointer-events: auto;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent);
  cursor: pointer;
  transition: transform 100ms, border-color 100ms;
}

.range-slider input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent);
  cursor: pointer;
  transition: transform 100ms, border-color 100ms;
}

.range-slider input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  border-color: var(--accent-hover);
}

.range-slider input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.1);
  border-color: var(--accent-hover);
}

#range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

#graph-legend {
  display: flex;
  gap: 20px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-dot.noisy { background: var(--dot-noisy); }
.legend-dot.true  { background: var(--dot-true); }

.legend-line {
  width: 16px;
  height: 2px;
  background: var(--dot-true);
  opacity: 0.3;
  flex-shrink: 0;
}

/* ── Controls ─────────────────────────────────────────────────────────────── */
#controls {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

#controls label {
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
}

#input-x {
  flex: 1;
  min-width: 80px;
  max-width: 160px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 100ms;
}

#input-x:focus { border-color: var(--accent); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
button {
  padding: 6px 14px;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 100ms, color 100ms, border-color 100ms;
  white-space: nowrap;
}

/* Default: outlined */
button:not(.btn-accent) {
  background: var(--bg);
  color: var(--accent);
  border: 1px solid var(--accent);
}

button:not(.btn-accent):hover {
  background: #eff6ff;
}

/* Accent: filled */
.btn-accent {
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent);
}

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

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

/* ── Log ──────────────────────────────────────────────────────────────────── */
#log-section {
  border-top: 1px solid var(--border);
  padding: 8px 20px;
  max-height: 88px;
  overflow-y: auto;
}

#log {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12px;
  color: var(--text-muted);
}

#log li::before { content: "·  "; }

/* ── Game Over Panel ──────────────────────────────────────────────────────── */
#game-over-panel {
  border-top: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
}

#game-over-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#game-over-title {
  font-size: 18px;
  font-weight: 600;
}

#game-over-title.win  { color: var(--win-color); }
#game-over-title.lose { color: var(--lose-color); }

#game-over-body {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
  white-space: pre-line;
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 200ms ease;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal {
  background: var(--bg);
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  border-radius: var(--border-radius-lg);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(0);
  transition: transform 250ms cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.hidden .modal {
  transform: translateY(20px);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--color-background-secondary);
  color: var(--text-muted);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: background 150ms, color 150ms;
}

.modal-close:hover {
  background: var(--border);
  color: var(--text);
}

#modal-content {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

#modal-content .loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #header-left { gap: 8px; }
  #formula { display: none; }
  #controls { gap: 8px; }
  #input-x { max-width: 100%; }
  .modal { width: 95%; max-height: 90vh; }
  #modal-content { padding: 16px; }
}
