:root {
  --bg: #0b0b12; --fg: #f4f4f8; --muted: #9a9ab0;
  --drink: #ff4d6d; --pass: #3ddc84; --judge: #ffd166; --red: #ff3355;
  --card: rgba(20, 20, 32, 0.92);
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; overflow: hidden; }
body { position: fixed; inset: 0; width: 100%; height: 100dvh; -webkit-user-select: none; user-select: none; }
button, input { font: inherit; }

#cam { position: fixed; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); background: #000; opacity: 0; transition: opacity .3s; }
body.cam-on #cam { opacity: 1; }
#overlay { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
#app { position: fixed; inset: 0; z-index: 3; }

.scr { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; padding: calc(16px + var(--sat)) 20px calc(20px + var(--sab)); background: var(--bg); overflow-y: auto; }
.scr.on { display: flex; }
.scr.transparent { background: transparent; justify-content: flex-start; }
.hidden { display: none !important; }

.brand { font-size: 40px; line-height: 1.05; margin: 0 0 6px; text-align: center; font-weight: 900; letter-spacing: -1px;
  background: linear-gradient(90deg, #ffd166, #ff4d6d); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand.small { font-size: 26px; }
.tag { color: var(--muted); margin: 0 0 24px; text-align: center; }
.card { background: var(--card); border: 1px solid rgba(255,255,255,.08); border-radius: 20px; padding: 24px 20px; width: 100%; max-width: 420px; }
.card.center { text-align: center; }
.card h2 { margin: 0 0 8px; font-size: 24px; }
.card p { color: var(--muted); line-height: 1.45; margin: 0 0 18px; }
.bigemoji { font-size: 64px; text-align: center; margin-bottom: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.label { color: var(--muted); letter-spacing: 2px; margin: 0; font-size: 14px; }
.huge { font-size: 56px; margin: 6px 0; text-align: center; font-weight: 900; line-height: 1.05; word-break: break-word; }
.warn { color: var(--drink); }

.btn { display: block; width: 100%; min-height: 56px; border: 0; border-radius: 16px; padding: 14px 18px; font-size: 18px; font-weight: 800; letter-spacing: .5px; color: #fff; background: #2a2a40; cursor: pointer; margin-top: 10px; }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(90deg, #ff4d6d, #ff7a5c); }
.btn.ghost { background: transparent; border: 1px solid rgba(255,255,255,.15); color: var(--muted); }
.btn.link { background: transparent; color: var(--muted); font-weight: 600; min-height: 44px; font-size: 15px; }
.btn.small { width: auto; min-height: 48px; margin-top: 0; padding: 10px 16px; }
.btn.icon { width: 56px; min-height: 56px; padding: 0; font-size: 24px; flex: 0 0 56px; margin-left: 10px; }
.btn.grow { flex: 1; }
.row { display: flex; align-items: stretch; width: 100%; max-width: 420px; }

.spinner { width: 44px; height: 44px; border: 4px solid rgba(255,255,255,.12); border-top-color: var(--judge); border-radius: 50%; margin: 0 auto 16px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* LOBBY */
#s-lobby h2 { margin: 12px 0 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 14px 0; min-height: 40px; max-width: 420px; }
.chip { background: #23233a; border-radius: 999px; padding: 8px 14px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.chip b { color: var(--muted); font-weight: 400; cursor: pointer; padding: 0 4px; }
.addrow { display: flex; gap: 8px; width: 100%; max-width: 420px; }
.addrow input { flex: 1; min-height: 48px; border-radius: 14px; border: 1px solid rgba(255,255,255,.15); background: #14141f; color: var(--fg); padding: 0 14px; font-size: 18px; }
.toggle { display: flex; align-items: center; gap: 10px; margin: 16px 0 4px; width: 100%; max-width: 420px; flex-wrap: wrap; }
.toggle input { width: 24px; height: 24px; }
.toggle span { font-weight: 800; }
.toggle small { color: var(--muted); width: 100%; padding-left: 34px; }

/* SHOW_TARGET */
.ring-wrap { position: relative; width: min(86vw, 60vh, 420px); aspect-ratio: 1; }
.ring { position: absolute; inset: -8px; width: calc(100% + 16px); height: calc(100% + 16px); transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3; }
.ring-bg { stroke: rgba(255,255,255,.1); }
.ring-fg { stroke: var(--judge); stroke-dasharray: 301.6; stroke-dashoffset: 0; stroke-linecap: round; }
.tgt-box { position: absolute; inset: 0; border-radius: 22px; overflow: hidden; background: #1a1a2a; display: flex; align-items: center; justify-content: center; }
.tgt-box img, .thumb img, .cmp-box img { width: 100%; height: 100%; object-fit: cover; display: block; }
.flip img { transform: scaleX(-1); }
.emoji-fb { display: none; font-size: 160px; line-height: 1; }
.no-img img { display: none !important; }
.no-img .emoji-fb { display: block; }
.thumb .emoji-fb { font-size: 56px; }
.cmp-box .emoji-fb { font-size: 84px; }
.tgt-box.second { position: absolute; right: 8px; bottom: 8px; width: 42%; height: 42%; inset: auto 8px 8px auto; border: 3px solid var(--judge); border-radius: 16px; }
.tgt-box.second .emoji-fb { font-size: 64px; }
.combo-arrow { position: absolute; left: 50%; bottom: 14px; transform: translateX(-70%); font-size: 40px; color: var(--judge); text-shadow: 0 2px 8px #000; }
.tname { font-size: 26px; margin: 18px 0 4px; text-align: center; font-weight: 900; }

/* PLAY */
.hud { position: absolute; top: calc(10px + var(--sat)); left: 10px; right: 10px; display: flex; justify-content: space-between; align-items: flex-start; }
.thumb { width: 28vw; max-width: 160px; aspect-ratio: 1; border-radius: 16px; overflow: hidden; border: 3px solid var(--judge); background: #1a1a2a; display: flex; align-items: center; justify-content: center; transition: border-color .15s; }
.hud-right { text-align: right; }
.hud-name { font-weight: 900; font-size: 20px; text-shadow: 0 1px 4px #000; }
.hud-drinks { font-size: 16px; color: var(--judge); text-shadow: 0 1px 4px #000; }
.center-num { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 140px; font-weight: 900; text-shadow: 0 4px 24px rgba(0,0,0,.7); animation: pop .3s ease-out; pointer-events: none; }
.center-num.small { font-size: 56px; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(1.5); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
.pct-wrap { position: absolute; bottom: calc(90px + var(--sab)); left: 0; right: 0; text-align: center; pointer-events: none; }
.pct { font-size: 96px; font-weight: 900; line-height: 1; text-shadow: 0 4px 24px rgba(0,0,0,.8); color: var(--drink); transition: color .15s; }
.pct.mid { color: var(--judge); } .pct.hi { color: var(--pass); }
.pct-label { color: #fff; text-shadow: 0 1px 6px #000; font-size: 14px; letter-spacing: 1px; text-transform: uppercase; }
.phase-hint { position: absolute; top: 34%; left: 0; right: 0; text-align: center; font-size: 40px; font-weight: 900; color: var(--judge); text-shadow: 0 2px 12px #000; animation: pop .3s ease-out; }
.noface { position: absolute; top: 40%; left: 0; right: 0; text-align: center; font-size: 44px; font-weight: 900; color: var(--red); text-shadow: 0 2px 12px #000; }
body.lostface #app::before { content: ""; position: absolute; inset: 0; border: 10px solid var(--red); animation: blink .4s steps(2) infinite; pointer-events: none; z-index: 5; }
@keyframes blink { to { opacity: 0; } }
.timebar { position: absolute; bottom: calc(52px + var(--sab)); left: 20px; right: 20px; height: 8px; background: rgba(255,255,255,.15); border-radius: 4px; overflow: hidden; }
#timebar-fg { height: 100%; width: 0; background: #fff; }
.cap-progress { position: absolute; top: 50%; left: 15%; right: 15%; height: 12px; background: rgba(0,0,0,.4); border-radius: 6px; overflow: hidden; }
#cap-fg { height: 100%; width: 0; background: var(--judge); }
.play-sub { position: absolute; bottom: calc(12px + var(--sab)); left: 0; right: 0; text-align: center; color: #fff; text-shadow: 0 1px 6px #000; font-weight: 700; }

/* RESULT / compare */
.compare { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; max-width: 460px; }
.cmp-col { flex: 1; text-align: center; min-width: 0; }
.cmp-box { width: 100%; aspect-ratio: 1; border-radius: 18px; overflow: hidden; border: 4px solid var(--judge); background: #1a1a2a; display: flex; align-items: center; justify-content: center; }
.cmp-box.big { width: min(70vw, 360px); border-color: var(--pass); }
.pass .cmp-box { border-color: var(--pass); } .drink .cmp-box { border-color: var(--drink); }
.cmp-cap { display: block; margin-top: 6px; font-size: 13px; letter-spacing: 2px; color: var(--muted); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmp-mid { flex: 0 0 auto; width: 74px; text-align: center; }
.cmp-pct { font-size: 30px; font-weight: 900; }
.pass .cmp-pct { color: var(--pass); } .drink .cmp-pct { color: var(--drink); }
.from-left, .from-right { opacity: 0; }
.slide-in .from-left { animation: inL .35s cubic-bezier(.2,.9,.3,1.2) forwards; }
.slide-in .from-right { animation: inR .35s cubic-bezier(.2,.9,.3,1.2) forwards; }
@keyframes inL { from { transform: translateX(-60vw); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes inR { from { transform: translateX(60vw); opacity: 0; } to { transform: none; opacity: 1; } }
.verdict { font-size: 72px; margin: 14px 0 0; font-weight: 900; line-height: 1; opacity: 0; }
.verdict.show { animation: verdict .15s ease-out forwards; }
@keyframes verdict { from { transform: scale(1.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.pass .verdict { color: var(--pass); } .drink .verdict { color: var(--drink); }
#res-sub { min-height: 22px; margin: 6px 0 12px; text-align: center; }
.auto-bar { width: 100%; max-width: 420px; height: 4px; background: rgba(255,255,255,.12); border-radius: 2px; margin-top: 8px; overflow: hidden; }
#auto-fg { height: 100%; width: 0; background: var(--muted); }

/* SUMMARY */
.rank { list-style: none; padding: 0; margin: 10px 0 20px; width: 100%; max-width: 420px; }
.rank li { display: flex; justify-content: space-between; align-items: center; background: #1a1a2a; border-radius: 14px; padding: 12px 16px; margin-bottom: 8px; font-size: 18px; }
.rank li .t { font-size: 12px; color: var(--muted); letter-spacing: 1px; display: block; }
.rank li.first { border: 2px solid var(--drink); }

/* fx */
body.flash #app::after { content: ""; position: absolute; inset: 0; background: #fff; z-index: 40; animation: fl 80ms linear forwards; pointer-events: none; }
@keyframes fl { to { opacity: 0; } }
.shake { animation: shake .4s; }
@keyframes shake { 10%, 90% { transform: translate(-2px, 0); } 20%, 80% { transform: translate(4px, 0); } 30%, 50%, 70% { transform: translate(-8px, 0); } 40%, 60% { transform: translate(8px, 0); } }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.toast { position: fixed; bottom: calc(80px + var(--sab)); left: 50%; transform: translateX(-50%); background: #23233a; color: #fff; padding: 12px 18px; border-radius: 14px; z-index: 70; font-weight: 700; max-width: 90vw; text-align: center; }

.debug { position: fixed; left: 0; right: 0; bottom: 0; max-height: 45vh; overflow: auto; background: rgba(0,0,0,.85); color: #9f9; font: 11px/1.3 Menlo, monospace; padding: 6px; z-index: 80; pointer-events: auto; }
.debug pre { margin: 4px 0; white-space: pre-wrap; }
.debug select, .debug textarea { width: 100%; margin-top: 4px; background: #111; color: #9f9; border: 1px solid #333; font: inherit; }
.debug .btn { min-height: 36px; font-size: 13px; margin-top: 4px; }

@media (orientation: landscape) and (max-height: 500px) {
  .ring-wrap { width: min(50vh, 300px); }
  .huge { font-size: 40px; } .verdict { font-size: 48px; } .pct { font-size: 64px; }
  .compare { max-width: 380px; }
}

/* ---- chọn độ khó: nút đang chọn phải nhìn ra ngay từ xa 1m ---- */
.modes{margin:14px 0 6px}
.modes-lab{display:block;font:700 11px/1 var(--mono,ui-monospace,Menlo,monospace);letter-spacing:.14em;color:#9a9ab0;margin-bottom:8px}
.modes-row{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.mode{display:flex;flex-direction:column;gap:3px;align-items:flex-start;text-align:left;
  background:#161622;color:#f4f4f8;border:2px solid #2a2a3c;border-radius:12px;padding:12px 14px;cursor:pointer;
  font-family:inherit;transition:background .12s,border-color .12s,transform .12s}
.mode b{font-size:17px;font-weight:800;letter-spacing:.02em}
.mode small{font-size:11.5px;line-height:1.35;color:#9a9ab0}
.mode[aria-pressed="true"]{background:#ffd166;border-color:#ffd166;color:#14141c;transform:translateY(-1px)}
.mode[aria-pressed="true"] small{color:#4a3a12}
.mode[aria-pressed="true"] b::after{content:" ✓"}
.mode:focus-visible{outline:3px solid #3ddc84;outline-offset:2px}
.calib{margin:10px 0 0;padding:10px 12px;border:1px dashed #3ddc84;border-radius:10px;color:#3ddc84;font-size:13px;line-height:1.45}
.hud-mode{font:700 11px/1 var(--mono,ui-monospace,Menlo,monospace);letter-spacing:.1em;color:#9a9ab0;margin-left:8px}

/* ---- dừng chơi: luôn có lối ra, nhưng không nằm chỗ ngón cái hay chạm ---- */
.quit{position:fixed;top:calc(env(safe-area-inset-top,0px) + 10px);left:10px;z-index:40;
  width:38px;height:38px;border-radius:50%;border:1px solid #2a2a3c;background:rgba(11,11,18,.72);
  color:#9a9ab0;font:600 15px/1 -apple-system,Helvetica,Arial,sans-serif;cursor:pointer;backdrop-filter:blur(6px)}
.quit:active{transform:scale(.94)}
.quit:focus-visible{outline:3px solid #ffd166;outline-offset:2px}
.modal{position:fixed;inset:0;z-index:60;display:grid;place-items:center;background:rgba(6,6,10,.72);padding:22px}
.modal-box{background:#161622;border:1px solid #2a2a3c;border-radius:16px;padding:20px;max-width:340px;width:100%;text-align:center}
.modal-box p{margin:0 0 16px;font-size:17px;font-weight:700}

.mode.short{flex-direction:row;align-items:center;justify-content:center;padding:10px 12px}
.mode.short b{font-size:16px}
.tiny{font-size:11.5px;margin:8px 0 0}
.chip .g{font:700 9.5px/1 var(--mono,ui-monospace,Menlo,monospace);letter-spacing:.08em;opacity:.65;margin-left:6px;vertical-align:1px}
