/* Speaker Design Tools: the tools' own components.
   Fonts, colour tokens, the site header and footer come from /assets/site.css,
   shared with the rest of Audio Mission. The --color-* names below are aliases
   for those shared tokens, kept so the tools' components and chart theme
   (src/chart-theme.js) read the same names as before. */

:root {
  --color-bg: var(--bg);
  --color-panel: var(--surface);
  --color-ink: var(--ink);
  --color-ink-muted: var(--muted);
  --color-border: var(--line);
  --color-accent: var(--accent);
  --color-accent-strong: var(--accent-strong);
  --color-accent-ink: var(--accent-ink);
  --color-error: var(--error);

  /* Categorical chart series (per-driver lines) - a validated colour-blind-safe
     order, kept separate from --color-accent (reserved for a single summed
     total curve, told apart from these by line weight, not colour alone). */
  --color-series-1: #2a78d6;
  --color-series-2: #eb6834;
  --color-series-3: #1baf7a;
  --color-series-4: #6250d6;

  --font-sans: var(--font-body);
  --gutter: 1rem;
}

/* Dark series colours: follow the device unless the switch picks light (first
   block), or forced by the switch (second block). Keep both in step. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --color-series-1: #3987e5;
    --color-series-2: #d95926;
    --color-series-3: #199e70;
    --color-series-4: #9085e9;
  }
}

:root[data-theme='dark'] {
  --color-series-1: #3987e5;
  --color-series-2: #d95926;
  --color-series-3: #199e70;
  --color-series-4: #9085e9;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-sans);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
}

main.container {
  padding-top: 1.5rem;
}

main > header h1,
main > header h2 {
  font-family: var(--font-display);
  font-stretch: 125%;
  font-weight: 750;
  letter-spacing: -0.01em;
  line-height: 1.05;
  text-wrap: balance;
  font-size: var(--step-3);
  margin: 0.4rem 0 0.8rem;
}

a {
  color: var(--color-accent-strong);
}
a:hover {
  color: var(--color-accent);
}

main > header {
  padding-top: 0.5rem;
  margin-bottom: 1.5rem;
}
main > header h1 {
  margin-bottom: 0.4rem;
}
main > header p {
  color: var(--color-ink-muted);
  max-width: 42rem;
}

.breadcrumb {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--color-ink-muted);
  margin-bottom: 0.75rem;
}
.breadcrumb a {
  color: var(--color-ink-muted);
}
.breadcrumb a:hover {
  color: var(--color-accent-strong);
}

/* --- Panels (fieldsets, chart wrappers): bordered, flat, no card shadows --- */

fieldset,
.panel {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 0 0 1.25rem;
}
legend,
.panel > h2,
.panel > h3 {
  font-family: var(--font-mono);
  font-weight: 700;
  padding: 0 0.4rem;
  font-size: 0.95rem;
}
.panel > h2,
.panel > h3 {
  margin: -2rem 0 1rem -0.4rem;
  display: inline-block;
  background: var(--color-bg);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1rem 1.5rem;
}

/* --- Driver cards (crossover tool): one collapsible section per way --- */

.driver-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0 1.25rem 1.25rem;
  margin: 0 0 1.25rem;
}
.driver-card > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 -1.25rem;
  padding: 0.9rem 1.25rem;
  font-family: var(--font-mono);
  font-weight: 700;
}
.driver-card > summary::-webkit-details-marker {
  display: none;
}
.driver-card > summary::before {
  content: '▸';
  color: var(--color-ink-muted);
  font-size: 0.8rem;
}
.driver-card[open] > summary::before {
  content: '▾';
}
.driver-card > summary input[type='text'] {
  flex: 1;
}
.driver-color-dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  flex-shrink: 0;
}
.driver-card > fieldset {
  margin-top: 1.25rem;
}

/* A plain collapsible section (e.g. the saved-designs list) - same marker
   style as .driver-card's summary, without that class's own layout rules. */
details > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  padding: 0.4rem 0;
}
details > summary::-webkit-details-marker {
  display: none;
}
details > summary::before {
  content: '▸';
  color: var(--color-ink-muted);
  font-size: 0.8rem;
}
details[open] > summary::before {
  content: '▾';
}

label.checkbox {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.75rem;
  font-weight: 400;
}
label {
  display: block;
  font-weight: 500;
  font-size: 0.92rem;
  margin-bottom: 0.3rem;
}

.hint {
  display: block;
  font-size: 0.8rem;
  color: var(--color-ink-muted);
  margin-top: 0.3rem;
  font-weight: 400;
}

input[type='text'],
input[type='number'],
input[type='file'],
select {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--color-ink);
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.5rem 0.6rem;
}

select {
  font-family: var(--font-sans);
}

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

button {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 0.95rem;
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  border: 1px solid var(--color-accent-strong);
  background: var(--color-accent);
  color: var(--color-accent-ink);
  cursor: pointer;
}
button.secondary {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-ink);
}
@media (prefers-reduced-motion: no-preference) {
  button {
    transition: background-color 120ms ease, border-color 120ms ease;
  }
}
button:hover {
  border-color: var(--color-accent-strong);
  background: var(--color-accent-strong);
}
button.secondary:hover {
  background: var(--color-panel);
  border-color: var(--color-ink-muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.error-text {
  color: var(--color-error);
  font-size: 0.9rem;
}

/* --- Readout: the instrument-panel display for computed results --- */

.readout {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-accent);
  border-radius: var(--radius);
  padding: 0.9rem 1.25rem;
  margin-bottom: 1.25rem;
  background: var(--color-panel);
}
.readout-item {
  display: flex;
  flex-direction: column;
}
.readout-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-ink-muted);
}
.readout-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.4rem;
}
.readout-value small {
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--color-ink-muted);
}

/* --- Chart panels --- */

.chart-panel {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.chart-panel h2,
.chart-panel h3 {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  margin: 0 0 0.75rem;
}

/* --- Diffraction tool: two-column layout on wide screens --- */

/* Narrow screens keep the single column (inputs, then charts). From about
   1150px the page widens, the inputs take the left column and the baffle
   view + response chart sit side by side on the right, staying in view
   while you scroll the inputs, so you can see each change as you make it. */
@media (min-width: 72rem) {
  .container-wide {
    max-width: 88rem;
  }
  .diffraction-top {
    display: grid;
    grid-template-columns: minmax(20rem, 26rem) minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
    margin-bottom: 1.25rem;
  }
  .diffraction-top > form {
    margin-bottom: 0;
  }
  .diffraction-live {
    position: sticky;
    top: 7rem; /* clear the sticky site header */
    display: grid;
    grid-template-columns: minmax(11rem, 15rem) minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
    max-height: calc(100vh - 8rem);
    overflow-y: auto;
  }
  .diffraction-live .chart-panel {
    margin-bottom: 0;
  }
  /* Fixed height, drawing fitted inside, so a tall baffle can't push the
     chart off screen. */
  .diffraction-live .baffle-view {
    height: 18rem;
    max-width: none;
  }
}

/* --- Baffle view: drag-to-position driver --- */

.baffle-view {
  width: 100%;
  max-width: 22rem;
  display: block;
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  touch-action: none; /* dragging owns touch gestures on the driver handle */
}
.baffle-view .baffle-outline {
  fill: none;
  stroke: var(--color-ink-muted);
  stroke-width: 2;
}
.baffle-view .driver-handle {
  fill: var(--color-panel);
  stroke: var(--color-accent);
  stroke-width: 2;
  cursor: grab;
}
.baffle-view .driver-handle {
  fill-opacity: 0.55;
  vector-effect: non-scaling-stroke;
}
.baffle-view .driver-handle.selected {
  stroke-width: 3.5;
  fill-opacity: 0.85;
}
.baffle-view .listen-axis {
  fill: none;
  stroke: var(--color-ink);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.baffle-view .listen-axis * {
  vector-effect: non-scaling-stroke;
}
.series-swatch {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  flex: none;
}
.driver-picker {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.driver-picker select {
  flex: 1;
}
.baffle-view .driver-handle:active {
  cursor: grabbing;
}
.baffle-view .driver-handle:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}
.baffle-view .driver-crosshair {
  stroke: var(--color-accent);
  stroke-width: 1;
  opacity: 0.6;
}
.baffle-view .profile-start {
  fill: none;
  stroke: var(--color-ink-muted);
  stroke-width: 1;
  stroke-dasharray: 4 3;
  vector-effect: non-scaling-stroke;
}
.baffle-view .listener-direction {
  stroke: var(--color-ink-muted);
  stroke-width: 2;
  stroke-dasharray: 6 4;
  vector-effect: non-scaling-stroke;
}
.baffle-view-caption {
  font-size: 0.8rem;
  color: var(--color-ink-muted);
  margin: 0.5rem 0 0;
}

main > footer {
  padding: 2rem 0;
  color: var(--color-ink-muted);
  font-size: 0.85rem;
}

/* --- Home page tool list --- */

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
@media (max-width: 600px) {
  .tool-grid {
    grid-template-columns: 1fr;
  }
}

/* Tool cards, in the same style as the other Audio Mission sites: a preview
   on top, then the tool's name, a one-line summary and an Open tool footer.
   The whole card is the link. */
.tool-card {
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--color-panel);
  color: var(--color-ink);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tool-card:hover {
  color: var(--color-ink);
  border-color: var(--color-ink-muted);
}
.tool-card:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
.tool-card:hover .tool-open {
  color: var(--color-accent-strong);
}
.tool-card:hover .tool-open svg {
  translate: 3px 0;
}

.tool-preview {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 12 / 5;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}
.tool-preview path,
.tool-preview circle {
  fill: none;
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool-preview .grid {
  stroke: var(--color-border);
  stroke-width: 1;
}
.tool-preview .trace {
  stroke: var(--color-accent);
  stroke-width: 2.5;
}
.tool-preview .alt {
  stroke: var(--color-ink-muted);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}

.tool-body {
  display: grid;
  gap: 0.35rem;
  align-content: start;
  padding: 0.9rem 1.1rem 1rem;
}
.tool-tags {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-ink-muted);
}
.tool-name {
  font-family: var(--font-display);
  font-stretch: 125%;
  font-weight: 750;
  letter-spacing: -0.01em;
  font-size: 1.15rem;
  line-height: 1.2;
}
.tool-summary {
  color: var(--color-ink-muted);
  font-size: 0.92rem;
  line-height: 1.45;
}
.tool-open {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.4rem;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--color-accent-strong);
}
.tool-open svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: translate 0.15s;
}
@media (prefers-reduced-motion: reduce) {
  .tool-card,
  .tool-open svg {
    transition: none;
  }
}

.button-like {
  display: inline-block;
  text-decoration: none;
  font-family: var(--font-sans);
  font-weight: 500;
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  border: 1px solid var(--color-accent-strong);
  background: var(--color-accent);
  color: var(--color-accent-ink);
}
.button-like:hover {
  background: var(--color-accent-strong);
  color: var(--color-accent-ink);
}
.button-like.disabled {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-ink-muted);
  cursor: not-allowed;
}

/* --- Cabinet designer: cut list --- */

.table-scroll {
  overflow-x: auto;
}
.cut-list {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.cut-list th,
.cut-list td {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.cut-list th {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--color-ink-muted);
  font-weight: 500;
}

/* --- Diffraction tool: "Explain this" panel --- */

.explain-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin: 0.5rem 0 0.75rem;
}
.explain-controls label {
  flex: 1 1 18rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.6rem;
  margin: 0;
}
.explain-controls input[type='range'] {
  flex: 1 1 12rem;
  min-width: 0;
  accent-color: var(--color-accent);
}
.explain-frequency {
  font-family: var(--font-mono);
  min-width: 5.5rem;
}
.explain-text {
  min-height: 4.5em;
  margin: 0 0 1rem;
}
.explain-views {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 700px) {
  .explain-views {
    grid-template-columns: minmax(0, 1fr);
  }
}
.explain-views figure {
  margin: 0;
}
.explain-edges {
  width: 100%;
  max-height: 22rem;
  display: block;
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.explain-outline {
  fill: none;
  stroke: var(--color-border);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}
.explain-driver {
  fill: none;
  stroke: var(--color-ink-muted);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}
.explain-edge {
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.explain-edge.add {
  stroke: var(--color-series-2);
}
.explain-edge.cancel {
  stroke: var(--color-series-1);
}
.explain-edge.pending {
  opacity: 0.12;
}
.explain-map {
  width: 100%;
  height: auto;
  aspect-ratio: 8 / 5;
  display: block;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.explain-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.5rem;
  font-size: 0.8rem;
  color: var(--color-ink-muted);
  margin-top: 0.4rem;
}
.explain-swatch {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 3px;
  border: 1px solid var(--color-border);
}
.explain-swatch.add {
  background: var(--color-series-2);
}
.explain-swatch.cancel {
  background: var(--color-series-1);
}
.explain-swatch.neutral {
  background: var(--color-panel);
}

/* --- Cabinet designer: sheet layout --- */

.sheet-figure {
  margin: 0 0 1.25rem;
}
.sheet-drawing {
  width: 100%;
  height: auto;
  display: block;
}
.sheet-stock {
  fill: var(--color-panel);
  stroke: var(--color-ink-muted);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}
.sheet-trim {
  fill: none;
  stroke: var(--color-border);
  stroke-dasharray: 4 3;
  vector-effect: non-scaling-stroke;
}
.sheet-part {
  fill-opacity: 0.22;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}
.sheet-label {
  fill: var(--color-ink);
  text-anchor: middle;
  dominant-baseline: middle;
  font-family: var(--font-mono);
}

/* --- Beta note (every page) --- */

.beta-note {
  margin: 1rem 0 0;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-accent);
  border-radius: var(--radius);
  background: var(--color-panel);
  font-size: 0.85rem;
  color: var(--color-ink-muted);
}
.beta-note strong {
  color: var(--color-ink);
}
