/* ---------------- base ---------------- */
:root {
  --bg: #0b0d14;
  --card: #12151f;
  --card-2: #171b28;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e7e9f2;
  --muted: #8b90a5;
  --accent-1: #6366f1;
  --accent-2: #a855f7;
  --accent-3: #ec4899;
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.1);
  --warn: #fbbf24;
  --warn-bg: rgba(251, 191, 36, 0.09);
  --ok: #34d399;
  --radius: 16px;
}

* { box-sizing: border-box; }

/* Controls don't inherit the document font by default (UA stylesheets set
   their own) — normalize so buttons/inputs match the site typography. */
button, input, select, textarea { font: inherit; letter-spacing: inherit; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* soft glow backdrop */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(600px 360px at 18% -8%, rgba(99, 102, 241, 0.20), transparent 65%),
    radial-gradient(700px 420px at 88% 12%, rgba(236, 72, 153, 0.13), transparent 65%),
    radial-gradient(500px 400px at 50% 110%, rgba(168, 85, 247, 0.10), transparent 65%),
    var(--bg);
}

/* ---------------- header ---------------- */
.top {
  position: relative;
  text-align: center;
  padding: 44px 20px 8px;
  max-width: 640px;
  width: 100%;
}

/* user box (top-right) */
#user-box {
  position: absolute;
  top: 12px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.ub-name { font-weight: 700; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.badge.admin { color: var(--warn); border-color: rgba(251, 191, 36, 0.35); background: var(--warn-bg); }

.credits-chip {
  background: rgba(52, 211, 153, 0.12);
  color: var(--ok);
  border: 1px solid rgba(52, 211, 153, 0.3);
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.ub-btn {
  font: inherit;
  font-size: 12.5px;
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  transition: border-color .15s;
}
.ub-btn:hover { border-color: var(--accent-1); }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo {
  display: inline-flex;
  filter: drop-shadow(0 4px 14px rgba(168, 85, 247, 0.45));
}

.tagline {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.warnings { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }

.warn-chip {
  display: flex;
  gap: 8px;
  align-items: baseline;
  text-align: left;
  font-size: 13px;
  background: var(--warn-bg);
  border: 1px solid rgba(251, 191, 36, 0.25);
  color: var(--warn);
  padding: 9px 13px;
  border-radius: 10px;
}

/* ---------------- card & tabs ---------------- */
main { width: 100%; max-width: 640px; padding: 20px 16px 8px; }

.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0)) , var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 5px;
  margin-bottom: 18px;
}

.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 6px;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  transition: color .15s, background .15s;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--text);
  background: linear-gradient(135deg, rgba(99,102,241,.22), rgba(236,72,153,.18));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.09);
}

/* ---------------- dropzone ---------------- */
.dropzone {
  border: 1.5px dashed rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  padding: 34px 18px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .15s;
  outline: none;
}

.dropzone:hover, .dropzone:focus-visible { border-color: rgba(255,255,255,.34); background: rgba(255,255,255,.02); }

.dropzone.dragover {
  border-color: var(--accent-1);
  background: rgba(99, 102, 241, 0.08);
  transform: scale(1.01);
}

.dz-icon { color: var(--muted); margin-bottom: 10px; }
.dropzone.dragover .dz-icon { color: var(--accent-1); }

.dz-title { margin: 0; font-size: 15px; font-weight: 600; }
.linkish { color: var(--accent-2); }

.dz-hint { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }

.file-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
}

.file-chip .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .size { color: var(--muted); font-variant-numeric: tabular-nums; }

.file-chip .remove {
  border: 0; background: transparent; color: var(--muted);
  font-size: 16px; cursor: pointer; padding: 0 4px; line-height: 1;
}
.file-chip .remove:hover { color: var(--danger); }

/* ---------------- url mode ---------------- */
.field-label { display: block; font-size: 13.5px; font-weight: 600; margin: 2px 2px 8px; }

.url-row { position: relative; }

.url-icon {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}

#ig-url,
#yt-url,
#any-url {
  width: 100%;
  padding: 12px 14px 12px 40px;
  font-size: 14.5px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

#ig-url::placeholder,
#yt-url::placeholder,
#any-url::placeholder { color: #565b70; }

#ig-url:focus,
#yt-url:focus,
#any-url:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.22);
}

.field-hint { margin: 8px 2px 0; font-size: 12.5px; color: var(--muted); }

/* ---------------- youtube format picker ---------------- */
.dl-seg-label { margin-top: 14px; }

.seg {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.seg-btn {
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  transition: color .15s, background .15s;
}

.seg-btn:hover:enabled { color: var(--text); }

.seg-btn.active {
  color: var(--text);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.22), rgba(236, 72, 153, 0.18));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.09);
}

.seg-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------------- record mode ---------------- */
.rec-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 14px 0 4px;
}

.rec-btn {
  position: relative;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  background: var(--card-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .12s, border-color .15s, background .15s;
}

/* level-driven ring around the rec button (JS scales it while recording) */
.rec-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 2px solid rgba(248, 113, 113, 0.6);
  transform: translate(-50%, -50%) scale(1);
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
}

.rec-btn:hover:not(:disabled) { transform: scale(1.05); border-color: rgba(255, 255, 255, 0.4); }
.rec-btn:disabled { opacity: .4; cursor: not-allowed; }

.rec-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f87171, #ef4444);
  transition: width .18s, height .18s, border-radius .18s;
}

.rec-btn.recording {
  border-color: rgba(248, 113, 113, 0.7);
  background: rgba(248, 113, 113, 0.12);
  animation: rec-pulse 1.6s ease-out infinite;
}

.rec-btn.recording .rec-dot { width: 26px; height: 26px; border-radius: 7px; }

@keyframes rec-pulse {
  0% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.45); }
  100% { box-shadow: 0 0 0 22px rgba(248, 113, 113, 0); }
}

.rec-readout { display: flex; align-items: center; gap: 16px; }

.rec-timer {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}

/* mic-driven variant: heights are set from JS, so no CSS animation */
.rec-eq span { animation: none; height: 5px; background: linear-gradient(180deg, #f87171, var(--accent-1)); }

.rec-status { margin: 0; color: var(--muted); font-size: 13.5px; text-align: center; }

#rec-preview { width: 100%; margin-top: 14px; }

.btn.ghost {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}

.btn.ghost:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.25); }

/* ---------------- button ---------------- */
.btn.primary {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2) 55%, var(--accent-3));
  border: 0;
  border-radius: 11px;
  cursor: pointer;
  transition: transform .12s, box-shadow .15s, opacity .15s;
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.35);
}

.btn.primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 12px 30px rgba(139, 92, 246, 0.45); }
.btn.primary:active:not(:disabled) { transform: translateY(0); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

/* ---------------- status / loading ---------------- */
#status { min-height: 0; }

.status-box {
  margin-top: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  color: var(--muted);
  font-size: 14px;
}

.error-box {
  margin-top: 18px;
  background: var(--danger-bg);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--danger);
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* equalizer */
.eq { display: inline-flex; align-items: flex-end; gap: 3px; height: 22px; }
.eq span {
  width: 4px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent-1));
  animation: bounce 1s ease-in-out infinite;
}
.eq span:nth-child(2) { animation-delay: .15s; }
.eq span:nth-child(3) { animation-delay: .3s; }
.eq span:nth-child(4) { animation-delay: .45s; }
.eq span:nth-child(5) { animation-delay: .6s; }

@keyframes bounce {
  0%, 100% { height: 6px; }
  50% { height: 22px; }
}

/* ---------------- result ---------------- */
.result-box {
  margin-top: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  animation: rise .35s ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-head {
  display: flex;
  gap: 16px;
  padding: 20px;
  background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,0));
}

.result-head .right { flex: 1; min-width: 0; }

td.empty { color: var(--muted); text-align: center; padding: 14px 0; }

.cover {
  width: 96px;
  height: 96px;
  flex: none;
  border-radius: 12px;
  object-fit: cover;
  background: var(--card-2);
  border: 1px solid var(--line);
}

.cover.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-3));
}

.result-title { margin: 2px 0 2px; font-size: 21px; font-weight: 700; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.result-artists { margin: 0; font-size: 15px; color: var(--accent-2); font-weight: 600; }

.match-note { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); font-style: italic; }

.meter-wrap { margin-top: 12px; }
.meter-label { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.meter { height: 6px; background: rgba(255,255,255,.07); border-radius: 4px; overflow: hidden; }
.meter i {
  display: block; height: 100%; border-radius: 4px;
  background: linear-gradient(90deg, var(--accent-1), var(--accent-3));
}

.result-body { padding: 4px 20px 20px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.chips li {
  font-size: 12.5px;
  color: var(--muted);
  background: var(--card-2);
  border: 1px solid var(--line);
  padding: 5px 11px;
  border-radius: 999px;
}
.chips li b { color: var(--text); font-weight: 600; }

.links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.links a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  background: var(--card-2);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 9px;
  transition: border-color .15s, background .15s;
}
.links a:hover { border-color: var(--accent-1); background: rgba(99, 102, 241, 0.12); }

.links a svg { color: var(--muted); }

.acrid {
  margin-top: 14px;
  font-size: 11.5px;
  color: #565b70;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

/* no-match */
.nomatch { text-align: center; padding: 30px 20px; }
.nomatch .big { font-size: 34px; }
.nomatch h3 { margin: 10px 0 6px; font-size: 17px; }
.nomatch p { margin: 0 auto; max-width: 420px; color: var(--muted); font-size: 14px; }
.nomatch ul { margin: 14px auto 0; max-width: 420px; text-align: left; color: var(--muted); font-size: 13px; padding-left: 20px; }

/* youtube download result */
.dl-done { text-align: center; padding: 28px 20px; }
.dl-done .big { font-size: 34px; }
.dl-done h3 { margin: 10px 0 4px; font-size: 17px; }
.dl-name {
  margin: 0 auto;
  max-width: 480px;
  font-weight: 600;
  font-size: 14px;
  overflow-wrap: anywhere;
}
.dl-meta { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.dl-btn { display: block; margin-top: 18px; text-decoration: none; }
.dl-copy { overflow-wrap: anywhere; font-size: 12px; }

details.raw { margin-top: 16px; }
details.raw summary { cursor: pointer; font-size: 12.5px; color: var(--muted); }
details.raw pre {
  margin: 10px 0 0;
  max-height: 260px;
  overflow: auto;
  font-size: 11.5px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  color: #a5abc4;
}

/* ---------------- login ---------------- */
.login-card { max-width: 380px; margin: 0 auto; }

.login-title { margin: 4px 0 6px; font-size: 19px; text-align: center; }

.input {
  width: 100%;
  padding: 12px 14px;
  font-size: 14.5px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.input:focus { border-color: var(--accent-1); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.22); }

.error-text { color: var(--danger); font-size: 13.5px; margin: 12px 0 0; }

/* ---------------- admin ---------------- */
#view-admin .card { margin-top: 14px; }

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

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

.admin-form {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 110px auto;
  gap: 8px;
  margin-top: 12px;
}

.admin-form .btn.primary { margin-top: 0; width: auto; }

.admin-msg { font-size: 13px; color: var(--muted); margin: 10px 0 0; min-height: 1.2em; }
.admin-msg.err { color: var(--danger); }
.admin-msg.ok { color: var(--ok); }

.tbl-wrap { overflow-x: auto; margin-top: 12px; }

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }

.tbl th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.tbl td {
  padding: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  vertical-align: top;
}

.tbl tr:last-child td { border-bottom: 0; }

.tbl .nowrap { white-space: nowrap; }
.tbl td.src { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.you { color: var(--muted); font-size: 11.5px; }
.credits-cell { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ok); }
.nomatch-txt { color: var(--muted); }

.mini-btn {
  font: inherit;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  cursor: pointer;
  margin: 1px 4px 1px 0;
  transition: border-color .15s;
}

.mini-btn:hover { border-color: var(--accent-1); }
.mini-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.select { width: auto; padding: 6px 10px; font-size: 13px; }

/* ---------------- footer ---------------- */
footer {
  margin: 26px 0 30px;
  color: #565b70;
  font-size: 12.5px;
  text-align: center;
}
footer a { color: var(--muted); text-decoration: none; border-bottom: 1px dotted #565b70; }
footer a:hover { color: var(--text); }

.noscript-msg { text-align: center; color: var(--warn); padding: 12px; }

/* ---------------- responsive / a11y ---------------- */
@media (max-width: 480px) {
  .top { padding-top: 30px; }
  #user-box { position: static; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
  .tab { font-size: 10.5px; gap: 3px; padding: 9px 1px; }
  .admin-form { grid-template-columns: 1fr 1fr; }
  .admin-form .btn.primary { grid-column: 1 / -1; }
  .result-head { flex-direction: column; align-items: center; text-align: center; }
  .result-head .right { width: 100%; }
  .chips { justify-content: center; }
  .links { justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
