/* === Speak — mobile recorder === */

:root {
  --bg: #0a0a0a;
  --bg-2: #141414;
  --bg-3: #1d1d1d;
  --fg: #f0efed;
  --fg-dim: #9a9692;
  --fg-muted: #5f5b57;
  --border: #2a2a2a;
  --accent: #ff4d4d;
  --accent-pulse: rgba(255, 77, 77, 0.4);
  --success: #5cf299;
  --warning: #ffb86c;
  --danger: #ff4d4d;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

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

/* === Screens === */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.screen.active { display: flex; }

/* === PIN screen === */
#pin-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top, #1a0e0e 0%, var(--bg) 60%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 64px;
}
.brand-mark {
  font-size: 12px;
  color: var(--accent);
  animation: brand-pulse 2.5s ease-in-out infinite;
}
@keyframes brand-pulse {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.3); }
}
.brand h1 {
  font-size: 24px;
  font-weight: 300;
  letter-spacing: 0.5em;
  margin: 0;
  text-transform: lowercase;
  color: var(--fg-dim);
}

#pin-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 280px;
}

.pin-input-wrap {
  position: relative;
  width: 100%;
}

#pin-input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  font-size: 24px;
  color: var(--fg);
  text-align: center;
  letter-spacing: 1em;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}
#pin-input:focus {
  border-color: var(--accent);
  background: var(--bg-3);
}

#pin-submit {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 24px;
  font-weight: 300;
  transition: transform 0.15s, background 0.2s;
}
#pin-submit:active { transform: scale(0.92); }
#pin-submit:disabled { background: var(--bg-3); color: var(--fg-muted); }

.error-line {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
  text-align: center;
}

/* === Top bar === */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.top-bar h2 {
  font-size: 16px;
  font-weight: 500;
  margin: 0;
  color: var(--fg-dim);
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  color: var(--fg-dim);
  padding: 6px 14px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid var(--border);
}
.status-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg-muted);
}
.status-pill.recording { color: var(--accent); border-color: rgba(255, 77, 77, 0.3); }
.status-pill.recording::before {
  background: var(--accent);
  animation: dot-pulse 1.2s ease-in-out infinite;
}
.status-pill.paused { color: var(--warning); border-color: rgba(255, 184, 108, 0.3); }
.status-pill.paused::before { background: var(--warning); }
.status-pill.uploading { color: var(--success); border-color: rgba(92, 242, 153, 0.3); }
.status-pill.uploading::before { background: var(--success); animation: dot-pulse 1.2s infinite; }
@keyframes dot-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* === Recorder area === */
.recorder-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 36px;
  padding: 20px;
}

.timer {
  font-size: 72px;
  font-weight: 200;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  font-family: "SF Pro Display", system-ui, sans-serif;
}

.vu-meter {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  opacity: 0.3;
  transition: opacity 0.3s;
}
.vu-meter.active { opacity: 1; }
.vu-bar {
  width: 3px;
  height: 6px;
  background: var(--accent);
  border-radius: 2px;
  transition: height 0.08s ease-out;
}

.record-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.record-btn {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.3s;
  position: relative;
}
.record-btn:active { transform: scale(0.93); }

.record-btn .record-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: white;
  transition: all 0.2s ease;
}
.record-btn.recording {
  box-shadow: 0 0 0 0 var(--accent-pulse);
  animation: record-pulse 1.6s ease-out infinite;
}
.record-btn.recording .record-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}
@keyframes record-pulse {
  0% { box-shadow: 0 0 0 0 var(--accent-pulse); }
  100% { box-shadow: 0 0 0 32px rgba(255, 77, 77, 0); }
}

.record-btn.paused {
  background: var(--warning);
  animation: none;
}
.record-btn.paused .record-icon {
  width: 28px;
  height: 28px;
  background: white;
  border-radius: 4px;
  position: relative;
}

.secondary-controls {
  display: flex;
  gap: 24px;
}

.ghost-btn-large {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--fg-dim);
  font-size: 20px;
  transition: background 0.2s, color 0.2s, transform 0.15s;
}
.ghost-btn-large:active { transform: scale(0.92); }
.ghost-btn-large.stop { color: var(--accent); }

.upload-status {
  min-height: 20px;
  font-size: 12px;
  color: var(--fg-muted);
  letter-spacing: 0.05em;
}
.upload-status.warning { color: var(--warning); }
.upload-status.success { color: var(--success); }

/* === Bottom bar === */
.bottom-bar {
  display: flex;
  justify-content: center;
  padding: 16px 18px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--fg-dim);
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  transition: background 0.2s;
}
.nav-btn:active { background: var(--bg-3); }
.badge {
  background: var(--bg-3);
  color: var(--fg);
  font-size: 11px;
  font-weight: 600;
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 10px;
  text-align: center;
}

/* === List screen === */
.list-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0 12px;
}
#recordings-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.rec-item {
  border-bottom: 1px solid var(--border);
  position: relative;
  transition: background 0.15s;
}
.rec-item.just-finished {
  background: linear-gradient(90deg, rgba(92, 242, 153, 0.08), transparent 70%);
  animation: just-finished-pulse 2.5s ease-out 1;
}
@keyframes just-finished-pulse {
  0% { background: linear-gradient(90deg, rgba(92, 242, 153, 0.25), transparent 60%); }
  100% { background: linear-gradient(90deg, rgba(92, 242, 153, 0.08), transparent 70%); }
}
.rec-item .row-head {
  display: flex;
  align-items: center;
  padding: 14px 12px 14px 18px;
  gap: 10px;
  cursor: pointer;
  transition: background 0.12s;
  -webkit-user-select: none;
  user-select: none;
}
.rec-item .row-head:active { background: var(--bg-2); }
.rec-item .row-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.rec-item .row1 {
  display: flex;
  align-items: center;
  gap: 10px;
}
.rec-item .title {
  font-size: 15px;
  font-weight: 500;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.rec-item .status-tag {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border-radius: 100px;
  background: var(--bg-2);
  color: var(--fg-muted);
  flex-shrink: 0;
}
.rec-item .status-tag.done { color: var(--success); background: rgba(92, 242, 153, 0.1); }
.rec-item .status-tag.transcribing { color: var(--warning); background: rgba(255, 184, 108, 0.1); }
.rec-item .status-tag.failed { color: var(--danger); background: rgba(255, 77, 77, 0.1); }
.rec-item .status-tag.recording { color: var(--accent); }
.rec-item .row2 {
  font-size: 12px;
  color: var(--fg-muted);
  display: flex;
  gap: 12px;
  align-items: center;
}
.rec-item .preview {
  font-size: 12px;
  color: var(--fg-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}
.rec-item .expand-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: transparent;
  color: var(--fg-muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.25s ease;
}
.rec-item .expand-btn:active { background: var(--bg-2); }
.rec-item.expanded .expand-btn { transform: rotate(180deg); }

.rec-item .expanded-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.32s cubic-bezier(.16,1,.3,1);
}
.rec-item.expanded .expanded-content {
  max-height: 1200px;
}
.rec-item .expanded-inner {
  padding: 4px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.rec-item .expanded-text {
  font-size: 14px;
  line-height: 1.55;
  color: var(--fg);
  white-space: pre-wrap;
  max-height: 280px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-2);
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.rec-item .expanded-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.rec-item .action-chip {
  padding: 7px 14px;
  border-radius: 100px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--fg-dim);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s;
}
.rec-item .action-chip:active { background: var(--bg-3); color: var(--fg); }
.rec-item .action-chip.primary { background: var(--accent); border-color: var(--accent); color: white; }
.rec-item .action-chip.primary:active { background: #ff6666; }
.rec-item .action-chip.danger { color: var(--danger); }

/* Pulserande grön prick på just-färdiga rader */
.rec-item.just-finished .title::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  margin-right: 8px;
  vertical-align: middle;
  animation: dot-pulse 1.2s ease-in-out infinite;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--fg-muted);
  font-size: 14px;
}

/* === Detail screen === */
.detail-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
}
.detail-meta h2 {
  font-size: 22px;
  font-weight: 500;
  margin: 0 0 8px;
  line-height: 1.3;
  color: var(--fg);
}
.detail-info {
  color: var(--fg-muted);
  font-size: 12px;
  margin-bottom: 24px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.detail-status {
  padding: 14px 18px;
  border-radius: 10px;
  margin-bottom: 20px;
  font-size: 14px;
  display: none;
}
.detail-status.show { display: block; }
.detail-status.transcribing {
  background: rgba(255, 184, 108, 0.08);
  color: var(--warning);
  border: 1px solid rgba(255, 184, 108, 0.2);
}
.detail-status.failed {
  background: rgba(255, 77, 77, 0.08);
  color: var(--danger);
  border: 1px solid rgba(255, 77, 77, 0.2);
}
.detail-text {
  white-space: pre-wrap;
  line-height: 1.65;
  font-size: 15px;
  color: var(--fg);
}

/* === Ghost buttons === */
.ghost-btn {
  background: transparent;
  color: var(--fg-dim);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  transition: color 0.2s, background 0.2s;
}
.ghost-btn:active { background: var(--bg-2); color: var(--fg); }
.ghost-btn.danger { color: var(--danger); }

/* === Toast === */
.toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-3);
  color: var(--fg);
  padding: 12px 20px;
  border-radius: 100px;
  font-size: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error { border-color: rgba(255, 77, 77, 0.4); }
.toast.success { border-color: rgba(92, 242, 153, 0.4); }

/* CTA-toast: stor, ihållande, tap-to-copy */
.cta-toast {
  position: fixed;
  bottom: max(96px, calc(env(safe-area-inset-bottom) + 96px));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--accent);
  color: white;
  padding: 16px 26px;
  border-radius: 16px;
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 10px 40px rgba(255, 77, 77, 0.4), 0 0 0 4px rgba(255, 77, 77, 0.2);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s cubic-bezier(.16,1,.3,1);
  max-width: calc(100vw - 24px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.cta-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.cta-toast.copied {
  background: var(--success);
  color: var(--bg);
  box-shadow: 0 10px 40px rgba(92, 242, 153, 0.4);
}
.cta-toast .cta-icon {
  font-size: 20px;
  flex-shrink: 0;
}
.cta-toast .cta-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.cta-toast .cta-title {
  font-weight: 600;
  font-size: 15px;
}
.cta-toast .cta-sub {
  font-size: 12px;
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}
.cta-toast .cta-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.cta-toast.copied .cta-close { background: rgba(0, 0, 0, 0.15); color: var(--bg); }
