@font-face {
  font-family: "Pelak";
  src: url("fonts/Pelak-Light.woff2") format("woff2");
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Pelak";
  src: url("fonts/Pelak-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Pelak";
  src: url("fonts/Pelak-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --bg-top: #f8fafc;
  --card: #ffffff;
  --surface: #f8fafc;
  --text: #142033;
  --muted: #667085;
  --line: #dfe4ec;
  --primary: #1d4ed8;
  --primary2: #2563eb;
  --primary-soft: #eff6ff;
  --primary-border: #93c5fd;
  --primary-glow: rgba(37, 99, 235, 0.13);
  --danger: #c53030;
  --danger-bg: #fff5f5;
  --danger-border: #fecaca;
  --solid: #172033;
  --solid-text: #fff;
  --overlay: rgba(255, 255, 255, 0.92);
  --shadow: 0 12px 32px rgba(20, 32, 51, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Pelak", Tahoma, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f141d;
    --bg-top: #151b27;
    --card: #1a2230;
    --surface: #222b3b;
    --text: #e8eef8;
    --muted: #9aa8bc;
    --line: #2d384a;
    --primary: #3b82f6;
    --primary2: #60a5fa;
    --primary-soft: #1e3a5f;
    --primary-border: #3b82f6;
    --primary-glow: rgba(96, 165, 250, 0.18);
    --danger: #f87171;
    --danger-bg: #3a1d22;
    --danger-border: #7f1d1d;
    --solid: #e8eef8;
    --solid-text: #101826;
    --overlay: rgba(15, 20, 29, 0.9);
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141d;
  --bg-top: #151b27;
  --card: #1a2230;
  --surface: #222b3b;
  --text: #e8eef8;
  --muted: #9aa8bc;
  --line: #2d384a;
  --primary: #3b82f6;
  --primary2: #60a5fa;
  --primary-soft: #1e3a5f;
  --primary-border: #3b82f6;
  --primary-glow: rgba(96, 165, 250, 0.18);
  --danger: #f87171;
  --danger-bg: #3a1d22;
  --danger-border: #7f1d1d;
  --solid: #e8eef8;
  --solid-text: #101826;
  --overlay: rgba(15, 20, 29, 0.9);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 100%);
  color: var(--text);
  font-family: var(--font);
  font-weight: 400;
}

button, textarea, input, label { font: inherit; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.topbar h1 { margin: 0 0 4px; font-size: 20px; }
.topbar p { margin: 0; color: var(--muted); font-size: 12px; }

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.icon-btn,
.header-upload {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  height: 40px;
  min-width: 42px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.language-btn { font-weight: 700; padding: 0 10px; }

.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.theme-btn svg {
  width: 18px;
  fill: currentColor;
  display: none;
}

.theme-btn[data-theme="light"] .icon-moon,
.theme-btn:not([data-theme]) .icon-moon { display: block; }
.theme-btn[data-theme="dark"] .icon-sun { display: block; }

.header-upload {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
}

.header-upload svg { width: 16px; fill: currentColor; }
.header-upload span { font-size: 12px; font-weight: 700; }

.auth-bar {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  padding: 10px;
}

.auth-guest,
.auth-user {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.auth-guest input {
  flex: 1;
  min-width: 120px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  padding: 10px;
}

.auth-user-label,
.auth-usage {
  font-size: 12px;
  color: var(--muted);
}

.auth-guest .secondary-btn,
.auth-guest .discard-btn,
.auth-user .danger-ghost {
  flex: 0 0 auto;
  padding: 10px 12px;
}

.tab-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.tab-nav.has-new { grid-template-columns: 1fr auto 1fr; }

.tab-btn {
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 10px 8px;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
}

.tab-new-btn {
  border: 0;
  border-radius: 999px;
  padding: 0 12px;
  background: linear-gradient(145deg, var(--primary2), var(--primary));
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.recorder-card,
.result-section,
.activities-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.recorder-card { text-align: center; }

.mic-wrap {
  height: 110px;
  display: grid;
  place-items: center;
  position: relative;
}

.mic-pulse {
  position: absolute;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--primary-glow);
}

.mic-button {
  width: 72px;
  height: 72px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--primary2), var(--primary));
  display: grid;
  place-items: center;
  position: relative;
  z-index: 1;
  cursor: pointer;
}

.mic-button svg { width: 30px; fill: #fff; display: none; }
.mic-button .icon-mic { display: block; }
.mic-button.recording { background: linear-gradient(145deg, #ef4444, #b91c1c); }
.mic-button.recording .icon-mic,
.mic-button.recording .icon-play { display: none; }
.mic-button.recording .icon-pause { display: block; }
.mic-button.paused { background: linear-gradient(145deg, #f59e0b, #d97706); }
.mic-button.paused .icon-mic,
.mic-button.paused .icon-pause { display: none; }
.mic-button.paused .icon-play { display: block; }

.visualizer {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.bar {
  width: 3px;
  min-height: 3px;
  border-radius: 3px;
  background: var(--primary2);
}

.timer { font-weight: 700; margin-top: 6px; }
.status { color: var(--muted); font-size: 13px; min-height: 18px; }

.actions-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  min-height: 0;
  align-items: center;
  justify-content: center;
  transition: margin 180ms ease;
}

.actions-row.has-actions {
  margin-top: 12px;
  min-height: 48px;
}

.action-pop {
  opacity: 0;
  transform: translateY(10px) scale(0.92);
  pointer-events: none;
  max-width: 0;
  max-height: 0;
  overflow: hidden;
  padding: 0;
  margin: 0;
  border-width: 0;
  transition:
    opacity 220ms ease,
    transform 220ms cubic-bezier(0.22, 1, 0.36, 1),
    max-width 220ms ease,
    max-height 220ms ease,
    padding 220ms ease,
    margin 220ms ease,
    border-width 220ms ease;
}

.action-pop.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  max-width: 320px;
  max-height: 56px;
  padding: 12px;
  border-width: 1px;
}

#stopButton.action-pop.is-visible {
  flex: 1;
  padding: 12px 14px;
}

.trash-btn {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 12px;
  border: 1px solid var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.trash-btn.is-visible {
  max-width: 48px;
  padding: 0;
}

.trash-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.upload-link {
  display: inline-flex;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.upload-link:hover { color: var(--primary); }

.secondary-btn,
.danger-ghost,
.discard-btn,
.ghost-btn {
  border-radius: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  cursor: pointer;
}

.secondary-btn {
  flex: 1;
  background: var(--solid);
  color: var(--solid-text);
  border-color: var(--solid);
  font-weight: 700;
}

.ghost-btn {
  background: var(--card);
  color: var(--text);
  font-weight: 700;
}

.discard-btn,
.danger-ghost {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger-border);
}

.discard-btn { flex: 0.7; }
.secondary-btn:disabled,
.discard-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.selected-file {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.result-section { position: relative; margin-top: 4px; }

.result-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  align-items: flex-start;
}

.result-title-wrap { display: flex; flex-direction: column; gap: 4px; }
.provider-badge { font-size: 10px; color: var(--muted); }

.mode-picker { position: relative; }

.mode-menu-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.mode-menu {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-end: 0;
  z-index: 8;
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mode-option {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: start;
  padding: 10px;
  cursor: pointer;
  font-size: 12px;
}

.mode-option.active {
  background: var(--primary);
  color: #fff;
}

textarea {
  width: 100%;
  min-height: 42vh;
  padding: 12px;
  resize: vertical;
  line-height: 1.8;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  direction: auto;
}

textarea.is-ltr { direction: ltr; text-align: left; }
textarea.is-rtl { direction: rtl; text-align: right; }

.source-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
}

.result-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.result-actions .secondary-btn,
.result-actions .danger-ghost { flex: 1; }

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  border-radius: 18px;
  background: var(--overlay);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.loading-wave {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 28px;
}

.loading-wave i {
  width: 4px;
  height: 10px;
  border-radius: 999px;
  background: var(--primary2);
  animation: wavePulse 1s ease-in-out infinite;
}

.loading-wave i:nth-child(2) { animation-delay: 0.1s; }
.loading-wave i:nth-child(3) { animation-delay: 0.2s; }
.loading-wave i:nth-child(4) { animation-delay: 0.3s; }
.loading-wave i:nth-child(5) { animation-delay: 0.4s; }

@keyframes wavePulse {
  0%, 100% { height: 8px; opacity: 0.45; }
  50% { height: 26px; opacity: 1; }
}

.loading-text { margin: 0; font-weight: 700; }

.activities-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.activities-head h2 { margin: 0 0 4px; font-size: 16px; }
.activities-count { margin: 0; color: var(--muted); font-size: 11px; }

.activities-search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 12px;
  margin-bottom: 12px;
}

.activities-empty {
  padding: 36px 12px;
  text-align: center;
  color: var(--muted);
}

.activities-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.activity-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 12px;
  cursor: pointer;
}

.activity-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 6px;
  align-items: center;
}

.activity-badge {
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 10px;
  font-weight: 700;
}

.activity-badge-soft {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 600;
}

.activity-mode-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.activity-time { color: var(--muted); font-size: 10px; }
.activity-preview { margin: 0; font-size: 12px; line-height: 1.7; }
.activity-delete {
  margin-inline-start: auto;
  border: 0;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
}

.app-footer {
  margin-top: auto;
  text-align: center;
  padding-top: 8px;
}

.app-footer a {
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
}

.toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: calc(14px + var(--safe-bottom));
  background: var(--solid);
  color: var(--solid-text);
  padding: 12px;
  border-radius: 12px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 0.2s;
  font-size: 12px;
  z-index: 120;
  max-width: 560px;
  margin: 0 auto;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.landing {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 24px 8px 40px;
  text-align: center;
}

.landing-brand {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--primary);
}

.landing h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.45;
}

.landing-copy {
  margin: 0 auto;
  max-width: 36ch;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

.landing-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.landing-actions .secondary-btn,
.landing-actions .ghost-btn {
  width: 100%;
}

.text-link {
  border: 0;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  padding: 8px 0;
  font-size: 13px;
  font-weight: 700;
  align-self: flex-start;
}

.auth-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.auth-tab {
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  padding: 10px;
  font-weight: 700;
  cursor: pointer;
}

.auth-tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-form label,
.profile-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.auth-form input,
.profile-field input {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 12px;
}

.auth-forgot { align-self: center; }
.auth-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
  text-align: center;
}

.turnstile-box {
  display: flex;
  justify-content: center;
  min-height: 65px;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 20, 29, 0.42);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
}

.sheet-card {
  width: min(560px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px 18px 14px 14px;
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: min(86dvh, 640px);
  overflow: auto;
  animation: sheetUp 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes sheetUp {
  from { transform: translateY(18px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 16px;
}

.sheet-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.chip-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  min-width: 48px;
  height: 36px;
  padding: 0 12px;
  font-weight: 700;
  cursor: pointer;
}

.profile-line {
  margin: 0;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.profile-line.muted { color: var(--muted); font-size: 12px; }

.profile-plan-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.profile-plan-row .profile-line {
  flex: 1;
  min-width: 0;
}

.upgrade-wrap {
  position: relative;
  flex-shrink: 0;
}

.upgrade-btn {
  height: 32px;
  min-width: 0;
  padding: 0 12px;
  font-size: 12px;
}

.upgrade-btn.is-pending,
.upgrade-btn:disabled {
  opacity: 0.75;
  cursor: default;
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary-border);
}

.upgrade-menu {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-end: 0;
  z-index: 5;
  min-width: 140px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.upgrade-option {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: start;
  padding: 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.upgrade-option:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 130;
  background: rgba(15, 20, 29, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.dialog-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.dialog-card h3 {
  margin: 0;
  font-size: 18px;
}

.dialog-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.dialog-card .secondary-btn {
  width: 100%;
}

.is-hidden { display: none !important; }
