/* Levels to This — design system (approved concept: modern, sleek, smooth) */
:root {
  --ink: #0d0d10; --panel: #16161b; --card: #1e1e25; --line: #2b2b33;
  --white: #f5f5f7; --mute: #9aa0ab;
  --blue: #4a7cd6; --green: #8dc63f; --orange: #f0512e; --gold: #c99a2e;
  --link: #8fb0e8; --danger: #e5484d; --r: 16px;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
html { height: 100%; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
body {
  min-height: 100%;
  background: radial-gradient(1100px 700px at 75% -10%, #1a2033 0%, var(--ink) 55%);
  background-attachment: fixed;
  color: var(--white);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
  /* Safe areas: keep content clear of the notch/status bar and side cutouts.
     Bottom is handled below (nav sits there). Zero on non-notched devices + web. */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: calc(74px + env(safe-area-inset-bottom));
}
/* Native chrome shouldn't be text-selectable; keep scenario/library copy selectable. */
nav, nav button, .hud, .chip, .btn, button.ans { -webkit-user-select: none; user-select: none; }
#app { max-width: 480px; margin: 0 auto; padding: 18px 16px 24px; }
button { font-family: inherit; }
a { color: var(--link); }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 0 16px; }
.lmark { display: grid; gap: 2.5px; }
.lmark span { width: 11px; height: 11px; border-radius: 2.5px; display: block; }
.lmark span:nth-child(1) { background: var(--blue); }
.lmark span:nth-child(2) { background: var(--green); }
.lmark span:nth-child(3) { background: var(--orange); }
.lmark span:nth-child(4) { background: var(--gold); width: 24px; }
.brand h1 { font-size: 21px; font-weight: 900; letter-spacing: .5px; }
.brand small { display: block; font-size: 10px; font-weight: 700; letter-spacing: 2px; color: var(--gold); text-transform: uppercase; }
/* Pulled up under the wordmark. Reserving the img's width and height keeps the
   whole page from jumping when it decodes. */
.splcfrom { display: flex; align-items: center; gap: 8px; margin: -10px 0 16px; }
.splcfrom span { font-size: 10px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--mute); }
/* Full opacity, not a tint. SPLC's mark must be pure black or white, never a
   shade in between, so no opacity below 1. */
.splcfrom img { width: 170px; height: auto; display: block; }

/* ---------- views ---------- */
.view { animation: slidein .3s ease; }
@keyframes slidein { from { opacity: 0; transform: translateX(12px); } }
h2 { font-size: 24px; font-weight: 800; line-height: 1.15; margin-bottom: 8px; }
.sub { color: var(--mute); font-size: 13.5px; line-height: 1.55; margin-bottom: 16px; }
.section { font-size: 11px; font-weight: 800; letter-spacing: 1.6px; text-transform: uppercase; color: var(--gold); margin: 18px 0 10px; }

/* ---------- cards & buttons ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 12px; }
.btn {
  display: block; width: 100%; background: var(--white); color: var(--ink);
  border: none; border-radius: 14px; padding: 15px; font-size: 15.5px; font-weight: 800;
  cursor: pointer; transition: transform .15s ease, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .35; pointer-events: none; }
.btn.ghost { background: var(--card); color: var(--white); border: 1px solid var(--line); font-weight: 600; }
.btn.small { padding: 10px 14px; font-size: 13px; width: auto; display: inline-block; }
.btn.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.mode { display: flex; gap: 13px; align-items: flex-start; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 10px; width: 100%; cursor: pointer; color: var(--white); transition: transform .15s, border-color .2s; }
.mode:active { transform: scale(.985); }
.mode .sq { width: 22px; height: 22px; border-radius: 5px; flex: none; margin-top: 2px; }
.mode b { font-size: 15.5px; display: block; margin-bottom: 3px; }
.mode span { font-size: 12.5px; color: var(--mute); line-height: 1.45; display: block; }

/* ---------- forms ---------- */
.field { background: var(--card); border: 1px solid var(--line); border-radius: 13px; padding: 11px 14px; margin-bottom: 11px; transition: border-color .2s; }
.field:focus-within { border-color: var(--blue); }
.field.ok { border-color: rgba(141, 198, 63, .5); }
.field label { display: block; font-size: 10px; font-weight: 700; letter-spacing: 1.2px; color: var(--mute); text-transform: uppercase; margin-bottom: 4px; }
.field.ok label::after { content: " ✓"; color: var(--green); }
.field input, .field select {
  width: 100%; background: transparent; border: none; outline: none;
  color: var(--white); font-size: 15px; font-family: inherit;
}
.field select option { background: var(--card); color: var(--white); }
.steps { display: flex; gap: 5px; margin: 2px 0 16px; }
.steps i { height: 4px; flex: 1; border-radius: 99px; background: var(--line); }
.steps i.done { background: var(--green); }
.steps i.now { background: var(--white); }
.choice-row { display: flex; gap: 8px; margin-bottom: 12px; }
.choice-row button { flex: 1; background: var(--card); border: 1px solid var(--line); color: var(--mute); border-radius: 12px; padding: 11px 6px; font-size: 12.5px; font-weight: 600; cursor: pointer; transition: all .2s; }
.choice-row button.pick { background: rgba(141, 198, 63, .14); border-color: var(--green); color: var(--white); }
.check { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px; font-size: 12.5px; color: var(--mute); line-height: 1.5; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--green); flex: none; margin-top: 1px; }
.linkcard { display: block; background: linear-gradient(135deg, #1d2b45, #16233a); border: 1px solid #2e4166; border-radius: 13px; padding: 13px 15px; text-decoration: none; margin-bottom: 12px; }
.linkcard b { color: var(--white); font-size: 14px; }
.linkcard span { display: block; color: var(--link); font-size: 12px; margin-top: 3px; line-height: 1.45; }
.fine { color: var(--mute); font-size: 10.5px; line-height: 1.55; margin-top: 10px; }

/* ---------- shuffle (riffle) at run start ---------- */
.shufflewrap { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 62vh; }
.shufflezone { position: relative; width: 220px; height: 160px; }
.shufflecard {
  position: absolute; left: 50%; top: 50%; width: 80px; height: 112px;
  margin: -56px -40px; border-radius: 9px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='33'%3E%3Crect x='6' y='2' width='6' height='6' rx='1' fill='%234a7cd6'/%3E%3Crect x='6' y='10' width='6' height='6' rx='1' fill='%238dc63f'/%3E%3Crect x='6' y='18' width='6' height='6' rx='1' fill='%23f0512e'/%3E%3Crect x='6' y='26' width='14' height='6' rx='1' fill='%23c99a2e'/%3E%3C/svg%3E") #f7f5ef;
  background-size: 26px 33px;
  border: 1px solid #d8d4c8;
  box-shadow: 0 6px 18px rgba(0,0,0,.5);
  transition: transform .27s cubic-bezier(.4, .8, .35, 1);
  will-change: transform;
}
.shufflezone.gather { animation: gatherpulse .32s ease; }
@keyframes gatherpulse { 40% { transform: scale(1.06) rotate(.5deg); } }
.shufflecap {
  color: var(--mute); font-size: 12px; font-weight: 700; letter-spacing: 2px;
  text-transform: uppercase; margin-top: 22px; animation: capblink 1.1s ease infinite;
}
@keyframes capblink { 50% { opacity: .4; } }

/* ---------- the card table (deck, draw, flip, discard) ---------- */
.table { position: relative; display: flex; flex-direction: column; align-items: center; margin-bottom: 8px; }
.deck { position: relative; height: 58px; width: 96px; margin-bottom: 8px; z-index: 1; }
.deckcard {
  position: absolute; inset: 0; border-radius: 8px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='38'%3E%3Crect x='7' y='2' width='7' height='7' rx='1.2' fill='%234a7cd6'/%3E%3Crect x='7' y='11' width='7' height='7' rx='1.2' fill='%238dc63f'/%3E%3Crect x='7' y='20' width='7' height='7' rx='1.2' fill='%23f0512e'/%3E%3Crect x='7' y='29' width='16' height='7' rx='1.2' fill='%23c99a2e'/%3E%3C/svg%3E") #f7f5ef;
  background-size: 30px 38px;
  border: 1px solid #d8d4c8; box-shadow: 0 3px 10px rgba(0,0,0,.45);
}
.deckcard.dc2 { transform: translate(3px, -3px) rotate(1.6deg); }
.deckcard.dc3 { transform: translate(-3px, -6px) rotate(-2.2deg); }
.deckcount {
  position: absolute; right: -10px; top: -10px; z-index: 2;
  background: var(--gold); color: var(--ink); font-size: 11px; font-weight: 900;
  min-width: 22px; height: 22px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.card3d { perspective: 1400px; width: min(360px, 90vw); height: clamp(210px, 34vh, 330px); margin: 0 auto; }
.flipper {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transform: translateY(-64px) scale(.28) rotateY(0deg);
  transition: transform .75s cubic-bezier(.35, .9, .3, 1);
  will-change: transform;
}
.flipper.play { transform: translateY(0) scale(1) rotateY(180deg); }
.flipper.instant { transition: none; }
.flipper.discard { transition: transform .4s ease, opacity .4s ease; transform: translateY(0) translateX(-130%) rotate(-10deg) rotateY(180deg); opacity: 0; }
.face {
  position: absolute; inset: 0; border-radius: 14px; overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 14px 40px rgba(0,0,0,.5);
}
.face.back {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='34' height='42'%3E%3Crect x='8' y='2' width='8' height='8' rx='1.4' fill='%234a7cd6'/%3E%3Crect x='8' y='12' width='8' height='8' rx='1.4' fill='%238dc63f'/%3E%3Crect x='8' y='22' width='8' height='8' rx='1.4' fill='%23f0512e'/%3E%3Crect x='8' y='32' width='18' height='8' rx='1.4' fill='%23c99a2e'/%3E%3C/svg%3E") #f7f5ef;
  background-size: 34px 42px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid #d8d4c8;
}
/* Card back carries the product's own mark, not a recreation of the client's
   monogram. SPLC's identity rules forbid redrawing or recoloring their mark,
   and a hand-set "SP LC." tile did all of that. The four-block Levels to This
   mark is ours to place freely. */
.face.back .cardback {
  background: #f7f5ef; padding: 20px 22px; border-radius: 10px;
  box-shadow: 0 0 0 10px #f7f5ef; display: grid; place-items: center;
}
.face.back .cardback .lmark { display: grid; gap: 5px; }
.face.back .cardback .lmark span { width: 22px; height: 22px; border-radius: 5px; display: block; }
.face.back .cardback .lmark span:nth-child(1) { background: var(--blue); }
.face.back .cardback .lmark span:nth-child(2) { background: var(--green); }
.face.back .cardback .lmark span:nth-child(3) { background: var(--orange); }
.face.back .cardback .lmark span:nth-child(4) { background: var(--gold); width: 48px; }
.face.front {
  background: #faf9f5; color: #16161a; transform: rotateY(180deg);
  display: flex; flex-direction: column; padding: 16px 18px 14px;
}
.cardlogo { display: flex; align-items: center; gap: 8px; flex: none; }
.cardlogo .lmark span { width: 7px; height: 7px; border-radius: 1.5px; }
.cardlogo .lmark span:nth-child(4) { width: 15px; }
.cardlogo b { font-size: 13px; font-weight: 900; letter-spacing: .6px; color: #111; }
.cardlvl { flex: none; font-size: 9.5px; font-weight: 800; letter-spacing: 1.6px; text-transform: uppercase; color: #8a6d1f; margin: 10px 0 8px; }
.cardq {
  flex: 1; overflow-y: auto; font-family: Georgia, "Times New Roman", serif;
  font-size: 14.5px; line-height: 1.55; color: #1c1c1f; padding-right: 4px;
}
.cardfoot { flex: none; display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-size: 9px; font-weight: 700; letter-spacing: 1.2px; color: #6a6458; text-transform: uppercase; }
.answers.hidden, .pp-actions.hidden { opacity: 0; pointer-events: none; }
.answers, .pp-actions { transition: opacity .3s ease; }

/* ---------- gameplay ---------- */
.hud { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 7px 12px; font-size: 11px; font-weight: 700; color: var(--mute); }
.chip b { font-size: 15px; display: block; color: var(--white); }
.chip.score b { color: var(--green); }
.chip.streak b { color: var(--orange); }
.timerwrap { margin-left: auto; position: relative; width: 46px; height: 46px; flex: none; }
.timerwrap svg { transform: rotate(-90deg); display: block; }
.timerwrap .t { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px; }
.lvl { font-size: 10.5px; font-weight: 800; letter-spacing: 1.5px; color: var(--gold); text-transform: uppercase; margin-bottom: 8px; }
.qcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 17px; font-size: 14.5px; line-height: 1.6; margin-bottom: 13px; min-height: 96px; }
.answers { display: grid; gap: 9px; margin-bottom: 14px; }
.ans { background: var(--panel); border: 1px solid var(--line); border-radius: 13px; padding: 13px 15px; font-size: 14px; font-weight: 600; color: var(--white); text-align: left; cursor: pointer; transition: border-color .18s, transform .18s, background .18s; }
.ans:active { transform: translateX(3px); }
.ans.right { background: rgba(141, 198, 63, .16); border-color: var(--green); }
.ans.wrong { background: rgba(240, 81, 46, .14); border-color: var(--orange); }
.ans[disabled] { pointer-events: none; }
.explain { font-size: 12px; color: var(--mute); line-height: 1.5; background: var(--panel); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; animation: slidein .25s ease; }
/* Tower sits under the HUD so it's always in view (never below the fold). */
.stage { display: flex; align-items: flex-end; justify-content: center; margin: 2px 0 10px; }

/* ---------- tower (js/tower.js owns this DOM; presentation only) ---------- */
.tw { position: relative; display: flex; justify-content: center; align-items: flex-end; }
.tw-frame { position: relative; width: 160px; height: clamp(92px, 15vh, 150px); }
.tw-rig { position: absolute; inset: 0; transform-origin: 50% 100%; transition: transform .45s cubic-bezier(.22,.9,.36,1); }
.tw-stack { position: absolute; inset: 0; transform-origin: 50% 100%; will-change: transform; }
.tw-blk { position: absolute; left: 50%; bottom: 8px; width: 58px; height: 15px; margin-left: -29px; will-change: transform; }
.tw-settling .tw-blk { transition: transform .5s cubic-bezier(.34,1.56,.64,1); }
.tw-blk > i { display: block; width: 100%; height: 100%; border-radius: 4px; background: var(--c);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.22), inset 0 -2px 0 rgba(0,0,0,.28); }
.tw-c0 { --c: var(--blue,   #4f7cf7); }
.tw-c1 { --c: var(--green,  #8dc63f); }
.tw-c2 { --c: var(--orange, #f0512e); }
.tw-c3 { --c: var(--gold,   #e6a52e); }
.tw-shadow { position: absolute; left: 50%; bottom: 0; width: 100px; height: 13px; margin-left: -50px; border-radius: 50%;
  background: radial-gradient(50% 50% at 50% 50%, rgba(0,0,0,.5), transparent 72%); transition: transform .3s ease, opacity .4s ease; }
.tw-fallen .tw-shadow { opacity: .35; }
.tw-init, .tw-init * { animation: none !important; transition: none !important; }

.tw-drop-in { animation: tw-drop .58s both; }
.tw-stack.tw-bounce { animation: tw-bounce .42s ease-out; }
.tw-pull-l { animation: tw-pull-l .52s both; }
.tw-pull-r { animation: tw-pull-r .52s both; }
.tw-stack.tw-wobble-l { animation: tw-wobble-l .72s cubic-bezier(.36,.07,.19,.97); }
.tw-stack.tw-wobble-r { animation: tw-wobble-r .72s cubic-bezier(.36,.07,.19,.97); }
.tw-shadow.tw-pulse { animation: tw-shpulse .3s ease-out; }

@keyframes tw-drop {
  0% { transform: translateY(-118px) scale(1.04); opacity: 0; animation-timing-function: cubic-bezier(.55,.06,.68,.19); }
  12% { opacity: 1; }
  60% { transform: translateY(0) scale(1); animation-timing-function: cubic-bezier(.22,.9,.36,1); }
  72% { transform: translateY(2px) scale(1.08,.84); }
  86% { transform: translateY(-1.5px) scale(.98,1.04); }
  100% { transform: none; }
}
@keyframes tw-bounce { 0% { transform: none; } 35% { transform: translateY(1.5px) scale(1.01,.982); } 70% { transform: scale(.996,1.006); } 100% { transform: none; } }
@keyframes tw-pull-r { 0% { transform: none; opacity: 1; animation-timing-function: cubic-bezier(.5,.05,.8,.3); } 30% { transform: translateX(20px) rotate(3deg); } 100% { transform: translateX(150px) translateY(30px) rotate(34deg); opacity: 0; } }
@keyframes tw-pull-l { 0% { transform: none; opacity: 1; animation-timing-function: cubic-bezier(.5,.05,.8,.3); } 30% { transform: translateX(-20px) rotate(-3deg); } 100% { transform: translateX(-150px) translateY(30px) rotate(-34deg); opacity: 0; } }
@keyframes tw-wobble-r { 0% { transform: rotate(0); } 22% { transform: rotate(2.6deg); } 48% { transform: rotate(-1.8deg); } 72% { transform: rotate(.9deg); } 100% { transform: rotate(0); } }
@keyframes tw-wobble-l { 0% { transform: rotate(0); } 22% { transform: rotate(-2.6deg); } 48% { transform: rotate(1.8deg); } 72% { transform: rotate(-.9deg); } 100% { transform: rotate(0); } }
@keyframes tw-shpulse { 40% { transform: scaleX(1.12); } }

/* ---- collapse v2 ------------------------------------------------------- */

/* physics wrapper: owns the vertical axis (gravity + bounce) */
.tw-fw {
  position: absolute; left: 50%; bottom: 8px;
  width: 58px; height: 15px; margin-left: -29px;
  will-change: transform;
  pointer-events: none;
}
/* a freed block: wrapper owns Y, the block owns X + spin */
.tw-blk.tw-free { left: 0; bottom: 0; margin-left: 0; }

/* vertical: hang -> gravity slam -> squash -> bounce -> second touch -> rest */
@keyframes tw-fall-y {
  0%        { transform: translateY(var(--y0));  animation-timing-function: cubic-bezier(.62,.03,.96,.38); }
  52%       { transform: translateY(var(--yg));  animation-timing-function: cubic-bezier(.14,.8,.3,1); }
  70%       { transform: translateY(var(--yb));  animation-timing-function: cubic-bezier(.56,.04,.86,.42); }
  84%       { transform: translateY(var(--yg2)); animation-timing-function: cubic-bezier(.18,.85,.38,1); }
  93%, 100% { transform: translateY(var(--yr)); }
}

/* horizontal + spin: near-linear ballistic drift, then a friction skid to rest */
@keyframes tw-fall-x {
  0%   { transform: var(--x0); animation-timing-function: cubic-bezier(.3,.15,.65,.8); }
  52%  { transform: var(--x1); animation-timing-function: cubic-bezier(.13,.62,.29,.99); }
  84%  { transform: var(--x2); animation-timing-function: cubic-bezier(.33,.6,.55,1); }
  100% { transform: var(--x3); }
}

/* bulk camera shake — ~2x amplitude, 8 alternations, .62s, with a ground-anchored
   compression punch composed into the first keyframes (frame squashes on contact). */
.tw-frame.tw-shake2 { transform-origin: 50% 88%; animation: tw-shake2 .62s linear both; }
@keyframes tw-shake2 {
  0%   { transform: translate(0,0) rotate(0) scale(1); }
  5%   { transform: translate(-7px,5px) rotate(-.8deg) scale(1.035,.93); }
  13%  { transform: translate(8px,-4.5px) rotate(.7deg) scale(.985,1.02); }
  22%  { transform: translate(-7px,-3px) rotate(-.5deg) scale(1.008,.995); }
  32%  { transform: translate(6px,3.5px) rotate(.4deg) scale(1); }
  44%  { transform: translate(-4.5px,2px) rotate(-.28deg); }
  56%  { transform: translate(3px,-1.5px) rotate(.18deg); }
  70%  { transform: translate(-1.8px,.8px) rotate(-.1deg); }
  84%  { transform: translate(.9px,-.4px) rotate(0); }
  100% { transform: translate(0,0) rotate(0) scale(1); }
}

/* hero-landing body blow — one vertical drop-thud (reads different from the lateral bulk shake) */
.tw-frame.tw-thud { transform-origin: 50% 88%; animation: tw-thud .3s linear both; }
@keyframes tw-thud {
  0%   { transform: translate(0,0) scale(1); }
  14%  { transform: translate(0,3.5px) rotate(.25deg) scale(1.022,.95); }
  34%  { transform: translate(-2.5px,-1.2px) scale(.995,1.012); }
  58%  { transform: translate(1.4px,.6px) scale(1); }
  100% { transform: translate(0,0); }
}

/* sub-degree strain tremor while the tower hangs at the brink (parent-level; decay baked in) */
.tw-stack.tw-strain { animation: tw-tremor .42s linear both; }
@keyframes tw-tremor {
  0%,100% { transform: rotate(0); }
  12% { transform: rotate(.4deg); }  27% { transform: rotate(-.33deg); }
  44% { transform: rotate(.25deg); } 61% { transform: rotate(-.16deg); }
  80% { transform: rotate(.07deg); }
}

/* shadow: blooms on impact, settles wider + flatter (the rubble is wider) */
.tw-shadow.tw-flare { animation: tw-shbloom .9s cubic-bezier(.17,.67,.3,1) both; }
@keyframes tw-shbloom {
  0%   { transform: scale(1,1); }
  16%  { transform: scale(1.85,1.3); }
  48%  { transform: scale(1.5,1.12); }
  100% { transform: scale(1.38,1.05); }
}

/* one-shot ground flash under the hit — width set inline per blast; peak/end scales var-driven */
.tw-flash {
  position: absolute; left: 50%; bottom: 0;
  width: 110px; height: 16px; margin-left: -55px;
  border-radius: 50%;
  background: radial-gradient(50% 50% at 50% 50%, rgba(255,244,214,.85), rgba(255,244,214,.25) 55%, transparent 72%);
  transform-origin: 50% 100%;
  pointer-events: none;
  animation: tw-flash .32s cubic-bezier(.15,.6,.3,1) both;
}
@keyframes tw-flash {
  0%   { transform: scale(.5,.6); opacity: 0; }
  20%  { transform: scale(var(--fp,1.25),1.12); opacity: .85; }
  100% { transform: scale(var(--fs,1.7),1.28); opacity: 0; }
}

/* denser dust for the bulk hit (same var-driven transforms, punchier opacity) */
@keyframes tw-dust2 {
  0%   { transform: var(--d0); opacity: 0; }
  10%  { opacity: .62; }
  38%  { opacity: .4; }
  100% { transform: var(--d1); opacity: 0; }
}

/* shadow re-bloom under the keystone — starts where tw-shbloom ended (no snap) */
.tw-shadow.tw-flare2 { animation: tw-shbloom2 .55s cubic-bezier(.17,.67,.3,1) both; }
@keyframes tw-shbloom2 {
  0%   { transform: scale(1.38,1.05); }
  30%  { transform: scale(1.72,1.24); }
  100% { transform: scale(1.46,1.09); }
}

/* keystone: wrapper owns Y + the landing squash (origin pinned to its resting bottom so it
   crushes INTO the floor); block owns X + the slow graceful tumble. */
.tw-fw-hero { transform-origin: 50% 100%; }
@keyframes tw-fall-y-hero {
  0%    { transform: translateY(var(--y0)) scale(1);        animation-timing-function: cubic-bezier(.25,.8,.45,1); }
  28%   { transform: translateY(var(--ya)) scale(1);        animation-timing-function: cubic-bezier(.4,.15,.6,.85); }
  40%   { transform: translateY(var(--ya2)) scale(1);       animation-timing-function: cubic-bezier(.55,.03,.85,.4); }
  76%   { transform: translateY(var(--yg)) scale(1);        animation-timing-function: cubic-bezier(.1,.9,.2,1); }
  79.5% { transform: translateY(var(--yg)) scale(1.22,.64); animation-timing-function: cubic-bezier(.2,.7,.3,1); }
  87%   { transform: translateY(var(--yb)) scale(.95,1.07); animation-timing-function: cubic-bezier(.5,.05,.8,.4); }
  94%   { transform: translateY(var(--yr)) scale(1.05,.95); animation-timing-function: cubic-bezier(.25,.8,.4,1); }
  100%  { transform: translateY(var(--yr)) scale(1); }
}
@keyframes tw-fall-x-hero {
  0%   { transform: var(--hx0); animation-timing-function: cubic-bezier(.5,.15,.7,.6); }
  30%  { transform: var(--hx1); animation-timing-function: cubic-bezier(.35,.2,.6,.8); }
  62%  { transform: var(--hx2); animation-timing-function: cubic-bezier(.3,.4,.5,1); }
  76%  { transform: var(--hx3); animation-timing-function: cubic-bezier(.2,.8,.35,1); }
  88%  { transform: var(--hx4); }
  100% { transform: var(--hx4); }
}

/* dust: softness is baked into the gradient — blur is never animated */
.tw-dust {
  position: absolute; left: 50%; bottom: 1px;
  border-radius: 50%;
  background: radial-gradient(50% 58% at 50% 60%, rgba(167,146,113,.5), rgba(167,146,113,.22) 48%, transparent 72%);
  transform-origin: 50% 85%;
  will-change: transform, opacity;
  pointer-events: none;
}
@keyframes tw-dust {
  0%   { transform: var(--d0); opacity: 0; }
  14%  { opacity: .5; }
  40%  { opacity: .3; }
  100% { transform: var(--d1); opacity: 0; }
}

/* wood chips in the tower's palette (--c comes from the existing tw-c* classes) */
.tw-chip {
  position: absolute; left: 50%; bottom: 8px;
  width: 7px; height: 4px; margin-left: -3px;
  border-radius: 1px;
  background: var(--c, #b9a27e);
  will-change: transform, opacity;
  pointer-events: none;
}
@keyframes tw-chip {
  0%   { transform: var(--p0,translate(0,2px)) rotate(0deg); opacity: 1; animation-timing-function: cubic-bezier(.18,.7,.35,1); }
  46%  { transform: var(--p1); opacity: 1; animation-timing-function: cubic-bezier(.55,.04,.83,.4); }
  82%  { transform: var(--p2); opacity: 1; }
  100% { transform: var(--p2); opacity: 0; }
}
.toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%) translateY(8px) scale(.95);
  background: var(--white); color: var(--ink); font-weight: 800; font-size: 14px;
  padding: 11px 20px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: all .28s ease; z-index: 50; max-width: 90vw; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) scale(1); }

/* results */
.big { font-size: 44px; font-weight: 900; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 14px 0; }
.result-grid .card { margin: 0; text-align: center; padding: 13px; }
.result-grid .card b { font-size: 22px; display: block; }
.result-grid .card span { font-size: 10.5px; color: var(--mute); text-transform: uppercase; letter-spacing: 1px; }

/* ---------- leaderboard ---------- */
.filters { display: flex; gap: 7px; margin-bottom: 14px; flex-wrap: wrap; }
.f { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px; font-size: 12px; font-weight: 600; color: var(--mute); cursor: pointer; transition: all .2s; }
.f.on { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.row { display: flex; align-items: center; gap: 11px; background: var(--card); border: 1px solid var(--line); border-radius: 13px; padding: 11px 14px; margin-bottom: 8px; font-size: 13.5px; }
.row .rk { width: 22px; font-weight: 900; color: var(--mute); flex: none; }
.row .rk.top { color: var(--gold); }
.row .nm { font-weight: 700; }
.row .co { color: var(--mute); font-size: 11px; display: block; }
.row .pt { margin-left: auto; font-weight: 800; color: var(--green); }
.row .tm { color: var(--mute); font-size: 11px; width: 46px; text-align: right; flex: none; }
.row.me { border-color: var(--blue); background: rgba(74, 124, 214, .1); }
.empty { text-align: center; color: var(--mute); font-size: 13px; padding: 30px 10px; line-height: 1.6; }

/* ---------- library ---------- */
.acc { background: var(--card); border: 1px solid var(--line); border-radius: 13px; margin-bottom: 9px; overflow: hidden; }
.acc summary { padding: 14px 16px; font-weight: 800; font-size: 14.5px; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px; }
.acc summary::-webkit-details-marker { display: none; }
.acc summary .sq { width: 16px; height: 16px; border-radius: 4px; }
.acc .off { padding: 0 16px 8px; }
.acc .off div { padding: 9px 0; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--mute); line-height: 1.5; }
.acc .off b { color: var(--white); display: block; margin-bottom: 2px; font-size: 13px; }

/* ---------- pass & play ---------- */
.pp-player { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 8px; font-size: 14px; }
.pp-player.turn { border-color: var(--green); }
.pp-player.out { opacity: .4; text-decoration: line-through; }
.pp-player .bl { margin-left: auto; font-weight: 800; color: var(--gold); font-size: 13px; }
.pp-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 12px; }
.pp-actions .wide { grid-column: 1 / -1; }

/* ---------- bottom nav ---------- */
nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  background: rgba(13, 13, 16, .92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
}
nav button { background: none; border: none; color: var(--mute); font-size: 10px; font-weight: 700; letter-spacing: .3px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 10px; border-radius: 10px; transition: color .2s; }
nav button svg { width: 21px; height: 21px; }
nav button.on { color: var(--white); }
nav button.on svg { stroke: var(--green); }

/* ---------- accessibility: visible focus + non-color status cues ---------- */
/* Keyboard focus ring (WCAG 2.4.7 / 1.4.11). Mouse/touch clicks don't show it. */
:focus-visible { outline: 3px solid var(--link); outline-offset: 2px; border-radius: 6px; }
.btn:focus-visible, .f.on:focus-visible, nav button:focus-visible, .lh-choice:focus-visible { outline-color: var(--blue); }
.sw:focus-visible { outline: 3px solid var(--link); outline-offset: 3px; }
/* Answer correctness is never conveyed by color alone (WCAG 1.4.1): add a glyph. */
.ans.right::after { content: " \2713"; color: var(--green); font-weight: 900; }
.ans.wrong::after { content: " \2715"; color: var(--orange); font-weight: 900; }
.lh-choice.right::after { content: "\2713"; margin-left: 6px; color: var(--green); font-weight: 900; font-size: 18px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ===================== Live Host (facilitated multiplayer) ===================== */
.lh { max-width: 640px; }
.lh-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.lh-title { font-weight: 800; color: var(--mute); font-size: 13px; letter-spacing: .04em; }
.lh-code { font-size: clamp(48px, 16vw, 104px); font-weight: 900; letter-spacing: .12em; text-align: center;
  background: var(--panel); border-radius: 18px; padding: 18px 10px; margin: 8px 0; color: var(--white, #f5f5f7); }
.lh-join { text-align: center; color: var(--mute); font-size: 13px; margin: 0 0 14px; word-break: break-all; }
.lh-roster { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 16px; }
.lh-count { width: 100%; text-align: center; font-weight: 800; margin-bottom: 6px; }
.lh-chip { border: 2px solid var(--blue); border-radius: 999px; padding: 5px 12px; font-weight: 700; font-size: 13px; }
.lh-q { font-size: clamp(20px, 4.4vw, 30px); font-weight: 800; line-height: 1.25; margin: 6px 0 16px; }
.lh-choices { display: grid; gap: 10px; margin-bottom: 14px; }
.lh-choices.big .lh-choice { font-size: clamp(17px, 3vw, 22px); }
.lh-choice { background: var(--panel); border-radius: 12px; padding: 12px 14px; display: flex; align-items: center; gap: 10px; position: relative; }
.lh-choice b { display: inline-flex; width: 26px; height: 26px; align-items: center; justify-content: center; background: rgba(255,255,255,.1); border-radius: 7px; flex: none; }
.lh-choice.right { background: rgba(141,198,63,.18); outline: 2px solid var(--green); }
.lh-ct { margin-left: auto; font-weight: 800; color: var(--mute); }
.lh-timerbar { position: relative; height: 12px; background: var(--panel); border-radius: 999px; overflow: hidden; margin: 10px 0 14px; }
.lh-timerfill { position: absolute; inset: 0; width: 100%; background: linear-gradient(90deg, var(--green), var(--gold), var(--orange)); transition: width .2s linear; }
.lh-timernum { position: absolute; right: 8px; top: -22px; font-weight: 800; font-size: 13px; }
.lh-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lh-answered { font-weight: 800; color: var(--mute); }
.lh-towers { display: flex; gap: 12px; justify-content: center; align-items: flex-end; margin: 8px 0 16px; flex-wrap: wrap; }
.lh-tw { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.lh-tw-stage { width: 92px; display: flex; align-items: flex-end; justify-content: center; }
.lh-tw-stage .tw-frame { width: 90px; height: clamp(96px, 16vh, 132px); }
.lh-tw-name { font-weight: 800; font-size: 13px; }
.lh-tw-score { font-weight: 900; font-size: 18px; }
.lh-board { width: 100%; border-collapse: collapse; margin: 6px 0 16px; }
.lh-board td { padding: 9px 8px; border-bottom: 1px solid rgba(255,255,255,.07); font-weight: 700; }
.lh-board td:first-child { color: var(--mute); width: 28px; }
.lh-board .lh-s { text-align: right; font-weight: 900; }
.lh-steal { text-align: center; font-weight: 800; color: var(--orange); }
.lh-winner { text-align: center; font-size: clamp(24px, 6vw, 40px); font-weight: 900; margin: 12px 0; }
.lh-big { text-align: center; font-size: 64px; margin: 20px 0 4px; }
.lh-result { text-align: center; font-size: 26px; font-weight: 900; margin: 18px 0 6px; }
.lh-result.ok { color: var(--green); }
.lh-result.no { color: var(--orange); }
.lh-delta { text-align: center; font-size: 34px; font-weight: 900; margin-bottom: 10px; }
#lhDbl.on { background: var(--orange); color: #fff; }
.ans.chosen { outline: 2px solid var(--blue); }

/* ===================== badges / achievements ===================== */
.bdg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.bdg { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 12px 12px; text-align: center; }
.bdg.off { opacity: .45; filter: grayscale(1); }
.bdg.on { border-color: rgba(141,198,63,.5); }
.bdg-ic { font-size: 34px; line-height: 1; margin-bottom: 6px; }
.bdg-nm { font-weight: 800; font-size: 13.5px; margin-bottom: 3px; }
.bdg-ds { font-size: 11px; color: var(--mute); line-height: 1.4; }
.bdg-tick { position: absolute; top: 8px; right: 10px; color: var(--green); font-weight: 900; }

/* ---- notifications opt-in ---- */
.notif-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.notif-row:first-of-type { border-top: none; }
.notif-lbl { flex: 1; }
.notif-lbl b { color: var(--white); font-size: 14.5px; }
.notif-note { display: block; color: var(--mute); font-size: 12px; margin-top: 2px; }
.a-18 { font-size: 9.5px; font-weight: 800; letter-spacing: .5px; color: var(--gold); border: 1px solid var(--gold); border-radius: 5px; padding: 0 5px; margin-left: 4px; vertical-align: middle; }
.sw { width: 50px; height: 30px; border-radius: 999px; background: #3a3a44; position: relative; flex: none; cursor: pointer; transition: background .2s; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .2s; }
.sw.on { background: var(--green); }
.sw.on::after { left: 23px; }
.sw.off { opacity: .4; cursor: not-allowed; }
