/* ===================================================================
   Alarm Audio Tuner - Catppuccin Mocha + Claude-Inspired Design
   A premium, modern interface with sophisticated aesthetics
   =================================================================== */

/* === Catppuccin Mocha Palette === */
:root {
  /* Base colors */
  --ctp-rosewater: #f5e0dc;
  --ctp-flamingo: #f2cdcd;
  --ctp-pink: #f5c2e7;
  --ctp-mauve: #cba6f7;
  --ctp-red: #f38ba8;
  --ctp-maroon: #eba0ac;
  --ctp-peach: #fab387;
  --ctp-yellow: #f9e2af;
  --ctp-green: #a6e3a1;
  --ctp-teal: #94e2d5;
  --ctp-sky: #89dceb;
  --ctp-sapphire: #74c7ec;
  --ctp-blue: #89b4fa;
  --ctp-lavender: #b4befe;

  /* Surface & Background */
  --ctp-text: #cdd6f4;
  --ctp-subtext1: #bac2de;
  --ctp-subtext0: #a6adc8;
  --ctp-overlay2: #9399b2;
  --ctp-overlay1: #7f849c;
  --ctp-overlay0: #6c7086;
  --ctp-surface2: #585b70;
  --ctp-surface1: #45475a;
  --ctp-surface0: #313244;
  --ctp-base: #1e1e2e;
  --ctp-mantle: #181825;
  --ctp-crust: #11111b;

  /* Semantic mappings */
  --bg-primary: var(--ctp-crust);
  --bg-secondary: var(--ctp-base);
  --bg-elevated: var(--ctp-mantle);
  --bg-surface: var(--ctp-surface0);
  --bg-surface-hover: var(--ctp-surface1);

  --text-primary: var(--ctp-text);
  --text-secondary: var(--ctp-subtext1);
  --text-muted: var(--ctp-overlay1);

  --accent-primary: var(--ctp-mauve);
  --accent-secondary: var(--ctp-lavender);
  --accent-success: var(--ctp-green);
  --accent-danger: var(--ctp-red);
  --accent-warning: var(--ctp-peach);
  --accent-info: var(--ctp-sapphire);

  --border-color: var(--ctp-surface1);
  --border-subtle: rgba(69, 71, 90, 0.5);

  /* Design tokens */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 0 40px rgba(203, 166, 247, 0.1);

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Glassmorphism */
  --glass-bg: rgba(30, 30, 46, 0.7);
  --glass-border: rgba(180, 190, 254, 0.1);
  --glass-blur: blur(20px);
}

/* === Reset & Base === */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Animated background gradient */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(
      ellipse 80% 50% at 20% -10%,
      rgba(203, 166, 247, 0.12) 0%,
      transparent 50%
    ),
    radial-gradient(
      ellipse 60% 40% at 80% 100%,
      rgba(137, 180, 250, 0.08) 0%,
      transparent 50%
    ),
    radial-gradient(
      ellipse 50% 30% at 50% 50%,
      rgba(180, 190, 254, 0.04) 0%,
      transparent 50%
    );
  pointer-events: none;
  z-index: -1;
  animation: ambientShift 30s ease-in-out infinite;
}

@keyframes ambientShift {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* === Typography === */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

/* === Layout === */
.app-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 32px 40px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Header === */
.app-header {
  text-align: center;
  margin-bottom: 48px;
  padding: 32px 0;
  position: relative;
}

.app-header::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--accent-primary),
    transparent
  );
}

.app-header h1 {
  font-size: 2.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  letter-spacing: -0.03em;
  display: inline-flex;
  align-items: center;
  gap: 16px;
}

.app-header h1 .icon {
  font-size: 2.25rem;
  filter: drop-shadow(0 4px 12px rgba(203, 166, 247, 0.3));
  animation: gentlePulse 4s ease-in-out infinite;
}

@keyframes gentlePulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.subtitle {
  font-size: 1.125rem;
  color: var(--text-secondary);
  font-weight: 400;
  letter-spacing: 0.01em;
}

/* === Main Content Grid === */
.main-content {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 32px;
  flex: 1;
}

/* === Panels (Glass Cards) === */
.panel {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: var(--radius-xl);
  padding: 28px;
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-normal),
    box-shadow var(--transition-normal);
}

.panel:hover {
  box-shadow: var(--shadow-lg), 0 0 60px rgba(203, 166, 247, 0.12);
}

/* Subtle inner glow */
.panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--glass-border),
    transparent
  );
}

.panel h2 {
  font-size: 1.375rem;
  font-weight: 600;
  margin-bottom: 24px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.panel h2::before {
  content: "";
  width: 4px;
  height: 20px;
  background: linear-gradient(
    180deg,
    var(--accent-primary),
    var(--accent-secondary)
  );
  border-radius: 2px;
}

.panel h3 {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 20px 0 12px;
}

/* === Buttons === */
.btn {
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
  font-family: inherit;
}

.btn::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.08) 0%,
    transparent 50%
  );
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.btn:hover::before {
  opacity: 1;
}

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

.btn:disabled::before {
  display: none;
}

.btn .icon {
  font-size: 1em;
  line-height: 1;
}

/* Button variants */
.btn-record {
  background: linear-gradient(135deg, var(--ctp-red), var(--ctp-maroon));
  color: var(--ctp-crust);
  box-shadow: 0 4px 16px rgba(243, 139, 168, 0.3);
}

.btn-record:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(243, 139, 168, 0.4);
}

.btn-record.recording {
  animation: recordPulse 1.5s ease-in-out infinite;
}

@keyframes recordPulse {
  0%,
  100% {
    box-shadow: 0 4px 16px rgba(243, 139, 168, 0.3);
  }
  50% {
    box-shadow: 0 4px 32px rgba(243, 139, 168, 0.6);
  }
}

.btn-stop {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-stop:hover:not(:disabled) {
  background: var(--bg-surface-hover);
  border-color: var(--text-muted);
}

.btn-play {
  background: linear-gradient(135deg, var(--ctp-green), var(--ctp-teal));
  color: var(--ctp-crust);
  box-shadow: 0 4px 16px rgba(166, 227, 161, 0.25);
}

.btn-play:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(166, 227, 161, 0.35);
}

.btn-analyze {
  background: linear-gradient(135deg, var(--ctp-peach), var(--ctp-yellow));
  color: var(--ctp-crust);
  box-shadow: 0 4px 16px rgba(250, 179, 135, 0.25);
}

.btn-analyze:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(250, 179, 135, 0.35);
}

.btn-add {
  background: transparent;
  color: var(--accent-secondary);
  border: 1px dashed var(--border-color);
  width: 100%;
  margin-top: 16px;
  padding: 14px;
}

.btn-add:hover {
  background: rgba(180, 190, 254, 0.08);
  border-color: var(--accent-secondary);
  border-style: solid;
}

.btn-generate {
  background: linear-gradient(135deg, var(--ctp-mauve), var(--ctp-pink));
  color: var(--ctp-crust);
  flex: 1;
  box-shadow: 0 4px 16px rgba(203, 166, 247, 0.25);
}

.btn-generate:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(203, 166, 247, 0.4);
}

.btn-export {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-export:hover:not(:disabled) {
  background: var(--bg-surface-hover);
  border-color: var(--accent-secondary);
  color: var(--accent-secondary);
}

/* Button rows */
.controls-row,
.actions-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.controls-row {
  margin-bottom: 24px;
}

.actions-row {
  margin: 24px 0;
}

/* === Visualization Container === */
.visualization-container {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  border: 1px solid var(--border-subtle);
}

canvas {
  width: 100%;
  background: var(--ctp-crust);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  transition: border-color var(--transition-fast);
}

canvas:hover {
  border-color: var(--border-color);
}

/* === Status Bar === */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
  color: var(--text-muted);
  padding: 12px 16px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

#statusText {
  display: flex;
  align-items: center;
  gap: 8px;
}

#statusText::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ctp-green);
  box-shadow: 0 0 8px var(--ctp-green);
}

#durationText {
  font-family: "JetBrains Mono", "SF Mono", "Fira Code", monospace;
  color: var(--accent-info);
  font-weight: 500;
}

/* === Form Elements === */
.profile-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

input,
select {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.9375rem;
  font-family: inherit;
  transition: all var(--transition-fast);
}

input::placeholder {
  color: var(--text-muted);
}

input:hover,
select:hover {
  border-color: var(--ctp-overlay1);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(203, 166, 247, 0.15);
  background: var(--bg-surface-hover);
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237f849c' d='M2.5 4.5L6 8l3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* === Segment List === */
.segment-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 8px;
  margin-right: -8px; 
}

/* === Segment Item Card Design === */
.segment-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  overflow: hidden;
  transition: all var(--transition-fast);
  position: relative;
  flex-shrink: 0; /* Prevent shrinking which clips content */
}

.segment-item.selected {
  border-color: var(--ctp-blue);
  box-shadow: 0 0 0 2px rgba(137, 180, 250, 0.2);
}

.segment-item:hover {
  background: var(--bg-surface-hover);
}

/* Header with Title and Toolbar */
.segment-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
}

.segment-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.segment-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}

.segment-item.segment-tone .segment-icon {
  background: rgba(166, 227, 161, 0.2);
  color: var(--ctp-green);
}

.segment-item.segment-silence .segment-icon {
  background: rgba(108, 112, 134, 0.2);
  color: var(--ctp-overlay2);
}

.segment-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.segment-type-select {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.segment-type-select:hover {
  background: var(--bg-surface);
}

/* Toolbar - Always Visible */
.segment-toolbar {
  display: flex;
  gap: 4px;
  align-items: center;
}

.tool-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tool-btn:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-subtle);
  transform: translateY(-1px);
}

.tool-btn.move-up:hover, .tool-btn.move-down:hover { color: var(--ctp-blue); }
.tool-btn.duplicate:hover { color: var(--ctp-mauve); }
.tool-btn.remove-btn:hover { color: var(--ctp-red); background: rgba(243, 139, 168, 0.1); border-color: rgba(243, 139, 168, 0.2); }

.tool-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

/* Body showing inputs */
.segment-body {
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.field-input {
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-primary);
  transition: border-color 0.2s;
}

.field-input:focus {
  border-color: var(--ctp-blue);
  outline: none;
}

/* Specific styling for Tone vs Silence bodies */
.segment-item.segment-tone { border-left: 3px solid var(--ctp-green); }
.segment-item.segment-silence { border-left: 3px solid var(--ctp-overlay0); }

/* Config Output Styles */
.config-output {
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--ctp-green);
  overflow-x: auto;
  min-height: 150px;
}

/* === Footer === */
.app-footer {
  text-align: center;
  padding: 24px 0 8px;
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin-top: 40px;
  border-top: 1px solid var(--border-subtle);
}

.app-footer p {
  opacity: 0.6;
  transition: opacity var(--transition-fast);
}

.app-footer:hover p {
  opacity: 1;
}

/* === Custom Scrollbar === */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-elevated);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--ctp-surface2);
  border-radius: 4px;
  transition: background var(--transition-fast);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--ctp-surface2) var(--bg-elevated);
}

/* === Animations === */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.panel {
  animation: fadeIn 0.5s ease-out backwards;
}

.audio-panel {
  animation-delay: 0.1s;
}

.ruleset-panel {
  animation-delay: 0.2s;
}

/* === Responsive Design === */
@media (max-width: 1024px) {
  .main-content {
    grid-template-columns: 1fr;
  }

  .app-container {
    padding: 20px;
  }

  .app-header h1 {
    font-size: 2rem;
  }
}

@media (max-width: 640px) {
  .controls-row,
  .actions-row {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }

  .profile-form,
  .segment-item .segment-fields {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 20px;
  }
}

/* === Focus Visible (Accessibility) === */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible) {
  outline: none;
}

/* === Selection === */
::selection {
  background: rgba(203, 166, 247, 0.3);
  color: var(--text-primary);
}

/* === Secondary Controls Row === */
.controls-row-secondary {
  margin-top: -8px;
  margin-bottom: 24px;
}

/* === Upload Button === */
.btn-upload {
  background: linear-gradient(135deg, var(--ctp-sapphire), var(--ctp-blue));
  color: var(--ctp-crust);
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(116, 199, 236, 0.25);
  flex-direction: row;
  gap: 10px;
}

.btn-upload:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(116, 199, 236, 0.35);
}

/* === Download Button === */
.btn-download {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-download:hover:not(:disabled) {
  background: var(--bg-surface-hover);
  border-color: var(--ctp-teal);
  color: var(--ctp-teal);
}

/* === Frequency Query Section === */
.frequency-query-section {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  border: 1px solid var(--border-subtle);
}

.frequency-query-section h3 {
  margin-top: 0;
  margin-bottom: 16px;
}

.query-controls {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.query-controls label {
  flex: 1;
  min-width: 100px;
}

.query-controls input {
  width: 100%;
}

.btn-query {
  background: linear-gradient(135deg, var(--ctp-lavender), var(--ctp-mauve));
  color: var(--ctp-crust);
  box-shadow: 0 4px 16px rgba(180, 190, 254, 0.25);
  flex-shrink: 0;
}

.btn-query:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(180, 190, 254, 0.35);
}

/* === Query Results === */
.query-results {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  font-size: 0.875rem;
}

.query-results .placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.query-results .error {
  color: var(--ctp-red);
}

.query-result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.query-result-item:last-of-type {
  border-bottom: none;
}

.query-result-item .label {
  color: var(--text-muted);
  font-weight: 500;
}

.query-result-item .value {
  color: var(--text-primary);
  font-family: "JetBrains Mono", monospace;
  font-weight: 500;
}

.query-result-item .value.highlight {
  color: var(--ctp-green);
  font-size: 1rem;
}

.query-windows {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.query-windows .label {
  color: var(--text-muted);
  font-weight: 500;
  display: block;
  margin-bottom: 8px;
}

.query-windows ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.query-windows li {
  background: var(--bg-elevated);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  color: var(--ctp-sapphire);
  border: 1px solid var(--border-subtle);
}

/* === Analysis Hint === */
.analysis-hint {
  font-weight: 400;
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: normal;
  margin-left: 6px;
}

/* === Zoom Controls === */
.zoom-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}

.btn-zoom {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  font-size: 0.8125rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-zoom:hover {
  background: var(--bg-surface-hover);
  border-color: var(--ctp-sapphire);
  color: var(--ctp-sapphire);
}

.zoom-level {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  margin-left: 8px;
}

/* === Frequency Timeline Wrapper === */
.frequency-timeline-wrapper {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--ctp-crust);
}

.frequency-timeline-wrapper canvas {
  display: block;
  border: none;
  cursor: crosshair;
}

/* === Frequency Tooltip === */
.freq-tooltip {
  position: absolute;
  padding: 8px 12px;
  background: var(--ctp-surface0);
  border: 1px solid var(--ctp-surface2);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-primary);
  pointer-events: none;
  z-index: 100;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}

.freq-tooltip .tooltip-freq {
  color: var(--ctp-green);
  font-weight: 600;
  font-size: 0.875rem;
}

.freq-tooltip .tooltip-time {
  color: var(--ctp-sapphire);
}

.freq-tooltip .tooltip-amp {
  color: var(--ctp-peach);
}

/* === Crop Controls === */
.crop-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  margin-top: 8px;
  border: 1px solid var(--ctp-peach);
  animation: fadeIn 0.2s ease-out;
}

.crop-controls #cropRange {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-family: 'JetBrains Mono', monospace;
  flex: 1;
}

.btn-crop {
  background: linear-gradient(135deg, var(--ctp-peach), var(--ctp-yellow));
  color: var(--ctp-crust);
  font-size: 0.8125rem;
  padding: 8px 14px;
  box-shadow: 0 2px 8px rgba(250, 179, 135, 0.25);
}

.btn-crop:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(250, 179, 135, 0.35);
}

.btn-clear-crop {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  font-size: 0.8125rem;
  padding: 8px 12px;
}

.btn-clear-crop:hover {
  background: var(--bg-surface-hover);
  color: var(--ctp-red);
  border-color: var(--ctp-red);
}

/* === Audiogram Canvas === */
#audiogramCanvas {
  cursor: crosshair;
}

/* === Analysis Settings Section === */
.analysis-settings-section {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  border: 1px solid var(--border-subtle);
}

.analysis-settings-section h3 {
  margin-top: 0;
  margin-bottom: 16px;
}

.settings-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.settings-row label {
  flex: 1;
  min-width: 200px;
}

.settings-row select {
  width: 100%;
}

.btn-reanalyze {
  background: linear-gradient(135deg, var(--ctp-teal), var(--ctp-green));
  color: var(--ctp-crust);
  font-size: 0.8125rem;
  padding: 10px 16px;
  box-shadow: 0 2px 8px rgba(148, 226, 213, 0.25);
  flex-shrink: 0;
}

.btn-reanalyze:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(148, 226, 213, 0.35);
}

.settings-hint {
  margin-top: 12px;
  margin-bottom: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* === Auto-Tune Settings === */
.range-control {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-surface);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.range-control label {
  white-space: nowrap;
  font-size: 0.8125rem;
  margin: 0;
}

.range-control input[type="range"] {
  flex: 1;
  width: 100px;
}

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 0;
}

/* Pattern Info Badge */
.pattern-info {
  background: var(--bg-surface-hover);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-top: 12px;
  border: 1px solid var(--accent-secondary);
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.pattern-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.pattern-badge.pattern-T3 {
  background: rgba(243, 139, 168, 0.2); /* Red tint */
  color: var(--ctp-red);
  border: 1px solid var(--ctp-red);
}

.pattern-badge.pattern-T4 {
  background: rgba(250, 179, 135, 0.2); /* Peach tint */
  color: var(--ctp-peach);
  border: 1px solid var(--ctp-peach);
}

.pattern-badge.pattern-repeating {
  background: rgba(137, 180, 250, 0.2); /* Blue tint */
  color: var(--ctp-blue);
  border: 1px solid var(--ctp-blue);
}

.pattern-details {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* === Editor Toolbar === */
.editor-toolbar {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 10px;
}

.toolbar-group {
  display: flex;
  gap: 8px;
}

.toolbar-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-priority);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-btn:hover:not(:disabled) {
  background: var(--bg-surface-hover);
  border-color: var(--ctp-blue);
  color: var(--text-primary);
}

.toolbar-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === Segment Selection === */
.segment-item {
  border: 2px solid transparent; /* Prepare for border change */
  transition: border-color 0.2s, box-shadow 0.2s;
  cursor: pointer; /* Indicate selectable */
}

/* Make inputs readable on selected items */
.segment-item input, .segment-item select {
    cursor: text;
}
.segment-item select {
    cursor: pointer;
}

.segment-item.selected {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(203, 166, 247, 0.2); /* Mauve glow */
  background: var(--bg-surface-hover);
}

.segment-item:hover:not(.selected) {
    border-color: var(--overlay0);
}

/* === Questionnaire Modal === */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(17, 17, 27, 0.9);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--bg-secondary);
  border-radius: var(--radius-xl);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-lg), 0 0 80px rgba(203, 166, 247, 0.15);
  max-width: 520px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  padding: 24px 28px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h2 {
  font-size: 1.5rem;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-subtitle {
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

.questionnaire-body {
  padding: 20px 28px;
}

.question-group {
  margin-bottom: 24px;
}

.question-group:last-child {
  margin-bottom: 0;
}

.question-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  display: block;
}

.question-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.radio-option:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-color);
}

.radio-option input[type="radio"] {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-color);
  border-radius: 50%;
  background: var(--bg-surface);
  cursor: pointer;
  position: relative;
  transition: all var(--transition-fast);
}

.radio-option input[type="radio"]:checked {
  border-color: var(--accent-primary);
  background: var(--accent-primary);
}

.radio-option input[type="radio"]:checked::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 6px;
  height: 6px;
  background: var(--ctp-crust);
  border-radius: 50%;
}

.beep-count-row {
  display: flex;
  gap: 16px;
  align-items: center;
}

.beep-count-row input[type="number"] {
  width: 100px;
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.checkbox-inline input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.modal-footer {
  padding: 16px 28px 24px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  border-top: 1px solid var(--border-subtle);
}

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

.btn-secondary:hover {
  background: var(--bg-surface-hover);
  border-color: var(--text-muted);
}

.btn-primary {
  background: linear-gradient(135deg, var(--ctp-mauve), var(--ctp-lavender));
  color: var(--ctp-crust);
  box-shadow: 0 4px 16px rgba(203, 166, 247, 0.25);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(203, 166, 247, 0.4);
}

/* === A/B Comparison Section === */
.ab-compare-section {
  margin-top: 20px;
  padding: 16px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.ab-compare-section h3 {
  margin-top: 0;
  margin-bottom: 12px;
}

.ab-controls-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.btn-preview {
  background: linear-gradient(135deg, var(--ctp-sapphire), var(--ctp-sky));
  color: var(--ctp-crust);
  box-shadow: 0 4px 16px rgba(116, 199, 236, 0.25);
}

.btn-preview:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(116, 199, 236, 0.35);
}

.btn-compare {
  background: linear-gradient(135deg, var(--ctp-yellow), var(--ctp-peach));
  color: var(--ctp-crust);
  box-shadow: 0 4px 16px rgba(249, 226, 175, 0.25);
}

.btn-compare:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(249, 226, 175, 0.4);
}

.ab-timeline {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.ab-track {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ab-track-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  width: 70px;
  flex-shrink: 0;
}

.ab-track-bar {
  flex: 1;
  height: 24px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}

.ab-track-original .ab-track-bar {
  border: 1px solid var(--ctp-sapphire);
}

.ab-track-detected .ab-track-bar {
  border: 1px solid var(--ctp-green);
}

.ab-track-bar .playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--ctp-red);
  box-shadow: 0 0 8px var(--ctp-red);
  transition: left 0.05s linear;
}

.ab-track-bar.playing {
  background: rgba(166, 227, 161, 0.1);
}

.ab-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0;
}

/* A/B Compare Floating Indicator */
.ab-compare-indicator {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 16px 24px;
  box-shadow: var(--shadow-lg), 0 0 40px rgba(203, 166, 247, 0.2);
  z-index: 1001;
  min-width: 300px;
  animation: slideUpFade 0.3s ease-out;
}

@keyframes slideUpFade {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.ab-label {
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 12px;
}

.ab-label.playing-original {
  color: var(--ctp-sapphire);
}

.ab-label.playing-detected {
  color: var(--ctp-green);
}

.ab-progress {
  height: 6px;
  background: var(--bg-surface);
  border-radius: 3px;
  overflow: hidden;
}

.ab-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--ctp-sapphire), var(--ctp-green));
  width: 0%;
  transition: width 0.1s linear;
}

/* Confidence Badge */
.confidence-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
}

.confidence-high {
  background: rgba(166, 227, 161, 0.2);
  color: var(--ctp-green);
}

.confidence-medium {
  background: rgba(249, 226, 175, 0.2);
  color: var(--ctp-yellow);
}

.confidence-low {
  background: rgba(243, 139, 168, 0.2);
  color: var(--ctp-red);
}

