:root {
  --navy: #06111a;
  --navy-2: #0b1f2e;
  --yellow: #f5c517;
  --teal: #2dd4bf;
  --red: #ef4444;
  --text: #e8f0f4;
  --font: "Fredoka One", "Arial Rounded MT Bold", "Comic Sans MS", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--navy);
  color: var(--text);
  font-family: var(--font);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

#ui { position: fixed; inset: 0; pointer-events: none; }

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 20px;
  pointer-events: auto;
}
.screen.active { display: flex; }

/* full-bleed backdrop for menu screens so 3D doesn't distract */
#landing, #lobby, #gameover {
  background: radial-gradient(ellipse at 50% 30%, var(--navy-2) 0%, var(--navy) 70%);
}

.hidden { display: none !important; }

.brandmark {
  width: clamp(180px, 42vw, 340px);
  height: auto;
  margin-bottom: 10px;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,.5));
}
.logo {
  font-size: clamp(2.4rem, 9vw, 4.5rem);
  color: var(--yellow);
  letter-spacing: 0.04em;
  text-shadow: 0 4px 0 rgba(0,0,0,.45), 0 0 34px rgba(245,197,23,.35);
  text-align: center;
  transform: rotate(-2deg);
}
.logo-sub {
  display: block;
  font-size: clamp(0.9rem, 3vw, 1.2rem);
  color: var(--teal);
  letter-spacing: .22em;
  text-shadow: none;
  margin-top: 4px;
}

.panel {
  background: rgba(11, 31, 46, .92);
  border: 2px solid rgba(45, 212, 191, .35);
  border-radius: 20px;
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(92vw, 360px);
  align-items: stretch;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}

input[type=text] {
  font-family: var(--font);
  font-size: 1.15rem;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid rgba(45,212,191,.4);
  background: var(--navy);
  color: var(--text);
  outline: none;
  text-align: center;
}
input[type=text]:focus { border-color: var(--teal); }
#codeInput { text-transform: uppercase; letter-spacing: .35em; width: 0; flex: 1; }

.join-row { display: flex; gap: 10px; }

.btn {
  font-family: var(--font);
  font-size: 1.1rem;
  padding: 13px 20px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  letter-spacing: .04em;
  transition: transform .08s, filter .15s;
  box-shadow: 0 4px 0 rgba(0,0,0,.35);
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.35); }
.btn:disabled { filter: grayscale(.8) brightness(.6); cursor: default; }
.btn-yellow { background: var(--yellow); color: var(--navy); }
.btn-teal { background: var(--teal); color: var(--navy); }
.btn-red { background: var(--red); color: #fff; }
.btn-ghost { background: rgba(232,240,244,.12); color: var(--text); border: 2px solid rgba(232,240,244,.3); }
.btn.big { font-size: 1.25rem; padding: 15px 26px; border-radius: 18px; }

.err { color: var(--red); font-size: .95rem; min-height: 1.2em; text-align: center; }

.footer-note { color: rgba(232,240,244,.45); font-size: .85rem; }
.footer-note a { color: var(--teal); text-decoration: none; }

/* Lobby */
.lobby-label { text-align: center; color: var(--teal); letter-spacing: .25em; font-size: .85rem; }
.room-code {
  text-align: center;
  font-size: 3.2rem;
  color: var(--yellow);
  letter-spacing: .3em;
  text-shadow: 0 0 24px rgba(245,197,23,.4);
}
.lobby-hint { text-align: center; color: rgba(232,240,244,.5); font-size: .85rem; }

.player-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  background: rgba(6,17,26,.7);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  font-size: 1.05rem;
}
.player-list .tag { color: var(--teal); font-size: .8rem; }
.player-list .off { color: var(--red); }

.host-controls { display: flex; gap: 10px; }
.host-controls .btn { flex: 1; }

/* HUD */
#hud { justify-content: space-between; pointer-events: none; }
/* Only actual controls catch taps; the bars themselves pass through to the
   3D hand fan rendered on the canvas behind them. */
#hud button, #hud .doubt-bar, #hud .toast { pointer-events: auto; }

.topbar {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
}
.rank-badge {
  background: var(--yellow);
  color: var(--navy);
  border-radius: 12px;
  padding: 6px 16px;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  box-shadow: 0 3px 0 rgba(0,0,0,.35);
}
.rank-badge small {
  display: block;
  font-size: .55rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  opacity: .75;
  margin-bottom: 2px;
}
.turn-label { flex: 1; font-size: 1rem; color: var(--text); text-shadow: 0 2px 4px rgba(0,0,0,.6); }
.mute-btn { background: none; border: none; font-size: 1.4rem; cursor: pointer; }
.quit-btn {
  font-family: var(--font);
  background: rgba(232,240,244,.12);
  color: var(--text);
  border: 2px solid rgba(232,240,244,.3);
  border-radius: 12px;
  padding: 6px 14px;
  font-size: .95rem;
  cursor: pointer;
}
.quit-btn:active { transform: translateY(1px); }

.table-info {
  align-self: center;
  text-align: center;
  color: rgba(232,240,244,.75);
  font-size: .95rem;
  text-shadow: 0 2px 6px rgba(0,0,0,.7);
}

.bottombar {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
}
.doubt-bar { display: flex; flex-direction: column; gap: 10px; align-items: center; width: min(92vw, 380px); }
.doubt-bar .btn { width: 100%; }

/* Endgame "Final Play" emphasis */
.final-note {
  width: 100%;
  text-align: center;
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1.3;
  color: #ffd9d2;
  background: rgba(239, 68, 68, .18);
  border: 1px solid rgba(239, 68, 68, .55);
  border-radius: 12px;
  padding: 8px 12px;
}
.doubt-bar.final-play #doubtBtn {
  box-shadow: 0 0 0 0 rgba(239, 68, 68, .6);
  animation: finalPulse 1.1s ease-out infinite;
}
@keyframes finalPulse {
  0%   { box-shadow: 0 0 0 0 rgba(239,68,68,.6); }
  70%  { box-shadow: 0 0 0 14px rgba(239,68,68,0); }
  100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}
.countdown-track {
  width: 100%; height: 8px;
  background: rgba(232,240,244,.15);
  border-radius: 999px;
  overflow: hidden;
}
.countdown-fill {
  height: 100%; width: 100%;
  background: var(--yellow);
  border-radius: 999px;
  transform-origin: left;
}

.toast {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(6,17,26,.92);
  border: 2px solid var(--teal);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 22px;
  font-size: 1.1rem;
  text-align: center;
  max-width: 88vw;
  z-index: 5;
}
.toast.lie { border-color: var(--red); }
.toast.truth { border-color: var(--teal); }

.win-bowl {
  display: block;
  width: clamp(140px, 34vw, 220px);
  height: auto;
  margin: 0 auto 12px;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,.55));
  animation: winBowlPop .5s cubic-bezier(.2,1.4,.4,1) both;
}
@keyframes winBowlPop {
  from { transform: scale(.3) rotate(-12deg); opacity: 0; }
  to   { transform: scale(1) rotate(0); opacity: 1; }
}
.winner-text { color: var(--yellow); font-size: 2rem; text-align: center; }

.reconnect {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6,17,26,.85);
  color: var(--yellow);
  font-size: 1.4rem;
  z-index: 50;
  pointer-events: auto;
}

/* ---- How-to-play tutorial ---- */
.tutorial {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(6,17,26,.9);
  z-index: 40;
  pointer-events: auto;
}
.tut-card {
  position: relative;
  background: rgba(11,31,46,.96);
  border: 2px solid rgba(45,212,191,.4);
  border-radius: 22px;
  box-shadow: 0 14px 44px rgba(0,0,0,.6);
  width: min(94vw, 440px);
  padding: 20px 20px 16px;
  display: flex; flex-direction: column; gap: 12px; align-items: center;
}
.tut-title { color: var(--yellow); letter-spacing: .12em; font-size: 1.3rem; }
.tut-close {
  position: absolute; top: 10px; right: 14px;
  background: none; border: none; color: rgba(232,240,244,.6);
  font-size: 1.3rem; cursor: pointer;
}
.tut-stage {
  position: relative; width: 100%; height: 180px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.tut-caption {
  min-height: 3em; text-align: center; font-size: 1.02rem; line-height: 1.35;
  color: var(--text);
}
.tut-foot { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tut-dots { display: flex; gap: 7px; }
.tut-dot { width: 9px; height: 9px; border-radius: 999px; background: rgba(232,240,244,.25); }
.tut-dot.on { background: var(--yellow); }
.tut-foot .btn { padding: 10px 18px; font-size: 1rem; }

/* cartoon cards used only inside the tutorial */
.tcard {
  width: 56px; height: 80px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 10px rgba(0,0,0,.45);
}
.tcard.back {
  background: linear-gradient(150deg, var(--navy-2), #07263a);
  border: 2px solid rgba(45,212,191,.5);
}
.tcard.back::after {
  content: ""; width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, var(--yellow), #b9930f);
}
.tcard.face { background: #f4f7f9; border: 2px solid #cdd8de; }
.tcard.face span { color: var(--navy); font-size: 1.5rem; }

.tut-fan { position: relative; width: 100%; height: 100%; }
.tut-fan .tcard {
  position: absolute; top: 50%; left: 50%;
  margin: -40px 0 0 -28px;
  transform: translateX(calc(var(--i) * 40px)) rotate(calc(var(--i) * 7deg));
}
.tut-fan .deal { animation: tDeal .5s ease both; }
@keyframes tDeal {
  from { transform: translate(0, 120px) rotate(0); opacity: 0; }
}

.tut-pile {
  position: relative; width: 70px; height: 90px;
  display: flex; align-items: center; justify-content: center;
}
.tut-pile .tcard { position: absolute; }
.tut-pile .toPile { animation: tToPile .55s ease both; }
@keyframes tToPile { from { transform: translateY(120px) rotate(8deg); opacity: 0; } }
.tut-pile .sneaky { animation: tToPile .55s ease both, tWiggle 1.4s ease 0.7s; }
@keyframes tWiggle { 0%,100%{ transform: rotate(0); } 25%{ transform: rotate(-7deg);} 75%{ transform: rotate(7deg);} }
.tut-pile .flip { animation: tFlip .5s ease both; transform-style: preserve-3d; }
@keyframes tFlip { from { transform: rotateY(180deg) scale(.9); opacity: .2; } }
.tut-pile.toLoser { animation: tToLoser 1.1s ease .4s both; }
@keyframes tToLoser { to { transform: translate(120px, 26px) scale(.55); opacity: .25; } }

.tut-badge {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  background: var(--yellow); color: var(--navy);
  padding: 5px 14px; border-radius: 999px; font-size: .9rem;
}
.tut-tag {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  color: var(--teal); font-size: .95rem;
}
.tut-stamp {
  position: absolute; top: 46%; left: 50%;
  color: var(--red); font-size: 1.9rem; letter-spacing: .03em;
  text-shadow: 0 2px 0 rgba(0,0,0,.4);
  transform: translate(-50%,-50%) rotate(-12deg);
  border: 4px solid var(--red); border-radius: 12px; padding: 4px 14px;
  animation: tStamp .45s cubic-bezier(.2,1.3,.5,1) .4s both;
}
@keyframes tStamp { from { transform: translate(-50%,-50%) rotate(-12deg) scale(2.6); opacity: 0; } }
.tut-loser {
  position: absolute; right: 16%; top: 50%; transform: translateY(-50%);
  font-size: 2.4rem;
}

/* ---- Portrait rotate hint ---- */
.orient-hint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6,17,26,.82);
  z-index: 45; pointer-events: auto; padding: 24px;
}
.orient-card {
  background: rgba(11,31,46,.96);
  border: 2px solid rgba(45,212,191,.4);
  border-radius: 20px; padding: 26px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center; width: min(86vw, 320px);
}
.orient-icon { font-size: 2.6rem; animation: tRock 1.6s ease-in-out infinite; }
@keyframes tRock { 0%,100%{ transform: rotate(-12deg);} 50%{ transform: rotate(78deg);} }
.orient-card p { font-size: 1.05rem; line-height: 1.4; }
.orient-card b { color: var(--yellow); }
