/* MESH — style.css
   The Lab · dark arcade / retro-terminal. A gradient foundry cabinet:
   pixel type for the wordmark and HUD labels, clean mono controls,
   neon-on-near-black surfaces, subtle CRT scanlines. Dark only. */

/* ---------- fonts (self-hosted, shared with the lab root) ---------- */

@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%; }

/* ---------- tokens ---------- */

:root {
  color-scheme: dark;

  --bg: #0a0a12;
  --surface: #12121d;
  --surface-2: #1a1a2a;
  --surface-3: #20203200;
  --line: #28283c;
  --control-line: #5e5e80; /* >=3:1 against --surface for control boundaries */
  --text: #e9e9f2;
  --dim: #9aa0b5;
  --cyan: #45f0ff;
  --magenta: #ff3d8b;
  --gold: #ffc857;
  --green: #41ff8b;
  --red: #ff5560;

  --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;

  --radius: 10px;
  --radius-sm: 6px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 150ms;
  --dur: 280ms;
  --glow-cyan: 0 0 14px rgba(69, 240, 255, 0.4);
  --glow-magenta: 0 0 14px rgba(255, 61, 139, 0.4);
  --checker: repeating-conic-gradient(#16161f 0% 25%, #101019 0% 50%);
  --gutter: clamp(14px, 3.5vw, 34px);
}

/* ---------- base ---------- */

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

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  background:
    radial-gradient(1100px 480px at 78% -8%, rgba(255, 61, 139, 0.07), transparent 64%),
    radial-gradient(1000px 520px at 16% -6%, rgba(69, 240, 255, 0.07), transparent 62%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(69, 240, 255, 0.3); color: var(--text); }

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled, input:disabled { cursor: not-allowed; }

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

/* full-screen CRT scanline veil */
.scanlines {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.16) 0 1px,
    transparent 1px 3px
  );
  mix-blend-mode: multiply;
  opacity: 0.55;
}

/* ---------- focus + a11y ---------- */

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

.sr-only {
  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-link {
  position: absolute;
  left: 12px; top: -64px;
  z-index: 300;
  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 var(--dur) var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(78px); }

/* fixed back-to-lab link */
.lab-link {
  position: fixed;
  top: 14px; left: 14px;
  z-index: 120;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--pixel);
  font-size: 9px;
  line-height: 1;
  letter-spacing: 1px;
  color: var(--dim);
  text-decoration: none;
  padding: 9px 12px;
  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 var(--dur-fast), border-color var(--dur-fast),
    text-shadow var(--dur-fast), transform var(--dur-fast) 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);
}

/* ---------- app shell ---------- */

.mesh-app {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gutter);
  align-items: start;
  min-height: 100svh;
  padding: clamp(58px, 9vw, 78px) var(--gutter) var(--gutter);
}

.workspace,
.control-panel { min-width: 0; }

.workspace {
  display: flex;
  flex-direction: column;
  gap: clamp(16px, 2.5vw, 24px);
}

/* ---------- header ---------- */

.app-header {
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: flex-start;
}

.app-brand { min-width: 0; }

.eyebrow {
  margin: 0 0 12px;
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(255, 200, 87, 0.3);
}

.wordmark {
  position: relative;
  margin: 0;
  font-family: var(--pixel);
  font-weight: 400;
  font-size: clamp(30px, 8vw, 60px);
  letter-spacing: 3px;
  line-height: 1;
  color: var(--text);
  text-shadow: 0 0 22px rgba(69, 240, 255, 0.5), 3px 3px 0 var(--magenta);
}

.tagline {
  margin: 14px 0 0;
  font-family: var(--mono);
  font-size: clamp(11px, 2.4vw, 13px);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--dim);
}

.cursor {
  display: inline-block;
  margin-left: 4px;
  color: var(--cyan);
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ---------- buttons ---------- */

.button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 2.75rem;
  padding: 0.7rem 1.05rem;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 0.5px;
  line-height: 1;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: transform var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast), border-color var(--dur-fast),
    color var(--dur-fast);
}

.button__key {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1;
  opacity: 0.85;
}

.button-primary {
  color: var(--bg);
  background: var(--cyan);
  box-shadow: 0 0 0 0 rgba(69, 240, 255, 0), 0 6px 18px rgba(0, 0, 0, 0.4);
}
.button-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 26px rgba(69, 240, 255, 0.55), 0 8px 22px rgba(0, 0, 0, 0.45);
}

.button-secondary {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--line);
}
.button-secondary:hover {
  transform: translateY(-2px);
  color: var(--cyan);
  border-color: var(--cyan);
  box-shadow: var(--glow-cyan);
}

.button-ghost {
  color: var(--gold);
  background: transparent;
  border-color: rgba(255, 200, 87, 0.45);
}
.button-ghost:hover {
  transform: translateY(-2px);
  background: rgba(255, 200, 87, 0.08);
  border-color: var(--gold);
  box-shadow: 0 0 14px rgba(255, 200, 87, 0.28);
}

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

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  font-family: var(--pixel);
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-sm);
  transition: transform var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast), color var(--dur-fast),
    box-shadow var(--dur-fast);
}
.icon-button:hover {
  color: var(--cyan);
  border-color: var(--cyan);
  box-shadow: var(--glow-cyan);
}
.icon-button:active { transform: translateY(1px); }
.icon-button:disabled {
  opacity: 0.4;
  color: var(--dim);
  border-color: var(--line);
  box-shadow: none;
}

/* ---------- canvas stage ---------- */

.canvas-frame {
  position: relative;
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--checker);
  background-size: 22px 22px;
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.55),
    inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    0 0 40px rgba(69, 240, 255, 0.06);
}

/* corner registration ticks — arcade bezel detail */
.canvas-frame::before,
.canvas-frame::after {
  content: "";
  position: absolute;
  z-index: 3;
  width: 14px; height: 14px;
  pointer-events: none;
  border: 2px solid rgba(69, 240, 255, 0.55);
}
.canvas-frame::before {
  top: 8px; left: 8px;
  border-right: 0; border-bottom: 0;
  border-top-left-radius: 3px;
}
.canvas-frame::after {
  bottom: 8px; right: 8px;
  border-left: 0; border-top: 0;
  border-bottom-right-radius: 3px;
}

#meshCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  touch-action: none;
  background: #151824;
  cursor: crosshair;
}

.canvas-hint {
  position: absolute;
  left: 10px; bottom: 10px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 6px 11px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.3px;
  color: var(--text);
  background: rgba(10, 10, 18, 0.72);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
}

.canvas-hint__dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px rgba(65, 255, 139, 0.8);
  animation: pulse-dot 2.2s var(--ease-out) infinite;
}
@keyframes pulse-dot { 50% { opacity: 0.35; transform: scale(0.82); } }

/* ---------- control panel ---------- */

.control-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(26, 26, 42, 0.6), rgba(18, 18, 29, 0.9)),
    var(--surface);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
}

.controls-form {
  display: grid;
  gap: clamp(16px, 2.2vw, 22px);
  padding: clamp(16px, 2.4vw, 22px);
}

.control-section {
  display: grid;
  gap: 0.9rem;
  min-width: 0;
}

.control-section + .control-section {
  border-top: 1px dashed var(--line);
  padding-top: clamp(16px, 2.2vw, 22px);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-family: var(--pixel);
  font-size: 11px;
  letter-spacing: 1px;
  line-height: 1.3;
  color: var(--text);
}

.panel-title__tick {
  font-size: 8px;
  color: var(--bg);
  background: var(--magenta);
  padding: 4px 5px;
  border-radius: 3px;
  box-shadow: 0 0 12px rgba(255, 61, 139, 0.35);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.inline-actions { display: flex; gap: 8px; }

/* ---------- form fields ---------- */

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

.field-row { min-height: 2.75rem; }

.field-stack { display: grid; gap: 0.45rem; }

label {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--dim);
}

output {
  font-family: var(--pixel);
  font-size: 9px;
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(69, 240, 255, 0.3);
}

input[type="color"] {
  width: 4rem;
  min-height: 2.5rem;
  padding: 0.25rem;
  background: var(--surface-2);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
input[type="color"]:hover { border-color: var(--cyan); }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 3px; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 3px; }

input[type="number"] {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.5rem 0.7rem;
  font-family: var(--mono);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-sm);
}
input[type="number"]:hover { border-color: #74749a; }
input[type="number"]:focus-visible { border-color: var(--cyan); }

/* range — custom arcade slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 2rem;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.4);
}
input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  margin-top: -6px;
  border-radius: 3px;
  background: var(--text);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--cyan), 0 0 12px rgba(69, 240, 255, 0.5);
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 3px;
  background: var(--text);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--cyan), 0 0 12px rgba(69, 240, 255, 0.5);
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.12); box-shadow: 0 0 0 1px var(--cyan), 0 0 18px rgba(69, 240, 255, 0.75); }
input[type="range"]:hover::-moz-range-thumb { box-shadow: 0 0 0 1px var(--cyan), 0 0 18px rgba(69, 240, 255, 0.75); }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(0.94); }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 2px var(--gold), 0 0 16px rgba(255, 200, 87, 0.6); }
input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 2px var(--gold), 0 0 16px rgba(255, 200, 87, 0.6); }
input[type="range"]:disabled { opacity: 0.4; }

/* ---------- point list ---------- */

.point-list {
  display: grid;
  gap: 0.5rem;
  max-height: 14rem;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: var(--control-line) transparent;
}
.point-list::-webkit-scrollbar { width: 8px; }
.point-list::-webkit-scrollbar-thumb { background: var(--control-line); border-radius: 999px; }

.point-button {
  display: grid;
  grid-template-columns: 1.5rem 1fr auto;
  gap: 0.7rem;
  align-items: center;
  width: 100%;
  min-height: 2.75rem;
  padding: 0.5rem 0.65rem;
  text-align: left;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast), background-color var(--dur-fast),
    transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast);
}
.point-button:hover {
  transform: translateX(2px);
  border-color: var(--control-line);
}
.point-button.is-selected {
  border-color: var(--cyan);
  background: rgba(69, 240, 255, 0.06);
  box-shadow: var(--glow-cyan);
}

.point-swatch {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 0 10px rgba(0, 0, 0, 0.4);
}

.point-name {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0.5px;
  color: var(--text);
}
.point-button.is-selected .point-name { color: var(--cyan); }

.point-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
}

/* ---------- export ---------- */

.export-size-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}
.export-actions .button { flex: 1 1 auto; justify-content: center; }

.css-output {
  width: 100%;
  min-height: 11rem;
  resize: vertical;
  padding: 0.8rem;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  color: var(--green);
  background:
    repeating-linear-gradient(0deg, rgba(65, 255, 139, 0.03) 0 1px, transparent 1px 3px),
    #0c0c14;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.5);
}
.css-output:focus-visible { border-color: var(--cyan); }

.status-message {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 1.4rem;
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.4px;
  color: var(--gold);
}
.status-message::before {
  content: "\203A";
  color: var(--green);
  font-weight: 700;
}
.status-message.is-error { color: var(--red); }
.status-message.is-error::before { content: "\2716"; color: var(--red); }

.panel-footnote {
  margin: 0;
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 1px;
  text-align: center;
  color: var(--dim);
  opacity: 0.7;
}

/* ---------- responsive ---------- */

@media (min-width: 720px) {
  .app-header {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
  }
}

@media (min-width: 1040px) {
  .mesh-app {
    grid-template-columns: minmax(0, 1fr) minmax(20rem, 23rem);
  }
  .control-panel {
    position: sticky;
    top: clamp(58px, 9vw, 78px);
  }
  .controls-form {
    max-height: calc(100svh - clamp(58px, 9vw, 78px) - var(--gutter));
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--control-line) transparent;
  }
  .controls-form::-webkit-scrollbar { width: 8px; }
  .controls-form::-webkit-scrollbar-thumb { background: var(--control-line); border-radius: 999px; }
}

@media (max-width: 420px) {
  .header-actions { width: 100%; }
  .header-actions .button { flex: 1 1 auto; justify-content: center; }
  .canvas-hint { font-size: 10px; padding: 5px 9px; left: 8px; bottom: 8px; }
  .lab-link { font-size: 8px; padding: 8px 10px; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .cursor { animation: none; }
  .button:hover,
  .button-secondary:hover,
  .button-ghost:hover,
  .icon-button:hover,
  .point-button:hover,
  .lab-link:hover { transform: none; }
}
