/* TRACE TRAIL — Level 15 · The Lab */

@font-face { font-family: "Press Start 2P"; font-style: normal; font-weight: 400; font-display: swap; src: url("/press-start-2p.woff2") format("woff2"); }
@font-face { font-family: "Press Start 2P Fallback"; src: local("Courier New"); size-adjust: 166.64%; ascent-override: 60%; descent-override: 0%; line-gap-override: 0%; }

:root {
  color-scheme: dark;

  --bg: #0a0a12;
  --surface: #12121d;
  --surface-2: #1a1a2a;
  --line: #28283c;
  --line-strong: #3a3a55;
  --text: #e9e9f2;
  --dim: #9aa0b5;
  --cyan: #45f0ff;
  --magenta: #ff3d8b;
  --gold: #ffc857;
  --green: #41ff8b;
  --red: #ff5560;

  --stage: #07070f;
  --field: #0d0d18;

  --pixel: "Press Start 2P", "Press Start 2P Fallback", "Courier New", monospace;
  --body: -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --glow-cyan: 0 0 14px rgba(69, 240, 255, 0.35);
  --space-gutter: clamp(16px, 4vw, 48px);
  --radius: 10px;
  --radius-sm: 6px;
}

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

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 520px at 50% -8%, rgba(69, 240, 255, 0.05), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Subtle CRT scanline texture over the whole experience */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.14) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
}

::selection { background: rgba(69, 240, 255, 0.3); }
[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; }
button, select, input[type="checkbox"], input[type="range"] { cursor: pointer; }
button:disabled, input:disabled, select:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

a { color: var(--cyan); }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(69, 240, 255, 0.18);
  border-radius: 3px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- skip + fixed lab link ---------- */
.skip-link {
  position: absolute;
  left: 12px; top: -56px;
  z-index: 200;
  background: var(--cyan);
  color: #05050d;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.2s var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(68px); }

.lab-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 120;
  display: inline-flex;
  align-items: center;
  font-family: var(--pixel);
  font-size: 10px;
  line-height: 1;
  letter-spacing: 1px;
  color: var(--dim);
  text-decoration: none;
  padding: 9px 11px;
  background: rgba(10, 10, 18, 0.78);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: color 0.15s, border-color 0.15s, text-shadow 0.15s, transform 0.15s var(--ease-out);
}
.lab-link:hover,
.lab-link:focus-visible {
  color: var(--cyan);
  border-color: var(--cyan);
  text-shadow: var(--glow-cyan);
  transform: translateX(-2px);
}

/* ---------- header ---------- */
.site-header {
  padding: 58px var(--space-gutter) 8px;
  text-align: center;
}

.brand { display: grid; justify-items: center; gap: 4px; }

.level {
  margin: 0;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(255, 200, 87, 0.4);
}

.wordmark {
  position: relative;
  margin: 8px 0 6px;
  font-family: var(--pixel);
  font-weight: 400;
  font-size: clamp(20px, 5.4vw, 38px);
  letter-spacing: 2px;
  color: var(--text);
  text-shadow: 0 0 18px rgba(69, 240, 255, 0.55), 3px 3px 0 var(--magenta);
}

/* glitch fringe on hover, echoing lab.css */
.wordmark::before,
.wordmark::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  text-shadow: none;
}
.wordmark::before { color: var(--cyan); }
.wordmark::after { color: var(--magenta); }
.wordmark:hover::before { animation: glitch-a 0.4s steps(3, jump-none) 1; }
.wordmark:hover::after { animation: glitch-b 0.4s steps(3, jump-none) 1; }

@keyframes glitch-a {
  0%   { opacity: 0.85; clip-path: inset(8% 0 72% 0);  transform: translate3d(-4px, -2px, 0); }
  50%  { opacity: 0.85; clip-path: inset(46% 0 28% 0); transform: translate3d(3px, 1px, 0); }
  100% { opacity: 0;    clip-path: inset(45% 0 45% 0); transform: translate3d(0, 0, 0); }
}
@keyframes glitch-b {
  0%   { opacity: 0.85; clip-path: inset(64% 0 16% 0); transform: translate3d(4px, 2px, 0); }
  50%  { opacity: 0.85; clip-path: inset(14% 0 66% 0); transform: translate3d(-3px, -1px, 0); }
  100% { opacity: 0;    clip-path: inset(45% 0 45% 0); transform: translate3d(0, 0, 0); }
}

.tagline {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
}
.cursor { color: var(--cyan); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- shell + grids ---------- */
.app-shell {
  flex: 1;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px var(--space-gutter) 64px;
}

.workspace,
.output-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.output-grid { margin-top: 16px; }

/* ---------- panels ---------- */
.panel {
  position: relative;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.4);
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.panel__header > div { display: grid; gap: 4px; }

.section-kicker {
  margin: 0;
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--magenta);
  text-shadow: 0 0 10px rgba(255, 61, 139, 0.4);
}

.panel-title {
  margin: 0;
  font-family: var(--pixel);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(69, 240, 255, 0.4);
}

.status-pill {
  min-width: 7rem;
  margin: 0;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--field);
  color: var(--green);
  font-family: var(--mono);
  font-size: 12px;
  text-align: center;
  white-space: nowrap;
}

/* ---------- stage ---------- */
.stage-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 900 / 520;
  min-height: 18rem;
  overflow: hidden;
  border-radius: 0 0 var(--radius) var(--radius);
  background:
    linear-gradient(90deg, rgba(69, 240, 255, 0.045) 1px, transparent 1px),
    linear-gradient(rgba(69, 240, 255, 0.045) 1px, transparent 1px),
    var(--stage);
  background-size: 40px 40px, 40px 40px, auto;
  touch-action: none;
}

.path-canvas,
.motion-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.path-canvas { display: block; }

.canvas-hit-area { fill: transparent; }
.canvas-grid { pointer-events: none; }
.grid-line { fill: none; stroke: rgba(69, 240, 255, 0.07); stroke-width: 1; }

.editor-path-shadow,
.editor-path {
  pointer-events: none;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.editor-path-shadow {
  stroke: rgba(0, 0, 0, 0.55);
  stroke-width: 13;
}
.editor-path {
  stroke: var(--green);
  stroke-width: 5;
  filter: drop-shadow(0 0 6px rgba(65, 255, 139, 0.55));
}

.point-layer { cursor: grab; }
.point-layer:active { cursor: grabbing; }
.trace-point { outline: none; }

.trace-point__ring {
  fill: var(--surface-2);
  stroke: var(--cyan);
  stroke-width: 2;
  transition: stroke 0.12s, stroke-width 0.12s;
}
.trace-point__core {
  fill: var(--cyan);
  stroke: #05050d;
  stroke-width: 2;
  filter: drop-shadow(0 0 5px rgba(69, 240, 255, 0.5));
}
.trace-point--corner .trace-point__core {
  fill: var(--gold);
  filter: drop-shadow(0 0 5px rgba(255, 200, 87, 0.5));
}
.trace-point:hover .trace-point__ring,
.trace-point:focus-visible .trace-point__ring {
  stroke: var(--text);
}
.trace-point--selected .trace-point__ring {
  stroke: var(--magenta);
  stroke-width: 4;
}
.trace-point--selected .trace-point__core {
  filter: drop-shadow(0 0 8px rgba(255, 61, 139, 0.7));
}
.trace-point__label {
  fill: var(--text);
  font-family: var(--pixel);
  font-size: 11px;
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
}

/* ---------- moving sprite ---------- */
.motion-layer { pointer-events: none; }

.motion-target {
  --trace-duration: 4.5s;
  --trace-easing: ease-in-out;
  position: absolute;
  left: 0;
  top: 0;
  width: 1.85rem;
  height: 1.85rem;
  offset-position: 0 0;
  offset-anchor: center;
  offset-distance: 0%;
  offset-rotate: auto;
  animation: trace-preview-move var(--trace-duration) var(--trace-easing) infinite;
  filter: drop-shadow(0 0 0.7rem rgba(255, 61, 139, 0.6));
}
.motion-target--idle { opacity: 0; }

.motion-target__core {
  position: absolute;
  inset: 0.2rem;
  border-radius: 4px;
  background: var(--magenta);
  border: 2px solid var(--text);
}
.motion-target__nose {
  position: absolute;
  top: 50%;
  right: -0.3rem;
  width: 0;
  height: 0;
  border-top: 0.42rem solid transparent;
  border-bottom: 0.42rem solid transparent;
  border-left: 0.66rem solid var(--gold);
  transform: translateY(-50%);
}

@keyframes trace-preview-move {
  from { offset-distance: 0%; }
  to { offset-distance: 100%; }
}

.stage-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  margin: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.5px;
  color: var(--dim);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

.support-warning {
  margin: 0;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  color: var(--gold);
  font-family: var(--mono);
  font-size: 13px;
}

/* ---------- controls ---------- */
.controls-panel { align-self: start; }

.controls-form {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.control-group {
  display: grid;
  gap: 12px;
  min-width: 0;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.control-group legend {
  padding: 0 6px;
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--gold);
}

.control-row,
.checkbox-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.control-row label,
.stacked-field,
.checkbox-row,
.coordinate-grid label {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 700;
}

select,
input[type="number"],
input[type="text"] {
  min-height: 2.75rem;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--text);
  font-family: var(--mono);
  padding: 0.55rem 0.65rem;
  transition: border-color 0.12s, box-shadow 0.12s;
}
select:hover,
input[type="number"]:hover,
input[type="text"]:hover { border-color: var(--line-strong); }
select:focus-visible,
input[type="number"]:focus-visible,
input[type="text"]:focus-visible { border-color: var(--cyan); }

.control-row select { max-width: 12rem; }

.range-pair {
  display: grid;
  grid-template-columns: 1fr 5.4rem;
  gap: 12px;
  align-items: center;
}

input[type="range"] {
  width: 100%;
  min-width: 0;
  accent-color: var(--cyan);
}

.stacked-field { display: grid; gap: 8px; }
input[aria-invalid="true"] {
  border-color: var(--red);
  box-shadow: 0 0 0 1px rgba(255, 85, 96, 0.4);
}

.checkbox-row { justify-content: flex-start; }
.checkbox-row input {
  width: 1.2rem;
  height: 1.2rem;
  accent-color: var(--cyan);
}

output { font-family: var(--mono); color: var(--gold); }

/* ---------- buttons ---------- */
.button-row,
.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.segmented { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.button {
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 0 0.85rem;
  transition: transform 0.12s var(--ease-out), border-color 0.12s, box-shadow 0.12s, color 0.12s;
}
.button:hover:not(:disabled) {
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 12px rgba(69, 240, 255, 0.22);
  transform: translateY(-1px);
}
.button:active:not(:disabled) { transform: translateY(1px); }

.button--primary {
  background: var(--cyan);
  border-color: var(--cyan);
  color: #05050d;
  box-shadow: 0 0 16px rgba(69, 240, 255, 0.3);
}
.button--primary:hover:not(:disabled) {
  color: #05050d;
  filter: brightness(1.08);
  box-shadow: 0 0 22px rgba(69, 240, 255, 0.5);
}

.button--danger:hover:not(:disabled) {
  border-color: var(--red);
  color: var(--red);
  box-shadow: 0 0 12px rgba(255, 85, 96, 0.25);
}

.button--wide { width: 100%; }

.segmented__button[aria-pressed="true"] {
  border-color: var(--magenta);
  color: var(--magenta);
  background: rgba(255, 61, 139, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 61, 139, 0.35);
}

.selected-output {
  display: block;
  min-height: 2.75rem;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
}

.coordinate-grid {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 8px;
  align-items: center;
}

/* ---------- points list ---------- */
.points-list {
  display: grid;
  gap: 8px;
  max-height: 19rem;
  margin: 0;
  padding: 16px;
  overflow: auto;
  list-style: none;
}
.point-list-empty {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 13px;
}

.points-list li {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.points-list li:has(.point-list-button[aria-current="true"]) {
  border-color: var(--magenta);
  box-shadow: 0 0 12px rgba(255, 61, 139, 0.18);
}

.point-list-button {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 2.75rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  padding: 0.65rem;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.point-list-button:hover { background: rgba(69, 240, 255, 0.06); }
.point-list-button[aria-current="true"] { color: var(--magenta); }

.point-chip {
  min-width: 4.4rem;
  color: var(--cyan);
  font-family: var(--mono);
  font-size: 12px;
}
.point-kind {
  color: var(--gold);
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ---------- css export ---------- */
.css-panel {
  display: grid;
  grid-template-rows: auto minmax(20rem, 1fr) auto;
}
.css-output {
  width: calc(100% - 2rem);
  min-height: 20rem;
  margin: 16px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--green);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  padding: 14px;
}
.css-output:focus-visible { border-color: var(--cyan); }

.copy-status {
  min-height: 1.4rem;
  margin: 0;
  padding: 0 16px 14px;
  color: var(--green);
  font-family: var(--mono);
  font-size: 12.5px;
}

/* ---------- privacy + footer ---------- */
.privacy-note {
  max-width: 540px;
  margin: 22px auto 0;
  text-align: center;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 12px;
}

.site-footer {
  border-top: 1px solid var(--line);
  padding: 22px var(--space-gutter);
  text-align: center;
  color: var(--dim);
  font-size: 13px;
}
.site-footer a { color: var(--cyan); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; text-shadow: var(--glow-cyan); }

/* ---------- responsive ---------- */
@media (min-width: 768px) {
  .output-grid { grid-template-columns: minmax(18rem, 0.8fr) minmax(0, 1.8fr); }
}

@media (min-width: 1024px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 22rem;
    align-items: start;
  }
  .panel--stage { min-height: 100%; }
}

@media (min-width: 1280px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 24rem; }
}

@media (max-width: 480px) {
  .wordmark { letter-spacing: 1px; }
  .coordinate-grid { grid-template-columns: auto 1fr; }
}

@media (max-width: 360px) {
  .button-row { grid-template-columns: 1fr; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .cursor { animation: none; }
  .motion-target { animation: none; offset-distance: 0%; }
  .wordmark:hover::before,
  .wordmark:hover::after { animation: none; opacity: 0; }
}
