:root {
  --bg: #1b1530;
  --bg2: #241c3f;
  --panel: #2d2450;
  --panel2: #3a2f66;
  --text: #f1edff;
  --muted: #a99fd0;
  --accent: #ffcc33;
  --accent2: #ff8a3d;
  --good: #5be38a;
  --bad: #ff5c6c;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(circle at 30% 20%, #33285c 0, var(--bg) 60%) fixed;
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600;
  background: var(--panel2); color: var(--text); cursor: pointer; transition: transform .08s, filter .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; filter: none; }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent2)); color: #2a1a00; }
.btn.danger { background: var(--bad); color: #fff; margin-top: 10px; width: 100%; }
.btn.big { font-size: 20px; padding: 14px 28px; }
.small-btn { padding: 6px 10px; font-size: 13px; }

input, select {
  font: inherit; color: var(--text); background: var(--bg2); border: 2px solid var(--panel2);
  border-radius: 10px; padding: 10px 12px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

/* ---------- Home ---------- */
.screen { height: 100%; }
#home { display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.home-card {
  width: min(420px, 100%); background: var(--panel); border-radius: 20px; padding: 28px;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 20px 60px #0007; text-align: center;
}
.home-bomb { width: 110px; margin: 0 auto; animation: wobble 1.6s ease-in-out infinite; }
h1 { margin: 0; font-size: 40px; letter-spacing: 1px; }
.tagline { margin: 0 0 10px; color: var(--muted); }
.home-card label { text-align: left; color: var(--muted); font-size: 14px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: 4px; text-align: center; min-width: 0; }
.room-browser { text-align: left; margin-top: 6px; }
.room-browser h2 { margin: 0 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.room-empty { color: var(--muted); font-size: 14px; padding: 6px 2px; }
.room-item {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 0; border-radius: 10px;
  background: var(--bg2); color: var(--text); font: inherit; cursor: pointer; text-align: left;
}
.room-item:hover { background: var(--panel2); }
.room-code { font-weight: 800; letter-spacing: 3px; color: var(--accent); }
.room-info { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.room-status { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--panel2); color: var(--muted); flex: none; }
.room-status.playing { background: #1f5a37; color: var(--good); }
.rules { text-align: left; color: var(--muted); font-size: 14px; margin-top: 6px; }
.rules summary { cursor: pointer; }
.rules li { margin: 6px 0; }

/* ---------- Room ---------- */
#room { display: grid; grid-template-columns: 1fr 320px; height: 100%; }
.game { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.arena { position: relative; flex: 1; min-height: 360px; overflow: hidden; }
.seats { position: absolute; inset: 0; }
.center { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }

.bomb {
  position: absolute; width: 170px; height: 170px; left: -85px; top: -85px;
  display: grid; place-items: center; z-index: 2;
}
.bomb img { width: 100%; height: 100%; position: absolute; inset: 0; }
.bomb.ticking img { animation: wobble 0.9s ease-in-out infinite; }
.prompt {
  position: relative; top: 12px; left: -6px; font-size: 34px; font-weight: 800; letter-spacing: 1px;
  color: #fff; text-shadow: 0 2px 6px #000; text-transform: uppercase;
}
.bomb.boom img { animation: boom .6s ease-out; }

.arrow {
  position: absolute; left: 0; top: 0; width: 0; height: 0; transition: transform .25s ease-out; z-index: 1;
}
.arrow-head {
  position: absolute; left: 70px; top: -14px; width: 0; height: 0;
  border-top: 14px solid transparent; border-bottom: 14px solid transparent; border-left: 34px solid var(--accent);
  filter: drop-shadow(0 0 6px #ffcc3388);
}
.arrow.hidden-arrow { opacity: 0; }

.seat {
  position: absolute; width: 150px; transform: translate(-50%, -50%); text-align: center;
  transition: left .3s, top .3s;
}
.seat .avatar {
  width: 58px; height: 58px; border-radius: 50%; margin: 0 auto 4px; display: grid; place-items: center;
  font-size: 26px; font-weight: 800; color: #1b1530; border: 3px solid transparent;
}
.seat.current .avatar { border-color: var(--accent); box-shadow: 0 0 18px var(--accent); }
.seat.me .name { color: var(--accent); }
.seat.dead { opacity: .35; filter: grayscale(1); }
.seat.spectator { opacity: .55; }
.seat .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .lives { font-size: 18px; min-height: 22px; letter-spacing: 2px; color: var(--bad); }
.seat .typed {
  min-height: 26px; margin-top: 2px; font-size: 18px; font-weight: 700; letter-spacing: .5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.seat .typed b { color: var(--accent); }
.seat .typed.ok { color: var(--good); }
.seat .typed.bad { color: var(--bad); animation: shake .3s; }

.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; background: #1b153099; z-index: 5;
  backdrop-filter: blur(2px);
}
.overlay-card { background: var(--panel); border-radius: 18px; padding: 24px 30px; text-align: center; max-width: 90%; box-shadow: 0 10px 40px #0008; }
.overlay-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.winner { font-size: 26px; font-weight: 800; color: var(--accent); margin-bottom: 8px; }
.winner:empty { display: none; }

.flash {
  position: absolute; left: 50%; top: 18px; transform: translateX(-50%); padding: 8px 16px; border-radius: 10px;
  background: var(--panel2); font-weight: 600; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 6;
  max-width: 90%; text-align: center;
}
.flash.show { opacity: 1; }
.flash.bad { background: #5a1f2c; }
.flash.good { background: #1f5a37; }

.bottom { padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.letters { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; max-width: 720px; }
.letters span {
  width: 24px; height: 28px; display: grid; place-items: center; border-radius: 6px; font-weight: 700;
  background: var(--panel2); text-transform: uppercase; font-size: 14px;
}
.letters span.have { background: var(--good); color: #0b2a17; }
.input-row { display: flex; gap: 8px; width: min(560px, 100%); }
.input-row input { flex: 1; font-size: 22px; text-align: center; min-width: 0; }
.input-row input.my-turn { border-color: var(--accent); box-shadow: 0 0 14px #ffcc3355; }
.special { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.special button { width: 38px; padding: 6px 0; }

/* ---------- Sidebar ---------- */
.side { background: var(--bg2); border-left: 1px solid #ffffff10; display: flex; flex-direction: column; min-height: 0; padding: 12px; gap: 12px; overflow: auto; }
.room-head { display: flex; justify-content: space-between; align-items: center; }
.code { font-size: 28px; font-weight: 800; letter-spacing: 5px; color: var(--accent); }
.panel { background: var(--panel); border-radius: var(--radius); padding: 12px; }
.panel h3 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.player-list li { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 8px; }
.player-list li .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.player-list li .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-list li .tag { font-size: 11px; color: var(--muted); }
.player-list li button { padding: 2px 8px; font-size: 12px; }
.settings { display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.settings label { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.settings input[type=number] { width: 64px; padding: 6px 8px; }
.settings select { padding: 6px 8px; }
.settings .pair { display: flex; align-items: center; gap: 4px; }
.settings .pair input { width: 56px; }
.settings label.check { justify-content: flex-start; color: var(--muted); }
.settings input:disabled, .settings select:disabled { opacity: .5; }
.chat-panel { flex: 1; display: flex; flex-direction: column; min-height: 220px; }
.chat { flex: 1; overflow-y: auto; font-size: 14px; display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; min-height: 120px; max-height: 50vh; }
.chat .sys { color: var(--muted); font-style: italic; }
.chat .who { font-weight: 700; color: var(--accent); }
#chatInput { width: 100%; padding: 8px 10px; }

/* ---------- Búgvi Clicker ---------- */
.bugvi-fab {
  position: fixed; left: 14px; top: 14px; z-index: 50; width: 52px; height: 52px; padding: 0; border-radius: 50%;
  border: 3px solid var(--accent); overflow: hidden; cursor: pointer; background: var(--panel);
  box-shadow: 0 4px 14px #0008; transition: transform .12s;
}
.bugvi-fab:hover { transform: scale(1.08) rotate(-4deg); }
.bugvi-fab img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 15%; display: block; }
.bugvi-modal { position: fixed; inset: 0; z-index: 60; background: #0009; display: grid; place-items: center; padding: 16px; }
.bugvi-card {
  position: relative; width: min(420px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--panel);
  border-radius: 20px; padding: 20px; text-align: center; box-shadow: 0 20px 60px #000a; user-select: none;
}
.bugvi-card h2 { margin: 0 0 6px; font-size: 26px; color: var(--accent); }
.bugvi-close { position: absolute; right: 12px; top: 12px; border: 0; background: var(--panel2); color: var(--text); width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 15px; }
.bugvi-count { font-size: 28px; font-weight: 800; }
.bugvi-rate { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.bugvi-big {
  width: 170px; height: 170px; padding: 0; margin: 4px auto 14px; display: block; border-radius: 50%; overflow: hidden;
  border: 5px solid var(--accent); background: none; cursor: pointer; box-shadow: 0 0 30px #ffcc3355;
  transition: transform .08s; -webkit-tap-highlight-color: transparent;
}
.bugvi-big:hover { transform: scale(1.04); }
.bugvi-big:active { transform: scale(.94); }
.bugvi-big.pop { animation: bugvi-pop .15s ease-out; }
.bugvi-big img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 15%; display: block; pointer-events: none; }
.bugvi-plus { position: absolute; pointer-events: none; font-weight: 800; color: var(--accent); font-size: 20px; transform: translate(-50%, -50%); animation: bugvi-float .9s ease-out forwards; text-shadow: 0 2px 4px #000; }
.bugvi-shop { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.bugvi-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--bg2); color: var(--text); font: inherit; text-align: left;
}
.bugvi-item:hover:not(:disabled) { background: var(--panel2); }
.bugvi-item:disabled { opacity: .45; cursor: default; }
.bi-icon { font-size: 26px; width: 34px; text-align: center; flex: none; }
.bi-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bi-text small { color: var(--muted); font-size: 12px; }
.bi-side { display: flex; flex-direction: column; align-items: flex-end; flex: none; }
.bi-cost { color: var(--accent); font-weight: 700; font-size: 14px; }
.bi-owned { font-size: 18px; font-weight: 800; }
.bugvi-reset { margin-top: 12px; border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; text-decoration: underline; }
.bugvi-buffs { min-height: 24px; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.buff { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.buff.frenzy { background: linear-gradient(90deg, var(--accent), var(--accent2)); color: #2a1a00; animation: bugvi-glow 1s ease-in-out infinite; }
.buff.combo { background: #5a2a1f; color: #ffb38a; }
.bugvi-stage { position: relative; min-height: 190px; }
.bugvi-golden {
  position: absolute; width: 58px; height: 58px; padding: 0; border-radius: 50%; overflow: hidden; cursor: pointer; z-index: 2;
  border: 3px solid #ffe066; background: none; box-shadow: 0 0 22px #ffd700, 0 0 6px #fff; animation: bugvi-golden-bob 1.2s ease-in-out infinite;
}
.bugvi-golden img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 15%; display: block; filter: sepia(1) saturate(4) hue-rotate(5deg) brightness(1.15); pointer-events: none; }
.bugvi-plus.lucky { color: var(--good); font-size: 24px; }
.bugvi-plus.golden { color: #ffe066; font-size: 18px; white-space: nowrap; }
.bugvi-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.bugvi-tab { flex: 1; border: 0; border-radius: 10px; padding: 8px; font: inherit; font-weight: 700; cursor: pointer; background: var(--bg2); color: var(--muted); }
.bugvi-tab.active { background: var(--panel2); color: var(--text); }
.bugvi-pane h3 { margin: 10px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); text-align: left; }
.bugvi-pane h3:first-child { margin-top: 0; }
.bugvi-submit { background: var(--bg2); border-radius: 12px; padding: 10px; margin-bottom: 10px; text-align: left; }
.bugvi-submit-label { font-size: 14px; margin-bottom: 8px; }
.bugvi-submit form { display: flex; gap: 6px; }
.bugvi-submit input { flex: 1; min-width: 0; padding: 8px 10px; }
.bugvi-msg { font-size: 13px; min-height: 18px; margin-top: 6px; color: var(--muted); }
.bugvi-msg.good { color: var(--good); }
.bugvi-msg.bad { color: var(--bad); }
.bugvi-board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; text-align: left; }
.bugvi-board li { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 10px; background: var(--bg2); }
.bugvi-board li.mine { outline: 2px solid var(--accent); }
.bugvi-board li.empty { color: var(--muted); justify-content: center; }
.bugvi-board .rank { width: 28px; font-weight: 800; text-align: center; flex: none; }
.bugvi-board .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.bugvi-board .score { color: var(--accent); font-weight: 700; flex: none; }
@keyframes bugvi-glow { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.3); } }
@keyframes bugvi-golden-bob { 0%,100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-6px) rotate(6deg); } }
/* ---------- Super Búgvi Bros. ---------- */
.bros-fab {
  position: fixed; right: 14px; top: 14px; z-index: 50; width: 52px; height: 52px; padding: 0; border-radius: 50%;
  border: 3px solid var(--accent); cursor: pointer; background: linear-gradient(180deg, #6ec6ff, #3d8ed8);
  box-shadow: 0 4px 14px #0008; font-size: 26px; display: grid; place-items: center; transition: transform .12s;
}
.bros-fab:hover { transform: scale(1.08) rotate(4deg); }
.side .room-head { padding-right: 58px; } /* keep the room code clear of the corner button */
.bros-modal { position: fixed; inset: 0; z-index: 60; background: #000b; display: grid; place-items: center; padding: 12px; }
.bros-card { position: relative; width: min(1000px, 100%); background: var(--panel); border-radius: 18px; padding: 14px; box-shadow: 0 20px 60px #000a; }
.bros-close { position: absolute; right: 8px; top: 8px; z-index: 3; border: 0; background: var(--panel2); color: var(--text); width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 15px; }
.bros-screen { position: relative; border-radius: 10px; overflow: hidden; line-height: 0; }
.bros-screen canvas { width: 100%; height: auto; display: block; outline: none; image-rendering: pixelated; max-height: calc(100vh - 150px); object-fit: contain; background: #000; }
.bros-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: #0007; line-height: normal; padding: 12px; }
.bros-box { background: var(--panel); border-radius: 16px; padding: 20px 26px; text-align: center; max-width: 520px; box-shadow: 0 10px 40px #000a; }
.bros-box h2 { margin: 0 0 8px; color: var(--accent); font-size: 28px; }
.bros-box p { margin: 0 0 14px; color: var(--muted); }
.bros-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.bros-levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.bros-level { border: 0; border-radius: 12px; padding: 12px 0; font: inherit; font-size: 20px; font-weight: 800; cursor: pointer; background: linear-gradient(180deg, var(--accent), var(--accent2)); color: #2a1a00; }
.bros-level:disabled { background: var(--bg2); color: var(--muted); cursor: default; }
.bros-help { margin-top: 10px; color: var(--muted); font-size: 13px; text-align: center; }
.bros-touch { display: none; justify-content: space-between; gap: 10px; margin-top: 10px; }
.bros-touch button { flex: 1; border: 0; border-radius: 14px; padding: 16px 0; font-size: 24px; background: var(--panel2); color: var(--text); touch-action: none; user-select: none; }
.bros-touch button.jump { flex: 1.4; background: linear-gradient(180deg, var(--accent), var(--accent2)); color: #2a1a00; }
@media (pointer: coarse) { .bros-touch { display: flex; } .bros-help { display: none; } }

@keyframes bugvi-pop { 0% { transform: scale(.9); } 100% { transform: scale(1); } }
@keyframes bugvi-float { 0% { opacity: 1; transform: translate(-50%, -50%); } 100% { opacity: 0; transform: translate(-50%, -140%); } }

@keyframes wobble { 0%,100% { transform: rotate(-4deg) scale(1); } 50% { transform: rotate(4deg) scale(1.04); } }
@keyframes boom { 0% { transform: scale(1); filter: brightness(1); } 30% { transform: scale(1.5); filter: brightness(3) hue-rotate(-30deg); } 100% { transform: scale(1); filter: brightness(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

@media (max-width: 860px) {
  #room { grid-template-columns: 1fr; grid-template-rows: minmax(480px, 1fr) auto; height: auto; min-height: 100%; }
  .side { border-left: 0; border-top: 1px solid #ffffff10; }
  .arena { min-height: 400px; }
  .seat { width: 110px; }
  .seat .avatar { width: 44px; height: 44px; font-size: 20px; }
  .bomb { width: 130px; height: 130px; left: -65px; top: -65px; }
  .prompt { font-size: 26px; }
  .arrow-head { left: 54px; }
}
