/* ============ TOKENS ============ */
:root {
  --bg: #0f0d0a;
  --bg-soft: #141210;
  --surface: #1a1713;
  --surface-2: #221e17;
  --line: #2e2921;
  --line-soft: #262219;
  --text: #f1e9d7;
  --text-dim: #a39a86;
  --text-faint: #6f6757;
  --amber: #ffb03a;
  --amber-soft: #ffcf7d;
  --amber-dim: rgba(255, 176, 58, 0.14);
  --teal: #4cc9b0;
  --red: #ff5449;
  --ink: #181206;
  --radius: 12px;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --display: "Archivo", sans-serif;
  --body: "Be Vietnam Pro", system-ui, sans-serif;
}

/* ============ RESET ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
::selection { background: var(--amber); color: var(--ink); }
.hidden { display: none !important; }

/* ============ BASE ============ */
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--body);
  font-size: 15px;
  color: var(--text);
  background:
    radial-gradient(1100px 560px at 75% -10%, rgba(255, 176, 58, 0.09), transparent 60%),
    radial-gradient(900px 520px at 5% 110%, rgba(76, 201, 176, 0.06), transparent 60%),
    var(--bg);
}

/* Hạt grain phim */
.grain {
  position: fixed; inset: 0; z-index: 60;
  pointer-events: none; opacity: 0.055;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  animation: grain 1.4s steps(3) infinite;
}
@keyframes grain {
  0%   { background-position: 0 0; }
  33%  { background-position: -30px 15px; }
  66%  { background-position: 22px -25px; }
  100% { background-position: 0 0; }
}

/* ============ TICKER ============ */
.ticker {
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
  padding: 9px 0;
}
.ticker-track {
  display: flex; width: max-content;
  animation: tickerMove 38s linear infinite;
}
.ticker:hover .ticker-track { animation-play-state: paused; }
.ticker-group { display: flex; gap: 26px; padding-right: 26px; }
.ticker span {
  font: 600 11px/1 var(--mono);
  letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--text-dim); white-space: nowrap;
}
.ticker i { color: var(--amber); font-style: normal; font-size: 8px; align-self: center; }
@keyframes tickerMove { to { transform: translateX(-50%); } }

/* Vạch clapperboard */
.clapper {
  height: 12px;
  background: repeating-linear-gradient(-45deg, var(--amber) 0 18px, #161310 18px 36px);
  animation: clap 6s linear infinite;
}
@keyframes clap { to { background-position: 50.9px 0; } }

/* ============ LAYOUT ============ */
.wrap { max-width: 620px; width: 100%; margin: 0 auto; padding: 40px 20px 48px; flex: 1; }

/* ============ HEADER ============ */
.head { margin-bottom: 26px; }
.slate-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.rec {
  display: inline-flex; align-items: center; gap: 8px;
  font: 600 11px/1 var(--mono); letter-spacing: 0.2em;
  color: var(--red);
  border: 1px solid rgba(255, 84, 73, 0.35);
  background: rgba(255, 84, 73, 0.07);
  padding: 6px 10px; border-radius: 6px;
}
.rec .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--red);
  animation: blink 1.1s steps(2, start) infinite;
}
.slate-code { font: 500 11px var(--mono); letter-spacing: 0.18em; color: var(--text-faint); }

.title {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(44px, 9vw, 74px);
  line-height: 1;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}
.title .hl {
  display: inline-block;
  background: var(--amber); color: var(--ink);
  padding: 0.02em 0.16em; border-radius: 6px;
  transform: rotate(-1.2deg);
  box-shadow: 4px 4px 0 rgba(76, 201, 176, 0.85);
}
.title .cursor { color: var(--teal); animation: blink 1s steps(2, start) infinite; }
.sub { margin-top: 14px; color: var(--text-dim); font-size: 15px; max-width: 44ch; }

@keyframes blink { 50% { opacity: 0; } }

/* ============ STEPS ============ */
.steps { display: flex; gap: 10px; list-style: none; flex-wrap: wrap; margin-bottom: 24px; }
.steps li {
  flex: 1; min-width: 140px;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px; color: var(--text-dim);
  transition: transform 0.2s, border-color 0.2s, color 0.2s;
}
.steps li:hover { transform: translateY(-2px); border-color: var(--amber); color: var(--text); }
.steps b {
  font: 700 11px var(--mono); color: var(--amber);
  background: var(--amber-dim);
  border: 1px solid rgba(255, 176, 58, 0.4);
  border-radius: 6px; padding: 4px 6px;
}

/* ============ CONSOLE NHẬP LINK ============ */
.console {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 24px 50px -32px rgba(0, 0, 0, 0.9);
}
.field-label {
  display: block; margin-bottom: 10px;
  font: 600 11px var(--mono); letter-spacing: 0.22em;
  color: var(--teal);
}
.input-row { display: flex; gap: 10px; }
#urlInput {
  flex: 1; min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 14px;
  color: var(--text);
  font: 400 13.5px var(--mono);
  caret-color: var(--amber);
  transition: border-color 0.2s, box-shadow 0.2s;
}
#urlInput::placeholder { color: var(--text-faint); }
#urlInput:focus { outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px var(--amber-dim); }

/* Ô nhập + nút Dán / Xoá */
.field { position: relative; flex: 1; min-width: 0; display: flex; }
.field #urlInput { flex: 1; padding-right: 96px; }
.field-tools {
  position: absolute; right: 7px; top: 50%;
  transform: translateY(-50%);
  display: flex; gap: 5px;
}
.tool {
  font: 600 11px var(--mono); letter-spacing: 0.06em;
  background: var(--surface-2); color: var(--text-dim);
  border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 7px;
  box-shadow: none;
}
.tool:hover {
  background: var(--amber-dim);
  color: var(--amber);
  border-color: var(--amber);
  transform: none;
}

/* ============ BUTTONS ============ */
button {
  font: 600 14px var(--body);
  background: var(--amber); color: var(--ink);
  border: none; border-radius: 10px;
  padding: 13px 20px;
  cursor: pointer; white-space: nowrap;
  box-shadow: 0 8px 20px -10px rgba(255, 176, 58, 0.6);
  transition: transform 0.15s, background 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
}
button:hover { background: var(--amber-soft); transform: translateY(-1px); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: wait; transform: none; }
button:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
button.secondary {
  background: transparent; color: var(--text);
  border: 1px solid var(--line); box-shadow: none;
}
button.secondary:hover { border-color: var(--teal); color: var(--teal); background: rgba(76, 201, 176, 0.08); }

/* ============ STATUS ============ */
.status {
  margin-top: 12px; min-height: 18px;
  font: 500 12.5px var(--mono);
  color: var(--teal);
}
.status:not(:empty)::before { content: "● "; animation: blink 1.2s steps(2, start) infinite; }
.status.error { color: var(--red); }

/* ============ KẾT QUẢ (film strip) ============ */
.result {
  display: flex;
  margin-top: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  animation: reveal 0.5s cubic-bezier(0.22, 0.9, 0.3, 1) both;
}
@keyframes reveal {
  from { opacity: 0; transform: translateY(16px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

/* Viền lỗ bấm phim */
.film-edge {
  width: 26px; flex: none;
  background-color: #131009;
  background-image: radial-gradient(ellipse 5px 7px at 50% 50%, #050403 60%, transparent 62%);
  background-size: 26px 19px;
  border-inline: 1px solid var(--line-soft);
}

.result-main { flex: 1; padding: 16px; min-width: 0; }

.preview { display: flex; gap: 14px; }
.thumb-frame {
  position: relative;
  width: 104px; height: 104px; flex: none;
  border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line);
  background: #000;
}
.thumb-frame img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s ease; }
.thumb-frame:hover img { transform: scale(1.07); }
/* Scanline */
.thumb-frame::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px);
  pointer-events: none;
}

.meta { min-width: 0; }
.tag {
  display: inline-block; margin-bottom: 8px;
  font: 600 10px var(--mono); letter-spacing: 0.25em;
  background: var(--teal); color: var(--ink);
  padding: 4px 8px; border-radius: 5px;
}
.meta h2 {
  font: 600 15px/1.5 var(--body);
  margin-bottom: 8px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.duration { font: 500 11px var(--mono); letter-spacing: 0.15em; color: var(--amber); }
.duration::before { content: "THỜI LƯỢNG · "; color: var(--text-faint); }
.duration:empty { display: none; }

/* Hàng chất lượng + nút */
.actions {
  margin-top: 16px; padding-top: 16px;
  border-top: 1px dashed var(--line);
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
}
.quality-box { display: flex; align-items: center; gap: 10px; }
.quality-box label { font: 500 12px var(--mono); letter-spacing: 0.1em; color: var(--text-dim); }
#qualitySelect {
  max-width: 280px;
  appearance: none; -webkit-appearance: none;
  background: var(--bg) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 6"><path d="M1 1l4 4 4-4" stroke="%23a39a86" stroke-width="1.5" fill="none" stroke-linecap="round"/></svg>') no-repeat right 11px center / 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 32px 9px 12px;
  font: 500 13px var(--body);
  cursor: pointer;
  text-overflow: ellipsis;
  transition: border-color 0.2s;
}
#qualitySelect:hover, #qualitySelect:focus { border-color: var(--amber); outline: none; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============ DOWNLOAD ============ */
.download-area {
  margin-top: 22px; text-align: center;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 20px;
  animation: reveal 0.45s ease both;
}
#downloadLink {
  display: inline-block;
  font: 700 15px var(--body);
  color: var(--ink);
  background: var(--amber);
  padding: 15px 30px; border-radius: 10px;
  text-decoration: none;
  animation: glow 2.2s ease-in-out infinite;
  transition: transform 0.2s, background 0.2s;
}
#downloadLink::before { content: "↓  "; }
#downloadLink:hover { transform: translateY(-2px); background: var(--amber-soft); }
#downloadLink:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }
@keyframes glow {
  0%, 100% { box-shadow: 0 10px 28px -12px rgba(255, 176, 58, 0.55); }
  50%      { box-shadow: 0 12px 38px -8px rgba(255, 176, 58, 0.85); }
}

/* Ghi chú chất lượng thực tế */
.quality-note {
  margin-top: 14px;
  display: inline-block;
  font: 500 12px/1.6 var(--mono);
  color: var(--teal);
  border: 1px dashed rgba(76, 201, 176, 0.4);
  background: rgba(76, 201, 176, 0.07);
  padding: 8px 12px; border-radius: 8px;
}
.quality-note:empty { display: none; }

.download-note { margin-top: 12px; font: 400 12px var(--mono); color: var(--text-faint); }

/* ============ FOOTER ============ */
.foot {
  text-align: center; padding: 26px 20px 34px;
  font: 400 12px var(--mono); letter-spacing: 0.04em;
  color: var(--text-faint);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 560px) {
  .wrap { padding: 28px 16px 40px; }
  .input-row { flex-direction: column; }
  .actions { flex-direction: column; align-items: stretch; }
  .quality-box { justify-content: space-between; }
  #qualitySelect { max-width: none; flex: 1; }
  .btn-group { flex-direction: column; }
  .btn-group button { width: 100%; }
}

/* ============ REDUCED MOTION ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}