:root {
  --sky-top: #141836;
  --sky-low: #33397a;
  --window: #f5b841;
  --window-ink: #2a1d00;
  --ink: #1d2140;
  --muted: #5b6283;
  --paper: #eceef3;
  --surface: #ffffff;
  --line: #d6d9e3;
  --ok: #23845a;
  --danger: #c43d2b;
  --radius-lg: 18px;
  --radius-sm: 10px;
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --ink: #e8eaf5;
    --muted: #a0a7c8;
    --paper: #10132a;
    --surface: #1a1e3c;
    --line: #2c3163;
    --ok: #4fc58f;
    --danger: #ff7a66;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --ink: #e8eaf5;
  --muted: #a0a7c8;
  --paper: #10132a;
  --surface: #1a1e3c;
  --line: #2c3163;
  --ok: #4fc58f;
  --danger: #ff7a66;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--window); outline-offset: 2px; }

/* ---------- bảng tình trạng ---------- */
.panel {
  padding: 18px 16px 120px;
  max-width: 720px;
  margin: 0 auto;
}
.panel h2 {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 28px 0 10px;
}

.systems {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.system {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.3;
}
.system .ic { font-size: 20px; }
.system b { display: block; font-weight: 600; }
.system .st { color: var(--muted); }
.system.bad { border-color: currentColor; }
.system.bad .st { color: var(--danger); font-weight: 600; }

.reports { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.report {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 14px 16px 12px;
  border-left: 6px solid var(--cat, var(--muted));
}
.report.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--window); } to { box-shadow: 0 0 0 3px transparent; } }
.r-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.r-title { font-weight: 800; font-size: 17px; margin: 0; }
.r-where { color: var(--muted); font-size: 15px; }
.r-note { margin: 6px 0 0; overflow-wrap: anywhere; }
.r-meta { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.r-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.r-actions button {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  cursor: pointer;
  min-height: 38px;
}
.r-actions button[aria-pressed='true'] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.r-actions button:disabled { opacity: 0.5; cursor: default; }
.r-actions .hide-btn { margin-left: auto; color: var(--danger); border-color: currentColor; }
.done .report { opacity: 0.72; border-left-color: var(--ok); }
.done .r-title::before { content: '✓ '; color: var(--ok); }

.empty {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  color: var(--muted);
}
.empty p { margin: 0; }

.foot {
  margin-top: 40px;
  font-size: 13px;
  color: var(--muted);
  max-width: 60ch;
}
.foot p { margin: 0 0 8px; }
.foot strong { color: var(--ink); }

.fab {
  position: fixed;
  right: 16px;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 10;
  border: 0;
  border-radius: 999px;
  padding: 15px 24px;
  font-weight: 800;
  font-size: 16px;
  background: var(--window);
  color: var(--window-ink);
  box-shadow: 0 10px 30px rgba(245, 184, 65, 0.35), 0 2px 6px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}
.fab::before { content: '+ '; }

/* ---------- hộp thoại dạng sheet ---------- */
.sheet {
  border: 0;
  padding: 0;
  width: min(560px, 100vw);
  max-width: 100vw;
  max-height: 92vh;
  margin: auto auto 0;
  border-radius: 22px 22px 0 0;
  background: var(--paper);
  color: var(--ink);
}
@media (min-width: 700px) {
  .sheet { margin: auto; border-radius: 22px; }
}
.sheet::backdrop { background: rgba(10, 12, 40, 0.55); }
.sheet form { padding: 18px 16px max(20px, env(safe-area-inset-bottom)); }
.sheet[open] { animation: rise 0.22s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font-size: 21px; font-weight: 800; }
.x {
  border: 0; background: transparent; font-size: 28px; line-height: 1;
  width: 44px; height: 44px; cursor: pointer; color: var(--muted);
}
fieldset { border: 0; margin: 14px 0 0; padding: 0; }
legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.cats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cats button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--line);
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
  min-height: 64px;
}
.cats button span:first-child { font-size: 22px; }
.cats button[aria-pressed='true'] { border-color: var(--cat); box-shadow: inset 0 0 0 1px var(--cat); font-weight: 600; }
.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1;
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  min-height: 44px;
}
.seg button[aria-pressed='true'] { border-color: var(--ink); font-weight: 600; }
.field { display: grid; gap: 6px; margin-top: 14px; }
.field > span { font-weight: 600; }
.field em { font-style: normal; font-weight: 400; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 16px; /* tránh iOS tự zoom */
}
.field textarea { resize: vertical; }
.sheet p { color: var(--muted); }
.form-error { color: var(--danger) !important; min-height: 1.5em; margin: 10px 0 0; font-size: 14px; }
.primary {
  width: 100%;
  margin-top: 6px;
  border: 0;
  border-radius: 999px;
  padding: 14px;
  font-weight: 800;
  background: var(--window);
  color: var(--window-ink);
  cursor: pointer;
}
.primary:disabled { opacity: 0.6; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 30;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- máy tính: trời bên trái, bảng bên phải ---------- */
@media (min-width: 980px) {
  .layout { display: grid; grid-template-columns: 1.15fr 1fr; min-height: 100vh; }
  .sky { position: sticky; top: 0; height: 100vh; max-height: none; min-height: 560px; }
  .panel { max-width: none; width: 100%; padding: 24px 32px 120px; }
  .fab { right: 32px; }
}

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



/* ---------- tài khoản Zalo ---------- */
.top-right { display: inline-flex; align-items: center; gap: 10px; }
.account-slot { pointer-events: auto; display: inline-flex; }
.account-slot:empty { display: none; }
.login-btn {
  color: #fff;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  background: rgba(16, 19, 42, 0.6);
  white-space: nowrap;
}
.acc-btn { border: 0; padding: 0; background: none; cursor: pointer; border-radius: 50%; line-height: 0; }
.acc-btn .ava { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85); }
.ava { border-radius: 50%; object-fit: cover; flex: none; vertical-align: middle; background: var(--surface); }
.ava-txt {
  display: inline-grid;
  place-items: center;
  background: #5b6aa8;
  color: #fff;
  font-weight: 700;
  line-height: 1;
}
.r-meta .ava { margin-right: 6px; }
.acc-who { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.acc-who b { display: block; font-size: 17px; }
.acc-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.acc-actions .danger { color: var(--danger); border-color: currentColor; }
.small-btn {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 14px;
  cursor: pointer;
  min-height: 38px;
}
.hint { color: var(--muted); font-size: 13px; }

/* trang xác nhận đăng nhập Zalo (callback ở trình duyệt khác) */
.confirm { padding-top: 48px; }
.confirm h1 { font-size: 24px; font-weight: 800; }
.confirm a { color: var(--ink); }


/* ---------- phần mô hình 3D (Stratum, theme Night) ---------- */
.sky {
  position: relative;
  container: sky / inline-size; /* HUD xếp theo bề rộng vùng mô hình (ở màn rộng nó chỉ chiếm nửa trái) */
  height: min(76vh, 640px);
  min-height: 460px;
  background: var(--ground-void);
  overflow: hidden;
  color: var(--ink-strong);
}
#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: pan-y; /* cuộn dọc trang vẫn được trên điện thoại */
  cursor: grab;
}
.sky.is-grabbing #scene { cursor: grabbing; }
.sky-top {
  position: absolute;
  top: max(var(--space-4), env(safe-area-inset-top));
  left: var(--space-4);
  right: var(--space-4);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: var(--z-hud);
}
.sky .brand { white-space: nowrap; }
.sky .live { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--ink-muted); font: 500 12px/16px var(--font-text); white-space: nowrap; }
.sky .dot { width: 6px; height: 6px; border-radius: var(--st-radius-full); background: var(--line-strong); }
.sky .live.on .dot { background: var(--signal-ok); }
.sky-tabs { position: absolute; top: 60px; left: var(--space-4); z-index: var(--z-hud); }
.sky .login-btn { color: var(--ink-strong); border-color: var(--line-strong); background: var(--ground-panel); border-radius: var(--st-radius-md); }
.sky-bottom {
  position: absolute;
  left: var(--space-4);
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: var(--z-hud);
  pointer-events: none;
}
.sky-bottom h1 { margin: 0; max-width: 16em; text-wrap: balance; }
.sky-bottom .subline { margin: var(--space-1) 0 0; color: var(--ink-muted); max-width: 34em; }
.sky-bottom .hint { margin: var(--space-2) 0 0; color: var(--ink-muted); }
.sky-bottom .st-btn { pointer-events: auto; margin-top: var(--space-2); }
.sky.panel-open .sky-bottom { display: none; }

/* HUD đặt trên mô hình */
.hud-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; overflow: visible; }
.hud-sel { fill: var(--holo-soft); stroke: var(--holo); stroke-width: var(--stroke-select); stroke-linejoin: round; filter: drop-shadow(0 0 10px var(--holo-glow)); }
.hud-sel:not([points]) { display: none; }
.hud-leader { stroke: var(--holo); stroke-width: var(--stroke-hair); }
.hud-leader-dot { fill: var(--holo-core); filter: drop-shadow(0 0 4px var(--holo-glow)); }
.hud-markers { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.hud-marker { position: absolute; left: 0; top: 0; pointer-events: auto; }
.hud-rail { position: absolute; left: var(--space-4); top: 112px; z-index: var(--z-hud); max-height: 60%; }
.sky .hud-rail .rail-blocks { display: flex; width: 52px; margin-bottom: var(--space-1); }
.sky .hud-rail .rail-blocks .st-btn { width: 26px; height: 28px; padding: 0; font-family: var(--font-mono); font-size: 11px; color: var(--ink-muted); border: var(--stroke-hair) solid var(--line-soft); background: var(--ground-panel); }
.sky .hud-rail .rail-blocks .st-btn[aria-pressed='true'] { color: var(--holo); border-color: var(--holo); background: linear-gradient(var(--holo-soft), var(--holo-soft)), var(--ground-panel); }
.hud-rail .rail-list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; min-height: 0; scrollbar-width: thin; scrollbar-color: var(--line-soft) transparent; }
.hud-rail { display: flex; flex-direction: column; }
.hud-tools { position: absolute; right: var(--space-4); top: 60px; z-index: var(--z-hud); }
.hud-panel { position: absolute; left: 0; top: 0; z-index: var(--z-panel); }
.hud-panel[hidden] { display: none; }
.hud-panel-block { margin: 0 0 2px; color: var(--ink-muted); }
.hud-panel-head-right { display: inline-flex; align-items: center; gap: var(--space-1); }
.hud-panel-head-right .st-btn--icon { width: 28px; height: 28px; color: var(--ink-muted); }
.hud-panel-cats { margin: var(--space-3) 0 0; color: var(--ink-muted); }
.hud-panel-cta { width: 100%; margin-top: var(--space-3); }

/* Vùng mô hình hẹp (điện thoại, hoặc nửa trái màn rộng): thanh camera xuống hàng dưới thanh chuyển trang */
@container sky (max-width: 660px) {
  .hud-tools { top: 108px; }
}

/* Thanh tầng: màn rộng luôn mở; điện thoại thu gọn thành nút "Tầng", nhấn mới mở */
.sky.stratum .hud-rail .rail-toggle { display: none; }
@media (max-width: 560px) {
  .sky.stratum .hud-rail .rail-toggle { display: inline-flex; height: 40px; font-family: var(--font-mono); font-size: 11px; color: var(--ink-strong); white-space: nowrap; }
  .sky.stratum .hud-rail .rail-toggle[aria-expanded='true'] { color: var(--holo); }
  .hud-rail:not(.is-open) .rail-blocks, .hud-rail:not(.is-open) .rail-list { display: none; }
  .hud-rail.is-open .rail-toggle { margin-bottom: var(--space-1); }
}

/* Không chạy được WebGL: chỉ giữ tiêu đề */
.sky.no-3d { height: auto; min-height: 0; padding: 104px 0 var(--space-4); }
.sky.no-3d #scene { display: none; }
.sky.no-3d .sky-bottom { position: static; padding: 0 var(--space-4); }
@media (min-width: 980px) {
  .sky { height: 100vh; max-height: none; min-height: 560px; }
}

/* ---------- thông báo đẩy ---------- */
.notify {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line);
}
.notify[hidden] { display: none; }
.notify-text { flex: 1; min-width: 0; font-size: 14px; line-height: 1.4; }
.notify-text b { display: block; font-size: 15px; }
.notify-text span { color: var(--muted); }
.notify.on { border-color: var(--ok); }
.notify-guide { background: var(--surface); border-radius: var(--radius-sm); padding: 10px 12px; color: var(--ink) !important; font-size: 14px; }
.check { display: flex; align-items: flex-start; gap: 10px; margin-top: 10px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; flex: none; }
.acc-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.acc-actions .danger { color: var(--danger); border-color: currentColor; }
