/* Voice — voice recorder with live waveform + transcription
 * Palette: salmon + warm-cream + recording red
 * © אופיר ברנס (Ofir Baranes) 2026
 */

* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg-1: #180c0a;
  --bg-2: #21100d;
  --bg-3: #2c1612;
  --salmon-200: #fecaca;
  --salmon-300: #fca5a5;
  --salmon-400: #f87171;
  --salmon-500: #ef4444;
  --salmon-600: #dc2626;
  --salmon-700: #b91c1c;
  --salmon-800: #7f1d1d;
  --rec-red: #ef4444;
  --cream: #fef9c3;
  --cream-light: #fffbeb;
  --gold: #fcd34d;
  --text-primary: #fef9c3;
  --text-secondary: rgba(254,249,195,0.72);
  --text-muted: rgba(254,249,195,0.42);
  --surface: rgba(252,165,165,0.05);
  --surface-strong: rgba(252,165,165,0.10);
  --border: rgba(248,113,113,0.16);
  --border-strong: rgba(248,113,113,0.28);
  --shadow-glass: 0 30px 60px -25px rgba(24,12,10,0.7);
  --bezier: cubic-bezier(.34,1.56,.64,1);
  --bezier-soft: cubic-bezier(.4,0,.2,1);
}

html, body {
  background: var(--bg-1);
  color: var(--text-primary);
  font-family: 'Heebo', system-ui, sans-serif;
  font-weight: 400;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse 700px 800px at 80% -10%, rgba(248,113,113,0.20), transparent 60%),
    radial-gradient(ellipse 500px 600px at -10% 60%, rgba(220,38,38,0.16), transparent 65%),
    radial-gradient(ellipse 800px 1000px at 50% 110%, rgba(127,29,29,0.32), transparent 70%),
    linear-gradient(180deg, #180c0a 0%, #21100d 60%, #2c1612 110%);
  background-attachment: fixed;
  position: relative;
  padding-bottom: 40px;
}

.ambient-bg {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.orb-blur {
  position: absolute;
  border-radius: 50%;
  filter: blur(85px);
  opacity: 0.45;
}
.orb-blur.o1 { width: 420px; height: 420px; top: -120px; right: -120px; background: radial-gradient(circle, #f87171 0%, transparent 70%); animation: drift1 26s ease-in-out infinite; }
.orb-blur.o2 { width: 340px; height: 340px; bottom: 5%; left: -100px; background: radial-gradient(circle, #fcd34d 0%, transparent 70%); opacity: 0.18; animation: drift2 32s ease-in-out infinite; }
.orb-blur.o3 { width: 260px; height: 260px; top: 40%; right: 30%; background: radial-gradient(circle, #b91c1c 0%, transparent 70%); opacity: 0.32; animation: drift3 38s ease-in-out infinite; }
@keyframes drift1 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(-30px,40px) scale(1.1); } }
@keyframes drift2 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(40px,-30px) scale(1.08); } }
@keyframes drift3 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(-25px,-35px) scale(1.12); } }

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(24,12,10,0.85) 0%, rgba(24,12,10,0.55) 100%);
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--cream-light);
  letter-spacing: -0.01em;
}
.mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--salmon-400), var(--salmon-700));
  color: var(--cream-light);
  box-shadow: 0 0 18px rgba(248,113,113,0.45);
}
.mark svg { width: 18px; height: 18px; }

.header-actions { display: flex; gap: 8px; }
.icon-btn, .install-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  border-radius: 12px;
  padding: 7px 12px;
  cursor: pointer;
  transition: all 0.2s var(--bezier-soft);
  backdrop-filter: blur(10px);
}
.icon-btn { padding: 7px 9px; font-size: 16px; }
.icon-btn:hover, .install-btn:hover {
  background: var(--surface-strong);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.install-btn {
  background: linear-gradient(135deg, var(--salmon-400), var(--salmon-700));
  border: none;
  color: var(--cream-light);
  font-weight: 700;
}

main {
  position: relative;
  z-index: 1;
  padding: 22px 18px;
  max-width: 720px;
  margin: 0 auto;
}
.hidden { display: none !important; }

/* ===== Permission / Desktop ===== */
.perm-panel, .desktop-panel {
  text-align: center;
  padding: 60px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  backdrop-filter: blur(14px);
}
.perm-icon {
  font-size: 64px;
  margin-bottom: 18px;
}
.perm-panel h2, .desktop-panel h2 {
  font-family: 'Frank Ruhl Libre', 'Heebo', serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--cream-light);
  margin-bottom: 10px;
  letter-spacing: -0.015em;
}
.perm-panel p, .desktop-panel p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 22px;
  max-width: 380px;
  margin-left: auto;
  margin-right: auto;
}

/* ===== Recorder hero ===== */
.rec-hero {
  background: linear-gradient(140deg, var(--surface-strong) 0%, var(--surface) 60%, transparent 100%);
  backdrop-filter: blur(22px) saturate(180%);
  border: 1px solid var(--border-strong);
  border-radius: 26px;
  padding: 20px 22px 24px;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-glass);
  text-align: center;
}
.rec-hero::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 26px;
  padding: 1.5px;
  background: linear-gradient(135deg, rgba(248,113,113,0.4) 0%, rgba(254,249,195,0.18) 50%, transparent 80%);
  -webkit-mask: linear-gradient(#000,#000) content-box, linear-gradient(#000,#000);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.rec-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-secondary);
  margin-bottom: 18px;
}
.rec-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all 0.2s;
}
.rec-status.recording .rec-dot {
  background: var(--rec-red);
  box-shadow: 0 0 12px var(--rec-red);
  animation: pulse-dot 1s ease-in-out infinite;
}
.rec-status.paused .rec-dot { background: var(--gold); box-shadow: 0 0 12px var(--gold); }
@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.6; }
}

/* Wave stage */
.wave-stage {
  position: relative;
  width: 100%;
  height: 120px;
  margin-bottom: 14px;
  border-radius: 16px;
  overflow: hidden;
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--border);
}
#liveWave {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.wave-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  transition: opacity 0.3s;
}
.wave-overlay.hidden-overlay { opacity: 0; }
.rec-mic-glow {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  background: radial-gradient(circle, rgba(248,113,113,0.18), rgba(248,113,113,0));
  color: var(--salmon-300);
  border-radius: 50%;
}
.rec-mic-glow svg { width: 32px; height: 32px; }

/* Timer */
.rec-timer {
  font-family: 'IBM Plex Mono', monospace;
  font-size: clamp(40px, 9vw, 56px);
  font-weight: 300;
  color: var(--cream-light);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.025em;
  line-height: 1;
  margin-bottom: 18px;
  direction: ltr;
  text-shadow: 0 0 30px rgba(254,249,195,0.18);
}
.rec-timer.recording {
  color: var(--cream-light);
}

/* Record button */
.rec-btn {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--salmon-500), var(--salmon-700));
  border: 4px solid rgba(254,249,195,0.18);
  cursor: pointer;
  display: grid;
  place-items: center;
  margin: 0 auto;
  transition: all 0.3s var(--bezier);
  box-shadow: 0 14px 30px rgba(239,68,68,0.45), 0 0 24px rgba(248,113,113,0.30);
  position: relative;
}
.rec-btn:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 18px 40px rgba(239,68,68,0.6), 0 0 32px rgba(248,113,113,0.45);
}
.rec-btn:active { transform: scale(0.96); }
.rec-btn-inner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--cream-light);
  transition: all 0.25s var(--bezier);
}
.rec-btn.recording {
  animation: rec-pulse 2s ease-in-out infinite;
}
.rec-btn.recording .rec-btn-inner {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--cream-light);
}
@keyframes rec-pulse {
  0%, 100% { box-shadow: 0 14px 30px rgba(239,68,68,0.45), 0 0 24px rgba(248,113,113,0.30); }
  50% { box-shadow: 0 14px 30px rgba(239,68,68,0.65), 0 0 40px rgba(239,68,68,0.55); }
}

.rec-hint {
  margin-top: 14px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

/* ===== Library ===== */
.library-section {
  background: var(--surface);
  backdrop-filter: blur(14px) saturate(150%);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 18px;
}
.lib-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
}
.lib-title {
  font-family: 'Frank Ruhl Libre', 'Heebo', serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--cream-light);
  letter-spacing: -0.015em;
}
.lib-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.lib-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 460px;
  overflow-y: auto;
}
.lib-list::-webkit-scrollbar { width: 4px; }
.lib-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.rec-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(252,165,165,0.04);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s var(--bezier-soft);
}
.rec-row:hover {
  background: rgba(248,113,113,0.10);
  border-color: var(--border-strong);
  transform: translateX(-2px);
}

.rr-play {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--salmon-400), var(--salmon-700));
  border: none;
  color: var(--cream-light);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(239,68,68,0.30);
  transition: all 0.2s;
}
.rr-play:hover { transform: scale(1.06); }
.rr-play svg { width: 14px; height: 14px; }

.rr-thumbnail {
  width: 80px;
  height: 36px;
  flex-shrink: 0;
  position: relative;
}
.rr-thumbnail canvas { width: 100%; height: 100%; }

.rr-body { flex: 1; min-width: 0; }
.rr-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--cream-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.rr-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  font-variant-numeric: tabular-nums;
  display: flex;
  gap: 6px;
}
.rr-meta .duration { color: var(--salmon-300); font-weight: 600; }

.lib-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.lib-empty .icon { font-size: 36px; margin-bottom: 8px; opacity: 0.5; }
.lib-empty p { font-size: 13px; line-height: 1.6; max-width: 280px; margin: 0 auto; }

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0;
  background: rgba(15,7,5,0.7);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: modal-fade 0.25s var(--bezier-soft);
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: 100%;
  max-width: 540px;
  background: linear-gradient(180deg, #2c1612 0%, #180c0a 100%);
  border: 1px solid var(--border-strong);
  border-bottom: none;
  border-radius: 28px 28px 0 0;
  padding: 20px 22px 32px;
  padding-bottom: max(32px, env(safe-area-inset-bottom));
  animation: modal-slide 0.4s var(--bezier);
  max-height: 92vh;
  overflow-y: auto;
}
@keyframes modal-slide { from { transform: translateY(100%); } to { transform: translateY(0); } }
.handle {
  width: 38px; height: 4px;
  background: var(--border-strong);
  border-radius: 4px;
  margin: 0 auto 16px;
}
.modal-card h3 {
  font-family: 'Frank Ruhl Libre', 'Heebo', serif;
  color: var(--cream-light);
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 14px;
}
.modal-card p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.65;
  margin-bottom: 14px;
}
.mark-big {
  width: 64px; height: 64px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--salmon-400), var(--salmon-700));
  border-radius: 18px;
  color: var(--cream-light);
  margin: 4px auto 14px;
  box-shadow: 0 0 30px rgba(248,113,113,0.4);
}
.mark-big svg { width: 32px; height: 32px; }

/* Detail title */
.dm-title-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 16px;
}
.dm-title-input {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px dashed transparent;
  color: var(--cream-light);
  font-family: 'Frank Ruhl Libre', 'Heebo', serif;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: right;
  direction: rtl;
  padding: 4px 0;
  outline: none;
  transition: border-color 0.2s;
}
.dm-title-input:hover, .dm-title-input:focus {
  border-bottom-color: var(--border-strong);
}
.dm-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* Static waveform */
.dm-wave-stage {
  position: relative;
  height: 100px;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
}
#staticWave {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--cream-light);
  box-shadow: 0 0 8px rgba(254,249,195,0.6);
  pointer-events: none;
  transition: right 0.1s linear;
  right: 100%;
}

.dm-time-row {
  display: flex;
  justify-content: space-between;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 14px;
  direction: ltr;
}

/* Playback controls */
.play-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}
.pc-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--cream-light);
  cursor: pointer;
  display: grid;
  place-items: center;
  position: relative;
  transition: all 0.2s var(--bezier);
}
.pc-btn:hover { background: var(--surface-strong); border-color: var(--border-strong); transform: translateY(-2px); }
.pc-btn:active { transform: scale(0.94); }
.pc-btn svg { width: 22px; height: 22px; }
.pc-btn .pc-num {
  position: absolute;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  color: var(--text-muted);
  font-weight: 600;
}
.pc-btn.primary {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--salmon-400), var(--salmon-700));
  border: none;
  box-shadow: 0 10px 24px rgba(239,68,68,0.40);
}
.pc-btn.primary:hover { box-shadow: 0 14px 32px rgba(239,68,68,0.55); }
.pc-btn.primary svg { width: 28px; height: 28px; }

/* Speed pills */
.speed-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.sr-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--salmon-300);
  flex-shrink: 0;
}
.speed-pills {
  display: flex;
  gap: 4px;
  flex: 1;
}
.sp {
  flex: 1;
  padding: 6px 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-secondary);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-variant-numeric: tabular-nums;
}
.sp:hover { background: rgba(252,165,165,0.06); color: var(--cream-light); }
.sp.active {
  background: linear-gradient(135deg, var(--salmon-500), var(--salmon-700));
  color: var(--cream-light);
  font-weight: 700;
  box-shadow: 0 4px 10px rgba(239,68,68,0.30);
}

/* Transcript */
.transcript-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.ts-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.ts-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--salmon-300);
}
.ts-btn {
  background: rgba(252,211,77,0.12);
  border: 1px solid rgba(252,211,77,0.30);
  color: var(--gold);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.2s;
}
.ts-btn:hover { background: rgba(252,211,77,0.20); }
.ts-btn.recording {
  background: rgba(239,68,68,0.18);
  border-color: rgba(239,68,68,0.4);
  color: var(--salmon-200);
  animation: pulse-soft 1s ease-in-out infinite;
}
@keyframes pulse-soft { 0%,100% { opacity: 1; } 50% { opacity: 0.65; } }

.transcript-text {
  font-size: 14px;
  color: var(--cream-light);
  line-height: 1.7;
  min-height: 50px;
  white-space: pre-wrap;
  word-break: break-word;
}
.transcript-text.empty { color: var(--text-muted); font-family: 'IBM Plex Mono', monospace; font-size: 12px; }

/* Modal actions */
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.btn-primary, .btn-secondary, .btn-mini {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 18px;
  border-radius: 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s var(--bezier);
  border: none;
}
.btn-primary {
  background: linear-gradient(135deg, var(--salmon-400), var(--salmon-700));
  color: var(--cream-light);
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(239,68,68,0.40);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(239,68,68,0.55); }
.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--cream-light);
}
.btn-mini {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  flex: 0 1 auto;
  padding: 13px 18px;
}
.btn-mini.danger { color: #fda4af; border-color: rgba(253,164,175,0.3); }
.btn-mini.danger:hover { background: rgba(253,164,175,0.1); }
