:root {
  --bg: #faf7f2;
  --card: #fffdfa;
  --ink: #241f26;
  --muted: #7d7480;
  --line: #e7dfd6;
  --accent: #6c3fa8;
  --accent-ink: #fff;
  --ok: #2f7a55;
  --bad: #a8383f;
  --shadow: 0 1px 2px rgba(36, 31, 38, .05), 0 12px 32px -12px rgba(36, 31, 38, .16);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17151a;
    --card: #201d24;
    --ink: #f2eef4;
    --muted: #9b929f;
    --line: #332e38;
    --accent: #b79bea;
    --accent-ink: #1d1522;
    --ok: #6fd3a1;
    --bad: #f0989d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -12px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; margin: 0; }

body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.5 ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main { width: 100%; max-width: 440px; }

header { position: relative; text-align: center; margin-bottom: 24px; }
h1 { font-size: 34px; font-weight: 700; letter-spacing: -.02em; }

#lang {
  position: absolute;
  top: 0;
  right: 0;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
#lang:focus { outline: none; border-color: var(--accent); }
.sub { margin-top: 10px; color: var(--muted); font-size: 15px; text-wrap: balance; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px;
  box-shadow: var(--shadow);
}

/* idle: url form + file fallback */

#url-form { display: grid; gap: 10px; }

#url {
  width: 100%;
  padding: 15px 16px;
  border: 1.5px solid var(--line);
  border-radius: 13px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* keeps iOS Safari from zooming on focus */
}
#url::placeholder { color: var(--muted); }
#url:focus { outline: none; border-color: var(--accent); }

.or {
  margin: 16px 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.file-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px;
  border: 1.5px dashed var(--line);
  border-radius: 13px;
  color: var(--ink);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: border-color .18s ease, background .18s ease;
}
.file-fallback:hover, .file-fallback:focus-within {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 4%, transparent);
}

.zone-hint { margin-top: 10px; color: var(--muted); font-size: 13px; text-align: center; }

/* work */

.stage { font-weight: 600; text-align: center; }

.track {
  height: 7px;
  margin: 16px 0 12px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}

.bar {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .25s ease;
}

/* indeterminate: server work gives no real progress, so sweep a pill */
.track[data-mode="indeterminate"] .bar {
  width: 40%;
  transform: none;
  animation: sweep 1.1s ease-in-out infinite;
}
@keyframes sweep {
  0% { margin-left: -42%; }
  100% { margin-left: 102%; }
}

/* result */

#result { display: grid; gap: 10px; justify-items: center; }
.done { color: var(--ok); font-weight: 600; }
.oops { color: var(--bad); font-weight: 600; text-align: center; }
.out-name { font-weight: 600; word-break: break-all; text-align: center; }
.out-size { color: var(--muted); font-size: 14px; text-align: center; }
audio { width: 100%; margin: 6px 0; }

button {
  width: 100%;
  padding: 15px;
  border: 0;
  border-radius: 13px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s ease, transform .1s ease;
}
button:active { transform: scale(.985); }
button:hover { opacity: .92; }
.primary { background: var(--accent); color: var(--accent-ink); }
.ghost { background: transparent; color: var(--muted); }

#error { display: grid; gap: 10px; }

/* help */

.help {
  margin-top: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 14px;
  color: var(--muted);
}
.help summary { cursor: pointer; font-weight: 600; color: var(--ink); }
.help p { margin-top: 10px; }
.help b { color: var(--ink); }
.fine { font-size: 13px; opacity: .8; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
