:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6eb;
  --text: #1a1d23;
  --muted: #687080;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #c2341d;
  --track: #e8ebf0;
  --radius: 10px;
  --shadow: 0 8px 28px rgb(16 24 40 / 0.16);
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%23687080' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1 1.5 5 5 5-5'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --border: #2b2f38;
    --text: #e8eaee;
    --muted: #99a0ad;
    --accent: #4f8cff;
    --accent-text: #0b0d10;
    --danger: #ff7a66;
    --track: #2b2f38;
    --shadow: 0 8px 28px rgb(0 0 0 / 0.55);
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%2399a0ad' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1 1.5 5 5 5-5'/%3E%3C/svg%3E");
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 48px 16px;
}

h1 {
  margin: 0 0 24px;
  font-size: 1.6rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

input,
select {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--surface);
  color: inherit;
  font: inherit;
}

/* Narrow enough to keep the button beside it on a phone. */
input {
  flex: 1 1 180px;
  padding: 12px 14px;
}

input:focus,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* appearance: none takes the native arrow with it, so it comes back as an image. */
select {
  padding: 10px 36px 10px 12px;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px;
  text-overflow: ellipsis;
  appearance: none;
  cursor: pointer;
}

.media {
  display: grid;
  gap: 12px;
  margin: 16px 0 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.media select {
  background-color: var(--bg);
}

.source {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.source img {
  flex: none;
  width: 112px;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  background: var(--track);
  object-fit: cover;
}

.about {
  min-width: 0;
}

.media-title {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  font-weight: 600;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.meta {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.pick {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

/* A row of its own: its labels carry resolution, codec and size. */
.pick #video-resolution {
  grid-column: 1 / -1;
}

.pick button {
  min-width: 132px;
}

.formats {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

button,
.download {
  flex: 1 1 0;
  padding: 12px 20px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

form button {
  flex: none;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

.message {
  margin: 12px 0 0;
  color: var(--danger);
}

.hint {
  margin: 32px 0 0;
  color: var(--muted);
  text-align: center;
}

.jobs {
  margin: 32px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 12px;
}

.job {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mode {
  flex: none;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--track);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 550;
}

.status {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.job[data-state="failed"] .status {
  color: var(--danger);
}

.job .download,
.job .remove {
  flex: none;
  padding: 6px 14px;
  font-size: 0.9rem;
}

.job .remove {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

.bar {
  height: 6px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.4s ease;
}

.bar.indeterminate > span {
  width: 30%;
  animation: slide 1.2s ease-in-out infinite;
}

@keyframes slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(340%); }
}

/* Floats above the page until answered; see install.js. */
.install {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 16px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px 14px;
  max-width: 608px;
  margin: 0 auto;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.install img {
  border-radius: 10px;
}

.install-title {
  margin: 0;
  font-weight: 600;
}

.install-hint {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.install-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.install-actions button {
  flex: 1 1 auto;
  padding: 10px 16px;
}

button.quiet {
  border-color: var(--border);
  background: transparent;
  color: var(--text);
}

[hidden] {
  display: none !important;
}

@media (max-width: 480px) {
  main {
    padding-top: 24px;
  }

  .pick {
    grid-template-columns: minmax(0, 1fr);
  }

  .job .line:last-child {
    flex-wrap: wrap;
  }

  .job .status {
    flex-basis: 100%;
  }
}
