:root {
  --ink: #1b1611; --paper: #fbf3e4; --paper-2: #f3e7cf;
  --lotus: #ff4f8b; --lotus-soft: #ffc2d6; --pond: #3d8f88;
  --zap: #ffd23f; --danger: #ff6b35; --roach: #7a4322;
  --font: "Bricolage Grotesque", ui-rounded, system-ui, sans-serif;
  --shadow: 3px 3px 0 var(--ink);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--pond); color: var(--ink); font-family: var(--font);
  -webkit-tap-highlight-color: transparent; touch-action: none; overscroll-behavior: none; user-select: none; -webkit-user-select: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.card { background: var(--paper); border: 2.5px solid var(--ink); border-radius: 14px; box-shadow: var(--shadow); }
.chip { display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: .06em; padding: 2px 7px; border: 2px solid var(--ink); border-radius: 99px; background: var(--zap); }
kbd { font: 700 11px var(--font); background: var(--paper-2); border: 1.5px solid var(--ink); border-bottom-width: 3px; border-radius: 5px; padding: 0 5px; }

/* ---------------------------------------------------------------- intro */
#intro { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; gap: 14px;
  background: radial-gradient(ellipse at center, rgba(27,22,17,0) 30%, rgba(27,22,17,.35) 100%); transition: opacity .4s; }
#intro.leaving { opacity: 0; pointer-events: none; }
.intro-card { width: min(460px, 100%); padding: 26px 26px 20px; text-align: center; transform: rotate(-.6deg); }
.logo { margin: 0; font-size: clamp(46px, 13vw, 78px); font-weight: 800; letter-spacing: -.045em; line-height: .9; display: flex; align-items: center; justify-content: center; }
.logo span { color: var(--ink); }
.logo-roach { width: .6em; height: .9em; margin: 0 -.02em; transform: rotate(-90deg) translateX(-.04em); animation: wiggle 1.4s ease-in-out infinite; }
@keyframes wiggle { 50% { transform: rotate(-84deg) translateX(-.04em); } }
.tagline { font-size: 18px; font-weight: 800; margin: 14px 0 8px; line-height: 1.35; }
.tagline em { font-style: normal; background: var(--lotus); color: #fff; padding: 0 6px; border-radius: 4px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.pitch { margin: 0 0 18px; font-size: 14.5px; font-weight: 500; color: #4a4036; }
.name-row { display: flex; align-items: center; gap: 8px; border: 2.5px solid var(--ink); border-radius: 12px; padding: 4px 4px 4px 12px; background: #fff; text-align: left; }
.name-label { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: #8a7c6c; position: absolute; transform: translateY(-21px); background: var(--paper); padding: 0 4px; margin-left: -4px; }
.name-row { position: relative; }
#nameInput { flex: 1; min-width: 0; border: 0; outline: 0; font: 700 17px var(--font); padding: 8px 0; background: transparent; color: var(--ink); user-select: text; -webkit-user-select: text; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 2.5px solid var(--ink); background: var(--paper); display: grid; place-items: center; padding: 0; box-shadow: 2px 2px 0 var(--ink); }
.icon-btn:active { transform: translate(2px, 2px); box-shadow: none; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#reroll svg circle { fill: var(--ink); stroke: none; }
.big-btn { width: 100%; margin-top: 14px; padding: 15px; font-size: 20px; font-weight: 800; letter-spacing: .01em; background: var(--lotus); color: #fff;
  border: 2.5px solid var(--ink); border-radius: 12px; box-shadow: 4px 4px 0 var(--ink); transition: transform .08s, box-shadow .08s; text-shadow: 0 2px 0 rgba(0,0,0,.18); }
.big-btn:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.big-btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.big-btn:disabled { background: #d9cbb5; color: #6b5f52; cursor: wait; }
.live { margin: 14px 0 10px; font-size: 13.5px; font-weight: 600; min-height: 1.3em; }
.live b { background: var(--zap); padding: 0 4px; border-radius: 4px; }
.controls-hint { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; font-size: 12px; font-weight: 600; color: #5d5246; }
.footnote { margin: 0; font-size: 12px; font-weight: 600; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.4); text-align: center; }
@media (pointer: coarse) { .controls-hint { display: none; } }

/* ---------------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#hud .bloom { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); width: min(400px, calc(100% - 24px)); padding: 9px 12px 8px; }
.bloom-top { display: flex; align-items: center; gap: 8px; font-size: 15px; white-space: nowrap; overflow: hidden; }
.bloom-top b { overflow: hidden; text-overflow: ellipsis; }
.petals { display: flex; align-items: flex-end; gap: 3px; margin: 7px 0 5px; height: 18px; }
.pip { position: relative; flex: 1; height: 100%; border: 2px solid var(--ink); border-radius: 50% 50% 4px 4px / 70% 70% 4px 4px; background: #e9dccb; overflow: hidden; }
.pip.inner { height: 75%; }
.pip.core { flex: 1.6; border-radius: 6px; }
.pip i { position: absolute; left: 0; right: 0; bottom: 0; background: var(--lotus); transition: height .15s linear; }
.pip.inner i { background: #ff86ae; }
.pip.core i { background: #c7d65a; }
.pip.down { background: #9b6b4f; opacity: .45; }
.pip.shield { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px #6fd0ff; }
.pip.rally::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(45deg, transparent 0 3px, rgba(255,210,63,.75) 3px 6px); }
.pip.locked::before { content: '🔒'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 9px; z-index: 1; }
.gold .pip i { background: #ffb320; }
.hp { position: relative; height: 10px; border: 2px solid var(--ink); border-radius: 99px; background: #e9dccb; overflow: hidden; }
.hp-fill { position: absolute; inset: 0 auto 0 0; width: 100%; background: var(--lotus); transition: width .2s; }
.gold .hp-fill { background: #ffb320; }
.hp span { display: none; }
.stats { display: flex; align-items: center; justify-content: center; margin-top: 6px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stats b { font-weight: 800; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: #3ccf6e; margin-right: 6px; box-shadow: 0 0 0 0 rgba(60,207,110,.6); animation: pulse 1.6s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(60,207,110,0); } 100% { box-shadow: 0 0 0 0 rgba(60,207,110,0); } }

#ticker { position: absolute; top: 128px; left: 50%; transform: translateX(-50%); width: min(560px, calc(100% - 24px)); display: flex; align-items: stretch;
  background: var(--paper); border: 2.5px solid var(--ink); box-shadow: var(--shadow); overflow: hidden; animation: drop .3s ease-out; }
#ticker .tag { background: #e3262f; color: #fff; font-weight: 800; font-size: 12px; letter-spacing: .08em; padding: 6px 9px; border-right: 2.5px solid var(--ink); display: grid; place-items: center; }
#ticker .track { flex: 1; overflow: hidden; white-space: nowrap; position: relative; }
#tickerText { display: inline-block; padding: 6px 0 6px 100%; font-weight: 700; font-size: 14px; animation: scroll 13s linear infinite; }
@keyframes scroll { to { transform: translateX(-100%); } }
@keyframes drop { from { transform: translate(-50%, -20px); opacity: 0; } }

#board { position: absolute; top: 12px; right: 12px; width: 210px; padding: 4px 10px 8px; font-size: 13px; }
.board-head { all: unset; cursor: pointer; display: flex; justify-content: space-between; width: 100%; font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; padding: 4px 0; }
#board.collapsed ol { display: none; }
#board.collapsed .caret { transform: rotate(-90deg); display: inline-block; }
#lb { margin: 2px 0 0; padding: 0; list-style: none; counter-reset: r; }
#lb li { counter-increment: r; display: flex; align-items: center; gap: 6px; padding: 3px 0; border-top: 1.5px dashed #d8c9b0; font-weight: 600; }
#lb li::before { content: counter(r); font-weight: 800; width: 14px; }
#lb li .sw { width: 9px; height: 9px; border-radius: 3px; border: 1.5px solid var(--ink); flex: none; }
#lb li .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lb li .dm { font-variant-numeric: tabular-nums; font-weight: 800; }
#lb li.me { background: #fff5c7; margin: 0 -6px; padding: 3px 6px; border-radius: 6px; }
#lb .empty { font-weight: 500; color: #7a6d5f; border: 0; }
#lb .empty::before { content: none; }

#me { position: absolute; left: 12px; bottom: calc(12px + var(--safe-b)); display: flex; gap: 10px; align-items: center; padding: 8px 12px 8px 8px; width: 250px; }
.lvl { width: 44px; height: 44px; flex: none; display: grid; place-items: center; font-weight: 800; font-size: 20px; background: var(--zap); border: 2.5px solid var(--ink); border-radius: 50%; }
.me-body { flex: 1; min-width: 0; }
.me-name { font-weight: 800; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-title { font-size: 11.5px; font-weight: 600; color: #6e6152; margin-bottom: 5px; }
.xp { height: 8px; border: 2px solid var(--ink); border-radius: 99px; background: #e9dccb; overflow: hidden; }
.xp-fill { height: 100%; width: 0; background: var(--zap); transition: width .3s; }

#swarm { position: absolute; left: 50%; bottom: calc(22px + var(--safe-b)); transform: translateX(-50%); display: flex; align-items: baseline; gap: 6px; padding: 5px 12px;
  background: var(--zap); border: 2.5px solid var(--ink); border-radius: 99px; box-shadow: var(--shadow); font-size: 12px; font-weight: 700; }
#swarm b { font-size: 18px; font-weight: 800; }

#abilities { position: absolute; right: 12px; bottom: calc(12px + var(--safe-b)); display: flex; gap: 10px; align-items: flex-end; }
.ab { position: relative; width: 58px; height: 58px; border-radius: 50%; border: 2.5px solid var(--ink); background: var(--paper); box-shadow: var(--shadow);
  display: grid; place-items: center; padding: 0; touch-action: none; overflow: hidden; }
.ab.down, .ab.flash { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.ab-icon { font-size: 24px; font-weight: 800; line-height: 1; }
.ab-key { position: absolute; bottom: 5px; font-size: 9px; font-weight: 800; letter-spacing: .05em; color: #7a6d5f; }
.ab-lock { display: none; position: absolute; inset: 0; place-items: center; background: rgba(233,220,203,.9); font-size: 12px; font-weight: 800; }
.ab.locked .ab-lock { display: grid; }
.ab .cd { position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(rgba(27,22,17,.45) calc(var(--cd, 0) * 360deg), transparent 0); pointer-events: none; }
.ab.active { background: var(--zap); }
.ab-bite { width: 82px; height: 82px; background: var(--lotus); color: #fff; }
.ab-bite .ab-icon { font-size: 19px; letter-spacing: .02em; text-shadow: 0 2px 0 rgba(0,0,0,.2); }
.ab-bite .ab-key { color: rgba(255,255,255,.85); }
.ab-bite.ready { animation: throb .7s ease-in-out infinite; }
@keyframes throb { 50% { box-shadow: 0 0 0 6px rgba(255,79,139,.35), var(--shadow); } }
@media (pointer: coarse) { .ab-key { display: none; } .ab { width: 62px; height: 62px; } .ab-bite { width: 92px; height: 92px; } }

#toasts { position: absolute; top: 176px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; width: min(420px, 92vw); }
.toast { background: var(--paper); border: 2.5px solid var(--ink); border-radius: 10px; box-shadow: var(--shadow); padding: 7px 12px; font-size: 13.5px; font-weight: 700;
  animation: toastIn .25s ease-out, toastOut .4s ease-in forwards; animation-delay: 0s, var(--life, 3.2s); text-align: center; }
.toast.zap { background: var(--zap); }
.toast.pink { background: var(--lotus); color: #fff; }
.toast.ach { display: flex; gap: 10px; align-items: center; text-align: left; }
.toast.ach .medal { width: 30px; height: 30px; flex: none; border-radius: 50%; background: var(--zap); border: 2.5px solid var(--ink); display: grid; place-items: center; font-size: 15px; }
.toast small { display: block; font-weight: 500; font-size: 12px; }
@keyframes toastIn { from { transform: translateY(-10px) scale(.95); opacity: 0; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-6px); } }

#banner { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; width: 92vw; }
#banner .big { display: inline-block; font-size: clamp(38px, 9vw, 84px); font-weight: 800; letter-spacing: -.04em; line-height: .95; color: #fff;
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 5px 5px 0 var(--ink); animation: slam .45s cubic-bezier(.2,1.6,.4,1); transform: rotate(-2deg); }
#banner .big.gold { color: var(--zap); }
#banner .sub { display: inline-block; margin-top: 12px; background: var(--paper); border: 2.5px solid var(--ink); box-shadow: var(--shadow); border-radius: 10px; padding: 6px 14px; font-weight: 700; font-size: 15px; }
#banner .actions { margin-top: 12px; pointer-events: auto; }
#banner .actions button { padding: 9px 16px; font-weight: 800; font-size: 15px; background: var(--zap); border: 2.5px solid var(--ink); border-radius: 10px; box-shadow: var(--shadow); }
#banner .podium { margin: 12px auto 0; display: inline-flex; flex-direction: column; gap: 4px; background: var(--paper); border: 2.5px solid var(--ink); border-radius: 10px; padding: 8px 14px; box-shadow: var(--shadow); font-weight: 700; font-size: 14px; text-align: left; }
@keyframes slam { from { transform: scale(2.2) rotate(-8deg); opacity: 0; } }

#hint { position: absolute; left: 50%; bottom: calc(108px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: var(--paper); font-weight: 700; font-size: 14px;
  padding: 8px 14px; border-radius: 10px; pointer-events: none; white-space: nowrap; animation: toastIn .25s; }
#hint kbd { color: var(--ink); }

.corner-btns { position: absolute; left: 12px; top: 12px; display: flex; gap: 8px; }
#muteBtn svg { width: 20px; }
#conn { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 12px; font-weight: 700; }

.away { position: absolute; left: 12px; bottom: calc(86px + var(--safe-b)); width: 250px; padding: 10px 12px; font-size: 13px; animation: toastIn .3s; }
.away h4 { margin: 0 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.away ul { margin: 0; padding-left: 16px; font-weight: 600; }

/* phones: tighten everything around the game world */
@media (max-width: 720px) {
  #hud .bloom { top: 8px; width: calc(100% - 120px); left: 56px; transform: none; padding: 6px 9px; }
  .bloom-top { font-size: 12.5px; } .chip { font-size: 9.5px; padding: 1px 5px; }
  .petals { height: 13px; margin: 5px 0 4px; gap: 2px; } .pip { border-width: 1.5px; }
  .stats { font-size: 10.5px; margin-top: 4px; }
  #board { top: 8px; right: 8px; width: auto; max-width: 52px; padding: 2px 6px; }
  #board .board-head { font-size: 0; } #board .board-head .caret { font-size: 16px; }
  #board.open { max-width: 220px; } #board.open .board-head { font-size: 11px; }
  #board:not(.open) ol { display: none; }
  .corner-btns { top: 8px; left: 8px; flex-direction: column; } .icon-btn { width: 38px; height: 38px; }
  #me { top: 98px; bottom: auto; left: 56px; width: 168px; padding: 5px 8px 5px 5px; gap: 7px; }
  .lvl { width: 32px; height: 32px; font-size: 15px; border-width: 2px; }
  .me-name { font-size: 12px; } .me-title { font-size: 10.5px; margin-bottom: 3px; }
  #ticker { top: auto; bottom: calc(118px + var(--safe-b)); }
  #tickerText { font-size: 12.5px; } #ticker .tag { font-size: 10px; padding: 4px 6px; }
  #toasts { top: 160px; } .toast { font-size: 12.5px; padding: 6px 10px; }
  #hint { bottom: calc(166px + var(--safe-b)); font-size: 12.5px; white-space: normal; text-align: center; max-width: 88vw; }
  .away { top: 160px; bottom: auto; left: 8px; width: 210px; }
  #swarm { bottom: auto; top: 98px; left: auto; right: 8px; transform: none; padding: 4px 10px; }
  #swarm span { display: none; }
}

/* ---------------------------------------------------------------- rooms, invites, national scoreboard */
.room-chip { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; height: 40px; padding: 0 10px; border: 2.5px solid var(--ink);
  border-radius: 10px; background: var(--zap); box-shadow: 2px 2px 0 var(--ink); line-height: 1; }
.room-chip span { font-size: 8.5px; font-weight: 800; letter-spacing: .1em; }
.room-chip b { font-size: 14px; font-weight: 800; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.room-chip:active { transform: translate(2px, 2px); box-shadow: none; }
.nation { margin: 6px 0 0; padding-top: 6px; border-top: 2px solid var(--ink); font-size: 11.5px; font-weight: 700; }
.nation:empty { display: none; }
.invite-line { margin: -4px 0 10px; font-size: 13px; font-weight: 700; background: #fff5c7; border: 2px dashed var(--ink); border-radius: 8px; padding: 6px 8px; }
#lb li .sw { background: var(--sw, #ccc); }

/* ---------------------------------------------------------------- ticker share */
.ticker-share { border: 0; border-left: 2.5px solid var(--ink); background: var(--zap); font-weight: 800; font-size: 12px; padding: 0 12px; letter-spacing: .04em; }
.ticker-share:hover { background: #ffe27a; }

/* ---------------------------------------------------------------- overlays: queue, idle, share modal */
.overlay, .modal { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(27,22,17,.45); z-index: 20; }
.overlay-card { width: min(420px, 100%); padding: 22px; text-align: center; }
.overlay-card h2 { margin: 10px 0 6px; font-size: 26px; letter-spacing: -.02em; text-wrap: balance; }
.overlay-card p { margin: 6px 0; font-weight: 600; }
.overlay-card .muted { font-weight: 500; color: #6e6152; font-size: 13px; }
#queuePos { background: var(--zap); padding: 0 6px; border-radius: 6px; }
.modal-card { width: min(640px, 100%); padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.news-preview { width: 100%; height: auto; border: 2.5px solid var(--ink); border-radius: 8px; display: block; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn, .btn-primary { flex: 1 1 auto; text-align: center; text-decoration: none; color: var(--ink); padding: 10px 14px; font-weight: 800; font-size: 15px;
  border: 2.5px solid var(--ink); border-radius: 10px; box-shadow: 2px 2px 0 var(--ink); background: var(--paper); }
.btn-primary { background: var(--lotus); color: #fff; }
.btn-ghost { flex: 0 0 auto; box-shadow: none; }
.btn:active, .btn-primary:active { transform: translate(2px, 2px); box-shadow: none; }
:focus-visible { outline: 3px solid var(--zap); outline-offset: 2px; }
.sprites { position: absolute; width: 0; height: 0; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
@media (max-width: 720px) {
  .room-chip { height: 38px; padding: 0 7px; } .room-chip b { font-size: 12px; }
}

/* ---------------------------------------------------------------- detention pod card */
.detained { position: fixed; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%); width: min(440px, calc(100% - 24px));
  padding: 14px 16px; text-align: center; z-index: 15; }
.detained h2 { margin: 8px 0 4px; font-size: 21px; letter-spacing: -.01em; text-wrap: balance; }
.detained p { margin: 4px 0; font-weight: 600; font-size: 14px; }
.detained .muted { font-weight: 500; color: #6e6152; font-size: 12.5px; }
.chip-police { background: #2f5aa8; color: #fff; }
@media (max-width: 720px) { #board:not(.open) .nation { display: none; } }
/* While detained there is no cockroach to steer yet: hide the player card and controls. */
body.is-detained #me, body.is-detained #abilities, body.is-detained #swarm, body.is-detained #hint { display: none; }

.pip.hit { animation: pipHit .25s ease-out; }
@keyframes pipHit { 40% { transform: translateY(-3px) scale(1.18); background: #fff; } }
@media (max-width: 720px) { #toasts { top: 182px; } }
