/* styles.css — Forehand Degrees-of-Freedom Interactive Explorer
 * Implements modern-web-guidance patterns for tabs, search-hidden-content, slider, forms, and brand-consistent-forms. */

:root {
  color-scheme: light dark;
  --brand-color: #0284c7;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #edf2f9;
  --border: #cbd7e6;
  --fg: #0f1b2d;
  --muted: #4b5e78;
  --col-z: #d97706;
  --col-th: #0284c7;
  --col-r: #e11d48;
  --col-plane: #059669;
  --col-whip: #65a30d;
  --col-roll: #7c3aed;
  --slider-track-bg: #cbd5e1;
  --shadow: 0 1px 3px rgb(15 27 45 / 0.06), 0 6px 18px rgb(15 27 45 / 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --brand-color: #3ccbff;
    --bg: #070d16;
    --surface: #0e1726;
    --surface-2: #152236;
    --border: #243752;
    --fg: #ecf2f8;
    --muted: #93a7bf;
    --col-z: #ffb224;
    --col-th: #3ccbff;
    --col-r: #ff5f9e;
    --col-plane: #34d399;
    --col-whip: #d9f23b;
    --col-roll: #b692ff;
    --slider-track-bg: #24364f;
    --shadow: 0 2px 10px rgb(0 0 0 / 0.35);
  }
}

:root.dark {
  color-scheme: dark;
  --brand-color: #3ccbff;
  --bg: #070d16;
  --surface: #0e1726;
  --surface-2: #152236;
  --border: #243752;
  --fg: #ecf2f8;
  --muted: #93a7bf;
  --col-z: #ffb224;
  --col-th: #3ccbff;
  --col-r: #ff5f9e;
  --col-plane: #34d399;
  --col-whip: #d9f23b;
  --col-roll: #b692ff;
  --slider-track-bg: #24364f;
  --shadow: 0 2px 10px rgb(0 0 0 / 0.35);
}

:root.light {
  color-scheme: light;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  accent-color: var(--brand-color);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.875rem;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: 1500px;
  margin-inline: auto;
  padding: 0.875rem 1rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

/* Header & Live Telemetry Bar */
.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow);
}

.brand-title {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.brand-title h1 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-subtitle {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.telemetry-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 0.625rem;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.625rem 0.875rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.metric-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

.epistemic-chip {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.metric-val {
  font-size: 1.125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.metric-sub {
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Part 4 Topspin Source Decomposition Stacked Mini-Bar */
.spin-bar {
  display: flex;
  inline-size: 100%;
  block-size: 0.38rem;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-block: 0.08rem;
  gap: 1px;
}

.spin-seg {
  display: block;
  block-size: 100%;
  transition: width 0.18s ease, background-color 0.18s ease;
}

.spin-seg-plane {
  background: var(--col-plane);
}

.spin-seg-whip {
  background: var(--col-roll);
}

.spin-seg.is-backspin {
  background: var(--col-r);
}

.verdict-pill {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}
.verdict-IN { background: rgb(16 185 129 / 0.18); color: var(--col-plane); }
.verdict-LONG, .verdict-WIDE { background: rgb(245 158 11 / 0.18); color: var(--col-z); }
.verdict-NET { background: rgb(244 63 94 / 0.18); color: var(--col-r); }

/* Main Studio Grid */
.studio-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.32fr) minmax(380px, 1fr);
  gap: 0.875rem;
  align-items: start;
}

@media (max-width: 1060px) {
  .studio-grid {
    grid-template-columns: 1fr;
  }
}

.stage-col {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

/* Efficient background processing for rendering-heavy canvas containers */
.heavy-render-section {
  content-visibility: auto;
  contain-intrinsic-size: auto none auto 540px;
}

.stage-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  padding: 0.75rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.stage-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
}

.btn {
  appearance: none;
  min-inline-size: 24px;
  min-block-size: 24px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--fg);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.62rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.share-action {
  position: relative;
  display: inline-flex;
  align-items: center;
}

#btn-share[data-copied] {
  border-color: var(--col-plane);
  color: var(--col-plane);
}

#btn-share[data-failed] {
  border-color: var(--col-r);
  color: var(--col-r);
}

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .spin-seg,
  .dial-card {
    transition: none;
  }
}

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

.btn:focus-visible {
  outline: 2px solid var(--brand-color);
  outline-offset: 2px;
}

.btn[aria-pressed="true"],
.btn.is-active {
  background: var(--brand-color);
  border-color: var(--brand-color);
  color: #06121e;
}

:root.light .btn[aria-pressed="true"],
:root.light .btn.is-active {
  color: #ffffff;
}

@media (prefers-color-scheme: light) {
  :root:not(.dark) .btn[aria-pressed="true"],
  :root:not(.dark) .btn.is-active {
    color: #ffffff;
  }
}

.canvas-wrap {
  position: relative;
  width: 100%;
  height: 445px;
  border-radius: 0.65rem;
  overflow: hidden;
  border: 1px solid var(--border);
  touch-action: none;
  cursor: grab;
}

.canvas-wrap:active {
  cursor: grabbing;
}

.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.canvas-badge {
  position: absolute;
  bottom: 0.55rem;
  left: 0.65rem;
  right: 0.65rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  pointer-events: none;
  font-size: 0.75rem;
  color: var(--muted);
}

.canvas-badge span {
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  border: 1px solid var(--border);
  padding: 0.15rem 0.5rem;
  border-radius: 0.4rem;
}

/* Scrubber & Time Lens Controls */
.scrubber-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  padding: 0.55rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.scrubber-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.phase-jumps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.chip-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  cursor: pointer;
}

.chip-btn:hover {
  color: var(--fg);
  border-color: var(--brand-color);
}

.chip-btn:focus-visible {
  outline: 2px solid var(--brand-color);
  outline-offset: 2px;
}

/* Two Diagnostic Scopes Row */
.scopes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.875rem;
}

.scope-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  padding: 0.65rem 0.75rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.scope-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
}

.scope-canvas-box {
  width: 100%;
  height: 186px;
  border-radius: 0.55rem;
  overflow: hidden;
  border: 1px solid var(--border);
}

.scope-canvas-box canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* Right Column: Control Deck & Tabs */
.deck-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  padding: 0.75rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.deck-form {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.deck-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.deck-heading {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 700;
}

.deck-subhint {
  font-size: 0.75rem;
  color: var(--muted);
}

.preset-strip {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.preset-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.32rem;
}

/* Accessible Tablist (`modern-web-guidance` tabs pattern) */
.tabs {
  display: flex;
  flex-direction: column;
}

.tablist {
  display: flex;
  overflow-x: auto;
  border-block-end: 1px solid var(--border);
  scroll-snap-type: inline proximity;
}

[role="tab"] {
  position: relative;
  flex: none;
  scroll-snap-align: start;
  appearance: none;
  background: transparent;
  border: 0;
  margin: 0;
  padding: 0.5rem 0.85rem;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

[role="tab"]:hover {
  color: var(--fg);
}

[role="tab"]:focus-visible {
  outline: 2px solid var(--brand-color);
  outline-offset: -2px;
}

[role="tab"][aria-selected="true"] {
  color: var(--brand-color);
}

[role="tab"][aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  border-block-end: 3px solid var(--brand-color);
}

/* Avoid `gap` between panels and keep padding/borders off `[role="tabpanel"]` itself (`tabs` + `search-hidden-content`).
 * Disable pointer hit-testing on `[hidden]` panels without setting `display: none` or `visibility: hidden` so
 * `hidden="until-found"` stays indexed by find-in-page while never intercepting pointer drags on active controls. */
.tabpanels-stack {
  display: block;
}

[role="tabpanel"][hidden] {
  pointer-events: none;
}

.panel-inner {
  padding-block-start: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

/* Interactive 6-Dial Rotary Rack */
.dial-rack-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  padding: 0.55rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.dial-rack-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}

.dial-rack {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
}

@media (max-width: 460px) {
  .dial-rack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.dial-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  padding: 0.35rem 0.35rem 0.3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  cursor: ns-resize;
  user-select: none;
  touch-action: none;
  transition: border-color 0.15s, transform 0.1s;
}

.dial-card:hover,
.dial-card.is-dragging {
  border-color: var(--brand-color);
}

.dial-svg {
  width: 56px;
  height: 44px;
  display: block;
  overflow: visible;
}

.dial-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  line-height: 1.15;
}

.dial-val {
  font-size: 0.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}

/* Semantic `<fieldset>` + `<legend>` DoF Control Groups (`forms` guide) */
fieldset.dof-group {
  margin: 0;
  min-inline-size: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  padding: 0.45rem 0.75rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

legend.dof-group-title {
  padding-inline: 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}

.control-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.control-header label {
  font-size: 0.8125rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  cursor: pointer;
}

.swatch {
  inline-size: 0.58rem;
  block-size: 0.58rem;
  border-radius: 50%;
  display: inline-block;
  flex: none;
}

.control-readout {
  font-size: 0.8125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.num-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  flex: none;
}

.dof-num {
  appearance: textfield;
  inline-size: 4.35rem;
  min-block-size: 1.65rem;
  padding: 0.12rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.dof-num::-webkit-inner-spin-button,
.dof-num::-webkit-outer-spin-button {
  opacity: 0.75;
}

.dof-num:focus-visible {
  outline: 2px solid var(--brand-color);
  outline-offset: 1px;
  border-color: var(--brand-color);
}

.dof-num:user-invalid {
  border-color: var(--col-r);
  outline: 2px solid var(--col-r);
}

.dof-unit {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  min-inline-size: 1.65rem;
}

.control-hint {
  font-size: 0.75rem;
  color: var(--muted);
}

/* Brand-Consistent Native Range Slider (`modern-web-guidance` slider pattern) */
input[type="range"] {
  --slider-track-size: 0.42rem;
  --slider-thumb-size: 1.08rem;
  --slider-track-radius: 999px;
  --slider-thumb-radius: 50%;
  --slider-track-color: var(--slider-track-bg);
  --slider-fill-color: var(--brand-color);
  --slider-thumb-color: var(--slider-fill-color);
  --slider-direction: to right;

  --attr-min: attr(min type(<number>), 0);
  --attr-max: attr(max type(<number>), 100);
  --control-value: attr(value type(<number>), 50);
  --slider-progress: calc(
    progress(var(--control-value), var(--attr-min), var(--attr-max)) * 100%
  );

  appearance: none;
  inline-size: 100%;
  block-size: 1.75rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]:dir(rtl) {
  --slider-direction: to left;
}

@supports not (opacity: progress(1, 0, 100)) {
  input[type="range"] {
    --slider-progress: calc(
      (var(--control-value) - var(--attr-min)) /
      (var(--attr-max) - var(--attr-min)) * 100%
    );
  }
}

/* WebKit/Blink — declared in separate block from Firefox per `slider` guide */
input[type="range"]::-webkit-slider-runnable-track {
  block-size: var(--slider-track-size);
  border: 0;
  border-radius: var(--slider-track-radius);
  background: linear-gradient(
    var(--slider-direction),
    var(--slider-fill-color) var(--slider-progress),
    var(--slider-track-color) var(--slider-progress)
  );
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  inline-size: var(--slider-thumb-size);
  block-size: var(--slider-thumb-size);
  margin-block-start: calc(
    (var(--slider-track-size) - var(--slider-thumb-size)) / 2
  );
  border: 2px solid var(--surface);
  border-radius: var(--slider-thumb-radius);
  background: var(--slider-thumb-color);
}

/* Firefox — separate rule blocks */
input[type="range"]::-moz-range-track {
  block-size: var(--slider-track-size);
  border: 0;
  border-radius: var(--slider-track-radius);
  background: var(--slider-track-color);
}

input[type="range"]::-moz-range-progress {
  block-size: var(--slider-track-size);
  border-radius: var(--slider-track-radius);
  background: var(--slider-fill-color);
}

input[type="range"]::-moz-range-thumb {
  inline-size: var(--slider-thumb-size);
  block-size: var(--slider-thumb-size);
  border: 2px solid var(--surface);
  border-radius: var(--slider-thumb-radius);
  background: var(--slider-thumb-color);
}

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

/* DoF-specific slider accent fills */
input[type="range"].tone-z { --slider-fill-color: var(--col-z); }
input[type="range"].tone-th { --slider-fill-color: var(--col-th); }
input[type="range"].tone-r { --slider-fill-color: var(--col-r); }
input[type="range"].tone-plane { --slider-fill-color: var(--col-plane); }
input[type="range"].tone-whip { --slider-fill-color: var(--col-whip); }
input[type="range"].tone-roll { --slider-fill-color: var(--col-roll); }

/* Checkbox with progressive-enhancement fallback when `accent-color` is unsupported (`brand-consistent-forms`) */
.check-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.check-label input[type="checkbox"] {
  inline-size: 1rem;
  block-size: 1rem;
  margin: 0;
  cursor: pointer;
}

@supports not (accent-color: #0284c7) {
  .check-label input[type="checkbox"].visually-hidden-fallback {
    position: absolute !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    white-space: nowrap !important;
  }
  .check-label {
    position: relative;
    padding-inline-start: 1.5rem;
  }
  .check-label input[type="checkbox"].visually-hidden-fallback + span::before {
    content: "";
    position: absolute;
    inset-inline-start: 0;
    inset-block-start: 50%;
    transform: translateY(-50%);
    width: 1.05rem;
    height: 1.05rem;
    border: 2px solid var(--border);
    background: var(--surface);
    border-radius: 4px;
  }
  .check-label input[type="checkbox"].visually-hidden-fallback:focus-visible + span::before {
    outline: 2px solid var(--brand-color);
    outline-offset: 2px;
  }
  .check-label input[type="checkbox"].visually-hidden-fallback:checked + span::before {
    background-color: var(--brand-color);
    border-color: var(--brand-color);
  }
  .check-label input[type="checkbox"].visually-hidden-fallback:checked + span::after {
    content: "✓";
    position: absolute;
    inset-inline-start: 0.2rem;
    inset-block-start: 50%;
    transform: translateY(-50%);
    color: #fff;
    font-weight: 700;
    font-size: 0.75rem;
  }
}

.bevel-btn-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.28rem;
}

.puppet-pose-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
}
