:root{
  --navy:#0b3a5b; --navy2:#0f4f7a; --teal:#12b5a6; --ink:#14212b; --muted:#5d6b77;
  --card:#ffffffee; --ok:#1f9d55; --bad:#d64545; --gold:#f4b400;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;height:100%;overflow:hidden;background:#c9d6df;font-family:"Segoe UI","Heebo",Arial,sans-serif;color:var(--ink);touch-action:none;user-select:none;-webkit-user-select:none}
#c{position:fixed;inset:0;width:100%;height:100%;display:block}
.hidden{display:none!important}

/* HUD */
#hud{position:fixed;inset:0;pointer-events:none}
.hud-top{position:absolute;top:calc(env(safe-area-inset-top,0px) + 10px);left:172px;right:10px;display:flex;gap:10px;align-items:center}
.hud-stage{background:var(--card);border-radius:14px;padding:6px 14px;box-shadow:0 4px 14px #0002;line-height:1.15}
#hudStageNum{font-size:12px;color:var(--muted)} #hudStageName{font-weight:700;font-size:16px}
.hud-stats{display:flex;gap:6px;margin-inline-start:auto;flex-wrap:wrap;justify-content:flex-end}
.pill{background:var(--card);border-radius:999px;padding:6px 12px;box-shadow:0 4px 14px #0002;font-size:15px;display:flex;gap:6px;align-items:center}
.icon-btn{pointer-events:auto;width:44px;height:44px;border-radius:14px;border:0;background:var(--navy);color:#fff;font-size:22px;box-shadow:0 4px 14px #0003}
.toast{position:fixed;z-index:40;top:80px;left:50%;transform:translateX(-50%);background:#14212be6;color:#fff;padding:10px 18px;border-radius:12px;font-size:15px;max-width:90vw;text-align:center;animation:pop .25s}
@keyframes pop{from{transform:translateX(-50%) scale(.85);opacity:0}}

.dpad{position:absolute;left:18px;bottom:calc(var(--safe-b) + 18px);width:168px;height:168px;pointer-events:auto}
.dpad .d{position:absolute;width:58px;height:58px;border-radius:16px;border:0;background:#0b3a5bd9;color:#fff;font-size:24px;box-shadow:0 5px 14px #0004;touch-action:none}
.dpad .d.active{background:var(--teal);transform:scale(.94)}
.dpad .up{left:55px;top:0}.dpad .down{left:55px;bottom:0}.dpad .left{left:0;top:55px}.dpad .right{right:0;top:55px}
.actions{position:absolute;right:18px;bottom:calc(var(--safe-b) + 18px);display:flex;flex-direction:column;align-items:flex-end;gap:12px;pointer-events:auto}
.act{border:0;border-radius:50%;background:#0b3a5bd9;color:#fff;font-size:22px;box-shadow:0 5px 14px #0004;display:flex;flex-direction:column;align-items:center;justify-content:center;line-height:1}
.act small{font-size:11px;margin-top:2px}
.act.small{width:54px;height:54px}
.act.inspect{width:96px;height:96px;font-size:34px;background:linear-gradient(145deg,#f7c548,#f29d00);color:#3a2500;animation:pulse 1.2s infinite}
.act.inspect small{font-size:15px;font-weight:700}
@keyframes pulse{50%{box-shadow:0 0 0 12px #f4b40033}}
.act-row{display:flex;gap:10px}

/* screens */
.screen{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:linear-gradient(160deg,#0b3a5bcc,#12b5a699);padding:16px;z-index:10;backdrop-filter:blur(3px)}
.card{background:#fff;border-radius:22px;padding:24px 22px;max-width:440px;width:100%;box-shadow:0 20px 60px #0005;text-align:center;max-height:92vh;overflow:auto}
.card.wide{max-width:900px}
.card h1{margin:4px 0;font-size:34px;color:var(--navy)}
.card h2{margin:4px 0 10px;color:var(--navy)}
.sub{color:var(--muted);margin-top:0}
.logo{font-size:56px}
.big-emoji{font-size:60px}
.btn{display:block;width:100%;margin:10px 0 0;padding:14px;border-radius:14px;border:0;font-size:17px;font-weight:700;cursor:pointer;font-family:inherit}
.btn.primary{background:var(--navy);color:#fff}
.btn.ghost{background:#eef3f7;color:var(--navy)}
.btn.thin{padding:9px;font-size:14px;font-weight:600}
.btn.danger{background:var(--bad);color:#fff}
.btn.ok{background:var(--ok);color:#fff}
.row{display:flex;gap:10px}.row .btn{flex:1}
input#playerName{width:100%;padding:13px;font-size:17px;border-radius:12px;border:2px solid #d7e1e8;margin-top:8px;font-family:inherit;text-align:center}
.how{text-align:right;line-height:1.7;padding-inline-start:18px}
.toggle{display:flex;gap:8px;align-items:center;justify-content:center;margin-top:14px;font-size:15px}

.stage-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(230px,1fr));gap:12px;margin-top:10px}
.stage{border-radius:16px;padding:14px;background:#f3f7fa;text-align:right;border:2px solid transparent;cursor:pointer;position:relative}
.stage:hover{border-color:var(--teal)}
.stage .em{font-size:34px;float:left}
.stage .n{font-size:12px;color:var(--muted)}
.stage .t{font-weight:800;font-size:17px;color:var(--navy)}
.stage .s{font-size:13px;color:var(--muted);margin-top:4px}
.stage .st{margin-top:6px;font-size:16px}
.stage.locked{opacity:.5;cursor:not-allowed}
.stage.locked::after{content:"🔒";position:absolute;left:12px;bottom:10px;font-size:20px}
.map-foot{display:flex;align-items:center;gap:12px;margin-top:14px;justify-content:space-between}
.map-foot .btn{width:auto;padding:12px 20px;margin:0}

.dialog{position:fixed;inset:0;display:flex;align-items:flex-end;justify-content:center;z-index:12;pointer-events:none}
.sheet{pointer-events:auto;background:#fff;width:100%;max-width:560px;border-radius:22px 22px 0 0;padding:18px 18px calc(var(--safe-b) + 14px);box-shadow:0 -10px 40px #0004;animation:up .25s;max-height:62vh;overflow:auto}
@keyframes up{from{transform:translateY(40px);opacity:0}}
.sheet-head{display:flex;align-items:center;gap:10px}
.sheet-head h3{margin:0;font-size:19px;color:var(--navy)}
.tag{background:#e7f6f4;color:#0b7d72;padding:3px 10px;border-radius:999px;font-size:12px;font-weight:700;white-space:nowrap}
.look{color:#33414c;line-height:1.55;margin:10px 0}
.choice{display:flex;gap:10px}.choice .btn{flex:1;margin:0}
.res-badge{font-weight:800;font-size:18px;padding:8px 12px;border-radius:12px;display:inline-block}
.res-badge.good{background:#e3f6ea;color:var(--ok)}.res-badge.badr{background:#fde8e8;color:var(--bad)}
.result p{line-height:1.6;text-align:right}
.ref{font-size:13px;color:var(--muted);background:#f3f6f8;padding:8px 10px;border-radius:10px}

.stars{font-size:44px;letter-spacing:4px}
.done-stats{display:grid;grid-template-columns:repeat(3,1fr);gap:8px;margin:10px 0}
.done-stats div{background:#f3f7fa;border-radius:12px;padding:8px}
.done-stats b{display:block;font-size:20px;color:var(--navy)}
.done-list{text-align:right;font-size:14px;line-height:1.5;max-height:32vh;overflow:auto;background:#fafcfd;border-radius:12px;padding:6px 12px}
.done-list div{padding:4px 0;border-bottom:1px solid #eef2f5}
#certCanvas{width:100%;height:auto;border-radius:10px;box-shadow:0 4px 20px #0002}

#loading{flex-direction:column;color:#fff;font-size:18px}
.spinner{width:54px;height:54px;border-radius:50%;border:6px solid #ffffff55;border-top-color:#fff;animation:spin 1s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

@media (max-width:600px){
  .hud-stage{padding:5px 10px} #hudStageName{font-size:14px}
  .pill{padding:5px 9px;font-size:13px}
  .dpad{transform:scale(.88);transform-origin:left bottom}
  .hud-top{flex-wrap:wrap}
}
@media (max-height:500px){ .dpad{transform:scale(.75);transform-origin:left bottom} .act.inspect{width:80px;height:80px} }

/* inspection close-ups & zoom */
.closewrap{background:#f3f7fa;border-radius:14px;padding:8px 10px;margin:0 0 12px}
.closehead{font-size:13px;color:var(--muted);margin-bottom:6px}
.closeups{display:flex;gap:8px;overflow-x:auto;direction:rtl}
.closeups img{height:150px;border-radius:8px;border:2px solid #dbe4ea;background:#fff;cursor:zoom-in;flex:0 0 auto;max-width:78vw;object-fit:contain}
.zoombar{position:fixed;top:calc(env(safe-area-inset-top,0px) + 70px);left:12px;z-index:13;display:flex;flex-direction:column;gap:8px;align-items:center;background:#14212bd9;padding:8px 6px;border-radius:999px;color:#fff;font-size:11px}
.zoombar span{writing-mode:vertical-rl;opacity:.8;padding:4px 0}
body.inspecting .dpad,body.inspecting .actions{display:none}
.zoombar button{width:42px;height:42px;border-radius:50%;border:0;background:#fff;color:var(--navy);font-size:22px;font-weight:700}
.lightbox{position:fixed;inset:0;z-index:30;background:#000d;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;color:#fff;padding:16px}
.lightbox img{max-width:96vw;max-height:80vh;border-radius:10px;background:#fff;image-rendering:auto}
.btn.gold{background:linear-gradient(145deg,#f7c548,#f29d00);color:#3a2500}
.btn.wa{background:#25d366;color:#fff}
@media (max-width:600px){.zoombar span{display:none}.zoombar button{width:38px;height:38px}}

/* brand + credit */
#brand{position:fixed;top:calc(env(safe-area-inset-top,0px) + 10px);left:10px;z-index:11;height:44px;padding:0 14px;border-radius:14px;background:#fff;box-shadow:0 4px 14px #0002;display:flex;align-items:center;pointer-events:none}
#brand img{height:30px;width:auto;display:block}
#brand.has-img .wordmark{display:none}
#brand .wordmark{font-family:"Segoe UI",Arial,sans-serif;font-weight:800;font-size:22px;letter-spacing:.3px;color:#0b3a5b}
.credit{margin:-4px 0 12px;font-size:15px;color:#33414c;background:#f3f7fa;border-radius:999px;display:inline-block;padding:6px 14px}
.cert-img{width:100%;height:auto;border-radius:10px;box-shadow:0 4px 20px #0002;-webkit-touch-callout:default;user-select:auto;-webkit-user-select:auto}
.sub.small{font-size:13px;margin:8px 0 0}
@media (max-width:600px){#brand{height:38px;padding:0 10px}#brand .wordmark{font-size:18px}#brand img{height:24px}.hud-top{left:132px}}

/* today's date + running batch, always visible */
.hud-info{position:absolute;top:calc(env(safe-area-inset-top,0px) + 64px);left:50%;transform:translateX(-50%);display:flex;gap:14px;background:#0b3a5bee;color:#fff;padding:6px 16px;border-radius:999px;font-size:14px;white-space:nowrap;box-shadow:0 4px 14px #0003;pointer-events:none}
.hud-info b{color:#ffd166}
.ctx-line{margin:8px 0 0;font-size:13px;color:#0b3a5b;background:#fff6dc;border:1px solid #f2d27a;border-radius:10px;padding:5px 10px;display:inline-block}
.intro-chips{display:flex;gap:8px;justify-content:center;flex-wrap:wrap;margin:6px 0 4px}
.intro-chips span{background:#fff6dc;border:1px solid #f2d27a;color:#0b3a5b;border-radius:999px;padding:6px 12px;font-size:15px}
@media (max-width:600px){.hud-info{top:calc(env(safe-area-inset-top,0px) + 100px);font-size:12px;gap:10px;padding:5px 12px}}
body.inspecting .hud-info{display:none}
