:root {
  --bg: #0d1219;
  --panel: #141b25;
  --panel-2: #1a2330;
  --line: #26303f;
  --text: #e8ecf2;
  --muted: #93a0b3;
  --accent: #fabb14;
  --accent-2: #ff7a1a;
  --danger: #ff6b6b;
  --radius: 14px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: radial-gradient(1200px 700px at 50% -10%, #1a2130 0%, var(--bg) 55%);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px clamp(16px, 4vw, 32px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
  background: rgba(13, 18, 25, .82);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.mark {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 0 1px #ffffff14, 0 4px 14px #fabb1433;
}
.wordmark { font-size: 17px; letter-spacing: .2px; }
.wordmark b { color: var(--accent); font-weight: 700; }
.health {
  font-size: 13px; color: var(--muted); display: inline-flex;
  align-items: center; gap: 7px; white-space: nowrap;
}
.health::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: #4b5768;
}
.health.ok::before { background: #3ddc84; box-shadow: 0 0 8px #3ddc8480; }
.health.bad::before { background: var(--danger); }

.top-right { display: flex; align-items: center; gap: 12px; }
.signout {
  font: inherit; font-size: 13px; color: var(--muted); cursor: pointer;
  background: transparent; border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 11px;
}
.signout:hover { color: var(--text); border-color: #3a4557; }

/* ---------- layout ---------- */
.wrap {
  flex: 1; width: 100%; max-width: 1060px; margin: 0 auto;
  padding: clamp(16px, 4vw, 30px);
  display: grid; gap: 20px; align-content: start;
}
@media (min-width: 900px) {
  .wrap { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .wrap:has(.result[hidden]) { grid-template-columns: minmax(0, 620px); justify-content: center; }
  .wrap:has(.gate:not([hidden])) { grid-template-columns: minmax(0, 460px); justify-content: center; }
}
.gate { align-self: center; }
.gate input {
  font-size: 17px; letter-spacing: 1.2px; text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(16px, 3.4vw, 26px);
}

h1 { font-size: clamp(20px, 3.6vw, 25px); margin: 0 0 6px; letter-spacing: -.2px; }
.lead { margin: 0 0 20px; color: var(--muted); font-size: 14.5px; }

/* ---------- form ---------- */
.field { margin-bottom: 16px; min-width: 0; }
.field label {
  display: block; margin-bottom: 7px; font-size: 13.5px;
  font-weight: 600; color: #c6cfdc;
}
.opt { font-weight: 400; color: var(--muted); }
.hint { display: block; margin-top: 6px; color: var(--muted); font-size: 12.5px; }
.hint b { color: #c6cfdc; }

textarea, input[type=text], select {
  width: 100%; padding: 11px 13px; font: inherit; font-size: 15px;
  color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 62px; }
select { appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, #8892a3 50%),
                    linear-gradient(135deg, #8892a3 50%, transparent 50%);
  background-position: right 16px center, right 11px center;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
  padding-right: 34px;
}
textarea:focus, input:focus, select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px #fabb1426;
}

.row { display: grid; gap: 14px; }
@media (min-width: 520px) { .row { grid-template-columns: 1fr 1fr; } }

/* ---------- vùng thả ảnh ---------- */
.drop {
  position: relative; display: grid; place-items: center;
  min-height: 168px; padding: 16px; cursor: pointer;
  background: var(--panel-2);
  border: 1.5px dashed #33415a; border-radius: 12px;
  transition: border-color .15s, background .15s;
  overflow: hidden;
}
.drop:hover, .drop:focus-visible, .drop.over {
  border-color: var(--accent); background: #1c2534; outline: none;
}
.drop-hint {
  display: grid; justify-items: center; gap: 5px;
  color: var(--muted); text-align: center;
}
.drop-hint span { font-size: 14.5px; color: #c6cfdc; }
.drop-hint small { font-size: 12px; }
.thumbs {
  display: grid; gap: 8px; width: 100%;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
}
.thumb { position: relative; aspect-ratio: 1; border-radius: 9px; overflow: hidden;
  background: #0f151f; border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .n {
  position: absolute; left: 5px; top: 5px; min-width: 19px; height: 19px;
  border-radius: 5px; background: #000000b0; color: #fff;
  font-size: 11.5px; font-weight: 700; display: grid; place-items: center;
  padding: 0 4px;
}
.thumb .x {
  position: absolute; right: 4px; top: 4px; width: 21px; height: 21px;
  border: 0; border-radius: 50%; cursor: pointer; padding: 0;
  background: #000000b8; color: #fff; font-size: 15px; line-height: 1;
  display: grid; place-items: center;
}
.thumb .x:hover { background: var(--danger); }

/* ---------- công tắc ---------- */
.toggles { display: flex; flex-wrap: wrap; gap: 10px 22px; margin: 4px 0 20px; }
.switch {
  display: inline-flex; align-items: center; gap: 9px;
  font-size: 14px; cursor: pointer; user-select: none; color: #c6cfdc;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span {
  width: 40px; height: 23px; border-radius: 999px; flex: none;
  background: #303c4e; position: relative; transition: background .18s;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 17px; height: 17px; border-radius: 50%; background: #97a3b5;
  transition: transform .18s, background .18s;
}
.switch input:checked + span { background: #6b5410; }
.switch input:checked + span::after { transform: translateX(17px); background: var(--accent); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px #fabb1426; }

/* ---------- nút ---------- */
.go, .btn {
  font: inherit; font-size: 15px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 18px; cursor: pointer; text-decoration: none;
  color: var(--text); background: var(--panel-2);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: filter .15s, transform .06s;
}
.go {
  width: 100%; padding: 14px; border: 0; color: #1a1305;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.go:disabled { filter: grayscale(.7) brightness(.7); cursor: not-allowed; }
.btn:hover, .go:hover:not(:disabled) { filter: brightness(1.12); }
.go:active, .btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a1305; border: 0; }
.btn.fb { background: #1877f2; border-color: #1877f2; color: #fff; }
.btn.tt { background: #000; border-color: #3a3a3a; color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); }

.err { color: var(--danger); font-size: 14px; margin: 12px 0 0; }

/* ---------- tiến độ ---------- */
.progress { display: grid; justify-items: center; gap: 14px; text-align: center; }
.ring { position: relative; width: 132px; height: 132px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; stroke-linecap: round; }
.ring-bg { stroke: #26303f; }
.ring-fg {
  stroke: url(#g); stroke: var(--accent);
  stroke-dasharray: 327; stroke-dashoffset: 327;
  transition: stroke-dashoffset .45s ease;
}
.pct {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 25px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.stage { margin: 0; font-size: 16px; font-weight: 600; }
.steps {
  list-style: none; margin: 4px 0 0; padding: 0;
  display: grid; gap: 8px; width: 100%; max-width: 300px; text-align: left;
}
.steps li {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; color: var(--muted);
}
.steps li::before {
  content: ""; width: 16px; height: 16px; border-radius: 50%; flex: none;
  border: 2px solid #3a4557; transition: all .2s;
}
.steps li.active { color: var(--text); }
.steps li.active::before { border-color: var(--accent); box-shadow: 0 0 0 3px #fabb1426; }
.steps li.ok { color: #9fb0c4; }
.steps li.ok::before {
  border-color: #3ddc84; background: #3ddc84;
  box-shadow: inset 0 0 0 2px var(--panel);
}
.note { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }

/* ---------- kết quả ---------- */
.done { display: grid; gap: 16px; justify-items: center; }
#player {
  width: 100%; max-width: 330px; border-radius: 12px;
  background: #000; aspect-ratio: 9 / 16; object-fit: contain;
}
.actions { display: flex; flex-wrap: wrap; gap: 9px; justify-content: center; }
.tip {
  margin: 0; font-size: 13px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 13px; text-align: left;
}
.failed { text-align: center; display: grid; gap: 12px; justify-items: center; }
.failed h2 { margin: 0; font-size: 18px; }

/* ---------- chân trang ---------- */
.foot {
  padding: 18px; text-align: center; font-size: 13px; color: var(--muted);
  border-top: 1px solid var(--line);
}
.foot a { color: var(--accent); text-decoration: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
