:root {
  --bg: #0e1116;
  --card: #171b22;
  --line: #232936;
  --text: #e6e9ef;
  --dim: #8a93a6;
  --accent: #5b9dff;
  --accent-soft: rgba(91, 157, 255, 0.16);
  --error: #ff6b6b;
  --radius: 14px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", system-ui, sans-serif;
  -webkit-tap-highlight-color: rgba(91, 157, 255, 0.2);
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
  /* Respect notches/safe areas (viewport-fit=cover). */
  padding: clamp(20px, 5vw, 40px) clamp(14px, 4vw, 20px) 60px;
  padding-left: max(clamp(14px, 4vw, 20px), env(safe-area-inset-left));
  padding-right: max(clamp(14px, 4vw, 20px), env(safe-area-inset-right));
}

header h1 {
  margin: 0 0 6px;
  font-size: clamp(21px, 5.5vw, 26px);
  letter-spacing: 0.3px;
}
header .dim { font-weight: 400; font-size: clamp(14px, 4vw, 16px); }
.dim { color: var(--dim); }
.small { font-size: 13px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(16px, 4vw, 22px);
  margin-top: 20px;
}

.field { display: block; margin-bottom: 16px; }
.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--dim);
}
.field small { font-size: 11px; }

input[type="text"],
input[type="password"],
input[type="file"],
select,
textarea {
  width: 100%;
  /* 16px keeps iOS Safari from auto-zooming the page on focus. */
  font-size: 16px;
  padding: 12px;
  min-height: 44px; /* comfortable touch target */
  background: #0f131a;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 132px; line-height: 1.6; }

.row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.row .field { margin-bottom: 16px; }
@media (max-width: 720px) { .row { grid-template-columns: 1fr 1fr; } }
@media (max-width: 460px) { .row { grid-template-columns: 1fr; gap: 0; } }

button, .ghost-btn {
  cursor: pointer;
  font: inherit;
  font-size: 16px;
  border-radius: 10px;
  padding: 13px 18px;
  min-height: 48px;
  border: 1px solid transparent;
  -webkit-appearance: none;
  appearance: none;
}
#submit-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--accent);
  color: #06122b;
  font-weight: 600;
  border: none;
  transition: opacity 0.15s, filter 0.15s;
}
#submit-btn:not(:disabled):active { filter: brightness(0.92); }
#submit-btn:disabled { opacity: 0.65; cursor: progress; }

/* Button spinner — only visible while .loading. */
.btn-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(6, 18, 43, 0.35);
  border-top-color: #06122b;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
#submit-btn.loading .btn-spinner { display: inline-block; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ghost-btn:hover { border-color: var(--accent); }
.ghost-btn:active { background: rgba(255, 255, 255, 0.04); }
.primary-ghost { border-color: var(--accent); color: var(--accent); }

.hidden { display: none !important; }

/* progress */
.stage-head { display: flex; align-items: center; gap: 10px; }
#stage-label { margin: 0; font-size: 16px; font-weight: 600; }
.spinner {
  flex: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.bar {
  position: relative;
  height: 8px;
  background: #0f131a;
  border-radius: 999px;
  overflow: hidden;
  margin: 16px 0 10px;
}
#bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s ease;
}
/* Indeterminate: a sweeping highlight while we have no real % yet. */
.bar.indeterminate #bar-fill {
  width: 100% !important;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--accent) 50%,
    transparent 100%
  );
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: sweep 1.1s ease-in-out infinite;
}
@keyframes sweep {
  0% { background-position: -40% 0; }
  100% { background-position: 140% 0; }
}

/* player */
#audio-el { width: 100%; margin-bottom: 14px; }
.player-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.player-actions .ghost-btn { flex: 1 1 auto; }

.lyrics-view {
  max-height: min(56vh, 460px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 2px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.lyric-row {
  padding: 11px 12px;
  margin: 2px 0;
  border-radius: 8px;
  color: var(--dim);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.lyric-row:hover { color: var(--text); }
.lyric-row.active {
  color: var(--text);
  background: var(--accent-soft);
  font-weight: 600;
}

.error {
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid var(--error);
  border-radius: 10px;
  color: var(--error);
  white-space: pre-wrap;
}

@media (prefers-reduced-motion: reduce) {
  .spinner, .btn-spinner, .bar.indeterminate #bar-fill { animation: none; }
  .lyrics-view, .lyric-row, #bar-fill { transition: none; scroll-behavior: auto; }
}
