*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Poppins', sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Default (pre-game) wrapper — constrained on page ──── */

#cube-game-section {
  padding: 24px 16px 40px;
}

/* ── Inner playable area ─────────────────────────────────  */

.game-inner {
  position: relative;
  width: 100%;
  height: 90dvh;
  border-radius: 20px;
  overflow: hidden;
  background: #fff;
  touch-action: manipulation;
}

#gameCanvas {
  display: block;
  width: 100%; height: 100%;
  position: absolute; top: 0; left: 0;
  z-index: 2;
  touch-action: none;
  cursor: pointer;
  border-radius: 20px;
}

/* ── Panels ────────────────────────────────────────────── */

#ui-overlay {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 5;
}

.panel {
  display: none;
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: all;
  flex-direction: column; align-items: center; justify-content: center;
}
.panel.active { display: flex; }

/* ── Menu ───────────────────────────────────────────────── */

#panel-menu {
  background: linear-gradient(160deg, #64B5F6 0%, #1565C0 100%);
  gap: 0;
}

.toy-logo {
  font-size: clamp(2.8rem, 10vw, 5rem);
  color: #FFF;
  text-shadow: 4px 4px 0 #0D47A1, 8px 8px 0 rgba(0,0,0,0.2);
  letter-spacing: 3px;
  margin-bottom: 0.15em;
  line-height: 1;
}
.toy-logo em {
  font-style: normal;
  color: #FDD835;
}

.toy-subtitle {
  font-size: clamp(1rem, 3.5vw, 1.4rem);
  color: rgba(255,255,255,0.9);
  margin-bottom: 2.5em;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}

.toy-cubes-preview {
  display: flex; gap: 10px; margin-bottom: 2em;
}
.toy-cubes-preview img {
  width: clamp(4.5rem, 10vw, 7rem); height: clamp(4.5rem, 10vw, 7rem); object-fit: contain;
}

.menu-buttons {
  display: flex; flex-direction: column;
  gap: 14px; width: 100%; max-width: 280px;
  align-items: center;
}

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.4em;
  padding: 0.7em 1.8em;
  border: none; border-radius: 50px;
  font-family: 'Poppins', sans-serif;
  font-size: clamp(1rem, 3vw, 1.25rem);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 6px 0 rgba(0,0,0,0.22);
  min-width: 200px; letter-spacing: 1px;
  text-decoration: none;
}
.btn:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,0.22); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: 0 6px 0 rgba(0,0,0,0.22); }

.btn-primary   { background: #F5A623; color: #FFF; }
.btn-secondary { background: #5C2D91; color: #FFF; }
.btn-success   { background: #388E3C; color: #FFF; }
.btn-warning   { background: #E84D8A; color: #FFF; }
.btn-dark      { background: #4E342E; color: #FFF; min-width: 140px; }
.btn-sm        { font-size: 0.95rem; padding: 0.5em 1.2em; min-width: 120px; }

/* ── HUD (in-game overlay) ────────────────────────────── */

#hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 4px;
  padding: 10px 14px;
  background: rgba(21,101,192,0.92);
  color: #FFF;
  pointer-events: none;
  z-index: 30;
  backdrop-filter: blur(4px);
}

#hud-round { font-size: clamp(0.85rem, 2.5vw, 1.1rem); }
#hud-lives { font-size: clamp(1rem, 2.8vw, 1.3rem); letter-spacing: 2px; }
#hud-score { font-size: clamp(0.85rem, 2.5vw, 1.1rem); color: #FDD835; }
#hud-combo { font-size: clamp(0.8rem, 2vw, 1rem); color: #FFE082; display: none; }

#hud-timer {
  position: absolute; top: 52px; left: 0; right: 0;
  height: 7px; background: rgba(0,0,0,0.25);
  pointer-events: none; z-index: 30;
}
#hud-timer-bar {
  height: 100%;
  background: linear-gradient(90deg, #66BB6A 0%, #FFA726 60%, #EF5350 100%);
  width: 100%;
  transition: width 0.1s linear;
  border-radius: 0 4px 4px 0;
}

#hud-bottom {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 10px 14px;
  background: rgba(21,101,192,0.92);
  z-index: 30; pointer-events: all;
  backdrop-filter: blur(4px);
}

#tap-display {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center;
  opacity: 0.5; pointer-events: none;
  z-index: 1;
}

#tap-count {
  font-size: clamp(6rem, 22vw, 14rem);
  font-weight: 700;
  color: #333;
  text-align: center;
  /* text-shadow: 4px 4px 0 rgba(0,0,0,0.4); */
  transition: transform 0.1s;
  line-height: 1;
}
#tap-count.pulse { transform: scale(1.12); }

.tap-btn {
  display: flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: 50%;
  border: none; font-size: 1.3rem; cursor: pointer;
  font-family: 'Poppins', sans-serif;
  /* box-shadow: 0 4px 0 rgba(0,0,0,0.25); */
  transition: transform 0.1s, box-shadow 0.1s;
  color: #FFF;
}
.tap-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.25); }
#btn-backspace { background: #FF8F00; }
#btn-pause     { background: rgba(0,0,0,0.35); pointer-events: all; }
#btn-exit-game { background: rgba(183,28,28,0.75); pointer-events: all; }

#btn-submit {
  background: #388E3C; color: #FFF;
  min-width: 100px; height: 48px; border-radius: 24px;
  padding: 0 18px; font-size: 1.05rem;
  border: none; cursor: pointer;
  font-family: 'Poppins', sans-serif;
  box-shadow: 0 4px 0 rgba(0,0,0,0.25);
  transition: transform 0.1s, box-shadow 0.1s;
}
#btn-submit:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.25); }
#btn-submit:disabled { background: #9E9E9E; cursor: not-allowed; transform: none; }
#btn-submit::after { content: ' [Enter]'; opacity: 0.7; font-size: 0.8em; }
@media (pointer: coarse) { #btn-submit::after { content: ''; } }

/* ── Tap hint button ─────────────────────────────────── */

#btn-tap-hint {
  position: absolute; bottom: 0%; right: 0%; transform: translateX(-50%) translateY(-200%);
  background: rgba(255, 152, 0, 0.92);
  color: #fff;
  border: none; border-radius: 50px;
  padding: 12px 32px;
  font-size: clamp(1rem, 4vw, 1.4rem);
  font-weight: 700; font-family: 'Poppins', sans-serif;
  cursor: pointer; pointer-events: all; z-index: 35;
  box-shadow: 0 6px 0 rgba(0,0,0,0.3), 0 0 24px rgba(255,152,0,0.45);
  white-space: nowrap;
  animation: tapHintPulse 1s ease-in-out infinite;
}
#btn-tap-hint:active {
  transform: translateX(-50%) translateY(-200%);
  box-shadow: 0 3px 0 rgba(0,0,0,0.3);
  animation: none;
}
#btn-tap-hint:disabled {
  background: rgba(150, 150, 150, 0.6);
  box-shadow: none;
  cursor: not-allowed;
  pointer-events: none;
  animation: none;
  opacity: 0.5;
}

@keyframes tapHintPulse {
  0%, 100% { transform: translateX(-50%) translateY(-200%) scale(1); }
  50%       { transform: translateX(-50%) translateY(-200%) scale(1.1); }
}

/* ── Feedback overlay ────────────────────────────────── */

#feedback-overlay {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  display: none; align-items: center; justify-content: center;
  flex-direction: column; z-index: 20; pointer-events: none;
}
#feedback-overlay.active { display: flex; }
.feedback-correct { background: rgba(27,94,32,0.82); }
.feedback-wrong   { background: rgba(183,28,28,0.82); }

#feedback-text {
  font-size: clamp(2.5rem, 9vw, 5rem); color: #FFF;
  text-shadow: 3px 3px 0 rgba(0,0,0,0.25);
  animation: feedPop 0.35s cubic-bezier(0.34,1.56,0.64,1) both;
}
#feedback-sub {
  font-size: clamp(1rem, 3.5vw, 1.6rem);
  color: rgba(255,255,255,0.92); margin-top: 0.4em;
}
@keyframes feedPop {
  from { transform: scale(0.4); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ── Countdown overlay ───────────────────────────────── */

#countdown-overlay {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  display: none; align-items: center; justify-content: center;
  z-index: 25; background: rgba(21,101,192,0.65);
  pointer-events: none;
}
#countdown-overlay.active { display: flex; }
#countdown-num {
  font-size: clamp(5rem, 22vw, 11rem); color: #FFF;
  text-shadow: 4px 4px 0 rgba(0,0,0,0.25);
  animation: cdPop 0.75s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes cdPop {
  0%   { transform: scale(2.2); opacity: 0; }
  60%  { transform: scale(0.93); opacity: 1; }
  100% { transform: scale(1);   opacity: 1; }
}

/* ── Lobby ───────────────────────────────────────────── */

#panel-lobby {
  background: linear-gradient(160deg, #1E88E5 0%, #0D47A1 100%);
  gap: 0; overflow-y: auto; padding: 20px;
}

.lobby-title {
  font-size: clamp(1.5rem, 5.5vw, 2.2rem);
  color: #FFF; text-shadow: 2px 2px 0 rgba(0,0,0,0.2);
  margin-bottom: 1.2em;
}

.lobby-input {
  font-family: 'Poppins', sans-serif; font-size: 1.1rem;
  padding: 10px 16px; border-radius: 50px;
  border: 3px solid rgba(255,255,255,0.35);
  background: rgba(255,255,255,0.15); color: #FFF;
  width: 100%; max-width: 280px; text-align: center; outline: none;
  margin-bottom: 10px;
}
.lobby-input::placeholder { color: rgba(255,255,255,0.5); }
.lobby-input:focus { border-color: #FDD835; }

.lobby-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 12px; }

.room-code-box {
  background: rgba(255,255,255,0.12); border-radius: 14px;
  padding: 10px 20px; margin-bottom: 1.2em; text-align: center;
}
.room-code-label { font-size: 0.85rem; color: rgba(255,255,255,0.65); }
.room-code-value { font-size: clamp(1.8rem, 7vw, 2.8rem); color: #FDD835; letter-spacing: 8px; }

.player-list {
  list-style: none; width: 100%; max-width: 360px;
  margin-bottom: 1.2em; max-height: 200px; overflow-y: auto;
}
.player-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; background: rgba(255,255,255,0.1);
  border-radius: 10px; margin-bottom: 6px; color: #FFF; font-size: 1rem;
}
.player-badge { margin-left: auto; border-radius: 20px; padding: 2px 10px; font-size: 0.8rem; }
.player-ready-badge   { background: #388E3C; color: #FFF; }
.player-waiting-badge { background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.6); }

.lobby-status { color: rgba(255,255,255,0.75); font-size: 0.95rem; text-align: center; margin-bottom: 10px; }

/* ── Game Over ───────────────────────────────────────── */

#panel-gameover {
  background: linear-gradient(160deg, #1E88E5 0%, #0D47A1 100%);
  gap: 0; overflow-y: auto; padding: 20px;
}

#gameover-title {
  font-size: clamp(2rem, 7vw, 3.5rem);
  color: #FDD835; text-shadow: 3px 3px 0 rgba(0,0,0,0.25);
  margin-bottom: 0.5em;
}

.score-list { list-style: none; width: 100%; max-width: 380px; margin-bottom: 1.5em; }
.score-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 12px;
  margin-bottom: 8px; font-size: 1rem; color: #FFF;
}
.score-item:nth-child(1) { background: rgba(255,215,0,0.25); border: 2px solid gold; }
.score-item:nth-child(2) { background: rgba(192,192,192,0.18); }
.score-item:nth-child(3) { background: rgba(205,127,50,0.18); }
.score-item:not(:nth-child(-n+3)) { background: rgba(255,255,255,0.08); }
.score-rank { font-size: 1.2rem; min-width: 2em; text-align: center; }
.score-name { flex: 1; }
.score-pts  { color: #FDD835; }

.gameover-buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

/* ── Scoreboard ──────────────────────────────────────── */

#scoreboard {
  position: absolute; top: 64px; right: 8px;
  background: rgba(21,101,192,0.88);
  border-radius: 12px; padding: 8px 12px;
  z-index: 10; pointer-events: none;
  min-width: 130px; display: none;
  backdrop-filter: blur(3px);
}
#scoreboard.active { display: block; }
.sb-title { color: rgba(255,255,255,0.6); font-size: 0.75rem; margin-bottom: 5px; text-align: center; }
.sb-entry { display: flex; justify-content: space-between; gap: 8px; color: #FFF; font-size: 0.88rem; padding: 2px 0; }
.sb-entry.eliminated { color: rgba(255,255,255,0.35); text-decoration: line-through; }
.sb-entry.local { color: #FDD835; }
.sb-score { color: #FDD835; }

/* ── Spectator & tiebreaker banners ──────────────────── */

#spectator-banner, #tiebreaker-banner {
  position: absolute; top: 62px; left: 0; right: 0;
  text-align: center; padding: 7px; z-index: 15;
  pointer-events: none; display: none; color: #FFF; font-size: 0.95rem;
}
#spectator-banner.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  top: 50%;
  left: 50%;
  right: auto;
  bottom: auto;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: 90%;
  padding: 20px 36px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.78);
  border: 2px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(8px);
  gap: 6px;
  animation: spectator-pulse 2.4s ease-in-out infinite;
}
#spectator-banner .spec-icon {
  font-size: 2.6rem;
  line-height: 1;
}
#spectator-banner .spec-label {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #fff;
}
#spectator-banner .spec-sub {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.55);
  letter-spacing: 0.06em;
}
@keyframes spectator-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.10); opacity: 1; }
  50%       { box-shadow: 0 0 0 12px rgba(255,255,255,0); opacity: 0.85; }
}

/* ── Pause overlay ─────────────────────────────────────── */
#panel-pause {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  z-index: 50;
  pointer-events: all;
}
.pause-box {
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  background: rgba(21,101,192,0.96);
  border-radius: 20px; padding: 36px 48px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.pause-title {
  font-size: clamp(1.8rem, 6vw, 2.5rem);
  color: #FFF;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.3);
  margin: 0;
}
.pause-buttons {
  display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%;
}

#tiebreaker-banner.active {
  display: block;
  animation: tbPulse 0.9s infinite;
}
@keyframes tbPulse {
  0%,100% { background: rgba(106,27,154,0.9); }
  50%      { background: rgba(233,30,99,0.9); }
}

/* ── Floating score text ─────────────────────────────── */

.float-text {
  position: absolute;
  font-family: 'Poppins', sans-serif;
  font-size: 1.4rem; color: #FFF;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.25);
  pointer-events: none;
  animation: floatUp 1.1s ease-out forwards;
  z-index: 30;
}
.float-text.correct { color: #FDD835; }
.float-text.wrong   { color: #EF9A9A; }
.float-text.tap     { color: #80DEEA; font-size: 1rem; }
@keyframes floatUp {
  0%   { transform: translateY(0);    opacity: 1; }
  100% { transform: translateY(-70px); opacity: 0; }
}

/* ── Toast ───────────────────────────────────────────── */

.toast {
  position: absolute; bottom: 90px; left: 50%;
  transform: translateX(-50%);
  background: rgba(183,28,28,0.95); color: #FFF;
  padding: 9px 22px; border-radius: 50px; font-size: 0.95rem;
  z-index: 100; animation: toastIn 0.3s ease-out;
  white-space: nowrap;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 16px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ── Round Reveal (multiplayer answer summary) ───────── */

#round-reveal {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  display: none; align-items: center; justify-content: center;
  flex-direction: column;
  z-index: 20;
  background: linear-gradient(160deg, rgba(8,32,90,0.97) 0%, rgba(13,71,161,0.97) 100%);
  backdrop-filter: blur(8px);
  pointer-events: none;
  padding: 20px;
  gap: 12px;
}
#round-reveal.active { display: flex; animation: feedPop 0.3s ease-out both; }

.reveal-correct-label {
  color: rgba(255,255,255,0.5);
  font-size: clamp(0.65rem, 1.8vw, 0.8rem);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 4px;
}

.reveal-correct-num {
  color: #FDD835;
  font-size: clamp(3.5rem, 13vw, 6rem);
  font-weight: 800;
  text-shadow: 0 0 40px rgba(253,216,53,0.45), 3px 3px 0 rgba(0,0,0,0.3);
  line-height: 1;
}

.reveal-players-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 600px;
  margin-top: 4px;
}

.reveal-player-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.07);
  border-radius: 16px;
  padding: 14px 16px 10px;
  min-width: 90px;
  border: 1.5px solid rgba(255,255,255,0.12);
}
.reveal-player-card.correct {
  border-color: rgba(102,187,106,0.55);
  background: rgba(102,187,106,0.14);
  box-shadow: 0 0 20px rgba(102,187,106,0.15);
}
.reveal-player-card.wrong {
  border-color: rgba(239,83,80,0.45);
  background: rgba(239,83,80,0.11);
}
.reveal-player-card.me {
  border-color: #FDD835;
  background: rgba(253,216,53,0.1);
  box-shadow: 0 0 22px rgba(253,216,53,0.28);
}
.reveal-player-card.me::after {
  content: 'YOU';
  position: absolute;
  top: -10px; left: 50%; transform: translateX(-50%);
  background: #FDD835;
  color: #000;
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  padding: 2px 7px;
  border-radius: 20px;
}
.reveal-player-card.me .reveal-player-name { color: #FDD835; }

.reveal-player-indicator {
  order: -1;
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 2px;
}
.reveal-player-card.correct .reveal-player-indicator { background: #66BB6A; color: #fff; }
.reveal-player-card.wrong   .reveal-player-indicator { background: #EF5350; color: #fff; }

.reveal-player-name {
  color: rgba(255,255,255,0.88);
  font-size: clamp(0.68rem, 1.9vw, 0.82rem);
  font-weight: 600;
  max-width: 100px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.reveal-player-answer {
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 800;
  color: #FFF;
  line-height: 1.1;
}

/* ── Error message ───────────────────────────────────── */

.error-msg { color: #EF9A9A; font-size: 0.9rem; margin-top: 6px; min-height: 1.2em; }

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 480px) {
  #hud-top { padding: 8px 10px; }
  #hud-bottom { padding: 8px 10px; gap: 8px; }
  .tap-btn { width: 42px; height: 42px; }
  #btn-submit { min-width: 80px; height: 42px; }
  .btn { min-width: 180px; }
}

@media (min-width: 768px) {
  .menu-buttons { max-width: 600px; flex-direction: row; justify-content: center; }
}
