/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --text: #111827;
  --text-dim: #6b7280;
  --border: #e5e7eb;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --radius: 12px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,.1), 0 10px 10px -5px rgba(0,0,0,.04);
  --ease: cubic-bezier(.4,0,.2,1);
  --dur: 200ms;
  --dur-slow: 300ms;
}

[data-theme="dark"] {
  --bg: #111117;
  --surface: #1e1e2a;
  --text: #e5e5ef;
  --text-dim: #9ca3af;
  --border: #2e2e3e;
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --danger: #f87171;
  --danger-hover: #ef4444;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.4), 0 2px 4px -1px rgba(0,0,0,.3);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.4), 0 4px 6px -2px rgba(0,0,0,.3);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,.4), 0 10px 10px -5px rgba(0,0,0,.3);
}

html { height: 100%; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* === Views === */
.view { display: none; }
.view.active { display: block; }
.view.active.landing-view { display: flex; }
.hidden { display: none !important; }

/* === Landing === */
.landing-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.landing-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 48px 32px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-xl);
  text-align: center;
  animation: slideUp .5s var(--ease);
}

.landing-icon {
  font-size: 48px;
  margin-bottom: 8px;
  line-height: 1;
}

.landing-card h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 6px;
}

.landing-card p {
  color: var(--text-dim);
  margin-bottom: 32px;
  font-size: 15px;
}

.landing-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* === Inputs === */
input[type="text"] {
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--dur) var(--ease);
  width: 100%;
  background: var(--surface);
  color: var(--text);
}

input[type="text"]:focus {
  border-color: var(--primary);
}

/* === Buttons === */
.btn-primary {
  padding: 14px 24px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: scale(.97); }
.btn-primary.full { width: 100%; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-danger {
  padding: 14px 20px;
  background: none;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-ghost {
  padding: 10px 20px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
  transition: color var(--dur) var(--ease);
}
.btn-ghost:hover { color: var(--text); }

/* === Board Header === */
.board-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}

.board-header h1 {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.icon-btn {
  background: none;
  border: none;
  padding: 8px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--bg); }

.header-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
  transition: all var(--dur) var(--ease);
  white-space: nowrap;
  flex-shrink: 0;
}
.header-btn:hover { background: var(--bg); }
.header-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.size-controls {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 2px;
  flex-shrink: 0;
}
.size-controls .icon-btn {
  padding: 6px;
  border-radius: 8px;
}
.size-controls .icon-btn:disabled {
  opacity: .3;
  cursor: not-allowed;
}

/* === Grid === */
#buttons-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), 1fr);
  gap: 12px;
  padding: 16px;
  padding-bottom: 100px;
}

@media (min-width: 480px) {
  #buttons-grid { grid-template-columns: repeat(var(--cols, 3), 1fr); }
}
@media (min-width: 768px) {
  #buttons-grid { grid-template-columns: repeat(var(--cols, 4), 1fr); gap: 16px; padding: 24px; padding-bottom: 100px; }
}
@media (min-width: 1024px) {
  #buttons-grid { grid-template-columns: repeat(var(--cols, 5), 1fr); }
}

/* === Sound Buttons === */
.sound-btn {
  aspect-ratio: 1;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 8px;
  position: relative;
  font-family: inherit;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), opacity var(--dur) var(--ease);
  box-shadow: var(--shadow);
  -webkit-user-select: none;
  user-select: none;
}

.sound-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.sound-btn:active { transform: scale(.94); }

.sound-btn .btn-label {
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  word-break: break-word;
  line-height: 1.3;
  max-height: 3.9em;
  overflow: hidden;
}

/* Edit icon on each button */
.sound-btn .edit-icon {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0,0,0,.15);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--dur) var(--ease), background var(--dur) var(--ease);
  color: inherit;
  padding: 0;
}
.sound-btn .edit-icon svg { width: 14px; height: 14px; }
.sound-btn:hover .edit-icon { opacity: 1; }
.sound-btn .edit-icon:hover { background: rgba(0,0,0,.3); }

@media (hover: none) {
  .sound-btn .edit-icon { opacity: .6; }
}

/* Playing state — transition only, no animation override */
.sound-btn.playing {
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.35), var(--shadow-md);
  transform: scale(1.03);
}

/* Reorder mode */
.reorder-mode .sound-btn {
  cursor: grab;
  animation: wiggle .25s ease-in-out infinite alternate;
}
.reorder-mode .sound-btn:active { cursor: grabbing; }
.reorder-mode #buttons-grid { touch-action: none; }

@keyframes wiggle {
  from { transform: rotate(-.7deg); }
  to { transform: rotate(.7deg); }
}

.sound-btn.dragging {
  opacity: .3;
  transform: scale(.92) !important;
  animation: none !important;
}

.drag-ghost {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  opacity: .85;
  transform: scale(1.08) rotate(2deg);
  box-shadow: var(--shadow-xl);
  border-radius: var(--radius);
}

/* === Empty State === */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: .5; }
.empty-state p { font-size: 16px; margin-bottom: 4px; }
.empty-state small { font-size: 13px; opacity: .6; }

/* === FAB === */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
.fab:hover { transform: scale(1.08); box-shadow: var(--shadow-xl); background: var(--primary-hover); }
.fab:active { transform: scale(.93); }

/* === Modals === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-slow) var(--ease), visibility var(--dur-slow) var(--ease);
}
.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform var(--dur-slow) var(--ease);
}
.modal-overlay.active .modal { transform: translateY(0); }

@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: 24px; }
  .modal {
    border-radius: var(--radius-lg);
    transform: translateY(16px) scale(.96);
  }
  .modal-overlay.active .modal { transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}
.modal-header h2 { font-size: 18px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-dim);
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: background var(--dur) var(--ease);
}
.modal-close:hover { background: var(--bg); }

.modal-body { padding: 20px 24px 28px; }

/* === Choice Grid === */
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.choice-btn {
  padding: 28px 16px 24px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  transition: all var(--dur) var(--ease);
}
.choice-btn:hover { border-color: var(--primary); background: var(--choice-hover-bg, #eef0ff); }
.choice-btn:active { transform: scale(.97); }
.choice-icon { display: block; margin-bottom: 10px; color: var(--text); }
.choice-label { font-size: 14px; font-weight: 600; color: var(--text); }

/* === Record UI === */
.record-ui { text-align: center; }

.record-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--danger);
  margin: 0 auto 8px;
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .4; transform: scale(1.3); }
}

.record-time {
  font-size: 36px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-bottom: 20px;
}

.record-controls { display: flex; justify-content: center; gap: 16px; margin-bottom: 20px; }

.rec-btn {
  width: 64px; height: 64px;
  border-radius: 50%; border: none;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}
.rec-btn.start { background: var(--danger); }
.rec-btn.start::after { content: ''; display: block; width: 20px; height: 20px; border-radius: 50%; background: #fff; margin: auto; }
.rec-btn.start:hover { background: var(--danger-hover); transform: scale(1.05); }

.rec-btn.stop { background: var(--text); border-radius: 14px; width: 52px; height: 52px; }
.rec-btn.stop::after { content: ''; display: block; width: 18px; height: 18px; border-radius: 4px; background: #fff; margin: auto; }
.rec-btn.stop:hover { transform: scale(1.05); }

/* === Audio Preview === */
.audio-preview {
  width: 100%;
  margin: 12px 0;
  border-radius: var(--radius);
  height: 44px;
}

/* === File Drop === */
.file-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 16px;
  text-align: center;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  display: block;
}
.file-drop:hover { border-color: var(--primary); background: var(--choice-hover-bg, #eef0ff); }
.file-drop input { display: none; }
.file-icon { display: block; margin-bottom: 10px; color: var(--text-dim); }
.file-text { font-size: 14px; color: var(--text-dim); }

/* === Details Form === */
.details-form { display: flex; flex-direction: column; gap: 12px; }

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* === Color Picker === */
.color-picker { display: flex; flex-wrap: wrap; gap: 8px; }

.color-swatch {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  flex-shrink: 0;
}
.color-swatch:hover { transform: scale(1.2); }
.color-swatch.selected {
  border-color: var(--text);
  transform: scale(1.2);
  box-shadow: var(--shadow);
}

/* === Edit Actions === */
.edit-actions { display: flex; gap: 12px; margin-top: 8px; }
.flex-1 { flex: 1; }

/* === Waveform & Trim === */
.waveform-wrap {
  position: relative;
  height: 88px;
  background: var(--bg);
  border-radius: var(--radius);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.waveform-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.trim-dim {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(255,255,255,.6);
  pointer-events: none;
  transition: width 0s;
}
.trim-dim-left { left: 0; }
.trim-dim-right { right: 0; }

.trim-handle {
  position: absolute;
  top: 0;
  width: 20px;
  height: 100%;
  cursor: ew-resize;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}
.trim-handle::before {
  content: '';
  width: 4px;
  height: 32px;
  border-radius: 2px;
  background: var(--primary);
  box-shadow: 0 0 0 2px rgba(255,255,255,.8);
  transition: height var(--dur) var(--ease), background var(--dur) var(--ease);
}
.trim-handle:hover::before,
.trim-handle.active::before {
  height: 44px;
  background: var(--primary-hover);
}

.trim-handle-start { transform: translateX(-50%); }
.trim-handle-end { transform: translateX(-50%); }

.waveform-playhead {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: var(--text);
  opacity: .7;
  z-index: 3;
  pointer-events: none;
  transition: none;
}

.waveform-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
}

.preview-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.preview-btn:hover { background: var(--primary-hover); }
.preview-btn:active { transform: scale(.92); }
.preview-btn svg { width: 16px; height: 16px; }

.trim-info {
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--text);
  color: #fff;
  padding: 10px 24px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: all var(--dur-slow) var(--ease);
  z-index: 200;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* === Animations === */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes btnIn {
  from { opacity: 0; transform: scale(.85); }
  to { opacity: 1; transform: scale(1); }
}

/* === Dark‑mode extras === */
[data-theme="dark"] {
  --choice-hover-bg: #2a2a3e;
}

[data-theme="dark"] .landing-view {
  background: linear-gradient(135deg, #312e81 0%, #4c1d95 100%);
}

[data-theme="dark"] .trim-dim { background: rgba(0,0,0,.5); }

[data-theme="dark"] .toast { background: #e5e5ef; color: #111117; }

/* === Theme Toggle === */
.theme-toggle {
  background: none;
  border: none;
  padding: 8px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur) var(--ease);
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--bg); }
.theme-toggle svg { width: 18px; height: 18px; }

.landing-theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  background: rgba(255,255,255,.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  padding: 10px;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur) var(--ease);
  z-index: 10;
}
.landing-theme-toggle:hover { background: rgba(255,255,255,.25); }
.landing-theme-toggle svg { width: 20px; height: 20px; }

/* === Volume Slider === */
.volume-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.volume-control svg {
  flex-shrink: 0;
  color: var(--text-dim);
}

.volume-control input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

.volume-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--dur) var(--ease);
}
.volume-control input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }

.volume-control input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

.volume-value {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  min-width: 36px;
  text-align: right;
}

.volume-badge {
  position: absolute;
  bottom: 5px;
  right: 6px;
  font-size: 10px;
  font-weight: 700;
  opacity: .6;
  pointer-events: none;
  line-height: 1;
}
