:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --surface: #ffffff;
  --surface-soft: #fbfaf6;
  --ink: #20231f;
  --muted: #6d7268;
  --faint: #9a9f94;
  --line: #e6e3d8;
  --sun: #f5a800;
  --sun-deep: #d98e00;
  --sun-soft: #fff4d9;
  --grass: #2f9e44;
  --danger: #d64545;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(40, 36, 16, 0.05), 0 4px 14px rgba(40, 36, 16, 0.06);
  --shadow-lift: 0 2px 4px rgba(40, 36, 16, 0.07), 0 10px 28px rgba(40, 36, 16, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Manrope", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  background:
    radial-gradient(900px 320px at 85% -80px, rgba(245, 168, 0, 0.14), transparent 70%),
    radial-gradient(700px 280px at 8% -60px, rgba(245, 168, 0, 0.08), transparent 70%),
    var(--bg);
  background-attachment: fixed;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button,
select {
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Top bar ---------- */

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

.brand {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  text-decoration: none;
  color: var(--ink);
}

.brand-mark {
  display: inline-flex;
  width: 26px;
}

.brand-mark svg {
  width: 100%;
  fill: var(--sun);
}

.brand-mark .play {
  fill: #fff;
}

.brand-name {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.status-pill {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--grass);
}

.user-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border: 1px solid var(--sun);
  border-radius: 999px;
  background: var(--sun-soft);
  color: var(--sun-deep);
  font-size: 11px;
  font-weight: 700;
}

/* ---------- Layout ---------- */

main {
  width: min(1200px, calc(100% - 28px));
  margin: 0 auto;
}

/* ---------- Hero / search ---------- */

.hero {
  padding: 20px 0 6px;
}

h1 {
  margin: 0 0 10px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

h1 em {
  font-style: normal;
  color: var(--sun-deep);
}

.search-form {
  display: flex;
  align-items: center;
  height: 44px;
  padding: 0 4px 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-form:focus-within {
  border-color: var(--sun);
  box-shadow: 0 0 0 3px rgba(245, 168, 0, 0.18), var(--shadow);
}

.search-form svg {
  flex: 0 0 auto;
  width: 18px;
  fill: none;
  stroke: var(--faint);
  stroke-width: 1.8;
  stroke-linecap: round;
}

.search-form input {
  flex: 1;
  min-width: 0;
  height: 100%;
  margin: 0 10px;
  border: 0;
  outline: 0;
  background: transparent;
}

.search-form input::placeholder {
  color: var(--faint);
}

#analyze-button {
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--sun);
  color: #fff;
  font-weight: 700;
  transition: background 0.15s ease;
}

#analyze-button:hover {
  background: var(--sun-deep);
}

#analyze-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.form-error {
  min-height: 18px;
  margin: 6px 2px 0;
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 600;
}

.runtime-note {
  margin: 0 2px;
  color: var(--danger);
  font-size: 12px;
}

.hero-meta {
  margin: 2px 2px 0;
  color: var(--faint);
  font-size: 11.5px;
}

.hero-meta b {
  color: var(--muted);
  font-weight: 700;
}

/* ---------- Analysis card ---------- */

.analysis-panel {
  margin: 12px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.analysis-panel[hidden] {
  display: none;
}

.analysis-panel {
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  gap: 14px;
}

.thumbnail-wrap {
  position: relative;
  display: grid;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #ffe9b8, #ffd27d);
  color: #8a6100;
  font-size: 30px;
}

.thumbnail-wrap img {
  position: absolute;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.analysis-copy {
  min-width: 0;
  padding-top: 2px;
}

.analysis-badges {
  display: flex;
  gap: 8px;
  align-items: center;
}

.media-badge {
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--sun);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.media-count {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
}

.analysis-copy h2 {
  margin: 5px 0 3px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.015em;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.analysis-copy > p {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.analysis-note {
  color: var(--faint);
  font-size: 11.5px;
}

/* ---------- Options ---------- */

.options-form {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.option-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.option-group {
  margin: 0;
  padding: 0;
  border: 0;
}

.option-group legend {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.segmented-control {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 3px;
  border-radius: 7px;
  background: var(--bg);
}

.segmented-control label {
  position: relative;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  display: block;
  padding: 6px 12px;
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.segmented-control input:checked + span {
  background: var(--sun);
  color: #fff;
  box-shadow: var(--shadow);
}

.option-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.option-field > span {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.option-field select {
  width: 100%;
  min-width: 130px;
  height: 34px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: 0;
  background: var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236d7268' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 8px center / 12px;
  appearance: none;
}

.option-field select:focus {
  border-color: var(--sun);
  box-shadow: 0 0 0 3px rgba(245, 168, 0, 0.15);
}

.option-field small {
  color: var(--faint);
  font-size: 10.5px;
}

.subtitle-option {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.toggle-row {
  display: flex;
  gap: 8px;
  align-items: center;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.toggle-row input {
  position: absolute;
  opacity: 0;
}

.toggle-row i {
  position: relative;
  width: 30px;
  height: 18px;
  border-radius: 30px;
  background: #cfd2c8;
  transition: background 0.15s;
}

.toggle-row i::after {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  content: "";
  transition: transform 0.15s;
}

.toggle-row input:checked + i {
  background: var(--grass);
}

.toggle-row input:checked + i::after {
  transform: translateX(12px);
}

.subtitle-option.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.download-action {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: var(--sun);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.01em;
  transition: background 0.15s ease;
}

.download-action:hover {
  background: var(--sun-deep);
}

.download-action:disabled {
  cursor: wait;
  opacity: 0.55;
}

.download-action svg {
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

/* ---------- Job panel ---------- */

.job-panel {
  margin: 12px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.job-panel[hidden] {
  display: none;
}

.job-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.job-topline > div {
  min-width: 0;
}

.job-label {
  color: var(--sun-deep);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.job-panel h2 {
  margin: 2px 0 0;
  font-size: 14.5px;
  font-weight: 800;
  line-height: 1.3;
  overflow: hidden;
  word-break: break-word;
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.job-percent {
  flex: 0 0 auto;
  color: var(--sun-deep);
  font-size: 20px;
  font-weight: 800;
}

.progress-track {
  height: 5px;
  margin: 10px 0 8px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--line);
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--sun), #ffc94d);
  transition: width 0.35s ease;
}

.job-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
}

.job-result {
  margin-top: 8px;
  font-size: 12.5px;
}

.job-result p {
  margin: 0;
}

.job-result a,
.job-result button {
  color: var(--sun-deep);
  font-weight: 700;
}

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

.warning-message {
  margin: 6px 0 0;
  padding: 6px 10px;
  border: 1px solid var(--sun);
  border-radius: 6px;
  background: var(--sun-soft);
  color: var(--sun-deep);
  font-size: 12px;
  font-weight: 600;
}

/* ---------- Library grid ---------- */

.library {
  padding: 18px 0 8px;
}

.library-head {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 10px;
}

.library-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.library-count {
  color: var(--faint);
  font-size: 11.5px;
  font-weight: 600;
}

.text-button {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-left: auto;
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: none;
  font-size: 12px;
  font-weight: 700;
}

.text-button:hover {
  color: var(--sun-deep);
  background: var(--sun-soft);
}

.text-button svg {
  width: 14px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.video-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.video-card:hover {
  box-shadow: var(--shadow-lift);
  transform: translateY(-2px);
}

.card-media {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #eceadf;
}

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

.card-thumb-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #ffe9b8, #ffd27d);
  color: #8a6100;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.video-card.is-playable .card-media {
  cursor: pointer;
}

.card-play {
  position: absolute;
  inset: 0;
  margin: auto;
  z-index: 1;
  display: grid;
  width: 46px;
  height: 46px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 18, 12, 0.55);
  color: #fff;
  backdrop-filter: blur(2px);
  transition: background 0.15s ease, transform 0.15s ease;
}

.card-play svg {
  width: 22px;
  fill: currentColor;
}

.video-card:hover .card-play {
  background: var(--sun);
  transform: scale(1.06);
}

.card-download {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.video-card:hover .card-download,
.card-download:focus-visible {
  opacity: 1;
}

.card-download:hover {
  background: var(--sun);
  color: #fff;
}

.card-download svg {
  width: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.card-info {
  padding: 8px 10px 10px;
}

.card-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  margin: 3px 0 0;
  color: var(--faint);
  font-size: 11px;
  font-weight: 600;
}

.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  justify-content: center;
  padding: 44px 16px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--faint);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.empty-icon {
  font-size: 22px;
  color: var(--sun);
}

/* ---------- Player overlay ---------- */

.player-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 16, 10, 0.92);
  padding: 16px;
}

.player-overlay[hidden] {
  display: none;
}

.player-box {
  position: relative;
  width: 100%;
  max-width: 980px;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.player-stage video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}

.player-stage audio {
  display: block;
  width: 100%;
  margin: 0;
  padding: 48px 20px;
  background: linear-gradient(135deg, #fff4d9, #ffe9b8);
}

.player-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 18, 12, 0.6);
  color: #fff;
  font-size: 20px;
  line-height: 1;
}

.player-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
}

.player-bar h2 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-download {
  flex: 0 0 auto;
  display: flex;
  gap: 7px;
  align-items: center;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--sun);
  color: #fff;
  font-size: 12.5px;
  font-weight: 800;
  text-decoration: none;
}

.player-download:hover {
  background: var(--sun-deep);
}

.player-download svg {
  width: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

@media (max-width: 720px) {
  .player-overlay {
    padding: 0;
    align-items: stretch;
  }

  .player-box {
    max-width: none;
    min-height: 100vh;
    border-radius: 0;
  }

  .player-stage video {
    aspect-ratio: auto;
    height: calc(100vh - 54px);
    object-fit: contain;
  }
}

/* ---------- Footer ---------- */

footer {
  width: min(1200px, calc(100% - 28px));
  margin: 0 auto;
  padding: 16px 0 22px;
  border-top: 1px solid var(--line);
}

footer p {
  margin: 0;
  color: var(--faint);
  font-size: 11.5px;
}

footer a {
  color: var(--muted);
  font-weight: 700;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .analysis-panel {
    grid-template-columns: 1fr;
  }

  .thumbnail-wrap {
    max-height: 158px;
  }

  .search-form input {
    font-size: 16px; /* prevents iOS Safari focus zoom */
  }

  .option-field {
    flex: 1 1 46%;
    min-width: 0;
  }

  .option-field select {
    min-width: 0;
  }

  .job-percent {
    font-size: 16px;
  }

  .video-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
  }

  .status-pill {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
