/* ─── Reset & tokens ───────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg:        #f8f8fa;
  --color-surface:   #ffffff;
  --color-border:    #e4e4e8;
  --color-text:      #111114;
  --color-text-2:    #6b6b80;
  --color-accent:    #2563eb;
  --color-accent-h:  #1d4ed8;
  --color-selected:  #eff6ff;
  --color-selected-b:#2563eb;
  --color-error:     #dc2626;
  --color-error-bg:  #fef2f2;

  --radius-sm:   10px;
  --radius-md:   14px;
  --radius-lg:   20px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 1px 4px rgba(0,0,0,.04);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --max-w: 600px;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-accent); }
a:hover { color: var(--color-accent-h); }
img { max-width: 100%; display: block; }

/* ─── Layout shell ─────────────────────────────────── */
.page-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 16px;
}

/* ─── Header ───────────────────────────────────────── */
.site-header {
  padding: 20px 0 0;
  display: flex;
  align-items: center;
}

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

.logo-mark {
  font-size: 22px;
  color: var(--color-accent);
}

.logo-text {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.3px;
}

/* ─── Main content ─────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 36px 0 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ─── State machine ────────────────────────────────── */
.state { display: flex; flex-direction: column; gap: 24px; }
.state[hidden] { display: none !important; }
.state.active { display: flex; flex-direction: column; gap: 24px; }

/* ─── Hero text ────────────────────────────────────── */
.hero-text h1 {
  font-size: clamp(26px, 6vw, 36px);
  font-weight: 700;
  letter-spacing: -.5px;
  line-height: 1.2;
}

.subtitle {
  margin-top: 8px;
  color: var(--color-text-2);
  font-size: 16px;
}

/* ─── URL form ─────────────────────────────────────── */
.url-form { display: flex; flex-direction: column; gap: 12px; }

.url-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}

.url-field {
  position: relative;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color .15s;
  min-height: 56px;
}

.url-field:focus-within { border-color: var(--color-accent); }

#media-url,
#url-input {
  width: 100%;
  min-height: 56px;
  padding: 16px;
  font-size: 16px;
  font-family: var(--font);
  border: none;
  outline: none;
  background: var(--color-surface);
  color: var(--color-text);
  appearance: none;
}

#media-url::placeholder,
#url-input::placeholder { color: #74748a; }

/* ─── Buttons ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font);
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, box-shadow .15s, opacity .15s;
  min-height: 52px;
}

.btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--color-accent-h); }
.btn-primary:active { opacity: .85; }

.btn-ghost {
  background: transparent;
  color: var(--color-accent);
  border: 1.5px solid var(--color-border);
}
.btn-ghost:hover { background: #f0f4ff; }

.btn-full { width: 100%; }

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.inline-error {
  color: var(--color-error);
  font-size: 14px;
  font-weight: 500;
}

.inline-error[hidden] {
  display: none !important;
}

/* ─── Analyzing state ──────────────────────────────── */
.analyzing-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 48px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}

.spinner {
  width: 48px;
  height: 48px;
  color: var(--color-accent);
  animation: spin 1s linear infinite;
}

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

.analyzing-label {
  font-size: 17px;
  font-weight: 500;
  color: var(--color-text-2);
}

/* ─── Media card (result) ──────────────────────────── */
.media-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.media-info {
  display: flex;
  gap: 16px;
  padding: 20px;
  align-items: flex-start;
}

.thumbnail-wrap {
  flex-shrink: 0;
  width: 100px;
  height: 68px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-bg);
}

.thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-meta { flex: 1; min-width: 0; }

.media-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.media-meta-secondary {
  margin-top: 4px;
  font-size: 13px;
  color: var(--color-text-2);
}

.hidden { display: none !important; }

/* ─── Quality sections ─────────────────────────────── */
.quality-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-2);
  text-transform: uppercase;
  letter-spacing: .6px;
}

/* ─── Quality grid ─────────────────────────────────── */
.quality-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
}

.quality-tile {
  position: relative;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  cursor: pointer;
  text-align: center;
  transition: border-color .12s, box-shadow .12s, background .12s;
  user-select: none;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.quality-tile:hover {
  border-color: #93b4fd;
  box-shadow: var(--shadow-sm);
}

.quality-tile:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.quality-tile.selected {
  border-color: var(--color-selected-b);
  background: var(--color-selected);
  box-shadow: 0 0 0 1px var(--color-selected-b);
}

.quality-tile.selected .tile-quality {
  color: var(--color-accent);
}

.tile-quality {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1;
}

.tile-type {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-2);
  text-transform: uppercase;
  letter-spacing: .4px;
}

.tile-size {
  font-size: 10px;
  color: var(--color-text-2);
  margin-top: 2px;
}

/* ─── Download summary ─────────────────────────────── */
.download-summary {
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.summary-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.summary-label {
  color: var(--color-text-2);
  font-weight: 500;
  white-space: nowrap;
}

.summary-value {
  font-weight: 600;
  color: var(--color-text);
}

/* ─── Error states ─────────────────────────────────── */
.error-card {
  background: var(--color-error-bg);
  border: 1.5px solid #fca5a5;
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.error-card.standalone {
  margin-top: 40px;
}

.error-icon {
  font-size: 32px;
  color: var(--color-error);
}

.error-heading {
  font-size: 20px;
  font-weight: 700;
}

.error-message {
  font-size: 15px;
  color: var(--color-text-2);
  max-width: 320px;
}

/* ─── Handoff page ─────────────────────────────────── */
.handoff-main {
  align-items: center;
  padding: 40px 0;
}

.handoff-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px 24px;
  text-align: center;
}

.handoff-thumbnail-wrap {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 16/9;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-bg);
}

.handoff-thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.handoff-title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  max-width: 400px;
}

.handoff-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 14px;
  color: var(--color-text-2);
  font-weight: 500;
}

.meta-sep { opacity: .4; }

.handoff-open-btn {
  max-width: 320px;
  font-size: 17px;
}

.handoff-note {
  font-size: 13px;
  color: var(--color-text-2);
}

/* ─── Footer ───────────────────────────────────────── */
.site-footer {
  padding: 20px 0;
  font-size: 13px;
  color: var(--color-text-2);
  text-align: center;
}

/* ─── Responsive ───────────────────────────────────── */
@media (min-width: 480px) {
  .quality-grid {
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  }
  .thumbnail-wrap {
    width: 120px;
    height: 80px;
  }
}

@media (min-width: 640px) {
  .url-form {
    flex-direction: row;
    align-items: center;
  }
  .url-field { flex: 1; }
  .btn-full.url-submit { width: auto; white-space: nowrap; }
}


/* ── Web download mode ───────────────────────────────────────────────────── */

.quality-tile.unavailable {
  cursor: not-allowed;
  background: var(--color-bg);
  border-style: dashed;
  opacity: .72;
}

.quality-tile.unavailable:hover {
  border-color: var(--color-border);
  box-shadow: none;
}

.tile-note {
  font-size: 10.5px;
  line-height: 1.25;
  color: var(--color-text-2);
  max-width: 100%;
}

.no-format-note {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--color-error-bg);
  color: var(--color-error);
  font-size: 14px;
}

.download-ready {
  margin: 14px 0 6px;
  padding: 14px;
  border: 1.5px solid var(--color-selected-b);
  border-radius: var(--radius-md);
  background: var(--color-selected);
  text-align: center;
}

.download-ready .ready-title { font-weight: 700; margin: 0 0 4px; }
.download-ready .ready-name  { margin: 0 0 6px; word-break: break-word; font-size: 14px; }
.download-ready .ready-hint  { margin: 0 0 12px; font-size: 13px; color: var(--color-text-2); }
.download-ready .btn         { text-decoration: none; display: block; }

.preparing-box {
  margin: 14px 0 6px;
  padding: 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  text-align: center;
}

.preparing-box .ready-title { font-weight: 700; margin: 0 0 8px; }
.preparing-box .ready-hint  { margin: 8px 0; font-size: 13px; color: var(--color-text-2); }
.preparing-box progress     { width: 100%; height: 10px; }
