:root {
  --bg: #0F1714; --surface: #18221E; --surface2: #212D28; --border: #2C3A34;
  --text: #EEF3EF; --muted: #9BAAA3; --accent: #C5F04A; --accent-ink: #0F1714;
  --warn: #F2A33A; --info: #6FB3FF; --low: #8A9791;
  --radius: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px; background: rgba(15,23,20,.92); border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; letter-spacing: .2px; }
.brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: var(--muted); text-decoration: none; padding: 10px 12px; border-radius: 10px; font-weight: 500; font-size: 14px; }
.topbar nav a.on, .topbar nav a:hover { color: var(--text); background: var(--surface); }
main { max-width: 1120px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 24px; margin: 4px 0 6px; }
h2 { font-size: 16px; margin: 0 0 10px; }
p { line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface2); cursor: pointer; font-weight: 600;
  text-decoration: none; color: var(--text); font-size: 14px; }
.btn:hover { border-color: #4A5C54; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; padding: 4px; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 8px 14px; border-radius: 9px; font-weight: 600; cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
input[type=text], input[type=number], input[type=password], select { height: 46px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); padding: 0 14px; font-size: 16px; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.45; color: #C9D3CE; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 9px;
  border-radius: 7px; background: var(--surface2); color: var(--muted); white-space: nowrap; }
.pill.cao { color: var(--accent); } .pill.TB { color: #E8C48E; } .pill.thap, .pill.none { color: var(--low); }
.dot { width: 10px; height: 10px; border-radius: 5px; flex-shrink: 0; display: inline-block; }
.dot.ok { background: var(--accent); } .dot.bad { background: var(--warn); } .dot.na { background: #5E6B66; }
.warn { border-color: #5A4220; background: #2A2113; }
.warn-text { color: #E8C48E; }
.info { border-color: #24405E; background: #13202C; }
.list { display: flex; flex-direction: column; gap: 10px; }
.item { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--border); text-decoration: none; color: var(--text); }
.item .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.item .title { font-weight: 600; font-size: 14px; }
.cp { align-items: flex-start; }
.cp .fb { display: flex; gap: 6px; }
.stage { position: relative; background: #16201C; border: 1px solid var(--border); border-radius: 16px; overflow: hidden;
  aspect-ratio: 3 / 4; width: min(100%, calc(72vh * 0.75)); margin: 0 auto; touch-action: none; }
.stage video, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage video { object-fit: contain; background: #000; }
.stage .tag { position: absolute; left: 10px; top: 10px; font-size: 12px; font-weight: 600; padding: 5px 9px; border-radius: 8px;
  background: rgba(15,23,20,.85); color: #C9D3CE; pointer-events: none; }
.stage .tools { position: absolute; right: 8px; top: 8px; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.legend { position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px;
  color: #C9D3CE; padding: 8px 10px; border-radius: 10px; background: rgba(15,23,20,.88); pointer-events: none; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.controls input[type=range] { flex: 1; min-width: 160px; accent-color: var(--accent); }
.phases { display: flex; gap: 6px; flex-wrap: wrap; }
.phases button { min-height: 38px; padding: 0 14px; border-radius: 19px; border: 1px solid var(--border); background: transparent;
  color: var(--muted); font-weight: 600; cursor: pointer; font-size: 13px; }
.phases button.on { border-color: var(--accent); background: var(--surface2); color: var(--text); }
.fault { border-color: #5A4220; background: #2A2113; }
.fault .label { color: var(--warn); font-size: 12px; font-weight: 700; letter-spacing: .4px; }
.infer { display: flex; flex-direction: column; gap: 4px; padding: 10px; border-radius: 10px; background: rgba(15,23,20,.5); font-size: 13px; line-height: 1.5; color: #C9D3CE; }
.infer b { color: var(--info); flex-shrink: 0; }
.progress { height: 8px; border-radius: 4px; background: var(--surface2); overflow: hidden; }
.progress div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--surface2); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.test { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 12px; border: 1px solid var(--border); }
.empty { text-align: center; padding: 30px 16px; }
svg text { font-family: inherit; }


/* ---------- Màn hình cú đánh (ưu tiên điện thoại) ---------- */
.swing { display: flex; flex-direction: column; gap: 14px; }
.swing-head { display: flex; gap: 10px; align-items: flex-start; }
.swing-head .grow { flex: 1; min-width: 0; }
.swing-head h1 { font-size: 20px; line-height: 1.3; margin: 0 0 4px; }
.ghostbtn { width: 40px; padding: 0; font-size: 18px; }
.warns { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.warns summary { cursor: pointer; color: #E8C48E; font-weight: 600; }
.warns div { margin-top: 6px; line-height: 1.45; }
.viewer { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.modes { width: 100%; max-width: 520px; }
.modes button { flex: 1; min-height: 40px; font-size: 14px; }
#stage { height: clamp(320px, calc(100vh - 330px), 80vh); width: auto; max-width: 100%; margin: 0; }
#stage .layer { position: absolute; inset: 0; }
.stage video { transform-origin: 0 0; }
.camchips { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 4px; }
.camchips button, .chips button { border: 1px solid var(--border); background: rgba(15,23,20,.85); color: var(--muted);
  font-weight: 600; font-size: 12px; border-radius: 16px; padding: 0 12px; min-height: 32px; cursor: pointer; white-space: nowrap; }
.chips { display: flex; gap: 6px; overflow-x: auto; width: 100%; max-width: 760px; padding: 2px 2px 4px; scrollbar-width: none; justify-content: safe center; }
.chips::-webkit-scrollbar { display: none; }
.chips button { background: var(--surface); min-height: 32px; font-size: 13px; }
.chips button.on { border-color: var(--accent); color: var(--text); background: var(--surface2); }
.chips button.on::before { content: "● "; color: var(--accent); font-size: 10px; }
.dock { position: sticky; bottom: 0; z-index: 5; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px;
  background: rgba(24,34,30,.96); border: 1px solid var(--border); border-radius: 16px; backdrop-filter: blur(8px); }
.dock .phases { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.dock .phases::-webkit-scrollbar { display: none; }
.dock .phases button { flex: 1 0 auto; min-height: 34px; }
.transport { display: flex; gap: 8px; align-items: center; }
.transport input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); height: 32px; }
.transport .btn.small { min-width: 40px; padding: 0 8px; }
.playbtn { width: 46px; height: 46px; border-radius: 23px; border: 0; background: var(--accent); color: var(--accent-ink);
  font-size: 17px; font-weight: 700; cursor: pointer; flex-shrink: 0; }
#stage .tag { left: 8px; top: 8px; }

@media (max-width: 720px) {
  main { padding: 12px 10px 92px; }
  h1 { font-size: 21px; }
  .topbar { padding: 10px 14px; backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); }
  /* thanh điều hướng thành thanh tab dưới đáy, dễ bấm bằng ngón cái */
  .topbar nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; justify-content: space-around; gap: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: rgba(15,23,20,.97); border-top: 1px solid var(--border); }
  .topbar nav a { flex: 1; text-align: center; padding: 10px 4px; font-size: 13px; }
  .dock { bottom: calc(62px + env(safe-area-inset-bottom)); border-radius: 14px; }
  /* khung xem vừa đủ để không bị thanh phát che: chừa tiêu đề + thanh phát + thanh tab */
  #stage { height: clamp(300px, calc(100svh - 430px), 70vh); width: auto; max-width: 100%; }
  .swing { gap: 10px; }
  .swing-head h1 { font-size: 17px; }
  .modes button { min-height: 34px; padding: 6px 10px; }
  .warns { padding: 8px 10px; }
  .camchips button { padding: 0 9px; }
}

/* ---------- gọn (lean) ---------- */
.lean { max-width: 720px; margin: 0 auto; gap: 12px; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pagehead h1 { margin: 0; }
.lean .item { padding: 12px 14px; }
.lean .card { padding: 14px; }
.swing { max-width: 960px; margin: 0 auto; }
