:root {
  --bg: #0a0f1f;
  --panel: rgba(17, 25, 50, 0.94);
  --line: #2a3a63;
  --ink: #e8ecf7;
  --muted: #9aa6c4;
  --gold: #ffcc4e;
  --ok: #34d399;
  --bad: #f87171;
  --teal: #2dd4bf;
  --left-w: 290px;
  --right-w: 330px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #1a2347 0%, var(--bg) 70%);
  color: var(--ink);
  font: 16px/1.5 'Be Vietnam Pro', system-ui, sans-serif;
}

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#leaders { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#labels { position: fixed; inset: 0; pointer-events: none; }

.panel {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

h2, h3 { margin: 14px 0 6px; font-size: 12.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h2:first-child { margin-top: 0; }

.title { top: 16px; left: 16px; width: var(--left-w); padding: 12px 18px; }
.title .tag { color: var(--gold); font-size: 13px; font-weight: 600; letter-spacing: .04em; }
.title h1 { margin: 2px 0 0; font-size: 21px; }

.lab {
  top: 100px; left: 16px; width: var(--left-w); padding: 14px 16px;
  max-height: calc(100vh - 100px - 48px); overflow-y: auto;
}
.desc { margin: 8px 0 0; font-weight: 600; font-size: 15px; }
.scenarios { display: flex; flex-direction: column; gap: 6px; }
.scn {
  font: inherit; font-size: 14.5px; text-align: left; color: var(--ink);
  background: rgba(10, 15, 31, 0.5); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; cursor: pointer;
}
.scn:hover { border-color: var(--gold); }
.scn.on { border-color: var(--gold); background: rgba(255, 204, 78, 0.12); }
.scnbox { margin-top: 10px; padding-left: 10px; border-left: 3px solid var(--gold); font-size: 14.5px; }
.scnbox p { margin: 0 0 6px; }
.scnbox summary, .assume summary { cursor: pointer; font-weight: 600; }
.assume { margin-top: 14px; font-size: 13.5px; color: var(--muted); }
.assume ul { padding-left: 18px; margin: 6px 0 0; }

.controls {
  top: 16px; right: 16px; width: var(--right-w); padding: 14px 16px;
  max-height: calc(100vh - 32px - 30px); overflow-y: auto;
}
.row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 4px; }
.row b { color: var(--gold); }
.row.ends { font-size: 14px; color: var(--muted); }

input[type=range] { width: 100%; accent-color: var(--gold); height: 26px; }
input[type=range]:disabled { opacity: 0.5; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  font: inherit; font-size: 14.5px;
  color: var(--ink); background: transparent;
  border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 12px; cursor: pointer;
}
.chip:hover { border-color: var(--gold); }
.chip.on { background: var(--gold); border-color: var(--gold); color: #0a0f1f; font-weight: 600; }

.lensbox { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.vrow { display: flex; flex-direction: column; margin-top: 6px; font-size: 14px; }
.vrow .chips { margin-top: 4px; }
.hint2 { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.msg { margin: 8px 0 0; font-size: 14px; font-weight: 600; color: var(--gold); min-height: 1em; }
.msg:empty { display: none; }
.sub { margin: 10px 0 2px; font-size: 14px; }
.pump { display: grid; grid-template-columns: 60px 1fr; gap: 12px; align-items: center; margin-top: 10px; }
.pump svg { width: 60px; height: 110px; }
.big { font-size: 20px; color: var(--gold); }
.chart { width: 100%; height: 70px; display: block; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; }
.dot.rich { background: #e3242b; }
.dot.poor { background: #5563e0; }

.phase { margin-top: 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.bar { position: relative; display: flex; height: 10px; border-radius: 5px; overflow: hidden; }
.bar span { display: block; height: 100%; }
.bar i { position: absolute; top: -2px; width: 3px; height: 14px; background: #fff; border-radius: 2px; }
.phase p { margin: 8px 0 6px; font-weight: 600; min-height: 48px; }
.phase dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 14px; color: var(--muted); }
.phase dd { margin: 0; font-weight: 600; }
.phase dd.open { color: var(--ok); }
.phase dd.shut { color: var(--bad); }

.card {
  left: 50%; bottom: 44px; transform: translateX(calc(-50% + (var(--left-w) - var(--right-w)) / 2));
  width: min(440px, calc(100vw - var(--left-w) - var(--right-w) - 80px)); padding: 12px 16px;
}
.card h3 { margin: 0 0 4px; color: var(--gold); font-size: 19px; text-transform: none; letter-spacing: 0; }
.card p { margin: 0; }

.hint { position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%); margin: 0; color: var(--muted); font-size: 14px; pointer-events: none; }

.label {
  position: absolute; white-space: nowrap;
  font-size: 15px; font-weight: 600;
  padding: 3px 10px; border-radius: 6px;
  background: rgba(10, 15, 31, 0.85); border: 1px solid var(--c, #888);
  transform: translateY(-50%);
}

.modal { position: fixed; inset: 0; background: rgba(5, 8, 18, 0.7); display: grid; place-items: center; z-index: 10; }
.modal[hidden] { display: none; }
.sheet { position: relative; width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; padding: 18px 22px; }
.sheet h2 { color: var(--gold); font-size: 15px; }
.sheet .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.sheet table { width: 100%; border-collapse: collapse; font-size: 14px; }
.sheet th, .sheet td { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; }
.sheet th { color: var(--muted); font-weight: 500; }
.sheet .plot { width: 100%; height: auto; margin-top: 8px; }
.sheet textarea { width: 100%; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.notes { padding-left: 18px; font-size: 14px; }
.notes small { color: var(--muted); }
.close { position: absolute; top: 10px; right: 12px; font: inherit; font-size: 22px; color: var(--ink); background: none; border: 0; cursor: pointer; }

#loading { position: fixed; inset: 0; display: grid; place-items: center; font-size: 18px; color: var(--muted); pointer-events: none; }

.credit { position: fixed; bottom: 8px; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--muted); pointer-events: none; }

#view { touch-action: none; }
.fab, .msheet { display: none; }

/* ---------- Điện thoại (xem mobile.js) ---------- */
body.mobile { --sheet-h: 176px; }
body.mobile.sheet-open { --sheet-h: 58vh; }
.mobile .title {
  top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left));
  width: auto; padding: 6px 12px; border-radius: 10px;
}
.mobile .title .tag { font-size: 11px; }
.mobile .title h1 { font-size: 16px; }
.mobile .hint { top: calc(max(8px, env(safe-area-inset-top)) + 52px); bottom: auto; font-size: 12px; width: max-content; max-width: calc(100vw - 32px); text-align: center; }
.mobile .label { font-size: 12px; padding: 1px 6px; }

.mobile .fab {
  display: block; position: fixed; z-index: 3;
  top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right));
  width: 44px; height: 44px; border-radius: 50%;
  font: inherit; font-size: 16px; color: #0a0f1f; background: var(--gold); border: 0; cursor: pointer;
}
.mobile .msheet {
  display: flex; flex-direction: column; position: fixed; z-index: 2;
  left: 0; right: 0; bottom: 0; height: var(--sheet-h);
  background: var(--panel); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  transition: height .25s ease, transform .25s ease;
}
.mtabs { display: flex; gap: 6px; padding: 8px 10px 6px; border-bottom: 1px solid var(--line); }
.mtab, .mtoggle {
  font: inherit; font-size: 15px; color: var(--ink); background: transparent;
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; cursor: pointer;
}
.mtab.on { background: var(--gold); border-color: var(--gold); color: #0a0f1f; font-weight: 600; }
.mtoggle { margin-left: auto; padding: 6px 12px; }
.mbody { flex: 1; overflow-y: auto; padding: 4px 14px 12px; -webkit-overflow-scrolling: touch; }
.mobile .mbody .panel { position: static; width: auto; max-height: none; overflow: visible; background: none; border: 0; padding: 0; }
.mobile .mbody .controls h2:first-child, .mobile .mbody .lab h2:first-child { margin-top: 8px; }
.mobile[data-mtab=controls] .mbody .lab, .mobile[data-mtab=lab] .mbody .controls { display: none; }
.mobile .mbody .credit { position: static; margin-top: 16px; text-align: left; }
.mobile .chip { padding: 6px 13px; }
.mobile input[type=range] { height: 32px; }
.mobile .card {
  left: 8px; right: 8px; bottom: calc(var(--sheet-h) + 8px); transform: none; width: auto;
  padding: 10px 14px; transition: bottom .25s ease;
}
.mobile .card h3 { font-size: 17px; }
.mobile .card p { font-size: 14.5px; }
.mobile .sheet .cols { grid-template-columns: 1fr; }

/* điện thoại xoay ngang: ngăn kéo ở cạnh phải */
.mobile.landscape .msheet {
  left: auto; top: 0; width: min(340px, 46vw); height: auto;
  border-radius: 16px 0 0 16px; border-top: 0; border-left: 1px solid var(--line);
  padding-bottom: 0; padding-right: env(safe-area-inset-right);
  transform: translateX(calc(100% - 64px));
}
.mobile.landscape.sheet-open .msheet { transform: none; }
.mobile.landscape .mtabs { flex-wrap: wrap; }
.mobile.landscape:not(.sheet-open) .mtab { visibility: hidden; }
.mobile.landscape:not(.sheet-open) .mbody { visibility: hidden; }
.mobile.landscape .mtoggle { order: -1; margin-left: 0; }
.mobile.landscape .fab { right: calc(64px + 8px); }
.mobile.landscape.sheet-open .fab { right: calc(min(340px, 46vw) + 8px); }
.mobile.sheet-open .hint { display: none; }
.mobile.landscape .card { right: calc(min(340px, 46vw) + 8px); bottom: 8px; max-width: 360px; }
.mobile.landscape:not(.sheet-open) .card { right: 72px; }
.mobile.landscape .hint { display: none; }
