:root {
  --bg: #0a0a0c;
  --panel: #121218;
  --panel-2: #1a1a22;
  --border: #2a2a36;
  --text: #f0f0f4;
  --muted: #8b8b9a;
  --accent: #6366f1;
  --accent-soft: rgba(99, 102, 241, 0.18);
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.15);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --radius: 12px;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 102, 241, 0.12), transparent),
    radial-gradient(ellipse 40% 30% at 100% 100%, rgba(52, 211, 153, 0.06), transparent);
}

.mono {
  font-family: var(--mono);
  font-size: 0.92em;
}

.back-link {
  position: fixed;
  top: 14px;
  left: 16px;
  z-index: 20;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
  padding: 0 12px;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}

.back-link:hover {
  color: var(--text);
  background: var(--panel-2);
}

.app {
  max-width: 920px;
  margin: 0 auto;
  padding: 52px 16px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.header {
  text-align: center;
  max-width: 560px;
  margin: 0;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.header h1 {
  margin: 0 0 8px;
  font-size: clamp(1.6rem, 4vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* Compact status above the grid */
.status-row {
  width: 100%;
  max-width: min(100%, 720px);
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
}

.status-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  min-width: 160px;
  transition: border-color 0.2s, background 0.2s;
}

.status-card[data-spans="true"] {
  border-color: rgba(52, 211, 153, 0.35);
  background: linear-gradient(145deg, var(--ok-soft), var(--panel));
}

.status-card[data-spans="false"] {
  border-color: rgba(248, 113, 113, 0.2);
  background: linear-gradient(145deg, var(--danger-soft), var(--panel));
}

.status-value {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.status-card[data-spans="true"] .status-value {
  color: var(--ok);
}

.status-card[data-spans="false"] .status-value {
  color: var(--danger);
}

.status-sub {
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--muted);
}

.stat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
  justify-content: center;
  min-width: 0;
}

.stat {
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  min-width: 88px;
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}

.stat-value {
  font-size: 0.9rem;
  font-weight: 600;
}

/* Centered pixel grid — visual focus */
.viz-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

#canvas {
  width: min(100%, min(92vw, 72vh, 720px));
  height: auto;
  aspect-ratio: 1;
  display: block;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #08080c;
  box-shadow:
    0 8px 40px rgba(0, 0, 0, 0.5),
    inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: grab;
}

#canvas.dragging {
  cursor: grabbing;
}

/* Controls below the grid */
.controls {
  width: 100%;
  max-width: min(100%, 560px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.control-block {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
}

.control-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  gap: 8px;
}

.control-head label {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
}

.control-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: #8b8ff8;
}

input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  border: 0;
  outline: none;
  cursor: pointer;
  accent-color: var(--accent);
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  box-sizing: border-box;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

input[type="range"]::-moz-range-track {
  height: 6px;
  box-sizing: border-box;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  margin-top: -7px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #c7d2fe;
  box-shadow: 0 1px 6px rgba(99, 102, 241, 0.5);
  cursor: grab;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #c7d2fe;
  box-shadow: 0 1px 6px rgba(99, 102, 241, 0.5);
  cursor: grab;
}

input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.slider-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--mono);
}

.pc-mark {
  color: #8b8ff8;
  opacity: 0.85;
}

.play-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.play-row .btn {
  flex: 1;
}

.speed-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.speed-row label {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
}

.speed-row select {
  flex: 0 0 auto;
  min-width: 5.5rem;
  padding: 8px 10px;
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  accent-color: var(--accent);
}

.speed-row select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  flex: 1 1 auto;
  min-width: 96px;
  min-height: 44px;
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: #4f46e5;
  border-color: #818cf8;
  color: #fff;
}

.btn-primary:hover {
  background: #4338ca;
}

.btn-ghost {
  background: var(--panel);
  color: var(--text);
}

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

.btn[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #c7d2fe;
}

.view-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
  text-align: center;
}

.help {
  width: 100%;
  max-width: min(100%, 560px);
  padding: 16px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
}

.help h2 {
  margin: 0 0 10px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.help p {
  margin: 0 0 10px;
  font-size: 0.86rem;
  line-height: 1.55;
  color: #b4b4c4;
}

.help p:last-child {
  margin-bottom: 0;
}

.help strong {
  color: var(--text);
  font-weight: 600;
}

@media (max-width: 520px) {
  .app {
    padding-top: 48px;
  }

  .play-row {
    flex-direction: column;
  }

  .buttons {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }

  .stat-pills {
    width: 100%;
  }

  .stat {
    flex: 1 1 40%;
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
