/* Morse Code App - Modern Minimal Premium UI
   Clean design tokens, refined dark/light themes, subtle elegance */

:root {
  /* Spacing - tighter rhythm for premium feel */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.25rem;
  --space-xl: 1.75rem;
  --space-2xl: 2.5rem;

  /* Typography */
  --font-sans: 'Outfit', system-ui, -apple-system, sans-serif;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;

  /* Radius - softer, more modern */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Transitions - smooth and refined */
  --transition-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 180ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 280ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark theme (default) - Deep, sophisticated neutrals */
:root,
html[data-theme="dark"] {
  --bg-primary: #0f0f11;
  --bg-secondary: #18181b;
  --bg-tertiary: #1f1f23;
  --bg-elevated: #27272a;

  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;

  --accent: #f59e0b;
  --accent-hover: #fbbf24;
  --accent-muted: rgba(245, 158, 11, 0.12);
  --accent-subtle: rgba(245, 158, 11, 0.06);

  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.12);
  --border-focus: var(--accent);

  --success: #22c55e;
  --success-muted: rgba(34, 197, 94, 0.12);
  --warning: #f59e0b;
  --warning-muted: rgba(245, 158, 11, 0.12);
  --error: #ef4444;
  --error-muted: rgba(239, 68, 68, 0.12);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5), 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 0 1px var(--accent-muted), 0 0 20px var(--accent-muted);
}

/* Light theme - Warm, refined */
html[data-theme="light"] {
  --bg-primary: #fafaf9;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f5f5f4;
  --bg-elevated: #ffffff;

  --text-primary: #1c1917;
  --text-secondary: #57534e;
  --text-muted: #a8a29e;

  --accent: #d97706;
  --accent-hover: #b45309;
  --accent-muted: rgba(217, 119, 6, 0.1);
  --accent-subtle: rgba(217, 119, 6, 0.04);

  --border: rgba(0, 0, 0, 0.06);
  --border-hover: rgba(0, 0, 0, 0.1);
  --border-focus: var(--accent);

  --success: #16a34a;
  --success-muted: rgba(22, 163, 74, 0.1);
  --warning: #d97706;
  --warning-muted: rgba(217, 119, 6, 0.1);
  --error: #dc2626;
  --error-muted: rgba(220, 38, 38, 0.1);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.1), 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-glow: 0 0 0 1px var(--accent-muted), 0 0 20px var(--accent-muted);
}

/* Base reset */
*,
*::before,
*::after {
  box-sizing: border-box;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
  transition: background var(--transition-base), color var(--transition-base);
}

/* Layout */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-xl) var(--space-md);
  position: relative;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: var(--space-2xl);
  position: relative;
  width: 100%;
  max-width: 720px;
}

.logo {
  font-family: var(--font-display);
  font-size: var(--text-4xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-xs);
  color: var(--text-primary);
}

.tagline {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin: 0;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 500;
}

.header-actions {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.help-btn {
  width: 36px;
  height: 36px;
  font-size: var(--text-base);
  font-weight: 600;
  padding: 0;
  border-radius: var(--radius-md);
}

.theme-toggle {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.theme-toggle:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
  background: var(--bg-elevated);
}

.theme-toggle:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.theme-icon {
  font-size: 1rem;
  line-height: 1;
}

.theme-icon.moon { display: none; }
.theme-icon.sun { display: inline; }
html[data-theme="light"] .theme-icon.moon { display: inline; }
html[data-theme="light"] .theme-icon.sun { display: none; }

/* Main content card */
.main {
  width: 100%;
  max-width: 720px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition-base), border-color var(--transition-base);
}

.main:focus-within {
  border-color: var(--border-hover);
}

/* Tabs - Pill style */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: var(--space-lg);
  padding: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
}

.tab {
  flex: 1;
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tab:hover:not(.active) {
  color: var(--text-secondary);
}

.tab:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.tab.active {
  color: #fff;
  background: var(--accent);
  box-shadow: var(--shadow-sm);
}

html[data-theme="light"] .tab.active {
  color: #fff;
}

/* Input groups */
.input-group {
  margin-bottom: var(--space-md);
}

.text-input {
  width: 100%;
  padding: var(--space-md);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  resize: vertical;
  min-height: 100px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

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

.text-input:hover {
  border-color: var(--border-hover);
}

.text-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.input-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-xs);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Quick presets */
.presets-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
}

.preset-btn {
  padding: 6px var(--space-sm);
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
  border-radius: var(--radius-sm);
}

.btn-sos {
  color: var(--error) !important;
}

.btn-sos:hover {
  background: var(--error-muted) !important;
}

/* Morse preview */
.morse-preview-wrap {
  display: flex;
  gap: var(--space-sm);
  align-items: flex-start;
  margin-bottom: var(--space-lg);
}

.morse-preview-wrap .morse-preview {
  flex: 1;
  margin-bottom: 0;
  min-width: 0;
}

.morse-preview,
.decode-result {
  padding: var(--space-md);
  font-family: var(--font-mono);
  font-size: var(--text-base);
  line-height: 1.8;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-height: 72px;
  word-break: break-word;
}

.morse-placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: var(--text-sm);
}

.morse-preview.has-content .morse-placeholder,
.decode-result.has-content .morse-placeholder {
  display: none;
}

.copy-morse-btn {
  flex-shrink: 0;
  height: fit-content;
}

/* Waveform */
.waveform-wrap {
  margin-bottom: var(--space-lg);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
}

.waveform-canvas {
  width: 100%;
  height: 64px;
  display: block;
}

/* Controls grid */
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md) var(--space-lg);
  margin-bottom: var(--space-xl);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-group label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.slider-row input[type="range"] {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
  cursor: pointer;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.slider-row input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

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

.slider-row input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.slider-row span {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  min-width: 3ch;
  text-align: right;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.control-toggle {
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
  grid-column: span 2;
}

.control-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  border-radius: 4px;
}

.control-toggle label {
  cursor: pointer;
  margin-left: var(--space-sm);
  text-transform: none;
  letter-spacing: normal;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.control-desc {
  width: 100%;
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-left: 24px;
  margin-top: 2px;
}

/* History */
.history-wrap {
  position: relative;
  margin-bottom: var(--space-md);
}

.history-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
}

.history-dropdown[hidden] {
  display: none !important;
}

.history-item {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-sm);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-fast);
}

.history-item:last-child {
  border-bottom: none;
}

.history-item:hover {
  background: var(--accent-muted);
}

/* Actions bar */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px var(--space-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

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

.btn:not(:disabled):active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:not(:disabled):hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow);
}

.btn-primary:focus-visible {
  outline: none;
  box-shadow: var(--shadow-glow);
}

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

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

.btn-secondary:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}

.btn-ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-ghost:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-muted);
}

.btn-icon {
  font-size: 0.9em;
  opacity: 0.9;
}

/* Export format toggle */
.export-format {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0 var(--space-xs);
}

.export-format input[type="radio"] {
  accent-color: var(--accent);
  cursor: pointer;
  width: 14px;
  height: 14px;
}

.export-format label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 500;
}

/* Panels */
.panel {
  display: none;
}

.panel.active {
  display: block;
}

/* Reference tab */
.ref-section-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--accent);
  margin: var(--space-lg) 0 var(--space-sm);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.ref-section-title:first-child {
  margin-top: 0;
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: var(--space-xs);
}

.ref-char {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-sm);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.ref-char:hover {
  background: var(--accent-muted);
  border-color: var(--accent);
}

.ref-char:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.ref-char .char {
  font-family: var(--font-mono);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
}

.ref-char .code {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}

.toast {
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  color: var(--text-primary);
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.toast::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.toast-success {
  border-color: var(--success);
}

.toast-success::before {
  background: var(--success);
}

.toast-error {
  border-color: var(--error);
}

.toast-error::before {
  background: var(--error);
}

.toast-warning {
  border-color: var(--warning);
}

.toast-warning::before {
  background: var(--warning);
}

.toast-info {
  border-color: var(--accent);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1500;
  padding: var(--space-lg);
  animation: fadeIn 0.15s ease;
}

.modal-overlay[hidden] {
  display: none !important;
}

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

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 440px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  margin: 0;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.modal-close:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-muted);
}

.modal-body {
  padding: var(--space-lg);
}

.modal-body h3 {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--accent);
  margin: var(--space-lg) 0 var(--space-sm);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.modal-body h3:first-child {
  margin-top: 0;
}

.modal-body p,
.modal-body ul {
  margin: 0 0 var(--space-sm);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.65;
}

.modal-body ul {
  padding-left: var(--space-lg);
}

.modal-body li {
  margin-bottom: 4px;
}

.modal-body kbd {
  font-family: var(--font-mono);
  font-size: 0.8em;
  padding: 2px 6px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  border: 1px solid var(--border);
}

.modal-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 1px 4px;
  background: var(--bg-tertiary);
  border-radius: 4px;
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  z-index: 2000;
}

.loading-overlay[hidden] {
  display: none !important;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay p {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

/* Responsive */
@media (max-width: 560px) {
  .app {
    padding: var(--space-md);
  }

  .header {
    padding-right: 80px;
  }

  .main {
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
  }

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

  .control-toggle {
    grid-column: span 1;
  }

  .actions {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }

  .export-format {
    width: 100%;
    justify-content: center;
    padding: var(--space-sm) 0;
  }

  .toast-container {
    left: var(--space-md);
    right: var(--space-md);
  }

  .toast {
    width: 100%;
  }
}

/* Focus visible polyfill fallback */
.btn:focus:not(:focus-visible),
.tab:focus:not(:focus-visible),
.theme-toggle:focus:not(:focus-visible),
.ref-char:focus:not(:focus-visible),
.modal-close:focus:not(:focus-visible) {
  outline: none;
  box-shadow: none;
}

/* ============== SELECT INPUT ============== */
.select-input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.select-input:hover {
  border-color: var(--border-hover);
}

.select-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ============== PRESET PACKS ============== */
.presets-section {
  margin-bottom: var(--space-md);
}

.presets-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: var(--space-sm);
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.preset-tab {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px var(--space-sm);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.preset-tab:hover {
  color: var(--text-secondary);
  border-color: var(--border-hover);
  background: var(--bg-elevated);
}

.preset-tab.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-muted);
}

.preset-tab-icon {
  font-size: 1em;
}

.preset-tab-name {
  display: none;
}

@media (min-width: 560px) {
  .preset-tab-name {
    display: inline;
  }
}

/* ============== CONTROLS SECTION ============== */
.controls-section {
  margin-bottom: var(--space-lg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.controls-summary {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  list-style: none;
}

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

.controls-summary::before {
  content: '▸';
  margin-right: var(--space-sm);
  transition: transform var(--transition-fast);
}

details[open] .controls-summary::before {
  transform: rotate(90deg);
}

.controls-section .controls {
  padding: var(--space-md);
  padding-top: 0;
  margin-bottom: 0;
}

/* ============== WAVEFORM EXPORT ============== */
.waveform-wrap {
  position: relative;
}

.waveform-export-btn {
  position: absolute;
  top: var(--space-xs);
  right: var(--space-xs);
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: var(--text-xs);
  opacity: 0.6;
}

.waveform-export-btn:hover {
  opacity: 1;
}

/* ============== DECODE PANEL ============== */
.decode-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

/* ============== STATS HEADER BUTTON ============== */
.stats-header-btn {
  position: relative;
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 1rem;
}

.streak-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  color: #fff;
  background: var(--accent);
  border-radius: var(--radius-full);
}

/* ============== PRACTICE MODE ============== */
.practice-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 600;
  margin: 0 0 var(--space-xs);
  text-align: center;
}

.practice-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: center;
  margin: 0 0 var(--space-xl);
}

.practice-options {
  display: grid;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.option-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.option-group label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.btn-large {
  width: 100%;
  padding: var(--space-md) var(--space-xl);
  font-size: var(--text-base);
}

/* Weak characters section */
.weak-chars-section {
  padding: var(--space-md);
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-xl);
}

.weak-chars-title {
  font-size: var(--text-sm);
  font-weight: 600;
  margin: 0 0 var(--space-xs);
}

.weak-chars-desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin: 0 0 var(--space-sm);
}

.weak-chars-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.weak-char {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--error);
  background: var(--error-muted);
  border-radius: var(--radius-sm);
}

/* Practice session */
.practice-stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-sm);
  padding: var(--space-md);
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-xl);
}

.stat-item {
  text-align: center;
}

.stat-label {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-bottom: 2px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
}

.stat-wrong {
  color: var(--error);
}

.stat-streak {
  color: var(--accent);
}

.practice-prompt {
  text-align: center;
  padding: var(--space-2xl) var(--space-md);
  margin-bottom: var(--space-lg);
}

.prompt-char {
  font-family: var(--font-mono);
  font-size: 4rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: var(--space-md);
}

.prompt-morse {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  color: var(--text-muted);
  letter-spacing: 0.1em;
}

.practice-input-wrap {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.practice-input {
  flex: 1;
  padding: var(--space-md);
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  text-align: center;
  text-transform: uppercase;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast);
}

.practice-input:focus {
  outline: none;
  border-color: var(--accent);
}

.practice-input::placeholder {
  text-transform: none;
  color: var(--text-muted);
}

.practice-feedback {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
  font-weight: 500;
}

.practice-feedback.correct {
  background: var(--success-muted);
  color: var(--success);
}

.practice-feedback.wrong {
  background: var(--error-muted);
  color: var(--error);
}

.feedback-icon {
  font-size: var(--text-xl);
}

.practice-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
}

/* Practice results */
.results-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 600;
  text-align: center;
  margin: 0 0 var(--space-xl);
}

.results-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.result-stat {
  text-align: center;
  padding: var(--space-lg);
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
}

.result-value {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.result-label {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.result-highlight {
  background: var(--accent-muted);
}

.result-highlight .result-value {
  color: var(--accent);
}

.results-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
}

/* ============== STATS MODAL ============== */
.modal-large {
  max-width: 560px;
}

.stats-overview {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.stat-card {
  text-align: center;
  padding: var(--space-lg);
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
}

.stat-card-value {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.stat-card-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-section {
  margin-bottom: var(--space-xl);
}

.stats-section h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--accent);
  margin: 0 0 var(--space-md);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chars-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.char-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-sm);
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  min-width: 48px;
}

.char-stat-char {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 600;
}

.char-stat-accuracy {
  font-size: var(--text-xs);
  color: var(--error);
}

/* Achievements */
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-sm);
}

.achievement {
  padding: var(--space-md);
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  text-align: center;
  transition: all var(--transition-fast);
}

.achievement.locked {
  opacity: 0.4;
  filter: grayscale(1);
}

.achievement.unlocked {
  border: 1px solid var(--accent-muted);
}

.achievement-icon {
  display: block;
  font-size: 1.5rem;
  margin-bottom: var(--space-xs);
}

.achievement-name {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: 2px;
}

.achievement-desc {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.3;
}

.stats-actions {
  text-align: center;
  padding-top: var(--space-md);
  border-top: 1px solid var(--border);
}

.btn-danger {
  color: var(--error);
}

.btn-danger:hover {
  background: var(--error-muted);
}

/* ============== QR MODAL ============== */
.qr-modal-body {
  text-align: center;
}

.qr-container {
  display: flex;
  justify-content: center;
  padding: var(--space-lg);
  background: #fff;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
}

.qr-container canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.qr-text {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin: 0 0 var(--space-lg);
  word-break: break-all;
}

.qr-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
}

/* ============== INSTALL PROMPT ============== */
.install-prompt {
  position: fixed;
  bottom: var(--space-lg);
  left: var(--space-lg);
  right: var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
}

.install-prompt p {
  flex: 1;
  margin: 0;
  font-size: var(--text-sm);
}

.btn-small {
  padding: 6px var(--space-md);
  font-size: var(--text-xs);
}

/* ============== REFERENCE SEARCH ============== */
.reference-search {
  margin-bottom: var(--space-lg);
}

.reference-search .text-input {
  min-height: auto;
}

/* ============== UTILITY CLASSES ============== */
.text-muted {
  color: var(--text-muted);
}

/* ============== MOBILE RESPONSIVE ============== */
@media (max-width: 560px) {
  .practice-stats-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  .prompt-char {
    font-size: 3rem;
  }

  .results-summary {
    grid-template-columns: 1fr;
  }

  .stats-overview {
    grid-template-columns: 1fr;
  }

  .achievements-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .practice-actions {
    flex-direction: column;
  }

  .practice-actions .btn {
    width: 100%;
  }

  .install-prompt {
    flex-wrap: wrap;
  }

  .install-prompt p {
    width: 100%;
    margin-bottom: var(--space-sm);
  }
}
