:root {
  color-scheme: light dark;

  /* Map <meta name="color-scheme"> override back to CSS light-dark() resolution */
  &:has(> head > meta[name="color-scheme"][content="dark"]) {
    color-scheme: dark;
  }
  &:has(> head > meta[name="color-scheme"][content="light"]) {
    color-scheme: light;
  }

  /* Surface Tokens (WCAG 2.1 AA tested in both Light & Dark schemes) */
  --bg-primary: light-dark(#f8fafc, #0f1117);
  --bg-secondary: light-dark(#f1f5f9, #181b24);
  --bg-tertiary: light-dark(#e2e8f0, #222634);
  --bg-card: light-dark(#ffffff, #1e2230);
  --bg-panel-subtle: light-dark(rgba(241, 245, 249, 0.9), rgba(15, 23, 42, 0.65));
  --bg-dialog: light-dark(#ffffff, #0b1120);

  /* Accent Tokens (Darkened in Light mode for >= 4.5:1 text contrast on white/slate) */
  --accent-cyan: light-dark(#0369a1, #00d2ff);
  --accent-blue: light-dark(#1d4ed8, #3a7bd5);
  --accent-purple: light-dark(#6d28d9, #c084fc);
  --accent-pink: light-dark(#9d174d, #f472b6);
  --accent-green: light-dark(#065f46, #10b981);
  --accent-yellow: light-dark(#92400e, #f59e0b);
  --accent-red: light-dark(#991b1b, #f87171);

  /* Typography & Border Tokens */
  --text-primary: light-dark(#0f172a, #f8fafc);
  --text-secondary: light-dark(#334155, #cbd5e1);
  --text-muted: light-dark(#475569, #94a3b8);
  --text-info-alert: light-dark(#0c4a6e, #bae6fd);
  --text-warn-alert: light-dark(#78350f, #fde68a);
  --text-danger-alert: light-dark(#991b1b, #fca5a5);
  --border-color: light-dark(#cbd5e1, #334155);
  --border-subtle: light-dark(rgba(148, 163, 184, 0.45), rgba(51, 65, 85, 0.65));
  --border-focus: light-dark(#0284c7, #00d2ff);
  --grid-line-color: light-dark(rgba(15, 23, 42, 0.09), rgba(255, 255, 255, 0.07));

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-family);
  line-height: 1.5;
  min-height: 100dvh;
  padding: clamp(0.75rem, 2.5vw, 1.5rem);
  overflow-x: hidden;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  container-type: inline-size;
  container-name: app-shell;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: clamp(1rem, 2vw, 1.5rem);
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  color: #ffffff;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: bold;
}

.brand h1 {
  font-size: clamp(1.2rem, 1rem + 1vw, 1.5rem);
  font-weight: 700;
  letter-spacing: -0.5px;
}

.brand .subtitle {
  font-size: clamp(0.76rem, 0.7rem + 0.25vw, 0.85rem);
  color: var(--text-secondary);
}

.device-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
}

.wasm-badge {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: light-dark(#047857, #34d399);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  gap: 4px;
  opacity: 0.55;
  transition: opacity 0.2s ease, background-color 0.2s ease;
}

.wasm-badge.active {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(16, 185, 129, 0.45);
  color: light-dark(#047857, #34d399);
  opacity: 1;
}

/* Theme Toggle Button & Sun/Moon Icons */
.theme-toggle-btn {
  padding: 0.42rem 0.75rem;
  font-size: 0.8rem;
  gap: 0.4rem;
}

#iconThemeSun {
  display: none;
}

#iconThemeMoon {
  display: inline-block;
}

@media (prefers-color-scheme: dark) {
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) #iconThemeSun {
    display: inline-block;
  }
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) #iconThemeMoon {
    display: none;
  }
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) #iconThemeSun {
  display: inline-block;
}
:root:has(> head > meta[name="color-scheme"][content="dark"]) #iconThemeMoon {
  display: none;
}

.badge.disconnected {
  color: var(--text-muted);
}

.badge.connected {
  color: var(--accent-green);
  border-color: var(--accent-green);
  background-color: rgba(16, 185, 129, 0.1);
}

.badge.blocked {
  color: var(--accent-red);
  border-color: var(--accent-red);
  background-color: rgba(239, 68, 68, 0.1);
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: currentColor;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  color: #fff;
}
.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-burn {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
  color: #fff;
}
.btn-burn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover {
  background-color: var(--border-color);
}

.btn-success {
  background-color: var(--accent-green);
  color: #fff;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

/* Safety Alert Banner */
.safety-alert {
  display: none;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid var(--accent-red);
  padding: 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
  color: var(--text-danger-alert);
  font-size: 0.95rem;
}

.safety-alert.visible {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

/* Presets Grid */
.presets-section {
  margin-bottom: 1.5rem;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.75rem;
}

.preset-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem;
}

.preset-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.9rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.preset-card:hover {
  border-color: var(--accent-cyan);
  transform: translateY(-2px);
}

.preset-card:focus-visible,
.db-result-card:focus-visible,
.btn:focus-visible,
.quick-tag:focus-visible,
.dac-pill:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.preset-card.active {
  border-color: var(--accent-cyan);
  background-color: rgba(0, 210, 255, 0.08);
}

.preset-card h3 {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.3rem;
}

.preset-card .tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--accent-cyan);
}

.preset-card p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

/* Visual Graph Section */
.graph-container {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  position: relative;
}

.graph-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.graph-stats {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.svg-wrapper {
  width: 100%;
  height: clamp(220px, 32vw, 300px);
  position: relative;
  user-select: none;
  touch-action: pan-y;
}

#eqSvg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.grid-line {
  stroke: var(--grid-line-color);
  stroke-width: 1;
}

.zero-line {
  stroke: rgba(16, 185, 129, 0.45);
  stroke-dasharray: 4, 4;
  stroke-width: 1.5;
}

.curve-path {
  fill: none;
  stroke: var(--accent-cyan);
  stroke-width: 2.5;
  filter: drop-shadow(0 0 6px rgba(0, 210, 255, 0.3));
}

.reference-curve-path {
  fill: none;
  stroke: var(--accent-purple);
  stroke-width: 2.2;
  stroke-dasharray: 6, 4;
  opacity: 0.85;
}

.preference-envelope-path {
  fill: rgba(168, 85, 247, 0.12);
  stroke: rgba(168, 85, 247, 0.35);
  stroke-width: 1;
  stroke-dasharray: 4, 3;
}

.curve-diff-fill {
  fill: rgba(56, 189, 248, 0.14);
  stroke: none;
  pointer-events: none;
}

.tone-playhead-line {
  stroke: var(--accent-yellow);
  stroke-width: 1.5;
  stroke-dasharray: 4, 3;
  pointer-events: none;
  opacity: 0.85;
}

.macro-tweak-panel {
  background: var(--bg-panel-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.7rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.macro-sliders-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.85rem;
}

.macro-slider-box {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.eqcaps-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.55rem;
  font-size: 0.73rem;
  font-family: var(--font-mono);
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: var(--radius-sm);
  color: light-dark(#047857, #6ee7b7);
}

.tone-generator-panel {
  background: var(--bg-panel-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  margin-top: 0.75rem;
}

.tone-transport-group {
  display: inline-grid;
  grid-template-columns: repeat(3, 102px);
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.1rem;
  flex-shrink: 0;
}

.tone-transport-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 102px;
  min-width: 102px;
  padding: 0.2rem 0.35rem;
  font-size: 0.74rem;
  border: none;
  margin: 0;
  white-space: nowrap;
  text-align: center;
  font-variant-numeric: tabular-nums;
  box-sizing: border-box;
}

.tone-readout-freq {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  width: 68px;
  min-width: 68px;
  display: inline-block;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--accent-cyan);
  flex-shrink: 0;
}

.tone-readout-vol {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  width: 48px;
  min-width: 48px;
  display: inline-block;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  flex-shrink: 0;
}

.star-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  text-decoration: none;
  transition: all 0.2s ease;
  user-select: none;
}

.star-link-btn:hover {
  background-color: var(--border-color);
  border-color: light-dark(#f59e0b, #fbbf24);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.star-link-btn svg {
  color: light-dark(#d97706, #fbbf24);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.1));
}

.generator-guide-dialog {
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: var(--radius-md);
  background: var(--bg-dialog);
  color: var(--text-primary);
  max-width: 640px;
  width: 92%;
  padding: 1.5rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45), 0 0 30px rgba(56, 189, 248, 0.15);
  margin: auto;
}

.generator-guide-dialog::backdrop {
  background: rgba(3, 7, 18, 0.65);
  backdrop-filter: blur(4px);
}

.guide-step-card {
  background: var(--bg-panel-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  margin-top: 0.75rem;
}

.guide-step-card h4 {
  font-size: 0.88rem;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.guide-step-card p, .guide-step-card ul {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.guide-step-card ul {
  margin-top: 0.4rem;
  padding-left: 1.2rem;
}

.guide-step-card li {
  margin-bottom: 0.25rem;
}

.target-legend {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0.5rem;
  background: rgba(168, 85, 247, 0.12);
  border: 1px solid rgba(168, 85, 247, 0.3);
  border-radius: var(--radius-sm);
}

.band-marker {
  cursor: grab;
  transition: r 0.15s ease, stroke-width 0.15s ease;
}

.band-marker:hover,
.band-node-group:focus-visible .band-marker {
  r: 8.5;
  stroke: var(--accent-yellow);
  stroke-width: 2.5;
  cursor: grab;
}

.band-node-group:focus {
  outline: none;
}

.band-marker:active {
  cursor: grabbing;
}

.axis-text {
  fill: var(--text-muted);
  font-size: 11px;
  font-family: var(--font-mono);
}

/* EQ Controls Matrix */
.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  min-height: 232px;
}

.band-control {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.85rem;
  border-radius: var(--radius-md);
  position: relative;
}

.band-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.band-num {
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.band-pill {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-cyan);
  color: light-dark(#ffffff, #000000);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
}

.control-row {
  margin-bottom: 0.6rem;
}

.control-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.2rem;
  font-family: var(--font-mono);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent-cyan);
  height: 24px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: 4px;
}

select {
  width: 100%;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  outline: none;
}
select:focus {
  border-color: var(--border-focus);
}
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.guard-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.05rem 0.4rem;
  font-size: 0.66rem;
  font-weight: 700;
  font-family: var(--font-mono);
  border-radius: 4px;
  background: rgba(148, 163, 184, 0.15);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.guard-pill.guarded {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.45);
  color: light-dark(#92400e, #fcd34d);
}

.guard-pill.active {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.45);
  color: light-dark(#065f46, #6ee7b7);
}

/* Global Extras Panel */
.extras-panel {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  align-items: center;
}

.actions-toolbar {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
}

.action-tier {
  display: grid;
  grid-template-columns: 115px repeat(4, minmax(0, 1fr));
  align-items: center;
  gap: 0.55rem;
}

.actions-toolbar:has(#btnRestoreStock:not([style*="display: none"])) .action-tier {
  grid-template-columns: 115px repeat(5, minmax(0, 1fr));
}

.action-tier-label {
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

.action-tier .btn {
  width: 100%;
  min-height: 38px;
  padding: 0.5rem 0.75rem;
  font-size: 0.84rem;
  white-space: nowrap;
}

.extra-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.slot-filter-grid {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 0.5rem;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  min-height: 28px;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-cyan);
  cursor: pointer;
}

/* Host Exporters Section */
.exporters-section {
  background-color: var(--bg-secondary);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.exporters-grid {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

/* Audio Player */
.audio-tester {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

/* Footer */
footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

footer a {
  color: var(--accent-cyan);
  text-decoration: underline;
  text-underline-offset: 2px;
}
footer a:hover {
  color: var(--accent-blue);
}

/* Toast Notification */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background-color: var(--bg-card);
  border: 1px solid var(--accent-cyan);
  color: var(--text-primary);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.28);
  font-size: 0.9rem;
  z-index: 999;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.25s ease;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Community Database Search */
.db-section {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.db-search-bar {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.db-search-input {
  flex: 1 1 280px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.db-search-input:focus {
  border-color: var(--accent-cyan);
}

.db-source-select {
  flex: 0 1 220px;
}

.db-quick-tags {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 0.85rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.quick-tag {
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.25rem 0.65rem;
  min-height: 28px;
  border-radius: 20px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.quick-tag.active {
  background-color: rgba(0, 210, 255, 0.15);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.quick-tag:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.db-results-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.6rem;
  max-height: 250px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.db-result-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.db-result-card:hover {
  border-color: var(--accent-cyan);
  background-color: rgba(0, 210, 255, 0.05);
  transform: translateY(-1px);
}

.db-result-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.db-result-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  display: flex;
  justify-content: space-between;
}

/* DAC Hardware Directory */
.dac-directory-section {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.dac-filter-pills {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.dac-pill {
  padding: 0.35rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.dac-pill.active, .dac-pill:hover {
  background-color: rgba(0, 210, 255, 0.1);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.dac-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 0.85rem;
  min-height: 390px;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.dac-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.5rem;
  transition: all 0.2s ease;
}

.dac-card:hover {
  border-color: var(--accent-cyan);
  transform: translateY(-2px);
}

.dac-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.dac-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.dac-card-brand {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-cyan);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dac-badge-flash {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid var(--accent-green);
  color: var(--accent-green);
  white-space: nowrap;
}

.dac-badge-blocked {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid var(--accent-red);
  color: var(--accent-red);
  white-space: nowrap;
}

.dac-badge-host {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  background: rgba(157, 78, 221, 0.14);
  border: 1px solid var(--accent-purple);
  color: var(--accent-purple);
  white-space: nowrap;
}

.dac-card-meta {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.dac-chipset-tag {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background-color: var(--bg-tertiary);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  color: var(--text-secondary);
}

.dac-card-footer {
  font-size: 0.73rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.4rem;
}

/* ── Reactive Multi-Viewport & Container Query Adaptations ─────────────────── */
/* Large Desktop / Wide Studio Monitor (>= 1440px) */
@media (min-width: 1440px) {
  .container {
    max-width: 1400px;
  }
}

/* Tablet & Compact Laptop Adaptation (<= 960px container / viewport) */
@container app-shell (max-width: 920px) {
  header {
    flex-direction: column;
    align-items: stretch;
  }

  .device-bar {
    justify-content: flex-start;
  }

  .graph-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .extras-panel {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }

  .action-tier,
  .actions-toolbar:has(#btnRestoreStock:not([style*="display: none"])) .action-tier {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .action-tier-label {
    grid-column: 1 / -1;
  }
}

/* Mobile & Portrait Handset Adaptation (<= 640px container / viewport) */
@container app-shell (max-width: 600px) {
  .preset-cards {
    grid-template-columns: 1fr;
  }

  .controls-grid {
    grid-template-columns: 1fr;
  }

  .macro-sliders-grid {
    grid-template-columns: 1fr;
  }

  .slot-filter-grid {
    grid-template-columns: 1fr;
  }

  .graph-controls-bar,
  .target-bounds-pill,
  .matrix-arch-bar {
    width: 100%;
    max-width: 100%;
  }

  #selHardwareBandCount {
    width: 100% !important;
  }

  .graph-stats {
    font-size: 0.76rem;
    word-break: break-word;
  }

  .db-search-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .db-search-input,
  .db-source-select,
  #btnDbSearch {
    flex: 1 1 auto;
    width: 100%;
  }

  .db-results-container,
  .dac-grid {
    grid-template-columns: 1fr;
  }

  .action-tier,
  .actions-toolbar:has(#btnRestoreStock:not([style*="display: none"])) .action-tier {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .action-tier-label {
    margin-bottom: 0.1rem;
  }

  .action-tier .btn {
    width: 100%;
  }

  .exporters-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .exporters-grid .btn {
    width: 100%;
  }

  .graph-container,
  .extras-panel,
  .db-section,
  .exporters-section,
  .dac-directory-section {
    padding: 0.85rem;
    border-radius: var(--radius-md);
  }
}

/* Touch Device & Coarse Pointer Ergonomics */
@media (pointer: coarse) {
  .btn,
  select,
  .db-search-input {
    min-height: 40px;
  }

  .quick-tag,
  .dac-pill {
    min-height: 34px;
    padding: 0.35rem 0.75rem;
  }

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

  .band-marker {
    r: 8;
  }
}

@media (max-width: 640px) {
  #toast {
    left: 16px;
    right: 16px;
    bottom: 16px;
    text-align: center;
  }
}
