/* ==========================================================================
   Dependency Map Visualizer
   Pro-app visual language: layered translucent surfaces, concentric radii,
   hairlines drawn with inset shadows (never flat 1px grey), spring easing.
   ========================================================================== */

:root {
  --bg: #08090b;
  --bg-tint-a: rgba(233, 169, 77, 0.05);
  --bg-tint-b: rgba(63, 199, 192, 0.045);

  --surface: rgba(255, 255, 255, 0.032);
  --surface-2: rgba(255, 255, 255, 0.052);
  --surface-sunken: rgba(0, 0, 0, 0.28);
  --canvas-bg: #060709;
  --canvas-bg-rgb: 6, 7, 9;
  --canvas-fg: #f4f2ec;

  --text: #c9c7c2;
  --text-strong: #f7f5f0;
  --muted: #83868d;
  --faint: #5f6268;

  --hairline: rgba(255, 255, 255, 0.09);
  --hairline-strong: rgba(255, 255, 255, 0.16);
  --top-light: rgba(255, 255, 255, 0.07);

  --accent: #e9a94d;
  --accent-strong: #f6cb84;
  --accent-ink: #241706;
  --teal: #3fc7c0;

  --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  --shadow-lift: 0 2px 6px rgba(0, 0, 0, 0.35), 0 18px 40px -20px rgba(0, 0, 0, 0.75);

  --r-panel: 18px;
  --r-inner: 13px;
  --r-control: 11px;
  --r-sm: 8px;

  --sans: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  --serif: "Newsreader", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;

  --spring: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #eceae4;
  --bg-tint-a: rgba(181, 126, 40, 0.07);
  --bg-tint-b: rgba(45, 150, 145, 0.06);

  --surface: rgba(255, 255, 255, 0.82);
  --surface-2: rgba(255, 255, 255, 0.96);
  --surface-sunken: rgba(20, 18, 12, 0.05);
  --canvas-bg: #0a0b0e;
  --canvas-bg-rgb: 10, 11, 14;

  --text: #3b3a35;
  --text-strong: #14130e;
  --muted: #6b6963;
  --faint: #8b8880;

  --hairline: rgba(20, 18, 12, 0.1);
  --hairline-strong: rgba(20, 18, 12, 0.18);
  --top-light: rgba(255, 255, 255, 0.9);

  --accent: #b8802a;
  --accent-strong: #8f6317;
  --accent-ink: #fffaf0;
  --teal: #1f8f8a;

  --shadow-soft: 0 1px 2px rgba(20, 18, 12, 0.06), 0 8px 24px -14px rgba(20, 18, 12, 0.22);
  --shadow-lift: 0 2px 8px rgba(20, 18, 12, 0.08), 0 20px 44px -24px rgba(20, 18, 12, 0.32);

  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Fixed ambient wash — never attached to a scrolling container. */
.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(70ch 50ch at 12% -8%, var(--bg-tint-a), transparent 70%),
    radial-gradient(60ch 45ch at 92% 108%, var(--bg-tint-b), transparent 70%);
}

body > *:not(.ambient) {
  position: relative;
  z-index: 1;
}

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

/* ------------------------------------------------------------- primitives */

.eyebrow {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
}

/* Double-bezel: an outer tray that holds an inset control. */
.shell {
  padding: 3px;
  border-radius: var(--r-control);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--hairline), inset 0 1px 0 var(--top-light);
}

.select,
.input {
  appearance: none;
  width: 100%;
  background: var(--surface-sunken);
  color: var(--text-strong);
  border: none;
  border-radius: calc(var(--r-control) - 3px);
  padding: 0.5rem 0.7rem;
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: inset 0 0 0 1px transparent;
  transition: box-shadow 0.3s var(--spring);
}

.select {
  padding-right: 1.8rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4.5 6.5 8 10l3.5-3.5' stroke='%2383868d' stroke-width='1.3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 14px;
  cursor: pointer;
}

.input:focus-visible,
.select:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

.select-shell {
  min-width: 200px;
  flex: 0 1 240px;
}

.input-shell {
  flex: 1 1 auto;
  min-width: 0;
}

.button {
  appearance: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: none;
  border-radius: var(--r-control);
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: var(--accent-ink);
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.005em;
  padding: 0.55rem 0.95rem;
  box-shadow: var(--shadow-soft), inset 0 1px 0 rgba(255, 255, 255, 0.28);
  transition: transform 0.4s var(--spring), box-shadow 0.4s var(--spring), filter 0.3s var(--ease-out);
}

.button:hover {
  filter: brightness(1.05);
  box-shadow: var(--shadow-lift), inset 0 1px 0 rgba(255, 255, 255, 0.32);
}

.button:active {
  transform: scale(0.975);
}

.button:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

/* Nested trailing icon — its own circular well, flush to the inner padding. */
.button-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-right: -0.25rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.14);
  transition: transform 0.45s var(--spring);
}

.button-icon svg {
  width: 12px;
  height: 12px;
}

.button:hover .button-icon {
  transform: translateY(-1px) scale(1.06);
}

.button.ghost {
  background: var(--surface);
  color: var(--text-strong);
  box-shadow: inset 0 0 0 1px var(--hairline), inset 0 1px 0 var(--top-light);
}

.button.ghost:hover {
  background: var(--surface-2);
  filter: none;
  box-shadow: inset 0 0 0 1px var(--hairline-strong), inset 0 1px 0 var(--top-light);
}

.button.ghost .button-icon {
  background: var(--surface-2);
}

.button.quiet {
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  font-weight: 500;
  padding: 0.4rem 0.6rem;
}

.button.quiet:hover {
  background: var(--surface);
  color: var(--text-strong);
  filter: none;
  box-shadow: none;
}

.button.small {
  padding: 0.4rem 0.7rem;
  font-size: 0.74rem;
}

.icon-button {
  appearance: none;
  cursor: pointer;
  width: 30px;
  height: 30px;
  flex: none;
  border: none;
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px var(--hairline), inset 0 1px 0 var(--top-light);
  transition: transform 0.4s var(--spring), color 0.3s var(--ease-out), background 0.3s var(--ease-out);
}

.icon-button svg {
  width: 15px;
  height: 15px;
}

.icon-button:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text-strong);
}

.icon-button:active:not(:disabled) {
  transform: scale(0.92);
}

.icon-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.icon-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Segmented control — inset track with concentric inner pills (iOS-style). */
.segmented {
  display: inline-flex;
  align-items: stretch;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-control);
  background: var(--surface-sunken);
  box-shadow: inset 0 0 0 1px var(--hairline);
}

.segmented.grow {
  display: flex;
  flex: 1 1 auto;
}

.segmented.grow .segmented-option {
  flex: 1 1 0;
}

.segmented-option {
  appearance: none;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.005em;
  white-space: nowrap;
  padding: 0.4rem 0.8rem;
  border-radius: calc(var(--r-control) - 3px);
  transition: color 0.3s var(--ease-out), background 0.3s var(--ease-out), box-shadow 0.4s var(--spring);
}

.segmented-option:hover:not(.is-active) {
  color: var(--text-strong);
  background: var(--surface);
}

.segmented-option.is-active {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: var(--accent-ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.segmented-option:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 1px;
}

.segmented.compact .segmented-option {
  padding: 0.35rem 0.65rem;
  font-size: 0.72rem;
}

/* Long option names shorten instead of wrapping when space runs out. */
.label-short {
  display: none;
}

@media (max-width: 1280px) {
  .label-full {
    display: none;
  }

  .label-short {
    display: inline;
  }
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem clamp(0.85rem, 2.5vw, 1.6rem);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  min-width: 0;
}

.brand-mark {
  font-family: var(--serif);
  font-size: clamp(1.15rem, 3.4vw, 1.45rem);
  font-weight: 500;
  color: var(--text-strong);
  letter-spacing: -0.012em;
}

.brand-sub {
  font-size: 0.62rem;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: var(--faint);
  margin-top: 0.22rem;
}

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

.theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}

/* ------------------------------------------------------------ control bar */

/* The <details> stays a plain block: browsers wrap its non-summary children in
   a ::details-content box, so the flex row has to live one level deeper. */
.control-bar {
  display: block;
  margin: 0 clamp(0.85rem, 2.5vw, 1.6rem);
  padding: 0.85rem 1rem;
  border-radius: var(--r-panel);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--hairline), inset 0 1px 0 var(--top-light), var(--shadow-soft);
}

.control-body {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: clamp(0.9rem, 2.4vw, 2rem);
}

/* The summary is a phone affordance only; desktop always shows the controls. */
.control-summary {
  display: none;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  list-style: none;
}

.control-summary::-webkit-details-marker {
  display: none;
}

.summary-stats {
  margin-left: auto;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}

.control-bar[open] .control-summary .summary-chevron {
  transform: rotate(180deg);
}

.control-lead {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45rem;
  padding-top: 0.15rem;
  flex: none;
}

.params {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 0.9rem 1.5rem;
  flex: 1 1 440px;
  min-width: 0;
}

.param {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
}

.param-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.param-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-strong);
  letter-spacing: -0.005em;
}

.param-head output {
  font-family: var(--mono);
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
}

.param-hint {
  font-size: 0.66rem;
  line-height: 1.3;
  color: var(--faint);
}

.param-toggle .segmented {
  align-self: flex-start;
}

input[type="range"] {
  --fill: 40%;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--fill), var(--surface-sunken) var(--fill));
  box-shadow: inset 0 0 0 1px var(--hairline);
}

input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--fill), var(--surface-sunken) var(--fill));
  box-shadow: inset 0 0 0 1px var(--hairline);
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45), 0 0 0 0.5px rgba(0, 0, 0, 0.16);
  transition: transform 0.35s var(--spring);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

input[type="range"]:hover::-webkit-slider-thumb,
input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.14);
}

input[type="range"]:focus-visible {
  outline: none;
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px var(--accent);
}

/* Pinned to the trailing edge of the control bar, behind a hairline rule. */
.stats {
  display: flex;
  gap: clamp(0.9rem, 1.8vw, 1.5rem);
  padding-left: clamp(0.9rem, 2vw, 1.5rem);
  flex: none;
  align-self: center;
  border-left: 1px solid var(--hairline);
}

.stats > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.stat-value {
  font-family: var(--mono);
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ------------------------------------------------------------- workspace */

.workspace {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(0.7rem, 1.6vw, 1rem);
  padding: clamp(0.7rem, 1.6vw, 1rem) clamp(0.85rem, 2.5vw, 1.6rem);
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  border-radius: var(--r-panel);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--hairline), inset 0 1px 0 var(--top-light), var(--shadow-soft);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  padding: 0.7rem 0.85rem 0.55rem;
  flex-wrap: wrap;
}

.panel-header h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.02rem;
  letter-spacing: -0.012em;
  color: var(--text-strong);
}

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

.zoom {
  display: inline-flex;
  gap: 0.25rem;
}

.panel-note {
  margin: 0;
  padding: 0.5rem 0.9rem 0.7rem;
  font-size: 0.71rem;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------- depmap canvas */

.canvas-shell {
  flex: 1 1 auto;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
  padding: 0 0.6rem;
}

.matrix-frame {
  position: relative;
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  max-width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--canvas-bg);
  border-radius: var(--r-inner);
  box-shadow: inset 0 0 0 1px var(--hairline), 0 10px 30px -18px rgba(0, 0, 0, 0.8);
  cursor: grab;
  touch-action: none;
}

.matrix-frame.is-grabbing {
  cursor: grabbing;
}

.matrix-frame.is-dropping {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.matrix-frame canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  transform-origin: 0 0;
  will-change: transform;
}

#depmapOverlayCanvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.drop-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1rem;
  color: var(--faint);
  font-size: 0.78rem;
  pointer-events: none;
}

.drop-hint code {
  font-family: var(--mono);
  color: var(--text);
}

.drop-hint[hidden] {
  display: none;
}

.map-tooltip {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  padding: 0.3rem 0.5rem;
  border-radius: var(--r-sm);
  background: rgba(var(--canvas-bg-rgb), 0.9);
  box-shadow: inset 0 0 0 1px var(--hairline-strong);
  color: var(--canvas-fg);
  font-size: 0.68rem;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}

.map-tooltip[hidden] {
  display: none;
}

.depmap-axes {
  position: absolute;
  inset: 0;
  pointer-events: none;
  width: 100%;
  height: 100%;
}

.depmap-axes .depmap-axes-tick {
  stroke: rgba(255, 255, 255, 0.4);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.depmap-axes .depmap-axes-grid {
  stroke: rgba(255, 255, 255, 0.1);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.depmap-axes text {
  fill: rgba(255, 255, 255, 0.55);
  font-size: 9.5px;
  font-family: var(--mono);
  paint-order: stroke;
  stroke: rgba(var(--canvas-bg-rgb), 0.85);
  stroke-width: 2.5px;
  stroke-linejoin: round;
}

/* --------------------------------------------------------- fold controls */

.fold-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.85rem;
}

.temp-field {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
  flex: none;
  padding: 3px 0.5rem 3px 0.6rem;
  border-radius: var(--r-control);
  background: var(--surface-sunken);
  box-shadow: inset 0 0 0 1px var(--hairline);
}

.temp-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--faint);
  white-space: nowrap;
}

.temp-input {
  width: 3.1rem;
  padding: 0.36rem 0.3rem 0.36rem 0.5rem;
  text-align: right;
  background: transparent;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
}

.temp-input::-webkit-outer-spin-button,
.temp-input::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

.temp-unit {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
}

.mode-caption {
  margin: 0;
  padding: 0.45rem 0.9rem 0.1rem;
  font-size: 0.7rem;
  line-height: 1.35;
  color: var(--faint);
}

/* -------------------------------------------------------- structure view */

.structure-view {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 0.35rem;
}

.structure-view .panel-note {
  border: none;
  max-width: 42ch;
  margin: auto;
  text-align: center;
  line-height: 1.5;
}

.structure-toolbar {
  position: absolute;
  top: 0.35rem;
  left: 0.85rem;
  z-index: 2;
  display: flex;
  gap: 0.85rem;
  font-size: 0.68rem;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.structure-view svg.structure-svg {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  cursor: grab;
  touch-action: none;
}

.structure-view svg.structure-svg.is-grabbing {
  cursor: grabbing;
}

.structure-view.is-busy {
  opacity: 0.45;
  transition: opacity 0.2s var(--ease-out);
}

.structure-backbone line,
.structure-backbone path {
  stroke: var(--muted);
  stroke-width: 1.3;
  fill: none;
  opacity: 0.5;
}

.structure-pair-hit {
  stroke: transparent;
  stroke-width: 11;
  cursor: pointer;
}

.structure-pair-visible {
  stroke-width: 2.6;
  stroke-linecap: round;
  pointer-events: none;
}

.structure-stem-hit {
  stroke: transparent;
  stroke-width: 18;
  fill: none;
  cursor: pointer;
}

.structure-view text {
  font-family: var(--mono);
  fill: var(--text-strong);
  font-size: 7.5px;
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

.structure-residue circle {
  fill: var(--surface-2);
  stroke: var(--hairline-strong);
  stroke-width: 1;
  cursor: pointer;
}

.structure-residue:not(.paired) circle {
  fill: transparent;
  stroke: var(--hairline);
}

.structure-residue.paired text {
  fill: var(--canvas-bg);
  font-weight: 500;
}

.structure-position-labels text {
  fill: var(--faint);
  font-size: 8.5px;
}

/* linked brushing */
.structure-view.has-brushed [data-stem] {
  opacity: 0.12;
  transition: opacity 0.35s var(--ease-out);
}

.structure-view.has-brushed [data-stem].is-hot {
  opacity: 1;
}

.structure-view.has-brushed .structure-residue.is-hot circle {
  stroke: #fff;
  stroke-width: 2;
}

/* ------------------------------------------------------- legends */

.legend-row {
  display: flex;
  flex-direction: column;
}

.stem-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px;
  padding: 0.6rem 0.9rem 0.75rem;
  max-height: 80px;
  overflow-y: auto;
}

.stem-legend:empty {
  display: none;
}

.stem-legend-chip {
  width: 22px;
  height: 16px;
  border-radius: 5px;
  border: none;
  padding: 0;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
  transition: transform 0.4s var(--spring), box-shadow 0.3s var(--ease-out);
}

.stem-legend-chip:hover,
.stem-legend-chip.is-hot {
  transform: translateY(-1px) scale(1.12);
  box-shadow: 0 0 0 1.5px var(--text-strong);
}

.stem-legend-chip.is-selected {
  box-shadow: 0 0 0 1.5px var(--text-strong), 0 0 0 3.5px var(--accent);
}

.source-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1.1rem;
  padding: 0.6rem 0.9rem;
  margin: 0 0.5rem;
  border-radius: var(--r-inner);
  background: var(--surface-sunken);
  box-shadow: inset 0 0 0 1px var(--hairline);
  font-size: 0.75rem;
  color: var(--text-strong);
}

.source-legend[hidden] {
  display: none;
}

.source-key {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.source-swatch {
  width: 18px;
  height: 10px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.source-meta {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
}

.source-meta.warn {
  color: var(--accent-strong);
}

/* ------------------------------------------------------------- bottom bar */

.bottom-bar {
  display: flex;
  align-items: flex-start;
  gap: clamp(0.7rem, 2vw, 1.4rem);
  margin: 0 clamp(0.85rem, 2.5vw, 1.6rem) clamp(0.85rem, 2vw, 1.2rem);
  padding: 0.8rem 1rem;
  border-radius: var(--r-panel);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--hairline), inset 0 1px 0 var(--top-light), var(--shadow-soft);
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.field-label {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}

.seq-field {
  flex: 1 1 330px;
  min-width: 0;
}

.seq-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.seq-row .input {
  font-family: var(--mono);
  font-size: 0.75rem;
}

.dot-bracket {
  flex: 1 1 340px;
  min-width: 0;
  align-self: stretch;
  border-radius: var(--r-inner);
  background: var(--surface-sunken);
  box-shadow: inset 0 0 0 1px var(--hairline);
  padding: 0.5rem 0.75rem;
}

.dot-bracket summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-strong);
  list-style: none;
}

.dot-bracket summary::-webkit-details-marker {
  display: none;
}

.summary-title {
  margin-right: auto;
}

.summary-chevron {
  display: inline-flex;
  color: var(--muted);
  transition: transform 0.4s var(--spring);
}

.summary-chevron svg {
  width: 14px;
  height: 14px;
}

.dot-bracket[open] .summary-chevron {
  transform: rotate(180deg);
}

.export-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-top: 0.6rem;
}

.export-spacer {
  flex: 1 1 auto;
}

.copy-status {
  font-size: 0.68rem;
  color: var(--accent-strong);
}

.dot-bracket pre {
  margin: 0.55rem 0 0.1rem;
  padding: 0.65rem;
  background: var(--canvas-bg);
  color: var(--canvas-fg);
  border-radius: var(--r-sm);
  font-family: var(--mono);
  font-size: 0.68rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 150px;
  overflow-y: auto;
}

/* --------------------------------------------------------------- desktop */

@media (min-width: 1000px) {
  body {
    height: 100dvh;
    overflow: hidden;
  }
}

/* ---------------------------------------------------------------- tablet */

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

  .map-panel .canvas-shell {
    min-height: 58vw;
  }

  .structure-panel .structure-view {
    min-height: 52vh;
  }

  /* Label and Reset become a header row instead of a narrow left column. */
  .control-lead {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding-top: 0;
    order: -1;
  }
}

/* ----------------------------------------------------------------- phone */

@media (max-width: 680px) {
  body {
    font-size: 15px;
  }

  .app-header {
    padding: 0.7rem 0.85rem 0.5rem;
    gap: 0.6rem;
  }

  .brand-sub {
    display: none;
  }

  .header-controls {
    width: 100%;
    gap: 0.4rem;
  }

  .select-shell {
    flex: 1 1 auto;
    min-width: 0;
  }

  /* Touch targets: 44px minimum on every control. */
  .select,
  .input {
    padding: 0.62rem 0.7rem;
    font-size: 16px; /* prevents iOS zoom-on-focus */
  }

  .button {
    padding: 0.65rem 0.95rem;
    min-height: 42px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .control-bar {
    padding: 0.75rem 0.85rem;
  }

  .control-body {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .control-summary {
    display: flex;
  }

  .control-bar[open] .control-summary {
    margin-bottom: 0.9rem;
  }

  /* The summary carries the label on phones. */
  .control-lead .eyebrow {
    display: none;
  }

  .control-lead {
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    width: 100%;
    padding-top: 0;
    margin-bottom: 0.2rem;
  }

  .params {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .param-hint {
    font-size: 0.7rem;
  }

  input[type="range"] {
    height: 30px;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
    margin-top: -8.5px;
  }

  input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
  }

  .stats {
    border-left: none;
    border-top: 1px solid var(--hairline);
    padding: 0.75rem 0 0;
    margin-left: 0;
    justify-content: space-around;
    width: 100%;
  }

  .segmented-option {
    padding: 0.55rem 0.7rem;
    font-size: 0.78rem;
  }

  .segmented.grow .segmented-option {
    padding: 0.55rem 0.3rem;
    font-size: 0.74rem;
  }

  .panel-header {
    padding: 0.7rem 0.7rem 0.5rem;
  }

  .panel-header h2 {
    font-size: 0.98rem;
  }

  .canvas-shell {
    padding: 0 0.5rem;
  }

  .map-panel .canvas-shell {
    min-height: 84vw;
  }

  .structure-panel .structure-view {
    min-height: 62vh;
  }

  .fold-bar {
    flex-wrap: wrap;
    padding: 0 0.7rem;
    gap: 0.45rem;
  }

  .segmented.grow {
    width: 100%;
    flex: 1 1 100%;
  }

  .temp-field {
    flex: 1 1 auto;
    justify-content: flex-end;
  }

  .bottom-bar {
    flex-direction: column;
    gap: 0.9rem;
    padding: 0.85rem;
  }

  .seq-field,
  .dot-bracket {
    flex: 1 1 auto;
    width: 100%;
  }

  .stem-legend {
    max-height: 62px;
  }

  .export-row .button {
    min-height: 38px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
