@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,300..800&family=DM+Mono:wght@400;500&family=Fraunces:ital,opsz,wght@0,9..144,400..900;1,9..144,400..600&family=Montserrat:wght@600;700;800;900&display=swap');

:root {
  --bg: #0c0d10;
  --bg-raised: #15171c;
  --bg-line: #22252d;
  --fg: #f3f1ea;
  --fg-dim: #8b8f99;
  --fg-faint: #565a64;
  --signal: #ff4d3d;
  --signal-dim: #c93a2e;
  --good: #5fd08a;
  --warn: #f5c451;
  --fail: #ff4d3d;
  --grade-a: #5fd08a;
  --grade-b: #9ed06b;
  --grade-c: #f5c451;
  --grade-d: #f59451;
  --grade-f: #ff4d3d;
  --mono: 'DM Mono', ui-monospace, monospace;
  --display: 'Bricolage Grotesque', sans-serif;
  --serif: 'Fraunces', serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }
html, body { max-width: 100%; overflow-x: hidden; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--display);
  font-weight: 400;
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(circle at 15% -10%, rgba(255, 77, 61, 0.08), transparent 45%),
    linear-gradient(var(--bg-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-line) 1px, transparent 1px);
  background-size: 100% 100%, 64px 64px, 64px 64px;
  background-position: 0 0, -1px -1px, -1px -1px;
}

.shell { max-width: 880px; margin: 0 auto; padding: 0 24px; }

/* ── header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 0;
  border-bottom: 1px solid var(--bg-line);
}
.brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--fg);
  text-decoration: none;
}
.brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 0 0 rgba(255, 77, 61, 0.6);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 77, 61, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(255, 77, 61, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 77, 61, 0); }
}
.brand .tld { color: var(--signal); }
header .tag {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

/* ── hero ── */
.hero { padding: 72px 0 40px; }
.hero .kicker {
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--signal);
  margin-bottom: 20px;
}
.hero h1 {
  font-size: clamp(2.6rem, 7vw, 4.6rem);
  font-weight: 700;
  line-height: 0.98;
  letter-spacing: -0.035em;
  margin-bottom: 22px;
}
.hero h1 em {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  color: var(--signal);
}
.hero p.lede {
  font-size: 1.12rem;
  color: var(--fg-dim);
  max-width: 30ch;
  margin-bottom: 38px;
}

/* compact hero once a report shows: hide heading/kicker/lede, lift the form up */
.hero.compact { padding-top: 24px; }
.hero.compact h1,
.hero.compact .kicker,
.hero.compact p.lede { display: none; }
.reset-link {
  display: none;
  background: none;
  border: none;
  color: var(--fg-dim);
  font-family: var(--mono);
  font-size: 0.8rem;
  cursor: pointer;
  margin-top: 14px;
  padding: 0;
}
.reset-link:hover { color: var(--signal); }
.hero.compact .reset-link { display: inline-block; }

/* ── url form ── */
.analyze-form {
  display: flex;
  gap: 0;
  border: 1px solid var(--bg-line);
  border-radius: 14px;
  background: var(--bg-raised);
  padding: 6px;
  max-width: 620px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.analyze-form:focus-within {
  border-color: var(--signal-dim);
  box-shadow: 0 0 0 4px rgba(255, 77, 61, 0.1);
}
.analyze-form input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--fg);
  font-family: var(--mono);
  font-size: 0.95rem;
  padding: 14px 16px;
}
.analyze-form input::placeholder { color: var(--fg-faint); }
.analyze-form .paste-btn {
  background: transparent;
  border: none;
  color: var(--fg-dim);
  display: flex;
  align-items: center;
  padding: 0 10px;
  cursor: pointer;
  transition: color 0.15s;
}
.analyze-form .paste-btn:hover { color: var(--signal); }
.analyze-form button[type="submit"] {
  background: var(--signal);
  color: #160805;
  border: none;
  border-radius: 9px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0 26px;
  cursor: pointer;
  transition: transform 0.12s, background 0.2s;
}
.analyze-form button[type="submit"]:hover { background: #ff6757; }
.analyze-form button[type="submit"]:active { transform: scale(0.97); }
.analyze-form button[type="submit"]:disabled { opacity: 0.5; cursor: wait; }
.analyze-form button[type="submit"] .sm { display: none; }

/* ── video preview ── */
#preview { padding: 8px 0 0; }
#preview[hidden] { display: none; }
.preview-card {
  position: relative;
  display: block;
  max-width: 620px;
  border: 1px solid var(--bg-line);
  border-radius: 14px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  background: var(--bg-raised);
  text-decoration: none;
}
.preview-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview-card .play {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
.preview-card .play span {
  width: 64px; height: 64px; border-radius: 50%;
  background: rgba(255,77,61,0.92);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.4rem;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  transition: transform 0.15s;
}
.preview-card:hover .play span { transform: scale(1.08); }
.preview-card.skeleton { background: linear-gradient(100deg, var(--bg-raised) 30%, var(--bg-line) 50%, var(--bg-raised) 70%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.form-error {
  color: var(--signal);
  font-family: var(--mono);
  font-size: 0.82rem;
  margin-top: 12px;
  min-height: 1.2em;
}

/* ── report ── */
#report { padding: 16px 0 90px; }
#report[hidden] { display: none; }

.report-head {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 28px;
  align-items: center;
  padding: 28px 0;
  border-top: 1px solid var(--bg-line);
  border-bottom: 1px solid var(--bg-line);
  margin-bottom: 36px;
}
.grade {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 7rem;
  line-height: 0.8;
  letter-spacing: -0.04em;
}
.grade[data-grade="A"] { color: var(--grade-a); }
.grade[data-grade="B"] { color: var(--grade-b); }
.grade[data-grade="C"] { color: var(--grade-c); }
.grade[data-grade="D"] { color: var(--grade-d); }
.grade[data-grade="F"] { color: var(--grade-f); }
.grade-meta .vtitle {
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.grade-meta .vstats {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--fg-dim);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.grade-meta .score-bar {
  margin-top: 16px;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-line);
  overflow: hidden;
}
.grade-meta .score-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--signal-dim), var(--signal));
  width: 0;
  transition: width 0.9s cubic-bezier(0.2, 0.9, 0.2, 1);
}

/* top fixes */
.fixes {
  background: var(--bg-raised);
  border: 1px solid var(--bg-line);
  border-radius: 14px;
  padding: 22px 24px;
  margin-bottom: 36px;
}
.fixes h3 {
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--signal);
  margin-bottom: 16px;
}
.fixes ol { list-style: none; counter-reset: fix; }
.fixes li {
  counter-increment: fix;
  display: flex;
  gap: 14px;
  padding: 10px 0;
  font-size: 0.98rem;
  color: var(--fg);
  border-top: 1px solid var(--bg-line);
}
.fixes li:first-child { border-top: none; }
.fixes li::before {
  content: counter(fix);
  font-family: var(--mono);
  font-weight: 500;
  color: var(--signal);
  flex-shrink: 0;
}

/* checks grouped */
.group { margin-bottom: 30px; }
.group > h4 {
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--fg-faint);
  margin-bottom: 12px;
}
.check {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 14px;
  padding: 13px 0;
  border-top: 1px solid var(--bg-line);
}
.check .led {
  width: 12px; height: 12px; border-radius: 50%;
  margin-top: 5px;
}
.check[data-sev="pass"] .led { background: var(--good); box-shadow: 0 0 8px rgba(95, 208, 138, 0.5); }
.check[data-sev="warn"] .led { background: var(--warn); box-shadow: 0 0 8px rgba(245, 196, 81, 0.5); }
.check[data-sev="fail"] .led { background: var(--fail); box-shadow: 0 0 8px rgba(255, 77, 61, 0.5); }
.check .msg { font-size: 0.96rem; }
.check .fix {
  font-size: 0.85rem;
  color: var(--fg-dim);
  margin-top: 3px;
}

.editor-cta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  background: transparent;
  border: 1px solid var(--signal-dim);
  color: var(--signal);
  font-family: var(--display);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 13px 22px;
  border-radius: 10px;
  text-decoration: none;
  transition: background 0.2s, transform 0.12s;
}
.editor-cta:hover { background: rgba(255, 77, 61, 0.1); }
.editor-cta:active { transform: scale(0.98); }

/* re-analyze + cache lifetime, small, at the very bottom of the report */
.analyze-meta { display: flex; align-items: center; gap: 12px; margin-top: 22px; flex-wrap: wrap; }
.reanalyze-btn {
  font-family: var(--mono); font-size: 0.72rem; color: var(--fg-dim);
  background: transparent; border: 1px solid var(--bg-line); border-radius: 6px;
  padding: 5px 12px; cursor: pointer;
}
.reanalyze-btn:hover:not(:disabled) { color: var(--fg); border-color: var(--fg-faint); }
.reanalyze-btn:disabled { opacity: 0.5; cursor: default; }
.cache-life { font-family: var(--mono); font-size: 0.68rem; color: var(--fg-faint); }

/* skeleton / loading */
.loading {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--fg-dim);
  padding: 40px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.loading .scan {
  width: 32px; height: 2px; background: var(--signal);
  animation: scan 1.1s infinite;
}
@keyframes scan { 0%,100% { opacity: 0.3; transform: scaleX(0.4); } 50% { opacity: 1; transform: scaleX(1); } }

/* Trickle progress over the blurred draft while the AI generates (see startTrickle). */
.gen-progress { margin-bottom: 10px; }
.gen-progress-track { height: 4px; border-radius: 2px; background: rgba(255,255,255,0.12); overflow: hidden; }
.gen-progress-fill { display: block; height: 100%; width: 0; border-radius: 2px; background: var(--accent, #ff4d3d); transition: width 0.25s linear; }
.gen-progress-label { display: block; margin-top: 5px; font-family: var(--mono); font-size: 0.72rem; color: var(--fg-dim); }
.gen-progress.is-queued .gen-progress-track { animation: qpulse 1.3s ease-in-out infinite; }
@keyframes qpulse { 0%,100% { opacity: 0.4; } 50% { opacity: 0.9; } }

footer {
  border-top: 1px solid var(--bg-line);
  padding: 28px 0 48px;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--fg-faint);
  display: flex;
  justify-content: space-between;
}
footer a { color: var(--fg-dim); text-decoration: none; }
footer a:hover { color: var(--signal); }

/* history page */
.hist { max-width: 640px; margin: 0 auto; padding: 8px 0 40px; }
.hist-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 18px; }
.hist-head h1 { font-family: var(--display); font-size: 1.8rem; color: var(--fg); margin: 0; }
.hist-clear {
  background: none; border: 1px solid var(--bg-line); color: var(--fg-dim);
  font-family: var(--mono); font-size: 0.72rem; padding: 4px 12px; border-radius: 7px; cursor: pointer;
}
.hist-clear:hover { border-color: var(--signal); color: var(--signal); }
.hist-list { display: flex; flex-direction: column; gap: 8px; }
.hist-item {
  display: flex; align-items: center; gap: 12px; text-decoration: none;
  background: var(--bg-raised); border: 1px solid var(--bg-line); border-radius: 10px;
  padding: 8px 12px 8px 8px; transition: border-color .12s;
}
.hist-item:hover { border-color: var(--signal-dim); }
.hist-thumb { width: 88px; height: 50px; object-fit: cover; border-radius: 6px; flex-shrink: 0; background: var(--bg-line); }
.hist-meta { flex: 1; min-width: 0; }
.hist-title {
  color: var(--fg); font-size: 0.9rem; line-height: 1.3; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.hist-when { color: var(--fg-faint); font-family: var(--mono); font-size: 0.68rem; margin-top: 3px; }
.hist-score { font-family: var(--mono); font-weight: 600; font-size: 1.05rem; flex-shrink: 0; }
.hist-empty { color: var(--fg-dim); font-size: 0.9rem; text-align: center; padding: 40px 0; }

.reveal { animation: reveal 0.6s cubic-bezier(0.2, 0.9, 0.2, 1) both; }
@keyframes reveal { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ── mobile ── */
@media (max-width: 540px) {
  header .tag { display: none; }
  .hero { padding: 48px 0 32px; }
  /* drop forced line breaks → text wraps naturally, can't overflow */
  .hero h1 { font-size: clamp(2rem, 9vw, 3.2rem); text-wrap: balance; }
  .hero h1 br { display: none; }
  .analyze-form button[type="submit"] { padding: 0 20px; }
  .analyze-form button[type="submit"] .lg { display: none; }
  .analyze-form button[type="submit"] .sm { display: inline; }
  .report-head { grid-template-columns: 1fr; gap: 14px; }
  .grade { font-size: 5rem; }
  .preview-card { max-width: 100%; }
  /* thumbnail sample: stack it, and lift the style types (Bar/Punch) above the preview */
  .gen-thumb-stage { flex-direction: column; }
  .gen-types { flex-direction: row; flex-wrap: wrap; order: -1; }
}

/* --- draft generator (0.8.5, no AI) --- */
.gen { margin: 20px 0; }
.gen-btn {
  font-family: var(--mono); font-size: 0.9rem; font-weight: 500;
  background: var(--signal); color: #fff; border: none; border-radius: 8px;
  padding: 12px 18px; cursor: pointer; transition: filter 0.15s;
}
.gen-btn small { opacity: 0.8; font-weight: 400; }
.gen-btn:hover { filter: brightness(1.08); }
.gen-btn:disabled { opacity: 0.55; cursor: wait; }
.gen-out { margin-top: 16px; display: flex; flex-direction: column; gap: 16px; }
.gen-head { font-family: var(--mono); font-size: 0.85rem; color: var(--fg-dim); }
.gen-head b { color: var(--good); }
.gen-note { color: var(--fg-dim); font-size: 0.9rem; }
.gen-aifail {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 12px;
  color: var(--warn); font-family: var(--mono); font-size: 0.78rem;
}
.gen-retry {
  background: var(--warn); color: #160805; border: none; border-radius: 6px;
  font-family: var(--mono); font-weight: 600; font-size: 0.72rem; padding: 4px 12px; cursor: pointer;
}
.gen-retry:hover { filter: brightness(1.08); }

/* AI draft is generating in the background: blur the rule-based draft (text
   unreadable) and sweep a shimmer over it so it reads as "working". */
.gen-out.ai-pending { position: relative; }
.gen-out.ai-pending > .gen-head,
.gen-out.ai-pending > .gen-block {
  filter: blur(6px); opacity: 0.5; user-select: none; pointer-events: none;
}
.gen-out.ai-pending::after {
  content: '✨ AI is writing better drafts…';
  position: absolute; inset: 0; z-index: 2; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 0.82rem; letter-spacing: 0.03em; color: var(--fg);
  background: linear-gradient(100deg,
    transparent 20%,
    color-mix(in srgb, var(--signal) 16%, transparent) 45%,
    color-mix(in srgb, var(--signal) 24%, transparent) 55%,
    transparent 80%);
  background-size: 220% 100%;
  animation: aiSweep 1.4s linear infinite;
}
@keyframes aiSweep { 0% { background-position: 220% 0; } 100% { background-position: -120% 0; } }
.gen-block { background: var(--bg-raised); border: 1px solid var(--bg-line); border-radius: 10px; padding: 14px 16px; }
.gen-block h4 { font-family: var(--mono); font-size: 0.8rem; color: var(--fg-dim); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
.gen-titles { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.gen-titles li { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.gen-titles span { color: var(--fg); }
.gen-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.gen-tags span { background: var(--bg); border: 1px solid var(--bg-line); border-radius: 6px; padding: 3px 8px; font-size: 0.82rem; color: var(--fg-dim); }
.gen-desc { white-space: pre-wrap; font-family: var(--mono); font-size: 0.82rem; color: var(--fg); line-height: 1.5; }
.gen-hint { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--fg-dim); opacity: 0.7; margin-left: 6px; }
.gen-hooks { display: flex; flex-wrap: wrap; gap: 8px; }
.gen-hooks span { display: inline-flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--bg-line); border-radius: 8px; padding: 5px 6px 5px 12px; font-size: 0.9rem; color: var(--fg); cursor: pointer; }
.gen-hook.on { border-color: var(--accent, #ff4d3d); box-shadow: 0 0 0 1px var(--accent, #ff4d3d) inset; }
.gen-hook-title { color: var(--fg-dim); }
.gen-thumb-stage { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.gen-thumb { display: block; flex: 1 1 auto; width: 100%; max-width: 560px; aspect-ratio: 16 / 9; border-radius: 10px; border: 1px solid var(--bg-line); }
.gen-types { display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; }
.gen-type { font-family: var(--mono); font-size: 0.74rem; background: var(--bg); color: var(--fg-dim); border: 1px solid var(--bg-line); border-radius: 6px; padding: 7px 14px; cursor: pointer; }
.gen-type.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.gen-thumb-actions { display: flex; gap: 8px; margin-top: 12px; }
.gen-thumb-actions button { font-family: var(--mono); font-size: 0.78rem; background: var(--fg); color: var(--bg); border: none; border-radius: 6px; padding: 7px 14px; cursor: pointer; }
.gen-thumb-actions .gen-dlimg { background: transparent; color: var(--fg-dim); border: 1px solid var(--bg-line); }
.gen-thumb-actions .gen-editvar { display: inline-flex; align-items: center; font-family: var(--mono); font-size: 0.78rem; text-decoration: none; background: transparent; color: var(--accent, #ff4d3d); border: 1px solid var(--accent, #ff4d3d); border-radius: 6px; padding: 7px 14px; cursor: pointer; margin-left: auto; }
.cp { font-family: var(--mono); font-size: 0.72rem; background: transparent; border: 1px solid var(--bg-line); color: var(--fg-dim); border-radius: 6px; padding: 3px 8px; cursor: pointer; flex: 0 0 auto; }
.cp:hover { border-color: var(--signal); color: var(--fg); }
