/* Topple: the 3D tower (js/topple-scene.js) under a heads-up layer on the TV, and the turn
   controller on phones. Glassy night panels over warm maple, player colors for whose turn it is. */

.tp-canvas { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.tp-height { font: 700 0.85rem var(--body); color: var(--muted); }

/* ================= TV ================= */

.tp-tv { position: relative; height: 100%; }
/* The stage keeps a 5% overscan margin; the tower canvas bleeds past it to fill the screen */
.tv .tp-tv .tp-canvas { position: absolute; left: -5.5556%; top: -5.5556%; width: 111.1111%; height: 111.1111%; }
.tp-hud { position: absolute; inset: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 1.5rem; pointer-events: none; }
.tp-tv.no-3d .tp-canvas { display: none; }

/* No 3D on this TV: the tower as rows of three (js/topple-flat.js), right of the turn card */
.tp-flat {
  --c: var(--sun);
  position: absolute; left: 40%; right: 12%; top: 13%; bottom: 15%;
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
}
.tp-flat-head { display: flex; align-items: center; gap: 0.9rem; min-height: 4.4rem; }
.tp-flat-dial { position: relative; width: 4.4rem; height: 4.4rem; border-radius: 50%; border: 2px solid var(--line); background: var(--panel); }
.tp-flat-dial-tower { position: absolute; left: 50%; top: 50%; width: 1.1rem; height: 1.1rem; margin: -0.55rem; border-radius: 0.2rem; background: #e7c38c; box-shadow: inset 0 -0.15rem 0 #b98a52; }
/* The player's eye on the tower, going round as they spin it */
.tp-flat-dial-dot { position: absolute; inset: 0; transition: transform 0.15s linear; }
.tp-flat-dial-dot::after { content: ''; position: absolute; left: 50%; bottom: -0.45rem; width: 0.9rem; height: 0.9rem; margin-left: -0.45rem; border-radius: 50%; background: var(--c); box-shadow: 0 0 0.8rem var(--c); }
.tp-flat.idle .tp-flat-dial-dot { animation: tp-flat-orbit 9s linear infinite; }
@keyframes tp-flat-orbit { to { transform: rotate(-360deg); } }
.tp-flat-dial-label { font: 800 1.3rem var(--display); color: var(--c); }
.tp-flat-tower { flex: 1; min-height: 0; width: min(100%, 24rem); display: flex; flex-direction: column; justify-content: flex-end; gap: 0.28rem; }
.tp-flat-row { flex: 0 1 2.3rem; min-height: 0.5rem; display: grid; grid-template-columns: 2.2rem repeat(3, 1fr); gap: 0.28rem; align-items: stretch; }
.tp-flat-level { align-self: center; font: 700 0.95rem var(--body); color: var(--muted); text-align: right; padding-right: 0.3rem; }
.tp-flat-block { border-radius: 0.35rem; background: linear-gradient(180deg, #f1d3a1, #e2bb83); box-shadow: inset 0 -0.22rem 0 #b98a52; }
/* Levels alternate direction: these show the blocks' ends */
.tp-flat-row.across .tp-flat-block { background: repeating-linear-gradient(90deg, #ecc995 0 0.5rem, #e3bd86 0.5rem 0.9rem); }
.tp-flat-block.locked { filter: brightness(0.55) saturate(0.7); }
.tp-flat-gap { border-radius: 0.35rem; }
.tp-flat-block.picked { background: var(--c); box-shadow: 0 0 1.2rem var(--c), inset 0 -0.22rem 0 rgb(0 0 0 / 0.25); animation: tp-flat-pulse 0.9s ease-in-out infinite; }
@keyframes tp-flat-pulse { 50% { filter: brightness(1.25); } }
.tp-flat-gap.ghost { border: 2px dashed var(--c); background: rgb(255 255 255 / 0.08); background: color-mix(in srgb, var(--c) 18%, transparent); animation: tp-flat-pulse 0.9s ease-in-out infinite; }
/* A pull: wiggled loose, out it comes toward the room, then it drops onto the top */
.tp-flat-block.pulling { position: relative; z-index: 1; background: var(--c); animation: tp-flat-out 1.9s ease-in both; }
@keyframes tp-flat-out {
  0% { transform: none; }
  10% { transform: translateX(-4%); }
  20% { transform: translateX(4%); }
  30% { transform: none; }
  100% { transform: translateY(-40%) scale(1.6); opacity: 0; }
}
.tp-flat-gap.landing { background: var(--c); box-shadow: 0 0 1rem var(--c); animation: tp-flat-land 0.45s cubic-bezier(0.3, 1.5, 0.6, 1) both; }
@keyframes tp-flat-land { from { transform: translateY(-260%); opacity: 0; } }
/* The crash: every row tumbles off, the top first */
.tp-flat.crash .tp-flat-row { animation: tp-flat-fall 1.1s cubic-bezier(0.55, 0, 0.85, 0.4) both; animation-delay: calc((30 - var(--i)) * 25ms); }
.tp-flat.crash .tp-flat-row:nth-child(even) { --spin: -1; }
@keyframes tp-flat-fall { to { transform: translate(calc(var(--spin, 1) * 40%), 120vh) rotate(calc(var(--spin, 1) * 50deg)); opacity: 0.4; } }

.tp-top { display: flex; align-items: center; justify-content: space-between; }
.tp-top-left { display: flex; align-items: center; gap: 1.2rem; }
.tp-top-icon { width: 3.2rem; height: 3.2rem; filter: drop-shadow(0 0.2rem 0 rgb(0 0 0 / 0.3)); }
.tp-brand { font: 800 2.6rem/1 var(--display); letter-spacing: -0.03em; }
.tv .tp-height { font-size: 1.4rem; }

.tp-side { align-self: center; justify-self: start; width: 27rem; }
.tp-card {
  --c: var(--sun);
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.9rem;
  padding: 2rem 2.2rem 2.4rem; border-radius: 2rem;
  background: linear-gradient(180deg, rgb(34 23 71 / 0.86), rgb(22 15 46 / 0.86));
  border: 1px solid var(--line);
  box-shadow: inset 0 -0.45rem 0 var(--c), 0 1.6rem 3rem rgb(0 0 0 / 0.35);
  animation: tp-card-in 0.6s var(--spring) both;
}
@keyframes tp-card-in { from { opacity: 0; transform: translateX(-4rem) scale(0.92); } }
.tp-card .avatar-lg { --size: 6.2rem; animation: bob 2.6s ease-in-out infinite; }
.tp-card-title { font: 800 3.4rem/1.02 var(--display); letter-spacing: -0.025em; margin: 0; }
.tp-card-status { margin: 0; font: 700 1.6rem/1.3 var(--body); color: var(--sun); min-height: 1.3em; }
.tp-card-hint { margin: 0; font: 600 1.25rem var(--body); color: var(--muted); }
.tp-note { margin: 0; font: 800 1.1rem var(--body); letter-spacing: 0.06em; text-transform: uppercase; color: var(--coral); }
.tp-card.tense .tp-card-title { animation: tp-tense 0.9s ease-in-out infinite; }
@keyframes tp-tense { 50% { transform: translateX(0.25rem) rotate(-0.6deg); } }
.tp-card.win { --c: var(--mint); }
.tp-card.win .tp-card-title { color: var(--mint); animation: letter-up 0.7s var(--spring) both; }
.tp-points { font: 800 4rem/1 var(--display); color: var(--mint); animation: pop-in 0.5s var(--spring) 0.2s both; }

.tp-rules { width: 31rem; }
.tp-rule-list { list-style: none; margin: 0.4rem 0; padding: 0; display: flex; flex-direction: column; gap: 1rem; }
.tp-rule { display: flex; align-items: center; gap: 1.1rem; animation: pop-in 0.5s var(--spring) both; }
.tp-rule strong { display: block; font: 800 1.7rem/1.1 var(--display); }
.tp-rule span { display: block; font: 600 1.25rem/1.3 var(--body); color: var(--muted); }
.tp-rule-icon { flex: none; width: 3.8rem; height: 3.8rem; }

.tp-chips { justify-self: center; }
.tp-chip { transition: transform 0.4s var(--spring), box-shadow 0.4s; }
.tp-chip.active { transform: translateY(-0.5rem) scale(1.08); background: color-mix(in srgb, var(--c) 26%, transparent); border-color: var(--c); box-shadow: 0 0 1.6rem color-mix(in srgb, var(--c) 45%, transparent); }
.tp-chip.toppler { border-color: var(--coral); background: rgb(255 107 91 / 0.18); }
.tp-chip-icon { width: 1.8rem; height: 1.8rem; }

/* The crash */
.tp-slam { align-self: center; justify-self: center; display: flex; flex-direction: column; align-items: center; gap: 1.6rem; text-align: center; }
.tp-slam-word {
  font: 800 11rem/0.9 var(--display); letter-spacing: -0.04em; color: var(--coral);
  -webkit-text-stroke: 0.25rem #2b0d14; paint-order: stroke fill;
  text-shadow: 0 0.7rem 0 #7c1d1d, 0 1.6rem 3rem rgb(0 0 0 / 0.5);
  animation: tp-slam 0.8s cubic-bezier(0.2, 1.6, 0.4, 1) both, tp-quake 0.5s linear 0.8s 2;
}
@keyframes tp-slam { from { transform: scale(3) rotate(-8deg); opacity: 0; } 60% { opacity: 1; } }
@keyframes tp-quake { 25% { transform: translate(-0.6rem, 0.3rem) rotate(-1deg); } 75% { transform: translate(0.6rem, -0.3rem) rotate(1deg); } }
.tp-slam-who { display: inline-flex; align-items: center; gap: 0.8rem; padding: 0.7rem 1.6rem 0.7rem 0.7rem; border-radius: 999px; background: rgb(22 15 46 / 0.85); border: 1px solid var(--line); font: 800 1.8rem var(--display); animation: pop-in 0.5s var(--spring) 0.9s both; }
.tp-slam-who .avatar { --size: 3rem; }

/* Final results over a dimmed wreck */
.tp-final {
  position: absolute; inset: -5.5556%; padding: 5%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.2rem; text-align: center;
  background: radial-gradient(closest-side, rgb(22 15 46 / 0.78), rgb(22 15 46 / 0.92));
  animation: screen-in 0.6s var(--spring) both;
}
.tv .tp-final .eyebrow { font-size: 1.3rem; }

/* ================= Phone ================= */

.tp-turn { gap: 0.8rem; }
.tp-your-turn { color: var(--sun); }
.tp-view {
  position: relative; height: min(58dvh, 34rem); border-radius: 1.5rem; overflow: hidden;
  background: radial-gradient(circle at 50% 30%, rgb(255 201 60 / 0.1), transparent 60%), rgb(255 255 255 / 0.04);
  border: 1px solid var(--line);
}
.tp-view.small { height: min(32dvh, 18rem); }
.tp-view.no-3d { display: none; }
.tp-loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; font-weight: 700; color: var(--muted); }
.tp-view .tp-canvas { position: absolute; inset: 0; }
.tp-turn > .tp-note { min-height: 2.6em; margin: 0; text-align: center; font: 700 0.95rem/1.3 var(--body); letter-spacing: 0; text-transform: none; color: var(--muted); }
.tp-turn > .tp-note.warn { color: var(--coral); animation: shake 0.4s; }
.tp-remove { font-size: 1.3rem; padding-block: 1.1rem; }
.tp-outcome { align-items: center; text-align: center; }

.tp-wait { padding-top: 1rem; }
.tp-wait-avatar { animation: bob 2.4s ease-in-out infinite; }
.tp-wait .avatar-lg { --size: 6.5rem; }
.tp-watch {
  display: inline-flex; align-items: center; gap: 0.8rem; margin-top: 0.6rem;
  padding: 0.9rem 1.4rem; border-radius: 1.2rem; background: var(--panel); border: 1px solid var(--line);
  font: 800 1.2rem var(--display);
}
.tp-watch-icon { width: 2.4rem; height: 2.4rem; animation: bob 2s ease-in-out infinite; }
.tp-me-line { margin: 0.4rem 0 0; font-weight: 700; color: var(--sun); text-align: center; }
/* Watching someone else's turn: their view of the tower, live. Look, don't touch: the page still
   scrolls over it. */
.tp-wait.watching { padding-top: 0; gap: 0.6rem; }
.tp-wait-head { display: flex; align-items: center; justify-content: center; gap: 0.7rem; }
.tp-wait-head .game-title { font-size: clamp(1.6rem, 7vw, 2.1rem); }
.tp-wait-status { margin: 0; text-align: center; font-weight: 700; color: var(--muted); min-height: 1.3em; }
.tp-view.spectate { height: min(52dvh, 30rem); }
.tp-view.spectate .tp-canvas { pointer-events: none; touch-action: auto; }
.tp-crashed .game-title { color: var(--coral); animation: shake 0.5s 2; }

/* No-WebGL fallback: the tower as rows of three */
.tp-diagram { display: flex; flex-direction: column; gap: 0.25rem; max-height: 52dvh; overflow-y: auto; padding: 0.4rem; border-radius: 1.2rem; background: var(--panel); border: 1px solid var(--line); }
.tp-diagram-row { display: grid; grid-template-columns: 2rem repeat(3, 1fr); gap: 0.3rem; align-items: center; }
.tp-diagram-level { font: 700 0.75rem var(--body); color: var(--muted); text-align: right; padding-right: 0.3rem; }
.tp-diagram-cell { height: 1.7rem; border-radius: 0.35rem; background: #e7c38c; border: 0; box-shadow: inset 0 -0.2rem 0 #b98a52; }
.tp-diagram-cell.locked { opacity: 0.45; }
.tp-diagram-cell.gone { background: none; box-shadow: inset 0 0 0 1px var(--line); }
button.tp-diagram-cell { cursor: pointer; }
button.tp-diagram-cell.chosen { background: var(--sun); box-shadow: 0 0 0 0.2rem var(--ink); }
