html, body { overflow: hidden; background: #000; touch-action: manipulation; }
/* Fixed frame clips the 1920×1080 stage so it can't stretch the page on iPad/iPhone. */
#frame { position: fixed; inset: 0; overflow: hidden; }

#stage {
  position: absolute; left: 50%; top: 50%;
  width: 1920px; height: 1080px;
  transform-origin: 50% 50%;
  background:
    radial-gradient(70% 50% at 30% 0%, rgba(255, 61, 139, 0.16), transparent 70%),
    radial-gradient(60% 50% at 90% 10%, rgba(41, 227, 255, 0.12), transparent 70%),
    linear-gradient(180deg, #120d2a, var(--night) 60%);
  overflow: hidden;
  display: grid;
  grid-template-rows: 96px 1fr auto;
}

/* top bar */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 48px; border-bottom: 2px solid var(--line);
}
.top .logo { font-size: 44px; }
.top-frame { font-family: var(--display); font-size: 34px; color: var(--ink-dim); letter-spacing: 0.08em; }
.top-frame b { color: var(--cyan); font-weight: 400; }
.top-right { display: flex; align-items: center; gap: 18px; }
.top-right .conn { font-size: 18px; }
#fsBtn, #soundBtn { background: none; border: 1px solid var(--line); border-radius: 10px; min-width: 48px; height: 48px; font-size: 24px; color: var(--ink-dim); }
#soundBtn.wide { padding: 0 18px; font-size: 20px; font-weight: 700; color: var(--night); background: var(--amber); border-color: transparent; animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 50% { transform: scale(1.06); } }

/* middle */
.middle { display: grid; grid-template-columns: 1fr 640px; gap: 40px; padding: 24px 48px 16px; min-height: 0; }
.lane-wrap {
  position: relative; border-radius: 28px; overflow: hidden;
  background: linear-gradient(180deg, #05030d, #120c24);
  border: 2px solid var(--line);
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.8);
}
#lane { position: absolute; inset: 0; width: 100%; height: 100%; }

.side { display: grid; grid-template-rows: auto 1fr; gap: 24px; min-height: 0; }
.now-card {
  border-radius: 28px; padding: 22px 34px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 2px solid var(--line);
  transition: box-shadow 0.4s, border-color 0.4s;
}
.now-card.pulse { animation: pulse 0.9s ease-out; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255, 197, 49, 0.8); } 100% { box-shadow: 0 0 0 30px rgba(255, 197, 49, 0); } }
.label { font-size: 18px; text-transform: uppercase; letter-spacing: 0.22em; color: var(--ink-dim); font-weight: 500; }
.now-card .name {
  font-family: var(--display); font-size: 66px; line-height: 1.05; margin: 4px 0 6px; color: var(--amber);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.now-card .meta { font-size: 28px; color: var(--ink-dim); font-weight: 500; }
.totals { display: flex; gap: 56px; margin-top: 12px; }
.totals .big { font-family: var(--display); font-size: 54px; line-height: 1; margin-top: 6px; }
.totals .big.dim { color: var(--ink-dim); }

.deck-card {
  position: relative; border-radius: 28px; border: 2px solid var(--line); background: var(--night-2);
  display: grid; place-items: center; min-height: 0; overflow: hidden;
}
.deck-label { position: absolute; top: 22px; left: 30px; width: 150px; line-height: 1.5; }
.deck-card { padding: 16px 24px 16px 200px; display: flex; }
#deck { flex: 1; width: 100%; height: 100%; min-height: 0; }
#deck .dpin { transition: fill 0.35s, opacity 0.35s, transform 0.35s; transform-box: fill-box; transform-origin: center; }
#deck .dpin.down { fill: #2b2450; opacity: 0.6; transform: scale(0.8); }
#deck .dpin.up { fill: #fff; filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.6)); }
#deck .dpin.hit { fill: var(--pink); }
#deck text { font-family: var(--display); font-size: 18px; fill: #1a1430; text-anchor: middle; dominant-baseline: central; pointer-events: none; }

/* dice: black, blank on five sides, a pin on the sixth */
.dice {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 26px;
  pointer-events: none; opacity: 0; transition: opacity 0.25s;
}
.dice.show { opacity: 1; background: radial-gradient(closest-side, rgba(13, 10, 31, 0.9), rgba(13, 10, 31, 0.35)); }
.dice-tri { position: relative; width: 420px; height: 382px; }
.die {
  position: absolute; width: 82px; height: 82px; margin-left: -41px; border-radius: 16px;
  background: radial-gradient(120% 120% at 30% 20%, #3a3a42 0%, #151519 45%, #050507 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.14), inset 0 -5px 0 rgba(0, 0, 0, 0.6), 0 12px 22px rgba(0, 0, 0, 0.65);
  display: grid; place-items: center;
  transition: opacity 0.4s, transform 0.4s, filter 0.4s;
}
.die .pinface { width: 36px; height: 92px; opacity: 0; transform: scale(0.6); transition: opacity 0.08s, transform 0.12s; filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.45)); }
.die.showpin .pinface { opacity: 1; transform: scale(0.62); }
.die.tumble { animation: tumble 0.32s linear infinite; }
.die.land { animation: land 0.35s cubic-bezier(.2, 1.6, .4, 1); }
.die.land.showpin { box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.14), inset 0 -5px 0 rgba(0, 0, 0, 0.6), 0 0 0 3px rgba(255, 255, 255, 0.7), 0 0 26px rgba(255, 255, 255, 0.35); }
.die.blank-out { opacity: 0.3; transform: scale(0.88); filter: grayscale(1); }
@keyframes tumble {
  0% { transform: translateY(0) rotate(0deg) scale(1); }
  25% { transform: translateY(-34px) rotate(calc(var(--spin) * 0.25)) scale(1.08) skewX(var(--tilt)); }
  50% { transform: translateY(-8px) rotate(calc(var(--spin) * 0.5)) scale(0.94); }
  75% { transform: translateY(-26px) rotate(calc(var(--spin) * 0.75)) scale(1.05) skewY(var(--tilt)); }
  100% { transform: translateY(0) rotate(var(--spin)) scale(1); }
}
@keyframes land {
  0% { transform: translateY(-40px) rotate(-12deg) scale(1.15); }
  100% { transform: none; }
}
.dice-label { font-family: var(--display); font-size: 40px; color: var(--amber); letter-spacing: 0.1em; text-shadow: 0 4px 0 rgba(0, 0, 0, 0.5); }
.dice-label.result { color: #fff; animation: land 0.35s cubic-bezier(.2, 1.6, .4, 1); }

/* scoreboard */
.board { padding: 8px 48px 36px; display: grid; gap: 10px; }
.row {
  display: grid; grid-template-columns: 260px repeat(9, 1fr) 1.45fr 150px;
  border-radius: 18px; overflow: hidden; border: 2px solid var(--line); background: var(--night-2);
  transition: border-color 0.3s, box-shadow 0.3s, transform 0.3s;
}
.row.cur { border-color: var(--amber); box-shadow: 0 0 0 2px var(--amber), 0 0 40px rgba(255, 197, 49, 0.25); }
.row .pname {
  display: flex; align-items: center; padding: 0 22px; font-weight: 800; font-size: var(--fs-name, 30px);
  background: var(--panel); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row.cur .pname { background: linear-gradient(90deg, rgba(255, 197, 49, 0.3), var(--panel)); color: var(--amber); }
.row .pname .arrow { color: var(--amber); margin-right: 10px; font-size: 0.8em; }
.fr { border-left: 2px solid var(--line); display: grid; grid-template-rows: auto 1fr; min-width: 0; }
.fr .balls { display: flex; justify-content: flex-end; height: var(--ball-h, 40px); }
.fr .balls span {
  width: var(--ball-h, 40px); display: grid; place-items: center;
  border-left: 2px solid var(--line); border-bottom: 2px solid var(--line);
  font-family: var(--display); font-size: var(--fs-ball, 24px); color: var(--ink);
}
.fr .balls span.x { color: var(--amber); }
.fr .balls span.sp { color: var(--cyan); }
.fr .balls span.g { color: var(--ink-dim); }
.fr .balls span.new { animation: pop 0.6s cubic-bezier(.2, 1.6, .4, 1); }
.fr .fscore { display: grid; place-items: center; font-family: var(--display); font-size: var(--fs-score, 32px); }
.fr .fscore.new { animation: pop 0.6s cubic-bezier(.2, 1.6, .4, 1); color: var(--lime); }
.fr .num { position: absolute; }
.fr.active { background: rgba(41, 227, 255, 0.1); box-shadow: inset 0 0 0 2px var(--cyan); }
.row .ptotal {
  border-left: 2px solid var(--line); display: grid; place-items: center;
  font-family: var(--display); font-size: var(--fs-total, 44px); color: var(--amber); background: var(--panel);
}
.board-head { display: grid; grid-template-columns: 260px repeat(9, 1fr) 1.45fr 150px; color: var(--ink-dim); font-weight: 700; font-size: 18px; letter-spacing: 0.1em; }
.board-head div { text-align: center; }
.board-head div:first-child { text-align: left; padding-left: 24px; }
@keyframes pop { 0% { transform: scale(0.2); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* announcement */
.announce {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  pointer-events: none; z-index: 10;
}
.announce-text {
  font-family: var(--display-inline); font-size: 240px; line-height: 1; transform: scale(0); opacity: 0;
  background: linear-gradient(180deg, #fff 10%, var(--amber) 45%, var(--pink) 90%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 12px 0 rgba(0, 0, 0, 0.5)) drop-shadow(0 0 40px rgba(255, 61, 139, 0.7));
}
.announce-sub { font-family: var(--display); font-size: 56px; color: #fff; opacity: 0; margin-top: 10px; text-shadow: 0 6px 0 rgba(0, 0, 0, 0.5); }
.announce.go .announce-text { animation: slam 1.9s cubic-bezier(.2, 1.4, .4, 1) forwards; }
.announce.go .announce-sub { animation: fadeup 1.9s ease-out forwards; }
.announce.cool .announce-text { background: linear-gradient(180deg, #fff 10%, var(--cyan) 60%, #7a5cff 95%); -webkit-background-clip: text; background-clip: text; filter: drop-shadow(0 12px 0 rgba(0, 0, 0, 0.5)) drop-shadow(0 0 40px rgba(41, 227, 255, 0.7)); }
.announce.meh .announce-text { font-size: 180px; background: linear-gradient(180deg, #fff, var(--ink-dim)); -webkit-background-clip: text; background-clip: text; filter: drop-shadow(0 10px 0 rgba(0, 0, 0, 0.5)); }
.announce.count .announce-text { font-size: 200px; background: linear-gradient(180deg, #fff, var(--cyan)); -webkit-background-clip: text; background-clip: text; filter: drop-shadow(0 10px 0 rgba(0, 0, 0, 0.5)); }
.announce.go::before {
  content: ''; position: absolute; inset: 0; z-index: -1;
  background: radial-gradient(closest-side, rgba(13, 10, 31, 0.85), rgba(13, 10, 31, 0.3));
  animation: fadeinout 1.9s forwards;
}
@keyframes slam {
  0% { transform: scale(3) rotate(-8deg); opacity: 0; }
  18% { transform: scale(1) rotate(-4deg); opacity: 1; }
  80% { transform: scale(1.06) rotate(-4deg); opacity: 1; }
  100% { transform: scale(1.3) rotate(-4deg); opacity: 0; }
}
@keyframes fadeup { 0%, 15% { opacity: 0; transform: translateY(30px); } 30%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }
@keyframes fadeinout { 0% { opacity: 0; } 15%, 80% { opacity: 1; } 100% { opacity: 0; } }

.upnext {
  position: absolute; left: 50%; top: 440px; z-index: 9; transform: translate(-50%, -50%) scale(0.6); opacity: 0;
  padding: 26px 60px; border-radius: 999px; background: var(--amber); color: #2a1600;
  display: flex; align-items: center; gap: 28px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  font-family: var(--display); font-size: 64px; pointer-events: none; white-space: nowrap;
}
.upnext .label { color: rgba(42, 22, 0, 0.7); font-size: 24px; }
.upnext.go { animation: upnext 1.6s cubic-bezier(.2, 1.3, .4, 1) forwards; }
@keyframes upnext {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  20%, 80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

#confetti { position: absolute; inset: 0; width: 1920px; height: 1080px; pointer-events: none; z-index: 12; }

/* splash & final */
.splash, .final {
  position: absolute; inset: 0; z-index: 20; display: none; flex-direction: column; align-items: center; justify-content: center;
  background:
    radial-gradient(60% 50% at 50% 30%, rgba(255, 61, 139, 0.25), transparent 70%),
    rgba(13, 10, 31, 0.97);
}
.splash.show, .final.show { display: flex; }
.logo.huge { font-size: 150px; }
.tag { font-size: 40px; color: var(--ink-dim); margin: 6px 0 70px; }
.join { display: flex; align-items: center; gap: 56px; padding: 40px 56px; border-radius: 32px; background: var(--panel); border: 2px solid var(--line); }
.qr { width: 260px; height: 260px; background: #fff; border-radius: 18px; padding: 18px; display: grid; place-items: center; }
.qr:empty { display: none; }
.qr img, .qr canvas { width: 224px !important; height: 224px !important; }
.join-title { font-family: var(--display); font-size: 44px; }
.join-url { font-size: 40px; color: var(--cyan); margin: 14px 0; font-weight: 700; }
.join-hint { font-size: 26px; color: var(--ink-dim); }
.room-line { margin-top: 22px; font-size: 26px; color: var(--ink-dim); display: flex; align-items: center; gap: 16px; }
.room-code { font-family: var(--display); font-size: 52px; letter-spacing: 0.12em; color: var(--amber); }
.room-chip { font-family: var(--display); font-size: 20px; letter-spacing: 0.1em; color: var(--ink-dim); }

.final-title { font-family: var(--display-inline); font-size: 120px; color: var(--amber); }
.podium { display: flex; align-items: flex-end; gap: 30px; margin: 30px 0 50px; }
.pod {
  width: 320px; text-align: center; border-radius: 28px 28px 0 0; padding: 30px 20px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 2px solid var(--line); border-bottom: 0;
  animation: rise 0.9s cubic-bezier(.2, 1.2, .4, 1) both;
}
.pod .place { font-family: var(--display); font-size: 40px; color: var(--ink-dim); }
.pod .nm { font-size: 40px; font-weight: 800; margin: 10px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod .sc { font-family: var(--display); font-size: 90px; }
.pod.p1 { height: 440px; border-color: var(--amber); animation-delay: 0.6s; }
.pod.p1 .place, .pod.p1 .sc { color: var(--amber); }
.pod.p2 { height: 360px; animation-delay: 0.3s; }
.pod.p3 { height: 300px; }
.pod.rest { height: 240px; }
.final-hint { font-size: 30px; color: var(--ink-dim); }
.final-hint b { color: var(--pink); }
@keyframes rise { from { transform: translateY(120%); } to { transform: none; } }

/* lane svg */
#lane .pin { transform-box: fill-box; transform-origin: 50% 100%; transition: transform 0.7s cubic-bezier(.2, .8, .3, 1), opacity 0.7s ease-in 0.25s; }
#lane .pin.fall { opacity: 0; }
#lane .pin.reset { transition: none; }
#lane .pin.rise { animation: pinrise 0.5s ease-out both; }
@keyframes pinrise { from { transform: translateY(-60px); opacity: 0; } to { transform: none; opacity: 1; } }

/* portrait phones/tablets: ask to rotate (the stage is landscape) */
.rotate { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  .rotate {
    position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
    background: var(--night); color: var(--ink); font-family: var(--display); font-size: 24px; text-align: center; padding: 24px;
  }
  .rotate small { font-family: var(--body); font-size: 15px; color: var(--ink-dim); }
  .rotate-icon { font-size: 56px; margin-bottom: 8px; }
}
