:root {
  --paper: #f0eee8;
  --ink: #171813;
  --muted: #67675f;
  --line: #cbc8be;
  --acid: #dfff33;
  --coral: #ff654a;
  --blue: #2475ff;
  --panel: #f8f7f2;
  --shadow: 0 28px 80px rgba(24, 25, 20, 0.12);
  --font-ui: "Aptos", "Segoe UI Variable", "Segoe UI", sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 8%, rgba(223, 255, 51, 0.2), transparent 23rem),
    linear-gradient(180deg, #f5f3ed 0%, var(--paper) 58%, #e9e6dc 100%);
  font-family: var(--font-ui);
  min-height: 100vh;
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  z-index: 20;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.92' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.12'/%3E%3C/svg%3E");
}

.topbar {
  width: min(1180px, calc(100% - 48px));
  height: 92px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  font-weight: 800;
  font-size: 21px;
  letter-spacing: -0.04em;
}

.brand-mark {
  width: 36px;
  height: 36px;
  padding: 8px;
  background: var(--ink);
  border-radius: 50%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
}

.brand-mark i { width: 4px; background: var(--acid); border-radius: 3px; }
.brand-mark i:nth-child(1) { height: 8px; }
.brand-mark i:nth-child(2) { height: 18px; }
.brand-mark i:nth-child(3) { height: 12px; }

.local-status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: right;
  line-height: 1.35;
}

.local-status span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #37a654;
  box-shadow: 0 0 0 5px rgba(55, 166, 84, 0.12);
}

main { width: min(1180px, calc(100% - 48px)); margin: 0 auto; }

.hero {
  min-height: 430px;
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  align-items: center;
  gap: 50px;
  padding: 62px 0 54px;
}

.hero h1 {
  margin: 0;
  max-width: 720px;
  /* Co giãn liên tục theo bề ngang: trên điện thoại 375px chữ về ~41px thay vì 60px,
     cỡ mà dòng "Lấy nội dung." còn thở được thay vì chạm sát hai mép. */
  font-size: clamp(40px, 7.4vw, 112px);
  line-height: 0.88;
  letter-spacing: -0.06em;
  font-weight: 800;
  overflow-wrap: break-word;
}

.hero h1 em {
  position: relative;
  color: var(--coral);
  font-style: normal;
  font-weight: 500;
}

.hero h1 em::after {
  content: "";
  position: absolute;
  left: 2%;
  right: -2%;
  bottom: -5px;
  height: 8px;
  background: var(--ink);
  transform: rotate(-1deg) scaleX(0);
  transform-origin: left;
  animation: draw-line 0.75s 0.55s cubic-bezier(.2,.8,.2,1) forwards;
}

.hero-copy > p {
  max-width: 570px;
  margin: 36px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.65;
}

.platform-orbit {
  position: relative;
  justify-self: end;
  width: 290px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 50%;
  animation: reveal 0.7s 0.2s both;
}

.platform-orbit::before,
.platform-orbit::after {
  content: "";
  position: absolute;
  inset: 48px;
  border: 1px dashed #b8b4a8;
  border-radius: 50%;
}

.platform-orbit::after { inset: 96px; border-style: solid; background: var(--acid); }

.orbit-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 2;
  font-size: 42px;
  font-weight: 800;
}

.platform {
  position: absolute;
  z-index: 3;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: white;
  border: 4px solid var(--paper);
  font: 500 12px var(--font-mono);
  box-shadow: 0 10px 24px rgba(23, 24, 19, 0.16);
}

.p1 { left: 22px; top: 25px; background: #ff0033; }
.p2 { right: -4px; top: 74px; background: var(--blue); }
.p3 { right: 32px; bottom: 18px; background: linear-gradient(135deg, #8939c8, #ff7657); }
.p4 { left: 74px; bottom: -10px; }
.p5 { left: -20px; bottom: 80px; }
.p6 { left: 118px; top: -22px; background: #252525; }
.p7 { right: 42px; top: -10px; background: #111; }

.workbench {
  position: relative;
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 0;
  background: var(--panel);
  border: 1px solid var(--ink);
  box-shadow: var(--shadow);
}

.step-index {
  border-right: 1px solid var(--ink);
  padding-top: 45px;
  text-align: center;
  font: 500 13px var(--font-mono);
  color: var(--muted);
}

.workbench-main { padding: 44px 54px 48px; }
.workbench-main { min-width: 0; }
.workbench h2 { margin: 0 0 18px; font-size: 25px; letter-spacing: -0.04em; }

.url-row { display: flex; gap: 10px; }

.url-field {
  min-width: 0;
  flex: 1;
  height: 64px;
  display: flex;
  align-items: center;
  background: white;
  border: 1px solid #a7a49b;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.url-field:focus-within { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(36,117,255,.1); }
.url-field input { min-width: 0; flex: 1; height: 100%; padding: 0 20px; border: 0; outline: 0; background: transparent; font-family: var(--font-mono); font-size: 14px; }

.paste-button {
  height: 42px;
  margin-right: 10px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 0;
  background: #eae8e1;
  font-size: 13px;
  font-weight: 700;
}

.paste-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; }

.analyze-button {
  min-width: 150px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: white;
  font-size: 13px;
  font-weight: 700;
  transition: transform .2s, background .2s;
}

.analyze-button:hover { background: var(--blue); transform: translateY(-2px); }
.analyze-button:disabled { opacity: .55; cursor: wait; transform: none; }
.field-hint { margin: 10px 0 0; color: var(--muted); font: 400 11px var(--font-mono); }

.preview {
  margin-top: 24px;
  min-height: 110px;
  display: grid;
  grid-template-columns: 164px 1fr;
  gap: 22px;
  padding: 14px;
  border: 1px solid var(--line);
  background: #eeece5;
  animation: reveal .35s both;
}

.preview-image { min-height: 92px; background: #d9d6cd center/cover; }
.preview-copy { align-self: center; min-width: 0; }
.preview-meta { display: flex; gap: 12px; color: var(--blue); font: 500 11px var(--font-mono); text-transform: uppercase; }
.preview h3 { margin: 8px 0 4px; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview p { margin: 0; color: var(--muted); font-size: 13px; }

.divider { height: 1px; margin: 40px 0 34px; background: var(--line); }
.format-head { display: flex; justify-content: space-between; align-items: flex-end; }
.format-head > div { display: flex; gap: 22px; align-items: baseline; }
.format-head h2 { margin-bottom: 0; }
.section-number, .format-note { color: var(--muted); font: 500 12px var(--font-mono); }

.format-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 20px; }

.format-card {
  position: relative;
  min-height: 190px;
  padding: 24px;
  text-align: left;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  transition: transform .22s, border-color .22s, background .22s;
}

.format-card:hover { transform: translateY(-4px); border-color: var(--ink); }
.format-card.selected { background: var(--acid); border-color: var(--ink); box-shadow: 5px 5px 0 var(--ink); transform: translate(-3px, -3px); }
.format-card.selected::after { content: "✓"; position: absolute; top: 16px; right: 18px; font-weight: 800; }
.format-icon { height: 50px; display: flex; align-items: center; margin-bottom: 19px; }
.video-icon { width: 66px; height: 45px; border: 2px solid currentColor; }
.video-icon i { width: 0; height: 0; margin: auto; border-top: 7px solid transparent; border-bottom: 7px solid transparent; border-left: 12px solid currentColor; }
.audio-icon { gap: 5px; align-items: center; }
.audio-icon i { display: block; width: 5px; background: currentColor; border-radius: 4px; }
.audio-icon i:nth-child(1) { height: 18px; }.audio-icon i:nth-child(2) { height: 42px; }.audio-icon i:nth-child(3) { height: 30px; }.audio-icon i:nth-child(4) { height: 48px; }
.text-icon { width: 68px; flex-direction: column; align-items: stretch; justify-content: center; gap: 9px; }
.text-icon i { height: 3px; background: currentColor; }.text-icon i:nth-child(2) { width: 78%; }.text-icon i:nth-child(3) { width: 90%; }
.format-name { display: block; color: var(--muted); font: 500 11px var(--font-mono); text-transform: uppercase; }
.format-card strong { display: block; margin: 4px 0 3px; font-size: 27px; letter-spacing: -.04em; }
.format-card small { color: var(--muted); font-size: 12px; }
.subtitle-icon { display: grid; place-items: center; border: 2px solid currentColor; font-size: 13px; font-weight: 900; letter-spacing: .04em; }
.subtitle-icon i { font-style: normal; }
.visual-icon { position: relative; overflow: hidden; border: 2px solid currentColor; }
.visual-icon::before { content: ""; position: absolute; width: 10px; height: 10px; border: 2px solid currentColor; border-radius: 50%; top: 8px; right: 8px; }
.visual-icon::after { content: ""; position: absolute; width: 42px; height: 30px; background: currentColor; transform: rotate(36deg); left: -8px; bottom: -19px; box-shadow: 25px -8px 0 currentColor; }
.summary-icon { width: 68px; flex-direction: column; align-items: stretch; justify-content: center; gap: 8px; }
.summary-icon i { height: 4px; background: currentColor; }
.summary-icon i:nth-child(1) { width: 100%; }
.summary-icon i:nth-child(2) { width: 72%; }
.summary-icon i:nth-child(3) { width: 88%; }

.options-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 24px; }
.select-control, .toggle-control { min-height: 66px; padding: 12px 15px; border: 1px solid var(--line); background: white; }
.select-control { display: flex; flex-direction: column; justify-content: center; gap: 5px; }
.select-control > span, .toggle-control strong { font-size: 11px; font-weight: 700; color: var(--muted); }
/* Ô nhập giãn kín phần còn lại của khung: trước đây vùng bấm thật chỉ cao 19px, nhãn
   chiếm hết chỗ — khó trúng trên mọi màn cảm ứng, không riêng điện thoại. */
.select-control select { width: 100%; flex: 1; min-height: 34px; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 13px; font-weight: 700; }
.select-control input { width: 100%; flex: 1; min-height: 34px; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 13px; font-weight: 700; }
.select-control small { color: var(--muted); font-size: 10px; line-height: 1.35; }
.select-control select:disabled { opacity: .48; cursor: not-allowed; }
.clip-options { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.clip-options > small { grid-column: 1 / -1; color: var(--muted); font-size: 10px; }
.toggle-control { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 20px; cursor: pointer; }
.toggle-control span { display: flex; flex-direction: column; gap: 3px; }
.toggle-control small { color: var(--muted); font-size: 10px; }
.toggle-control input { position: absolute; opacity: 0; }
.toggle-control > i { width: 42px; height: 24px; padding: 3px; flex: none; background: #bbb8af; border-radius: 20px; transition: background .2s; }
.toggle-control > i::after { content: ""; display: block; width: 18px; height: 18px; border-radius: 50%; background: white; transition: transform .2s; }
.toggle-control input:checked + i { background: var(--blue); }
.toggle-control input:checked + i::after { transform: translateX(18px); }

.download-button {
  width: 100%;
  height: 70px;
  margin-top: 22px;
  padding: 0 25px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: white;
  font-weight: 800;
  font-size: 17px;
  transition: background .2s, color .2s;
}

.download-button:hover { background: var(--coral); color: var(--ink); }
.download-button:disabled { opacity: .55; cursor: wait; }
.download-button svg { width: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.legal-note { margin: 10px 0 0; text-align: center; color: var(--muted); font-size: 11px; }

.job-panel { margin-top: 24px; padding: 22px; border: 1px solid var(--ink); background: #fff; }
.job-topline { display: flex; justify-content: space-between; font: 500 12px var(--font-mono); }
.progress-track { height: 8px; margin: 13px 0; background: #dfddd5; overflow: hidden; }
.progress-track i { display: block; width: 0; height: 100%; background: var(--blue); transition: width .3s; }
.job-panel p { margin: 0; color: var(--muted); font-size: 12px; }
.file-button { display: flex; justify-content: center; align-items: center; height: 48px; margin-top: 18px; color: var(--ink); background: var(--acid); border: 1px solid var(--ink); text-decoration: none; font-weight: 800; font-size: 13px; }

.result-preview { display: grid; gap: 10px; margin-top: 18px; }
.result-preview img,
.result-preview video { display: block; width: 100%; max-height: 420px; object-fit: contain; background: var(--ink); border: 1px solid var(--ink); }
.result-preview audio { width: 100%; height: 40px; }
.preview-text { max-height: 320px; margin: 0; padding: 14px 16px; overflow: auto; background: var(--panel); border: 1px solid var(--line); font: 400 12.5px/1.65 var(--font-mono); white-space: pre-wrap; word-break: break-word; }
.preview-copy { justify-self: start; padding: 7px 14px; background: transparent; border: 1px solid var(--ink); color: var(--ink); font: 600 12px var(--font-ui); cursor: pointer; }
.preview-copy:hover { background: var(--acid); }
.preview-note { margin: 0; color: var(--muted); font: 400 11px var(--font-mono); }

.how-it-works { display: grid; grid-template-columns: .8fr 1.2fr; gap: 80px; padding: 110px 0; }
.how-title > span { font: 500 12px var(--font-mono); color: var(--muted); }
.how-title h2 { margin: 20px 0 0; font-size: clamp(38px, 4vw, 60px); line-height: 1; letter-spacing: -.055em; }
.how-it-works ol { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--ink); }
.how-it-works li { display: grid; grid-template-columns: 150px 1fr; align-items: center; min-height: 96px; border-bottom: 1px solid var(--line); }
.how-it-works li strong { font-size: 20px; }
.how-it-works li span { color: var(--muted); line-height: 1.5; }

footer { width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: 30px 0 40px; display: flex; justify-content: space-between; border-top: 1px solid var(--line); color: var(--muted); font: 400 11px var(--font-mono); }
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 50; max-width: min(520px, calc(100% - 32px)); padding: 14px 18px; background: var(--ink); color: white; font-size: 13px; opacity: 0; transform: translate(-50%, 16px); pointer-events: none; transition: .25s; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #a9291c; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

[hidden] { display: none !important; }

@keyframes reveal { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }
@keyframes draw-line { to { transform: rotate(-1deg) scaleX(1); } }

/* Tên file kết quả có thể dài cả trăm ký tự (tiêu đề video), nên nút tải phải xuống
   dòng được thay vì đẩy ngang ra khỏi khung. */
.file-button {
  height: auto;
  min-height: 48px;
  padding: 12px 16px;
  text-align: center;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

/* Laptop nhỏ: vòng tròn nền tảng thu lại theo tỉ lệ (các huy hiệu bên trong định vị
   tuyệt đối nên phải scale cả cụm, không được đổi width). */
@media (max-width: 1080px) {
  .platform-orbit { transform: scale(.85); transform-origin: right center; }
  .hero { gap: 32px; }
  .workbench-main { padding: 40px 38px 44px; }
}

@media (max-width: 960px) {
  .platform-orbit { transform: scale(.72); }
  .how-it-works { gap: 48px; padding: 90px 0; }
}

@media (max-width: 820px) {
  .topbar, main, footer { width: min(100% - 28px, 680px); }
  .topbar { height: 74px; gap: 14px; }
  /* Trạng thái do JS ghi (public hay chạy nội bộ) — chỉ cắt bớt khi hẹp, không thay
     bằng chữ cứng, vì trước đây bản public vẫn hiện "Local" trên điện thoại. */
  .local-status { min-width: 0; }
  .local-status span { flex: none; }
  .hero { min-height: auto; grid-template-columns: 1fr; padding: 48px 0; }
  .platform-orbit { display: none; }
  .workbench { grid-template-columns: 1fr; min-width: 0; }
  .step-index { display: none; }
  .workbench-main { padding: 30px 24px 32px; }
  /* Máy tính bảng vẫn đủ chỗ cho 2 cột: ép 1 cột là phí nửa màn hình. */
  .format-grid { grid-template-columns: repeat(2, 1fr); }
  .how-it-works { grid-template-columns: 1fr; gap: 42px; padding: 80px 0; }
}

@media (max-width: 640px) {
  .format-grid { grid-template-columns: 1fr; }
  .format-card {
    min-height: 122px;
    display: grid;
    grid-template-columns: 78px 1fr;
    grid-template-rows: repeat(3, auto);
    align-content: center;
    column-gap: 15px;
  }
  .format-icon { grid-row: 1 / 4; margin: 0; align-self: center; }
  .format-name, .format-card strong, .format-card small { grid-column: 2; }
  .options-row { grid-template-columns: 1fr; }
  .clip-options { grid-template-columns: 1fr; }
  .clip-options > small { grid-column: 1; }
  .hero-copy > p { margin-top: 28px; font-size: 16px; }
  .url-row { flex-direction: column; }
  .url-field { flex: none; height: 58px; }
  .analyze-button { height: 50px; }
  .preview { grid-template-columns: 1fr; }
  .preview-image { aspect-ratio: 16/9; }
  .format-head { align-items: flex-start; }
  .format-note { display: none; }
  /* iOS phóng to cả trang khi focus vào ô chữ nhỏ hơn 16px — nguồn gốc của cảm giác
     "nhảy layout" khi gõ trên iPhone. */
  .url-field input,
  .select-control select,
  .select-control input { font-size: 16px; }
  .select-control { min-height: 62px; }
  .select-control select,
  .select-control input { min-height: 38px; }
  .how-it-works li { grid-template-columns: 1fr; align-items: start; gap: 4px; padding: 18px 0; min-height: 0; }
  footer { flex-direction: column; gap: 10px; text-align: left; }
}

@media (max-width: 400px) {
  .topbar, main, footer { width: calc(100% - 20px); }
  .workbench-main { padding: 24px 16px 26px; }
  .job-panel { padding: 16px; }
  .format-card { padding: 18px 16px; grid-template-columns: 62px 1fr; column-gap: 12px; }
  .format-card strong { font-size: 23px; }
  .download-button { height: 62px; padding: 0 18px; font-size: 15px; }
  .brand span:last-child { font-size: 17px; }
  .local-status { font-size: 10px; }
}

/* Điện thoại xoay ngang: chiều cao rất thấp, cắt bớt khoảng đệm dọc để phần thao tác
   không bị đẩy xuống quá sâu. */
@media (max-height: 460px) and (orientation: landscape) {
  .hero { padding: 26px 0; min-height: auto; }
  .how-it-works { padding: 48px 0; }
  .topbar { height: 60px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
