:root {
  color-scheme: light;
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --line: #dde3e1;
  --line-strong: #cbd4d1;
  --ink: #18201e;
  --muted: #66716e;
  --muted-light: #8c9693;
  --green: #12684f;
  --green-dark: #0d4e3b;
  --green-soft: #e7f2ee;
  --amber: #a86813;
  --amber-soft: #fff5e3;
  --danger: #b33c36;
  --danger-soft: #fcebea;
  --shadow: 0 14px 38px rgba(25, 44, 38, 0.08);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(24, 32, 30, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(24, 32, 30, 0.025) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
}

button, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid rgba(18, 104, 79, 0.2);
  outline-offset: 2px;
}

.app-shell { min-height: 100vh; }

.topbar {
  height: 64px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 19px;
  font-weight: 750;
  text-decoration: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--green);
  border-radius: 7px;
}

.brand-mark svg, button svg, .input-icon svg, .usage-note svg, .empty-visual svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.brand-mark svg { width: 20px; height: 20px; }

.service-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.state-dot {
  width: 8px;
  height: 8px;
  background: #22a36f;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(34, 163, 111, 0.12);
}

.workspace {
  width: min(1180px, calc(100% - 48px));
  margin: 40px auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 24px;
  align-items: start;
}

.parser-panel, .history-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.parser-panel { padding: 34px; }
.history-panel { padding: 24px; position: sticky; top: 88px; }

.intro-row, .section-heading, .history-header, .form-footer, .stream-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.download-progress {
  margin: 0 0 18px;
  padding: 14px 14px 12px;
  border: 1px solid #c5ddd3;
  border-radius: 6px;
  background: linear-gradient(180deg, #f7fcf9 0%, #f2f8f5 100%);
}
.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.progress-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(18, 104, 79, .35);
  animation: progress-pulse 1.4s ease-in-out infinite;
}
.download-progress.is-done .progress-dot {
  background: #1f8f62;
  animation: none;
}
.download-progress.is-error .progress-dot {
  background: var(--danger);
  animation: none;
}
.progress-title-wrap strong {
  font-size: 13px;
  font-weight: 720;
  color: var(--ink);
}
.progress-percent {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 760;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}
.progress-track {
  height: 10px;
  border-radius: 999px;
  background: #d9e8e1;
  overflow: hidden;
}
.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1b7a58 0%, #2ea36f 55%, #49b981 100%);
  transition: width .25s ease;
  position: relative;
}
.progress-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent);
  transform: translateX(-100%);
  animation: progress-sheen 1.4s linear infinite;
}
.download-progress.is-done .progress-fill::after,
.download-progress.is-error .progress-fill::after {
  display: none;
}
.progress-meta {
  margin-top: 9px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}
.progress-meta span:last-child {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}
.download-button[disabled],
.download-button.is-busy {
  opacity: .65;
  pointer-events: none;
}
@keyframes progress-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(18, 104, 79, .28); }
  50% { box-shadow: 0 0 0 6px rgba(18, 104, 79, 0); }
}
@keyframes progress-sheen {
  100% { transform: translateX(100%); }
}

.stream-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow, .section-kicker {
  margin: 0 0 7px;
  color: var(--green);
  font-size: 11px;
  font-weight: 750;
  line-height: 1;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(28px, 4vw, 38px); line-height: 1.2; letter-spacing: 0; }
.subtitle { margin: 10px 0 0; color: var(--muted); font-size: 15px; line-height: 1.65; }
.platforms { display: flex; flex-shrink: 0; }

.platform-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  margin-left: -7px;
  border: 3px solid white;
  border-radius: 50%;
  color: white;
  font-size: 12px;
  font-weight: 750;
}
.platform-icon:first-child { margin-left: 0; }
.platform-icon.bili { background: #e7587c; }
.platform-icon.douyin { background: #1e2322; }
.platform-icon.kuaishou { background: #f08327; }

.parse-form {
  margin-top: 30px;
  padding: 22px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.parse-form > label { display: block; margin-bottom: 9px; font-size: 13px; font-weight: 700; }
.input-shell { position: relative; }
.input-shell:focus-within .input-icon { color: var(--green); }

.input-icon {
  position: absolute;
  top: 16px;
  left: 15px;
  color: var(--muted-light);
  pointer-events: none;
}
.input-icon svg { width: 20px; height: 20px; }

textarea {
  width: 100%;
  min-height: 102px;
  padding: 14px 46px 14px 47px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink);
  background: white;
  font-size: 14px;
  line-height: 1.65;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
textarea::placeholder { color: #9aa3a0; }
textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(18, 104, 79, 0.09); }

.clear-button {
  position: absolute;
  top: 11px;
  right: 11px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.clear-button:hover { color: var(--ink); background: #eef1f0; }
.clear-button svg { width: 17px; height: 17px; }

.form-footer { margin-top: 14px; }
.detector { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.detector-dot { width: 7px; height: 7px; border-radius: 50%; background: #a7b0ad; }
.detector.detected { color: var(--green); }
.detector.detected .detector-dot { background: var(--green); }
.detector.unsupported { color: var(--danger); }
.detector.unsupported .detector-dot { background: var(--danger); }

.primary-button, .download-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--green-dark);
  border-radius: 6px;
  color: white;
  background: var(--green);
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: background 160ms ease, transform 160ms ease;
}
.primary-button { min-width: 130px; padding: 0 18px; }
.primary-button:hover, .download-button:hover { background: var(--green-dark); }
.primary-button:active, .download-button:active { transform: translateY(1px); }
.primary-button:disabled { opacity: .7; cursor: wait; }
.primary-button svg, .download-button svg { width: 18px; height: 18px; }
.primary-button.loading svg { animation: spin 900ms linear infinite; }

.status-card {
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid #f0d0cd;
  border-radius: 6px;
  color: var(--danger);
  background: var(--danger-soft);
  font-size: 14px;
  line-height: 1.55;
}
.status-card.loading { color: var(--green); border-color: #cde1d9; background: var(--green-soft); }

.result { margin-top: 34px; border-top: 1px solid var(--line); padding-top: 30px; }
.section-heading h2, .history-header h2 { margin: 0; font-size: 20px; line-height: 1.2; letter-spacing: 0; }
.history-header h2 { font-size: 18px; }

.icon-button {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: white;
  cursor: pointer;
}
.icon-button:hover { color: var(--green); border-color: #b8cdc5; background: var(--green-soft); }
.icon-button svg { width: 17px; height: 17px; }

.video-summary {
  margin: 18px 0 24px;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 20px;
}

.cover-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 6px;
  background: #e6ebe9;
}
.cover-wrap img { width: 100%; height: 100%; display: block; object-fit: cover; }
.duration, .platform-badge {
  position: absolute;
  bottom: 8px;
  padding: 3px 7px;
  border-radius: 4px;
  color: white;
  background: rgba(13, 20, 18, .82);
  font-size: 11px;
  font-weight: 700;
}
.duration { right: 8px; }
.platform-badge { left: 8px; }
.video-copy { min-width: 0; padding: 3px 0; }
.video-copy h3 { margin: 0; font-size: 18px; line-height: 1.5; letter-spacing: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.author { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.stats { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.stat-item { padding: 5px 8px; border-radius: 4px; color: var(--muted); background: #f0f3f2; font-size: 12px; }
.result-note { margin: 12px 0 0; color: var(--amber); font-size: 12px; line-height: 1.55; }

.stream-toolbar { margin-bottom: 11px; }
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.segment {
  min-height: 30px;
  padding: 0 11px;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}
.segment.active { color: var(--green); background: white; box-shadow: 0 1px 3px rgba(25, 44, 38, .12); }
.expiry { color: var(--muted-light); font-size: 11px; }

.stream-list { display: grid; gap: 8px; }
.stream-item {
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}
.stream-item:first-child { border-color: #a9c9bd; background: #fbfdfc; }
.stream-main { min-width: 0; display: flex; align-items: center; gap: 12px; }
.stream-symbol { width: 36px; height: 36px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 6px; color: var(--green); background: var(--green-soft); }
.stream-symbol svg { width: 18px; height: 18px; }
.stream-name { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; font-size: 14px; font-weight: 720; }
.best-badge { padding: 2px 5px; border-radius: 3px; color: var(--green); background: var(--green-soft); font-size: 10px; font-weight: 750; }
.stream-meta { margin-top: 5px; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.download-button { min-width: 94px; min-height: 38px; padding: 0 12px; font-size: 13px; }

.history-list { margin-top: 18px; display: grid; gap: 8px; }
.history-item {
  width: 100%;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 18px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  text-align: left;
  background: transparent;
  cursor: pointer;
}
.history-item:hover { border-color: var(--line); background: var(--surface-soft); }
.history-platform { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; color: white; font-size: 11px; font-weight: 750; }
.history-platform.bilibili { background: #db5678; }
.history-platform.douyin { background: #242827; }
.history-platform.kuaishou { background: #e9771e; }
.history-copy { min-width: 0; }
.history-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 700; }
.history-time { margin-top: 4px; color: var(--muted-light); font-size: 10px; }
.history-arrow { color: var(--muted-light); }
.history-arrow svg { width: 15px; height: 15px; }

.history-empty { min-height: 190px; display: grid; place-content: center; justify-items: center; text-align: center; }
.empty-visual { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 50%; color: #84918d; background: #eef2f0; }
.empty-visual svg { width: 24px; height: 24px; }
.history-empty p { margin: 13px 0 4px; font-size: 13px; font-weight: 680; }
.history-empty > span:last-child { color: var(--muted-light); font-size: 11px; }

.usage-note { margin-top: 18px; padding-top: 17px; display: grid; grid-template-columns: 17px 1fr; gap: 9px; border-top: 1px solid var(--line); color: var(--muted); }
.usage-note svg { width: 16px; height: 16px; margin-top: 2px; }
.usage-note p { margin: 0; font-size: 11px; line-height: 1.6; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border-radius: 6px;
  color: white;
  background: #17221f;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

[hidden] { display: none !important; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .history-panel { position: static; }
}

@media (max-width: 620px) {
  .topbar { height: 58px; padding: 0 16px; }
  .service-state span:last-child { display: none; }
  .workspace { width: calc(100% - 24px); margin: 18px auto 28px; gap: 14px; }
  .parser-panel { padding: 22px 16px; }
  .history-panel { padding: 20px 16px; }
  .intro-row { align-items: flex-start; }
  h1 { font-size: 27px; }
  .subtitle { font-size: 13px; }
  .platforms { display: none; }
  .parse-form { margin-top: 22px; padding: 14px; }
  .form-footer { align-items: stretch; flex-direction: column; gap: 12px; }
  .primary-button { width: 100%; }
  .video-summary { grid-template-columns: 1fr; }
  .cover-wrap { width: 100%; }
  .stream-toolbar { align-items: flex-start; flex-direction: column; gap: 9px; }
  .segmented { max-width: 100%; overflow-x: auto; }
  .stream-item { grid-template-columns: 1fr; }
  .download-button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
