/*
 * Wing Theme &#8212; Flutterby Identity System
 *
 * Shared design system for all wing mark tools. Derived from
 * Ampersand gallery.css patterns, adapted for Flutterby's cooler
 * dark ground and tool-oriented layout.
 *
 * Consumed via: <link rel="stylesheet" href="wing-theme.css">
 *
 * Layers:
 *   1. Reset
 *   2. Custom properties (colour, glass, type, spacing)
 *   3. Body base
 *   4. SVG shared classes (quadrants, handles, waypoints, curve)
 *   5. Tool chrome (header, body, viewport, controls)
 *   6. Controls vocabulary (sliders, toggles, groups, buttons)
 *   7. Responsive adaptations
 *   8. Motion and hover preferences
 */

/* ---- 1. Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ---- 2. Custom properties ---- */
:root {
  /* Dark ground (constitutional &#8212; cooler than Ampersand) */
  --bg: #0a0a0b;
  --surface: #111113;
  --border: #1e1e21;
  --text: #fafafa;
  --text-muted: #71717a;
  --text-dim: #3f3f46;
  --accent: #9B59B6;
  --ink: #F5F2ED;

  /* Palette colours */
  --blue: #4A90D9;
  --green: #50B86C;
  --orange: #E8913A;
  --purple: #9B59B6;
  --red: #E74C3C;

  /* Glass material */
  --glass-blur: 10px;
  --glass-tint: color-mix(in oklch, var(--bg) 15%, transparent);
  --glass-edge: color-mix(in oklch, var(--text) 3%, transparent);

  /* Typography */
  --font-stack: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  /* Spacing scale (4px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;

  /* Transition */
  --transition-utility: 200ms ease;
}

/* ---- 3. Body base ---- */
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-stack);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  touch-action: manipulation;
  height: 100vh;
  overflow: hidden;
}

/* ---- 4. SVG shared classes ---- */

/* Quadrant fills */
.q         { fill-opacity: 0.05; stroke-opacity: 0.15; stroke-width: 0.5; }
.q-A       { fill: var(--blue);   stroke: var(--blue); }
.q-B       { fill: var(--green);  stroke: var(--green); }
.q-C       { fill: var(--orange); stroke: var(--orange); }
.q-D       { fill: var(--purple); stroke: var(--purple); }

/* Quadrant labels */
.q-label   { font: 600 10px system-ui; fill-opacity: 0.2; }

/* Waypoint dots */
.wp        { fill: var(--red); opacity: 0.45; }

/* Main curve stroke */
.curve     {
  fill: none;
  stroke: var(--ink);
  stroke-width: 4.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Handle groups */
.h         { opacity: 0.25; }
.h line    { stroke-width: 0.7; }
.h-A line, .h-A circle { stroke: var(--blue);   fill: var(--blue); }
.h-B line, .h-B circle { stroke: var(--green);  fill: var(--green); }
.h-C line, .h-C circle { stroke: var(--orange); fill: var(--orange); }
.h-D line, .h-D circle { stroke: var(--purple); fill: var(--purple); }
.h-x line, .h-x circle { stroke: var(--red);    fill: var(--red); }
.h-x line  { stroke-dasharray: 3; }

/* CP number labels (benchmarks) */
.cp-num    { font: 500 7px system-ui; fill: var(--text-muted); fill-opacity: 0.6; }

/* ---- 5. Tool chrome ---- */

/* Fixed glass header bar */
.tool-header {
  position: relative;
  z-index: 10;
  height: 48px;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--glass-edge);
  background: var(--bg);
  flex-shrink: 0;
}

@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .tool-header {
    background: var(--glass-tint);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.2);
    backdrop-filter: blur(var(--glass-blur)) saturate(1.2);
  }
}

.tool-header a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}

.tool-header h1 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.tool-header .tool-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: auto;
}

/* Body: viewport + controls */
.tool-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* Viewport: centred canvas/SVG area */
.tool-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-7);
  position: relative;
}

/* Controls sidebar */
.tool-controls {
  width: 300px;
  padding: var(--space-6) var(--space-5);
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}

.tool-controls h2 {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: var(--space-5);
}

/* ---- 6. Controls vocabulary ---- */

/* Group card */
.group {
  margin-bottom: var(--space-4);
  padding: 14px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.group-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

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

.group-head .name {
  font-size: 13px;
  font-weight: 600;
}

.group-head .desc,
.group-head .quad {
  font-size: 10px;
  color: var(--text-dim);
  margin-left: auto;
}

/* Axis toggle bar */
.axis-bar {
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: var(--space-3);
}

.axis-bar button {
  flex: 1;
  padding: 5px 0;
  border: none;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  font: 500 11px system-ui;
  color: var(--text-muted);
  transition: all var(--transition-utility);
  min-height: 44px;
}

.axis-bar button:first-child { border-right: 1px solid var(--border); }
.axis-bar button.on { background: var(--text); color: var(--bg); }

/* Slider row */
.slider-row,
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.slider-row:last-child,
.row:last-child { margin-bottom: 0; }

.row label {
  font: 500 10px system-ui;
  color: var(--text-muted);
  min-width: 56px;
}

.slider-row input[type="range"],
.row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  outline: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb,
.row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-muted);
  cursor: pointer;
}

.slider-row input[type="range"]::-moz-range-thumb,
.row input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-muted);
  border: none;
  cursor: pointer;
}

.slider-val,
.row .val {
  font: 500 11px system-ui;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  min-width: 38px;
  text-align: right;
}

.row .val { min-width: 32px; font-size: 10px; }

/* Toggle row */
.toggle-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  margin-top: var(--space-3);
}

.toggle-row label {
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.toggle-row input { cursor: pointer; }

/* Preset bar */
.preset-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: var(--space-2);
}

.preset-bar button {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font: 500 10px system-ui;
  padding: var(--space-1) 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: all var(--transition-utility);
  min-height: 44px;
}

/* Buttons */
.btn-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  border-radius: 6px;
  font: 500 11px var(--font-stack);
  cursor: pointer;
  transition: all var(--transition-utility);
  border: 1px solid var(--border);
  min-height: 44px;
}

.btn-label:active { transform: scale(0.92); }

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

.btn-secondary {
  background: none;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost {
  background: none;
  color: var(--text-muted);
  border-color: transparent;
}

/* ---- 7. Responsive ---- */
@media (max-width: 768px) {
  .tool-body {
    flex-direction: column;
  }

  .tool-viewport {
    padding: var(--space-4);
    min-height: 50vh;
  }

  .tool-controls {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 50vh;
  }
}

/* ---- 8. Motion and hover preferences ---- */
@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;
  }

  .tool-header {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: color-mix(in oklch, var(--bg) 80%, transparent);
  }
}

@media (hover: hover) {
  .tool-header a:hover { color: var(--text); }
  .preset-bar button:hover { color: var(--text); border-color: var(--text-dim); }
  .preset-bar button.on { color: var(--text); border-color: var(--accent); background: rgba(155, 89, 182, 0.12); }
  .btn-secondary:hover { color: var(--text); border-color: var(--text-dim); }
  .btn-ghost:hover { color: var(--text); }
}
