:root {
  --bg-primary: #0f1117;
  --bg-secondary: #181b24;
  --bg-tertiary: #222634;
  --bg-card: #1e2230;
  --accent-cyan: #00d2ff;
  --accent-blue: #3a7bd5;
  --accent-purple: #9d4edd;
  --accent-pink: #f72585;
  --accent-green: #10b981;
  --accent-yellow: #f59e0b;
  --accent-red: #ef4444;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #334155;
  --border-focus: #00d2ff;
  --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: 100vh;
  padding: 1.5rem;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 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;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: bold;
}

.brand h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.brand .subtitle {
  font-size: 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);
}

.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.15);
  border: 1px solid var(--accent-red);
  padding: 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
  color: #fca5a5;
  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.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: 280px;
  position: relative;
  user-select: none;
}

svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.grid-line {
  stroke: rgba(255, 255, 255, 0.07);
  stroke-width: 1;
}

.zero-line {
  stroke: rgba(16, 185, 129, 0.4);
  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.4));
}

.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;
}

.tone-generator-panel {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(51, 65, 85, 0.6);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  margin-top: 0.75rem;
}

.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;
}

.band-marker:hover {
  r: 8;
  cursor: grab;
}

.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;
}

.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: #000;
  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: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  outline: none;
}

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);
}

/* 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;
}

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

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  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: none;
}
footer a:hover {
  text-decoration: underline;
}

/* Toast Notification */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--accent-cyan);
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  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.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.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;
  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.15);
  border: 1px solid var(--accent-red);
  color: #fca5a5;
  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.15);
  border: 1px solid var(--accent-purple);
  color: #d8b4fe;
  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: #cbd5e1;
}

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