:root {
  --ink: #0b1e36;
  --panel: rgba(10, 28, 52, .86);
  --panel-b: rgba(255, 214, 120, .3);
  --cream: #fff6dd;
  --muted: #b7c8e0;
  --gold: #ffd36a;
  --gold2: #ffe9a8;
  --ok: #5fd68a;
  --bad: #ff6b5a;
  --font: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  --pirate: "Pirata One", "Fredoka", Georgia, serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; height: 100dvh; overflow: hidden; background: #0f2a4a; color: var(--cream); font-family: var(--font); user-select: none; -webkit-user-select: none; touch-action: manipulation; }
canvas#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font-family: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
#fade { position: fixed; inset: 0; background: #08162a; opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 80; }

.screen { position: fixed; inset: 0; z-index: 30; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.screen.center { display: flex; align-items: center; justify-content: center; padding: 16px; }
#loading { background: radial-gradient(ellipse at 50% 30%, #1f5d8f, #0a1a30 70%); z-index: 90; }
.load-box { text-align: center; }
.load-icon { font-size: 4rem; animation: bob 1.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-10px) rotate(8deg); } }
.error { color: #ffb3a6; }

/* ---------- botões e campos ---------- */
.btn { appearance: none; border: 0; cursor: pointer; font-weight: 700; font-size: 1.05rem; color: #3a2606; padding: 12px 24px; border-radius: 16px; background: linear-gradient(#ffe48a, #f0b53a); box-shadow: 0 5px 0 #a8710f, 0 12px 24px rgba(240, 181, 58, .28); transition: transform .08s, box-shadow .08s, filter .15s; }
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #a8710f; }
.btn:disabled { filter: grayscale(.8); opacity: .6; cursor: not-allowed; }
.btn.big { width: 100%; font-size: 1.4rem; padding: 15px; margin-top: 12px; }
.btn.ghost { background: rgba(255, 255, 255, .1); color: var(--cream); border: 1.5px solid rgba(255, 255, 255, .2); box-shadow: 0 4px 0 rgba(0, 0, 0, .35); }
.btn.small { font-size: .9rem; padding: 9px 14px; border-radius: 13px; }
.link { background: none; border: 0; color: var(--gold2); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.link.tiny { font-size: .85rem; opacity: .8; margin-top: 10px; align-self: center; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.round { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--panel-b); background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); font-size: 1.1rem; font-weight: 700; cursor: pointer; display: grid; place-items: center; box-shadow: 0 6px 16px rgba(0, 0, 0, .3); }
.round.txt { font-size: .85rem; }
.round:active { transform: scale(.94); }
.warn { color: #ffb3a6; text-align: center; margin-top: 10px; font-weight: 600; }
.hint { color: var(--muted); font-size: .95rem; line-height: 1.4; margin: 8px 0; }
.seg { display: inline-flex; background: rgba(255, 255, 255, .1); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; padding: 8px 14px; border-radius: 9px; font-weight: 700; cursor: pointer; font-size: .9rem; }
.seg button.on, .seg button[aria-pressed="true"] { background: var(--gold); color: #3a2606; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; color: var(--muted); margin-top: 14px; }
.field input, .join-row input { font: inherit; font-size: 1.1rem; padding: 12px 14px; border-radius: 14px; border: 1.5px solid rgba(255, 255, 255, .22); background: rgba(255, 255, 255, .08); color: var(--cream); outline: none; user-select: text; -webkit-user-select: text; }
.field input:focus, .join-row input:focus { border-color: var(--gold); }

/* ---------- menu ---------- */
#menu { background: linear-gradient(180deg, rgba(7, 22, 42, .5), rgba(7, 22, 42, .3) 40%, rgba(7, 22, 42, .78)); }
.menu-wrap { width: min(1040px, 100%); margin: 0 auto; padding: calc(22px + var(--safe-t)) 18px 34px; }
.menu-wrap.narrow { width: min(560px, 100%); }
.logo { text-align: center; text-shadow: 0 4px 22px rgba(0, 0, 0, .6); margin-bottom: 18px; }
.logo-kicker { letter-spacing: 4px; font-size: .78rem; color: var(--gold2); font-weight: 600; text-align: center; }
.logo h1 { font-family: var(--pirate); font-weight: 400; font-size: clamp(2.8rem, 9vw, 5rem); line-height: 1; margin: 4px 0 8px; letter-spacing: 1px; }
.logo h1 em { font-style: normal; color: var(--gold); }
.tagline { max-width: 580px; margin: 0 auto; color: #e8f0fb; font-size: 1.05rem; line-height: 1.45; }
.menu-grid { display: grid; grid-template-columns: 1fr 1.15fr; gap: 16px; align-items: start; }
.card { background: var(--panel); border: 1.5px solid var(--panel-b); border-radius: 24px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: 0 18px 50px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .08); padding: 22px; }
.card h3 { font-size: 1rem; color: var(--gold2); letter-spacing: .5px; margin: 14px 0 8px; }
.tabs { display: flex; gap: 6px; margin: 16px 0 4px; }
.tabs button { flex: 1; padding: 10px; border-radius: 14px; border: 1.5px solid rgba(255, 255, 255, .2); background: none; font-weight: 700; cursor: pointer; font-size: 1rem; }
.tabs button.on { background: var(--gold); color: #3a2606; border-color: var(--gold); }
.menu-row { margin-top: 16px; justify-content: space-between; }
.join-row { display: flex; gap: 8px; margin-top: 14px; }
.join-row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 6px; font-weight: 700; text-align: center; font-size: 1.3rem; }
.packs-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.packs-head h3 { margin: 0; }
.packs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pack { display: flex; align-items: center; gap: 10px; text-align: left; padding: 10px 12px; border-radius: 16px; border: 2px solid rgba(255, 255, 255, .15); background: rgba(255, 255, 255, .05); cursor: pointer; transition: transform .1s, background .15s; position: relative; }
.pack .pi { font-size: 1.5rem; }
.pack .pt { display: flex; flex-direction: column; min-width: 0; }
.pack b { font-size: .95rem; line-height: 1.1; }
.pack small { color: var(--muted); font-size: .72rem; line-height: 1.2; }
.pack em { margin-left: auto; font-style: normal; font-size: .72rem; color: var(--muted); background: rgba(0, 0, 0, .3); border-radius: 10px; padding: 1px 7px; }
.pack.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 28%, rgba(10, 28, 52, .6)); }
.pack:hover { transform: translateY(-2px); }
.history { margin-top: 14px; display: grid; gap: 6px; }
.hist { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 12px; background: rgba(255, 255, 255, .06); font-size: .9rem; }
.hist.won { background: rgba(95, 214, 138, .13); }
.hist small { color: var(--muted); margin-left: auto; }
.back { text-align: center; margin-top: 20px; }
.back a { color: var(--muted); text-decoration: none; font-size: .9rem; }

/* ---------- sala online ---------- */
.lobby-card { text-align: center; }
.big-code { font-family: var(--pirate); font-size: clamp(3.4rem, 18vw, 6rem); letter-spacing: 10px; color: var(--gold); text-shadow: 0 4px 0 rgba(0, 0, 0, .4); margin: 4px 0 10px; user-select: text; }
.lobby-players { display: grid; gap: 8px; margin: 10px 0; text-align: left; }
.lp { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 14px; background: rgba(255, 255, 255, .07); border-left: 6px solid var(--c); }
.lp .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); }
.lp small { color: var(--gold2); }
.mini-packs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.mini-packs span { font-size: .8rem; padding: 4px 10px; border-radius: 999px; background: color-mix(in srgb, var(--c) 35%, rgba(10, 28, 52, .6)); border: 1px solid var(--c); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#hud > * { pointer-events: auto; }
.topbar { position: absolute; top: calc(10px + var(--safe-t)); left: 10px; right: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.topbar .actions { display: flex; gap: 8px; }
.banner { flex: 1; max-width: 560px; text-align: center; padding: 10px 16px; border-radius: 16px; background: var(--panel); border: 1.5px solid var(--panel-b); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); font-size: 1rem; line-height: 1.2; min-height: 44px; display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
.banner:empty { visibility: hidden; }
.banner.mine { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255, 211, 106, .25), 0 0 24px rgba(255, 211, 106, .3); animation: glow 1.6s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 3px rgba(255, 211, 106, .5), 0 0 30px rgba(255, 211, 106, .5); } }
.clock { font-weight: 700; color: var(--gold2); }
.clock.low { color: var(--bad); animation: pulse 0.8s infinite; }
@keyframes pulse { 50% { transform: scale(1.25); } }
.roster { position: absolute; top: calc(66px + var(--safe-t)); left: 10px; display: flex; flex-direction: column; gap: 6px; max-width: 220px; }
.chip-p { display: flex; align-items: center; gap: 8px; text-align: left; padding: 7px 12px 7px 10px; border-radius: 14px; border: 2px solid transparent; background: var(--panel); cursor: pointer; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: transform .12s; }
.chip-p .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.chip-p .nm { font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.chip-p .nm small { color: var(--muted); font-weight: 400; }
.chip-p .pips { display: flex; gap: 3px; margin-left: auto; }
.chip-p .pips i { width: 7px; height: 12px; border-radius: 2px; background: rgba(255, 255, 255, .18); }
.chip-p .pips i.on { background: var(--c); }
.chip-p.sel { border-color: var(--c); transform: translateX(4px); box-shadow: 0 0 14px color-mix(in srgb, var(--c) 60%, transparent); }
.chip-p.turn::after { content: "⚓"; font-size: .8rem; margin-left: 2px; }
.chip-p.out { opacity: .4; text-decoration: line-through; }
.chip-p.me { cursor: default; }
.log { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--safe-b)); max-width: min(560px, calc(100vw - 150px)); text-align: center; font-size: .9rem; color: var(--gold2); text-shadow: 0 2px 6px rgba(0, 0, 0, .7); pointer-events: none; }
.bottom-tools { position: absolute; left: 10px; bottom: calc(10px + var(--safe-b)); right: 10px; display: flex; justify-content: space-between; align-items: flex-end; pointer-events: none; }
.bottom-tools > * { pointer-events: auto; }
.streak { padding: 8px 14px; border-radius: 14px; background: var(--panel); border: 1.5px solid var(--panel-b); font-size: .9rem; display: flex; gap: 8px; align-items: center; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.pipbar { display: inline-flex; gap: 3px; }
.pipbar i { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, .2); }
.pipbar i.on { background: var(--gold); }
.spy { padding: 11px 18px; border-radius: 16px; border: 2px solid var(--gold); background: linear-gradient(#1f4f80, #123256); font-weight: 700; cursor: pointer; font-size: 1rem; box-shadow: 0 6px 18px rgba(0, 0, 0, .4); animation: glow 1.8s ease-in-out infinite; }
.spy.on { background: linear-gradient(#ffe48a, #f0b53a); color: #3a2606; }

/* ---------- pergunta ---------- */
.sheet { position: fixed; z-index: 40; right: 14px; top: calc(70px + var(--safe-t)); bottom: 70px; width: min(440px, 42vw); display: flex; align-items: center; pointer-events: none; }
.sheet-card { pointer-events: auto; width: 100%; max-height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 18px 18px 20px; border-radius: 24px; background: var(--panel); border: 1.5px solid var(--c, var(--panel-b)); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: 0 20px 60px rgba(0, 0, 0, .5), 0 0 0 4px color-mix(in srgb, var(--c, #888) 22%, transparent); display: flex; flex-direction: column; gap: 10px; animation: slideIn .4s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes slideIn { from { opacity: 0; transform: translateX(40px) scale(.96); } }
.f-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chip { display: inline-block; font-weight: 700; font-size: .8rem; padding: 4px 11px; border-radius: 999px; background: var(--c); color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .35); }
.f-date { color: var(--gold2); font-weight: 600; font-size: .85rem; text-transform: uppercase; letter-spacing: 1px; }
.q-aim { color: var(--muted); font-size: .9rem; }
.q-aim b { color: var(--gold2); font-size: 1.1rem; }
.q-text { font-size: 1.35rem; line-height: 1.3; font-weight: 700; }
.opts { display: grid; gap: 9px; }
.opt { text-align: left; cursor: pointer; padding: 13px 16px; border-radius: 15px; border: 2px solid rgba(255, 255, 255, .2); background: rgba(255, 255, 255, .07); font-size: 1.05rem; transition: transform .1s, background .15s; }
.opt:hover:not(:disabled) { background: rgba(255, 255, 255, .14); transform: translateX(3px); }
.opt:disabled { cursor: default; }
.opt.bad { border-color: var(--bad); background: rgba(255, 90, 74, .18); animation: shake .35s; }
.opt.good { border-color: var(--ok); background: rgba(95, 214, 138, .22); }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.q-note { padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, .07); font-size: .95rem; line-height: 1.4; }
.q-note.ok { color: var(--ok); font-weight: 700; }
.q-note.no { color: #ffd0c8; }
.q-note b { color: var(--gold2); }

/* ---------- modais ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(5, 12, 24, .66); display: flex; align-items: center; justify-content: center; padding: 14px; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.modal-card { width: min(540px, 100%); max-height: calc(100vh - 28px); overflow-y: auto; background: var(--panel); border: 1.5px solid var(--panel-b); border-radius: 26px; box-shadow: 0 30px 80px rgba(0, 0, 0, .6); animation: popIn .4s cubic-bezier(.2, .9, .3, 1.25); padding: 22px; }
@keyframes popIn { from { opacity: 0; transform: translateY(24px) scale(.92); } }
.help h2 { font-family: var(--pirate); font-weight: 400; font-size: 2rem; margin-bottom: 10px; }
.help ul { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 10px; }
.help li { line-height: 1.45; padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, .06); }
.end { padding: 0; }
.end-head { text-align: center; padding: 22px 18px 16px; border-radius: 26px 26px 0 0; }
.end-head.win { background: linear-gradient(#3a6a2e, rgba(10, 28, 52, 0)); }
.end-head.lose { background: linear-gradient(#6a2e2e, rgba(10, 28, 52, 0)); }
.end-head .seal { font-size: 3.4rem; }
.end-head h2 { font-family: var(--pirate); font-weight: 400; font-size: 2.6rem; }
.end-body { padding: 4px 22px 22px; }
.end-body h3 { font-size: 1rem; color: var(--gold2); margin: 14px 0 8px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.kpis div { padding: 10px 6px; border-radius: 14px; background: rgba(255, 255, 255, .07); }
.kpis b { display: block; font-size: 1.6rem; color: var(--gold); }
.kpis small { color: var(--muted); font-size: .75rem; }
.prow { display: grid; grid-template-columns: 150px 1fr 44px; gap: 8px; align-items: center; font-size: .85rem; margin: 4px 0; }
.pbar { height: 10px; border-radius: 6px; background: rgba(255, 255, 255, .12); overflow: hidden; }
.pbar i { display: block; height: 100%; background: var(--c); }
.prow b { text-align: right; }
.missed { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.missed li { padding: 8px 12px; border-radius: 12px; background: rgba(255, 255, 255, .06); font-size: .85rem; display: flex; flex-direction: column; gap: 2px; }
.missed b { color: var(--ok); }
.end .row { margin-top: 16px; justify-content: center; }
.toast { position: fixed; z-index: 60; left: 50%; top: calc(124px + var(--safe-t)); transform: translate(-50%, -10px); opacity: 0; pointer-events: none; padding: 10px 18px; border-radius: 14px; background: rgba(10, 28, 52, .95); border: 1.5px solid var(--gold); transition: all .3s; max-width: calc(100vw - 24px); text-align: center; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- telas estreitas / retrato ---------- */
@media (max-width: 860px), (max-aspect-ratio: 1/1) {
  .menu-grid { grid-template-columns: 1fr; }
  .packs { grid-template-columns: 1fr; }
  .banner { font-size: .88rem; padding: 8px 12px; }
  .roster { top: calc(64px + var(--safe-t)); left: 10px; right: 10px; flex-direction: row; overflow-x: auto; max-width: none; padding-bottom: 4px; }
  .chip-p { flex: none; }
  .chip-p .nm { max-width: 80px; }
  .sheet { right: 0; left: 0; top: auto; bottom: 0; width: 100%; max-height: 58vh; align-items: flex-end; }
  .sheet-card { border-radius: 24px 24px 0 0; max-height: 58vh; padding-bottom: calc(20px + var(--safe-b)); animation-name: slideUp; }
  @keyframes slideUp { from { opacity: 0; transform: translateY(60px); } }
  .q-text { font-size: 1.18rem; }
  .toast { top: calc(150px + var(--safe-t)); }
  .log { bottom: calc(66px + var(--safe-b)); max-width: calc(100vw - 24px); }
  .prow { grid-template-columns: 120px 1fr 40px; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01s !important; } }
