:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #eef4f8;
  --text: #17202a;
  --muted: #647284;
  --line: #d8e1ea;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --blue: #2563eb;
  --danger: #b42318;
  --warning: #a15c07;
  --shadow: 0 18px 45px rgba(23, 32, 42, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  background: var(--text);
  color: #ffffff;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  filter: brightness(0.96);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

button.primary {
  background: var(--accent);
}

button.ghost {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
}

.shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 32px 18px 48px;
}

.hidden {
  display: none !important;
}

.auth-panel,
.download-panel,
.channel-panel,
.jobs-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-panel {
  width: min(560px, 100%);
  margin: 12vh auto 0;
  padding: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand.compact h1 {
  font-size: 24px;
}

.mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.05;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
}

.brand p,
.video-details p,
.section-heading span,
.message,
.job-meta {
  color: var(--muted);
}

.login-form,
.link-form {
  display: grid;
  gap: 10px;
  margin-top: 26px;
}

label,
legend {
  color: var(--text);
  font-weight: 700;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.14);
}

.message {
  min-height: 22px;
  font-size: 14px;
}

.message.error {
  color: var(--danger);
}

.message.success {
  color: var(--accent-strong);
}

.app {
  display: grid;
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.download-panel,
.channel-panel,
.jobs-panel {
  padding: 22px;
}

.video-result {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 16px;
  align-items: center;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.thumbnail {
  width: 180px;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  object-fit: cover;
  background: var(--panel-soft);
}

.video-details {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.video-details h2 {
  overflow-wrap: anywhere;
}

.controls {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(180px, 240px) auto;
  gap: 14px;
  align-items: end;
  margin-top: 20px;
}

.format-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.format-control legend {
  grid-column: 1 / -1;
  margin-bottom: 2px;
}

.segment {
  display: block;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
}

.segment input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.segment span {
  display: grid;
  min-height: 42px;
  place-items: center;
  padding: 0 10px;
  border-radius: 7px;
}

.segment input:checked + span {
  background: #e7f6f2;
  color: var(--accent-strong);
}

.segment:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.14);
}

.select-field {
  display: grid;
  gap: 7px;
}

.channel-result {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.channel-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.channel-summary h3 {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.25;
}

.channel-actions {
  display: flex;
  gap: 8px;
}

.batch-controls {
  margin-top: 16px;
}

.channel-list {
  display: grid;
  gap: 10px;
  max-height: 620px;
  margin-top: 16px;
  overflow: auto;
  padding-right: 4px;
}

.channel-video {
  display: grid;
  grid-template-columns: auto 132px 1fr;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
  cursor: pointer;
}

.channel-video.unavailable {
  opacity: 0.58;
  cursor: not-allowed;
}

.channel-video input {
  width: 18px;
  min-height: 18px;
}

.channel-thumb {
  width: 132px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 8px;
  background: var(--panel-soft);
}

.channel-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.channel-video-main {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.channel-video-title {
  overflow-wrap: anywhere;
}

.channel-video-meta {
  color: var(--muted);
  font-size: 14px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.jobs-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.job {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
}

.job-title {
  min-width: 0;
}

.job-title strong {
  display: block;
  overflow-wrap: anywhere;
}

.job-meta {
  margin-top: 5px;
  font-size: 14px;
}

.job-action {
  display: flex;
  align-items: center;
}

.download-link {
  display: inline-grid;
  min-height: 40px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  padding: 0 14px;
  text-decoration: none;
}

.progress {
  grid-column: 1 / -1;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6edf3;
}

.progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
  transition: width 180ms ease;
}

.status-failed .progress span {
  background: var(--danger);
}

.status-done .progress span {
  background: var(--accent);
}

.status-queued .progress span {
  background: var(--warning);
}

@media (max-width: 760px) {
  .shell {
    padding: 18px 12px 36px;
  }

  .auth-panel,
  .download-panel,
  .channel-panel,
  .jobs-panel {
    padding: 18px;
  }

  .topbar,
  .input-row,
  .video-result,
  .controls,
  .channel-summary,
  .channel-video,
  .job {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .thumbnail {
    width: 100%;
  }

  .channel-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .channel-thumb {
    width: 100%;
  }

  .job-action {
    justify-content: stretch;
  }

  .download-link,
  button {
    width: 100%;
  }
}
