    :root {
      color-scheme: dark; --bg:#10131c; --line:#303b50; --accent:#f5c518; --accent-ink:#1a1405; --muted:#aab5c8;
      --st:env(safe-area-inset-top,0px); --sr:env(safe-area-inset-right,0px); --sb:env(safe-area-inset-bottom,0px); --sl:env(safe-area-inset-left,0px);
    }
    * { box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
    html, body { margin:0; width:100%; height:100%; overflow:hidden; overscroll-behavior:none; background:var(--bg); color:#f4f7fb; font:14px/1.45 system-ui,-apple-system,Segoe UI,Roboto,sans-serif; -webkit-text-size-adjust:100%; }
    body { position:fixed; inset:0; }
    #stage { position:fixed; inset:0; background:#000; }
    #stage canvas { display:block; width:100%; height:100%; touch-action:none; -webkit-user-select:none; user-select:none; -webkit-touch-callout:none; }

    #panel { position:fixed; z-index:5; top:calc(14px + var(--st)); left:calc(14px + var(--sl)); width:min(360px,calc(100vw - 28px - var(--sl) - var(--sr))); max-height:calc(100dvh - 28px - var(--st) - var(--sb)); overflow:auto; overscroll-behavior:contain; -webkit-overflow-scrolling:touch; padding:16px; border:1px solid var(--line); border-radius:16px; background:rgba(20,26,38,.94); -webkit-backdrop-filter:blur(14px); backdrop-filter:blur(14px); box-shadow:0 12px 40px #0008; }
    .head { display:flex; align-items:center; gap:10px; margin-bottom:10px; }
    .head img { width:36px; height:40px; flex:none; object-fit:contain; }
    h1 { font-size:18px; margin:0; }
    .sub { color:var(--muted); font-size:12px; margin:2px 0 0; }
    label { display:block; color:#dce5f3; font-weight:600; margin:12px 0 6px; }
    input[type=file], select, button { width:100%; min-height:44px; border-radius:10px; border:1px solid var(--line); background:#111827; color:#f4f7fb; padding:9px 11px; font:inherit; touch-action:manipulation; }
    input[type=file] { padding:7px; font-size:12px; }
    input[type=file]::file-selector-button { margin-right:10px; padding:7px 12px; border:0; border-radius:8px; background:var(--accent); color:var(--accent-ink); font-weight:700; font:inherit; font-weight:700; }
    select { appearance:none; -webkit-appearance:none; padding-right:34px; background-image:linear-gradient(45deg,transparent 50%,#aab5c8 50%),linear-gradient(135deg,#aab5c8 50%,transparent 50%); background-position:calc(100% - 18px) 50%,calc(100% - 13px) 50%; background-size:5px 5px; background-repeat:no-repeat; }
    button { cursor:pointer; font-weight:650; transition:.15s ease; }
    button:active { transform:scale(.98); }
    @media (hover:hover) { button:hover { border-color:var(--accent); } }
    button.primary { background:var(--accent); color:var(--accent-ink); border-color:var(--accent); }
    button:disabled { opacity:.45; cursor:not-allowed; }
    input[type=range] { width:100%; height:32px; margin:0; accent-color:var(--accent); touch-action:manipulation; }
    .grid { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:10px; }
    #status { margin-top:10px; min-height:34px; color:var(--muted); font-size:12px; overflow-wrap:anywhere; }
    #installBtn { display:none; margin-top:8px; }
    #installBtn.show { display:block; }
    #hint { position:fixed; z-index:2; bottom:calc(16px + var(--sb)); left:50%; transform:translateX(-50%); width:max-content; max-width:calc(100vw - 24px); padding:8px 12px; border:1px solid #ffffff22; border-radius:999px; background:#080b12b8; color:#e5edf8; text-align:center; font-size:12px; pointer-events:none; }
    #hidePanel { position:fixed; z-index:6; right:calc(14px + var(--sr)); top:calc(14px + var(--st)); width:auto; min-height:40px; padding:7px 12px; }
    #panel.hidden, body.cb #hint, body.cb #hidePanel { display:none; }
    #reopen { display:none; position:fixed; z-index:6; top:calc(14px + var(--st)); left:calc(14px + var(--sl)); width:auto; min-height:40px; }
    #reopen.show { display:block; }
    body.cb #reopen { opacity:.35; }
    #divider { display:none; position:fixed; z-index:3; top:0; bottom:0; left:calc(50% - 1px); width:2px; background:#000; pointer-events:none; }
    body.cb #divider { display:block; }
    .note { color:var(--muted); font-size:11px; margin:10px 0 0; }
    #start { position:fixed; z-index:20; inset:0; width:100%; height:100%; min-height:0; border:0; border-radius:0; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:14px; padding:calc(20px + var(--st)) 24px calc(20px + var(--sb)); background:radial-gradient(circle at 50% 40%,#1b2232 0%,#0a0d14 70%); color:#f4f7fb; text-align:center; }
    #start.gone { display:none; }
    #start { cursor:pointer; -webkit-user-select:none; user-select:none; }
    #installCard { display:none; margin-top:18px; width:min(420px,100%); padding:12px 14px; border:1px solid #f5c51855; border-radius:14px; background:#f5c5180f; cursor:default; }
    #installCard.show { display:flex; align-items:center; gap:12px; text-align:left; }
    #installCard .t { flex:1; font-size:13px; color:#e5edf8; }
    #installCard .t b { display:block; color:#fff; font-size:14px; }
    #installCard button { width:auto; min-height:40px; padding:8px 14px; flex:none; }
    #installSheet { position:fixed; z-index:40; inset:0; display:none; align-items:flex-end; justify-content:center; background:#000a; padding:12px 12px calc(12px + var(--sb)); }
    #installSheet.show { display:flex; }
    #installSheet .card { width:min(460px,100%); max-height:calc(100dvh - 24px - var(--st)); overflow:auto; padding:18px; border:1px solid var(--line); border-radius:18px; background:#141a26; box-shadow:0 20px 60px #000c; }
    #installSheet .top { display:flex; align-items:center; gap:12px; margin-bottom:10px; }
    #installSheet .top img { width:48px; height:52px; object-fit:contain; }
    #installSheet h2 { margin:0; font-size:17px; }
    #installSheet .why { margin:2px 0 0; color:var(--muted); font-size:12px; }
    #installSheet ol { margin:12px 0; padding-left:22px; }
    #installSheet li { margin:8px 0; line-height:1.5; }
    #installSheet .ico { display:inline-flex; align-items:center; justify-content:center; min-width:24px; height:24px; padding:0 6px; border-radius:6px; background:#ffffff14; border:1px solid #ffffff22; font-weight:700; }
    #installSheet .warn { padding:10px 12px; border-radius:10px; background:#f5c51814; border:1px solid #f5c51844; color:#ffe9a6; font-size:13px; }
    #installSheet .row { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:12px; }
    @media (min-width:700px) { #installSheet { align-items:center; } }
    /* Sembunyi automatik: butang Menu & petunjuk pudar selepas 5 saat tanpa sentuhan */
    #reopen, #hint, #hidePanel { transition:opacity .4s ease; }
    body.idle #reopen, body.idle #hint, body.idle #hidePanel { opacity:0 !important; pointer-events:none !important; }
    #toast { position:fixed; z-index:30; left:50%; top:calc(12px + var(--st)); transform:translateX(-50%); width:max-content; max-width:min(560px,calc(100vw - 24px)); padding:10px 14px; border:1px solid #f5c51866; border-radius:12px; background:#1a1405f0; color:#ffe9a6; font-size:13px; text-align:center; display:none; }
    #toast.show { display:block; }
    #start img { width:min(220px, 56vw); height:auto; aspect-ratio:1; object-fit:contain; filter:drop-shadow(0 10px 30px #f5c51840); }
    #start .go { display:inline-flex; align-items:center; gap:10px; padding:14px 26px; border-radius:999px; background:var(--accent); color:var(--accent-ink); font-size:18px; font-weight:800; animation:pulse 1.8s ease-in-out infinite; }
    #start .msg { max-width:420px; color:var(--muted); font-size:13px; font-weight:500; }
    #start .skip { color:var(--muted); font-size:12px; font-weight:500; text-decoration:underline; }
    #syncBox { display:none; margin-top:12px; padding:10px 12px; border:1px solid #3ddc8455; border-radius:12px; background:#3ddc840d; }
    #syncBox.on { display:block; }
    #syncBox .sh { font-weight:700; color:#bff5d6; }
    #syncInfo { margin-top:4px; color:var(--muted); font-size:12px; }
    #syncCtl { display:none; }
    #sFilter { width:100%; min-height:40px; border-radius:10px; border:1px solid var(--line); background:#111827; color:#f4f7fb; padding:8px 11px; font:inherit; }
    #sList { margin-top:6px; max-height:260px; overflow:auto; overscroll-behavior:contain; border:1px solid var(--line); border-radius:10px; }
    #sList button { display:flex; gap:8px; align-items:center; min-height:40px; border:0; border-bottom:1px solid var(--line); border-radius:0; background:transparent; text-align:left; font-weight:550; }
    #sList button:last-child { border-bottom:0; }
    #sList button .n { color:var(--muted); font-size:11px; min-width:20px; }
    #sList button .tag { margin-left:auto; color:var(--muted); font-size:10px; }
    #sList button.cur { background:#3ddc841f; color:#bff5d6; }
    .dg { padding:6px 0; border-bottom:1px solid var(--line); color:#dce5f3; }
    .dg span { color:#ffcf66; }
    .dg.bad b { color:#ff8a7a; }
    .chk { display:flex; gap:8px; align-items:center; font-weight:500; font-size:12px; color:var(--muted); }
    .chk input { width:18px; height:18px; accent-color:var(--accent); }
    #syncBox.ctl #syncCtl { display:block; }
    #syncBox.ctl #sBecome { display:none; }
    #syncBadge { display:none; position:fixed; z-index:4; right:calc(14px + var(--sr)); bottom:calc(16px + var(--sb)); padding:5px 10px; border-radius:999px; background:#080b12b8; border:1px solid #3ddc8455; color:#bff5d6; font-size:11px; pointer-events:none; }
    body.sync #syncBadge { display:block; }
    body.idle #syncBadge { opacity:.35; }
    @keyframes pulse { 50% { transform:scale(1.05); box-shadow:0 0 0 10px #f5c51818; } }

    /* Telefon potret: panel jadi "bottom sheet" */
    @media (max-width:600px) and (orientation:portrait) {
      #panel { top:auto; left:0; right:0; bottom:0; width:100%; max-height:min(72dvh, calc(100dvh - 70px - var(--st))); padding:10px 16px calc(16px + var(--sb)); border-radius:20px 20px 0 0; border-width:1px 0 0; }
      #panel::before { content:""; display:block; width:40px; height:4px; margin:0 auto 10px; border-radius:4px; background:#ffffff33; }
      input[type=file], select, button { font-size:16px; } /* elak iOS zoom automatik */
      input[type=file] { font-size:13px; }
      #panel:not(.hidden) ~ #hint { display:none; }
      .head img { width:32px; height:36px; }
    }
    /* Telefon landskap (ketinggian kecil): panel sisi, padat */
    @media (max-height:500px) and (orientation:landscape) {
      #panel { top:calc(8px + var(--st)); left:calc(8px + var(--sl)); bottom:calc(8px + var(--sb)); width:min(330px,46vw); max-height:none; padding:12px; }
      #hidePanel, #reopen { top:calc(8px + var(--st)); }
      #hidePanel { right:calc(8px + var(--sr)); }
      #reopen { left:calc(8px + var(--sl)); }
      label { margin:8px 0 4px; }
      .grid { margin-top:6px; gap:6px; }
      .sub, .note { display:none; }
      #panel:not(.hidden) ~ #hint { left:calc(50% + min(330px,46vw)/2); max-width:calc(100vw - min(330px,46vw) - 32px); }
    }
  

    /* ===================== PENGIKUT (VR Client): tiada menu ===================== */
    body.role-client #panel, body.role-client #reopen, body.role-client #hidePanel, body.role-client #skipStart { display:none !important; }

    /* ===================== PENGAWAL (VR Controller) ===================== */
    body.role-ctl { background:#070a10; }
    #ctlBar { display:none; }
    body.role-ctl #ctlBar { position:fixed; z-index:7; top:0; left:0; right:0; height:calc(56px + var(--st)); padding:var(--st) calc(16px + var(--sr)) 0 calc(16px + var(--sl));
      display:flex; align-items:center; gap:10px; background:#0b1019; border-bottom:1px solid var(--line); }
    #ctlBar .brand { display:flex; align-items:center; gap:10px; font-weight:800; font-size:17px; white-space:nowrap; }
    #ctlBar .brand img { width:auto; height:34px; aspect-ratio:auto; object-fit:contain; }
    #ctlBar .pill { padding:5px 10px; border-radius:999px; border:1px solid var(--line); background:#111827; font-size:12.5px; color:#cfd8e6; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
    #ctlBar #ctlCount { border-color:#3ddc8466; color:#bff5d6; font-weight:700; }
    #ctlBar #ctlState { min-width:0; flex:0 1 auto; }
    #ctlBar .sp { flex:1; }
    #ctlBar #logout { width:auto; min-height:36px; padding:6px 12px; font-size:13px; }
    body.role-ctl #stage { top:calc(68px + var(--st)); left:calc(12px + var(--sl)); bottom:calc(12px + var(--sb)); right:auto; width:calc(58% - 18px);
      border:1px solid var(--line); border-radius:16px; overflow:hidden; }
    body.role-ctl #panel { top:calc(68px + var(--st)); right:calc(12px + var(--sr)); left:auto; bottom:calc(12px + var(--sb)); width:calc(42% - 6px);
      max-height:none; padding:12px; background:#0d131e; backdrop-filter:none; -webkit-backdrop-filter:none; box-shadow:none; }
    body.role-ctl #reopen, body.role-ctl #hidePanel, body.role-ctl #hint, body.role-ctl #start, body.role-ctl #divider { display:none !important; }
    body.role-ctl #syncBadge { right:auto; left:calc(24px + var(--sl)); bottom:calc(24px + var(--sb)); max-width:calc(58% - 48px); }
    body.role-ctl.cb #stage { inset:0; width:auto; border-radius:0; z-index:8; }
    @media (max-width:900px) {
      body.role-ctl #stage { right:calc(8px + var(--sr)); left:calc(8px + var(--sl)); width:auto; bottom:auto; height:40dvh; }
      body.role-ctl #panel, body.role-ctl #panel.hidden { display:block; top:calc(68px + 40dvh + 8px + var(--st)); left:calc(8px + var(--sl)); right:calc(8px + var(--sr)); width:auto;
        bottom:calc(8px + var(--sb)); max-height:none; border-radius:16px; border-width:1px; padding:10px; }
      body.role-ctl #panel::before { display:none; }
      body.role-ctl #syncBadge { max-width:calc(100% - 48px); bottom:auto; top:calc(68px + 40dvh - 36px + var(--st)); }
      #ctlBar .brand span, #ctlBar #ctlRoom { display:none; }
    }

    /* Kad panel */
    .pcard { margin:0 0 12px; padding:14px; border:1px solid var(--line); border-radius:14px; background:#121a27; }
    .pcard h3 { margin:0 0 10px; font-size:15px; }
    .pcard h4 { margin:0 0 4px; font-size:14px; }
    .pcard label:first-of-type { margin-top:6px; }
    .hrow { display:flex; align-items:center; justify-content:space-between; gap:8px; margin-bottom:6px; }
    .hrow h3 { margin:0; }
    button.small { width:auto; min-height:36px; padding:6px 12px; font-size:13px; }
    button.ic { width:auto; min-width:40px; padding:6px 10px; }
    button.danger, button.danger:hover { border-color:#ff6b5a; color:#ffb1a8; background:#3a1512; }
    .note { margin:4px 0 8px; color:var(--muted); font-size:12.5px; line-height:1.45; }
    .row { display:flex; gap:6px; flex-wrap:wrap; align-items:center; }
    .row > button { width:auto; flex:1 1 auto; min-height:40px; }
    .row > button.ic { flex:0 0 auto; }
    .row > select { flex:1 1 140px; min-width:0; }
    .kpi { display:grid; grid-template-columns:repeat(4, minmax(0,1fr)); gap:8px; }
    .kpi > div { padding:10px 6px; border-radius:12px; background:#0b111b; border:1px solid var(--line); text-align:center; }
    .kpi b { display:block; font-size:22px; font-variant-numeric:tabular-nums; }
    .kpi span { font-size:11.5px; color:var(--muted); }
    .kpi b.ok { color:#3ddc84; } .kpi b.warn { color:#f5c518; } .kpi b.bad { color:#ff8a7a; }
    #sDiag { margin-top:10px; } #sDiag summary { cursor:pointer; font-weight:650; font-size:13px; }
    #sDiagList { font-size:12px; margin-top:6px; max-height:260px; overflow:auto; }
    .now { display:flex; flex-direction:column; gap:2px; padding:10px 12px; border-radius:12px; background:#0b111b; border:1px solid var(--line); }
    .now .k { font-size:11.5px; color:var(--muted); }
    .now b { font-size:17px; }
    #nowState { font-size:12.5px; color:#bff5d6; }
    #partChips { display:flex; gap:6px; flex-wrap:wrap; margin:8px 0 2px; }
    #partChips:empty { display:none; }
    .chip { width:auto; flex:1 1 0; min-height:38px; padding:6px 8px; font-size:12.5px; border-radius:999px; }
    .chip.on { border-color:#3ddc84; background:#123322; color:#bff5d6; font-weight:750; }
    .chip.done { opacity:.6; }

    /* Kategori */
    .cat { margin-top:10px; padding:12px; border:1px solid var(--line); border-radius:12px; background:#0b111b; }
    .cat.live { border-color:#3ddc84; box-shadow:0 0 0 1px #3ddc8455 inset; }
    .cat .ch { display:flex; align-items:baseline; gap:8px; flex-wrap:wrap; margin-bottom:6px; }
    .cat .ch b { font-size:15px; }
    .cat .cm { font-size:12px; color:var(--muted); }
    .livetag { margin-left:auto; font-size:11px; font-weight:800; color:#3ddc84; }
    .slot { display:flex; gap:8px; padding:4px 0; font-size:12.5px; border-top:1px dashed #ffffff14; }
    .slot .sl { flex:0 0 108px; color:var(--muted); }
    .slot .sv { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
    .slot.empty .sv { color:#ffcf66; }
    .cat .row { margin-top:8px; }
    .editor { margin:8px 0 4px; padding:12px; border:1px solid var(--accent); border-radius:12px; background:#0f1826; }
    .editor input[type=text] { width:100%; min-height:42px; border-radius:10px; border:1px solid var(--line); background:#111827; color:#f4f7fb; padding:8px 11px; font:inherit; font-size:16px; }
    .eslot { margin-top:10px; }
    .eslot .sl { font-weight:700; font-size:13px; margin-bottom:4px; }
    .editor .grid { margin-top:12px; }

    /* Pustaka & muat naik */
    .vid { margin-top:8px; padding:10px; border:1px solid var(--line); border-radius:12px; background:#0b111b; }
    .vid .vt { width:100%; min-height:38px; border-radius:8px; border:1px solid transparent; background:transparent; color:#f4f7fb; padding:4px 6px; font:inherit; font-weight:700; font-size:14px; }
    .vid .vt:focus { border-color:var(--accent); background:#111827; outline:none; }
    .vid .vm { margin:2px 6px 6px; font-size:12px; color:var(--muted); }
    .prog { margin-top:8px; font-size:12px; color:#cfd8e6; }
    .prog .bar { height:8px; border-radius:6px; background:#1b2636; overflow:hidden; margin-bottom:4px; }
    .prog .bar i { display:block; height:100%; width:0; background:linear-gradient(90deg,#3ddc84,#5fe3ff); transition:width .2s; }
    .prog.ok span { color:#3ddc84; } .prog.err span { color:#ff8a7a; } .prog.err .bar i { background:#ff6b5a; }
    .dg { padding:6px 0; border-bottom:1px solid var(--line); color:#dce5f3; }
    .dg span { color:#ffcf66; } .dg.bad b { color:#ff8a7a; }

    /* Log masuk PIN 6 digit (OTP) — skrin penuh, bukan popup */
    #gate { display:none; }
    body.role-ctl #gate { position:fixed; inset:0; z-index:50; display:grid; place-items:center; padding:24px;
      background:radial-gradient(1200px 700px at 50% 0%, #15324a 0%, #070a10 60%); }
    #gate.gone { display:none !important; }
    #gate form { width:min(420px, calc(100vw - 32px - var(--sl) - var(--sr))); text-align:center; }
    #gate img { width:min(240px, 56vw); height:auto; aspect-ratio:1; object-fit:contain; filter:drop-shadow(0 12px 34px #f5c51838); }
    #gate h1 { color:var(--accent); letter-spacing:.5px; }
    #ctlBar .brand em { font-style:normal; color:var(--accent); font-weight:700; }
    #gate h1 { margin:14px 0 4px; font-size:26px; }
    #gate p { margin:0 0 20px; color:var(--muted); }
    #otp { display:flex; gap:10px; justify-content:center; }
    #otp input { flex:1 1 0; min-width:0; max-width:54px; width:auto; height:62px; padding:0; border-radius:14px; border:1.5px solid #2a3850; background:#0f1724; color:#fff;
      font:800 28px/1 system-ui,sans-serif; text-align:center; caret-color:var(--accent); -webkit-text-security:disc; }
    #otp input:focus { outline:none; border-color:var(--accent); box-shadow:0 0 0 3px #5fb3ff33; }
    #gateErr { min-height:22px; margin:14px 0 6px; color:#ff8a7a; font-size:14px; }
    #gate button { margin-top:6px; }
    #gate.shake form { animation:shake .4s; }
    @keyframes shake { 20%,60% { transform:translateX(-8px); } 40%,80% { transform:translateX(8px); } }
    @media (max-width:420px) { #otp { gap:7px; } #otp input { height:56px; font-size:24px; } body.role-ctl #gate { padding:16px; } }
    @media (prefers-reduced-motion:reduce) { #gate.shake form { animation:none; } }
    #tunBody .tl { display:flex; align-items:center; gap:8px; padding:6px 0; border-bottom:1px dashed #ffffff14; font-size:13px; }
    #tunBody .tl .sl { flex:0 0 72px; color:var(--muted); }
    #tunBody .tl a { flex:1; min-width:0; overflow-wrap:anywhere; color:#9fd8ff; }
    #tunBody .tl button { flex:0 0 auto; }
