:root {
  --violet: #beb0dd;
  --violet-deep: #a89acb;
  --yellow: #f3e59a;
  --white: #f7f6fb;
  --ink: #4f4a74;
  --shadow: rgba(0, 0, 0, 0.2);
  --ease-fluid: cubic-bezier(0.22, 0.7, 0.2, 1);
  --ease-glide: cubic-bezier(0.24, 0.78, 0.2, 1);
  --ease-soft: cubic-bezier(0.3, 0.62, 0.25, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Montserrat", sans-serif;
  background: #080808;
}

.dev-debug-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 4px 8px;
  font: 600 11px/1.2 "Montserrat", sans-serif;
  color: #ffffff !important;
  background: rgba(12, 12, 20, 0.85);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dev-debug-bar span {
  color: #ffffff !important;
  overflow: hidden;
  text-overflow: ellipsis;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  color: var(--yellow);
  isolation: isolate;
  background: #9f91c2;
  overflow: hidden;
  display: block;
}

@supports (height: 100dvh) {
  #app {
    height: 100dvh;
  }
}

.canvas {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--violet);
  overflow: hidden;
  isolation: isolate;
  --ui-scale: 1;
  --text-scale: 1.12;
  --rank-text-scale: 1;
  --footer-text-scale: 1;
}

@supports (height: 100dvh) {
  .canvas {
    height: 100dvh;
  }
}

#app.warning {
  background: var(--yellow);
  color: var(--violet);
}

#app.blink {
  filter: contrast(1.05) saturate(1.1) brightness(1.06);
}

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  z-index: 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity 320ms var(--ease-soft);
  transform: none;
  overflow: hidden;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
}

.fit-text {
  --fit-scale: 1;
  --fit-origin: center center;
  transform-origin: var(--fit-origin);
  scale: var(--fit-scale);
}

.screen-home {
  grid-template-rows:
    clamp(calc(196px * var(--ui-scale)), 18vw, calc(320px * var(--ui-scale)))
    1fr
    auto;
  padding: clamp(
    calc(24px * var(--ui-scale)),
    calc(3vw * var(--ui-scale)),
    calc(54px * var(--ui-scale))
  );
}

.home-head {
  display: grid;
  place-items: start center;
  opacity: 0;
  transform: translateY(-18px) scale(0.98);
}

.apm-logo {
  width: min(calc(38vw * var(--ui-scale)), calc(320px * var(--ui-scale)));
  max-width: 72%;
  filter: none;
  animation: none;
}

.home-center {
  display: grid;
  place-content: center;
  justify-items: center;
  align-items: center;
  align-content: center;
  text-align: center;
  width: 100%;
  padding-inline: clamp(
    calc(8px * var(--ui-scale)),
    calc(1.2vw * var(--ui-scale)),
    calc(22px * var(--ui-scale))
  );
  transform: rotate(-9deg);
  opacity: 0;
  transition: transform 340ms cubic-bezier(0.2, 0.72, 0.15, 1);
}

.floating-title {
  display: inline-grid;
  justify-items: center;
  width: max-content;
  max-width: 100%;
  margin-inline: auto;
}

.home-center h1 {
  display: inline-grid;
  justify-items: center;
  align-items: center;
  margin: 0;
  max-width: 100%;
  font-size: clamp(
    calc(58px * var(--ui-scale) * var(--text-scale)),
    calc(9.6vw * var(--ui-scale) * var(--text-scale)),
    calc(142px * var(--ui-scale) * var(--text-scale))
  );
  line-height: 0.84;
  letter-spacing: 0.01em;
  text-shadow: none;
  animation: none;
  font-family: "Montserrat", sans-serif;
  font-style: italic;
  font-weight: 900;
  text-transform: uppercase;
  transform: scale(calc(var(--title-fit-scale, 1) * var(--title-mode-scale, 1)));
  transform-origin: center center;
}

.home-center h1 > .line {
  display: block;
  letter-spacing: 0.04em;
  opacity: 0.96;
}

.home-center h1 > .line:last-child {
  font-weight: 700;
}

.floating-title .line {
  display: block;
  white-space: nowrap;
}

.floating-title .space {
  display: inline-block;
  width: 0.35em;
}

.floating-title .letter {
  display: inline-block;
  animation: floatLetter 4.4s var(--ease-fluid) infinite;
  will-change: transform;
  transform: translateZ(0);
}

.floating-title .letter:nth-child(1) { animation-delay: 0s; }
.floating-title .letter:nth-child(2) { animation-delay: 0.08s; }
.floating-title .letter:nth-child(3) { animation-delay: 0.16s; }
.floating-title .letter:nth-child(4) { animation-delay: 0.24s; }
.floating-title .letter:nth-child(5) { animation-delay: 0.32s; }
.floating-title .letter:nth-child(6) { animation-delay: 0.4s; }
.floating-title .letter:nth-child(7) { animation-delay: 0.48s; }
.floating-title .letter:nth-child(8) { animation-delay: 0.56s; }
.floating-title .letter:nth-child(9) { animation-delay: 0.64s; }
.floating-title .letter:nth-child(10) { animation-delay: 0.72s; }
.floating-title .letter:nth-child(11) { animation-delay: 0.8s; }

.home-footer {
  display: grid;
  justify-items: stretch;
  align-items: end;
  gap: clamp(
    calc(8px * var(--ui-scale)),
    calc(0.8vw * var(--ui-scale)),
    calc(14px * var(--ui-scale))
  );
  padding-bottom: clamp(
    calc(8px * var(--ui-scale)),
    calc(1.2vw * var(--ui-scale)),
    calc(18px * var(--ui-scale))
  );
  position: relative;
}

.home-signup {
  margin: 0;
  font-style: italic;
  font-weight: 700;
  font-size: clamp(
    calc(18px * var(--ui-scale) * var(--text-scale) * var(--footer-text-scale)),
    calc(2vw * var(--ui-scale) * var(--text-scale) * var(--footer-text-scale)),
    calc(38px * var(--ui-scale) * var(--text-scale) * var(--footer-text-scale))
  );
  letter-spacing: 0.01em;
  color: var(--yellow);
  transition: opacity 260ms ease, transform 260ms ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-board {
  display: grid;
  --qr-size: clamp(
    calc(142px * var(--ui-scale)),
    calc(11.2vw * var(--ui-scale)),
    calc(208px * var(--ui-scale))
  );
  --board-h: clamp(
    calc(154px * var(--ui-scale)),
    calc(13.2vw * var(--ui-scale)),
    calc(224px * var(--ui-scale))
  );
  grid-template-columns:
    calc(
      var(--qr-size) + clamp(
          calc(16px * var(--ui-scale)),
          calc(1vw * var(--ui-scale)),
          calc(22px * var(--ui-scale))
        )
    )
    1fr;
  height: var(--board-h);
  width: calc(
    100% + clamp(
        calc(52px * var(--ui-scale)),
        calc(6.4vw * var(--ui-scale)),
        calc(108px * var(--ui-scale))
      )
  );
  margin-left: calc(
    clamp(
        calc(24px * var(--ui-scale)),
        calc(3vw * var(--ui-scale)),
        calc(54px * var(--ui-scale))
      ) * -1
  );
  margin-right: calc(
    clamp(
        calc(24px * var(--ui-scale)),
        calc(3vw * var(--ui-scale)),
        calc(54px * var(--ui-scale))
      ) * -1
  );
  margin-bottom: calc(
    clamp(
        calc(8px * var(--ui-scale)),
        calc(1.2vw * var(--ui-scale)),
        calc(18px * var(--ui-scale))
      ) * -1
  );
  border-top: none;
  backdrop-filter: none;
  opacity: 0;
  transform: translateY(calc(24px * var(--ui-scale)));
  position: relative;
  overflow: visible;
  align-items: stretch;
  transition: opacity 260ms ease, transform 260ms ease;
}

.home-board::after {
  content: "";
  position: absolute;
  inset: 0 -35%;
  background: linear-gradient(
    100deg,
    transparent 35%,
    rgba(255, 255, 255, 0.24) 50%,
    transparent 65%
  );
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
  z-index: 2;
}

.qr-fake {
  background: #8d80ad;
  position: relative;
  display: grid;
  place-items: center;
  padding: clamp(
    calc(10px * var(--ui-scale)),
    calc(0.85vw * var(--ui-scale)),
    calc(16px * var(--ui-scale))
  );
}

.qr-code {
  width: var(--qr-size);
  aspect-ratio: 1;
  background: #ffffff;
  padding: clamp(6px, 0.55vw, 10px);
  display: grid;
  place-items: center;
  background:
    linear-gradient(90deg, transparent 15%, var(--yellow) 15% 85%, transparent 85%),
    linear-gradient(transparent 15%, var(--yellow) 15% 85%, transparent 85%),
    repeating-linear-gradient(90deg, var(--yellow) 0 8px, transparent 8px 16px),
    repeating-linear-gradient(var(--yellow) 0 8px, transparent 8px 16px);
  box-shadow: none;
  animation: qrBreath 2.8s ease-in-out infinite;
  position: relative;
  z-index: 1;
}

.qr-code img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #ffffff;
}

.signup-bubble {
  position: absolute;
  top: calc(
    -1 * clamp(
        calc(72px * var(--ui-scale)),
        calc(5.4vw * var(--ui-scale)),
        calc(86px * var(--ui-scale))
      )
  );
  left: 50%;
  transform: translateX(-50%) scale(0.88);
  background: linear-gradient(135deg, #fff4b9 0%, #f3e59a 100%);
  color: #5e547f;
  font-size: clamp(
    calc(11px * var(--ui-scale) * var(--text-scale)),
    calc(0.9vw * var(--ui-scale) * var(--text-scale)),
    calc(17px * var(--ui-scale) * var(--text-scale))
  );
  font-weight: 800;
  font-style: normal;
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  padding: 0.46em 0.9em;
  border-radius: 999px;
  opacity: 0;
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  white-space: nowrap;
  letter-spacing: 0.02em;
  z-index: 3;
}

.signup-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 12px;
  height: 12px;
  background: var(--yellow);
  transform: translateX(-50%) rotate(45deg);
  border-radius: 2px;
}

.rank-mock {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  background: #8d80ad;
  min-width: 0;
  padding-inline: clamp(
    calc(6px * var(--ui-scale)),
    calc(0.6vw * var(--ui-scale)),
    calc(12px * var(--ui-scale))
  );
}

.rank-row {
  display: grid;
  place-content: center;
  text-align: center;
  border-top: 3px solid rgba(255, 255, 255, 0.17);
  opacity: 1;
  transform: translateX(0);
  min-width: 0;
  padding-block: clamp(
    calc(6px * var(--ui-scale)),
    calc(0.7vw * var(--ui-scale)),
    calc(12px * var(--ui-scale))
  );
  padding-inline: clamp(
    calc(14px * var(--ui-scale)),
    calc(1.2vw * var(--ui-scale)),
    calc(24px * var(--ui-scale))
  );
}

.rank-row.top {
  background: var(--yellow);
  color: var(--ink);
  border-top: none;
}

.rank-row strong {
  font-size: clamp(
    calc(20px * var(--ui-scale) * var(--text-scale) * var(--footer-text-scale)),
    calc(1.7vw * var(--ui-scale) * var(--text-scale) * var(--footer-text-scale)),
    calc(30px * var(--ui-scale) * var(--text-scale) * var(--footer-text-scale))
  );
  line-height: 1;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  max-width: 100%;
}

.rank-row span {
  font-family: "Montserrat", sans-serif;
  font-weight: 700;
  opacity: 0.9;
  margin-top: 2px;
  font-size: clamp(
    calc(12px * var(--ui-scale) * var(--text-scale) * var(--footer-text-scale)),
    calc(0.95vw * var(--ui-scale) * var(--text-scale) * var(--footer-text-scale)),
    calc(17px * var(--ui-scale) * var(--text-scale) * var(--footer-text-scale))
  );
}

.screen-home.active .rank-row:nth-child(1) {
  animation: rankReveal 520ms cubic-bezier(0.2, 0.72, 0.15, 1) 360ms both;
}

.screen-home.active .rank-row:nth-child(2) {
  animation: rankReveal 520ms cubic-bezier(0.2, 0.72, 0.15, 1) 470ms both;
}

.screen-home.active .rank-row:nth-child(3) {
  animation: rankReveal 520ms cubic-bezier(0.2, 0.72, 0.15, 1) 580ms both;
}

.screen-home.ambient-sheen .home-board::after {
  opacity: 1;
  animation: boardSheen 1200ms ease forwards;
}

.screen-home.ambient-bubble .signup-bubble {
  animation: bubbleFlash 5200ms cubic-bezier(0.2, 0.75, 0.2, 1) forwards;
}

.screen-home.ambient-rank .rank-row.top strong {
  display: inline-block;
  animation: rankPulse 1200ms ease;
}

.screen-home.ambient-qr .qr-code {
  animation: qrBurst 720ms cubic-bezier(0.21, 0.84, 0.35, 1);
}

.screen-home.ambient-title .floating-title {
  animation: titleSway 2200ms var(--ease-fluid);
}

.screen-home.ambient-title .floating-title .letter {
  animation-duration: 2.8s;
}

.screen-home.ambient-rankglow .rank-mock {
  animation: boardLift 1300ms var(--ease-fluid);
}

.screen-home.ambient-rankglow .rank-row:nth-child(1) {
  animation: rankPulseSoft 1400ms ease;
}

.screen-home.ambient-rankglow .rank-row:nth-child(2) {
  animation: rankPulseSoft 1400ms ease 120ms;
}

.screen-home.ambient-rankglow .rank-row:nth-child(3) {
  animation: rankPulseSoft 1400ms ease 240ms;
}

.screen-home.ambient-qrflash .qr-code,
.screen-home.ambient-qrflash .rank-qr-reminder-code {
  animation: qrBurst 980ms var(--ease-glide);
}

#app.timer-ambient-wave .timer-flood {
  filter: brightness(1.03) saturate(1.04);
}

#app.timer-ambient-wave .count-layer {
  animation: timerWave 900ms ease;
}

#app.timer-ambient-pop .count-layer {
  animation: timerPop 660ms cubic-bezier(0.18, 0.8, 0.25, 1);
}

#app.timer-ambient-tilt .count-layer {
  animation: timerTilt 760ms ease;
}

#app.result-ambient-glow .result-score {
  animation: resultGlow 1300ms ease;
}

#app.result-ambient-bounce .result-block {
  animation: resultBounce 760ms ease;
}

.screen-timer {
  display: grid;
  place-items: center;
  --flood-px: 0px;
  --count-top-px: 0px;
  --timer-height-px: 100px;
  --count-fit-scale: 1;
}

.timer-flood {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  background: var(--yellow);
  z-index: 0;
  transition: height 120ms linear;
}

#app.warning .timer-flood {
  height: 100% !important;
}

.count-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  transform-origin: center center;
  transform: scale(calc(var(--count-scale, 1) * var(--count-fit-scale, 1)));
  transition: transform 180ms var(--ease-soft);
  animation: none;
}

.count-value {
  display: inline-block;
  position: relative;
  z-index: 1;
  font-size: clamp(
    calc(170px * var(--ui-scale) * var(--text-scale)),
    calc(31vw * var(--ui-scale) * var(--text-scale)),
    calc(620px * var(--ui-scale) * var(--text-scale))
  );
  line-height: 0.8;
  font-weight: 900;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transform-origin: center;
  text-shadow: none;
  letter-spacing: 0.01em;
  color: transparent;
  background: linear-gradient(
    to top,
    #7f73aa 0 var(--flood-px, 0px),
    var(--yellow) var(--flood-px, 0px) var(--timer-height-px, 100px)
  );
  background-size: 100% var(--timer-height-px, 100px);
  background-position: 0 calc(-1 * var(--count-top-px, 0px));
  background-repeat: no-repeat;
  background-clip: text;
  -webkit-background-clip: text;
  transition: none;
}

.screen-result {
  place-items: center;
  padding: clamp(
    calc(20px * var(--ui-scale)),
    calc(3vw * var(--ui-scale)),
    calc(52px * var(--ui-scale))
  );
}

.result-block {
  text-align: center;
  display: grid;
  width: 100%;
  justify-items: center;
  gap: clamp(
    calc(8px * var(--ui-scale)),
    calc(1vw * var(--ui-scale)),
    calc(16px * var(--ui-scale))
  );
}

.result-label {
  margin: 0;
  color: var(--white);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: clamp(
    calc(22px * var(--ui-scale) * var(--text-scale)),
    calc(2vw * var(--ui-scale) * var(--text-scale)),
    calc(34px * var(--ui-scale) * var(--text-scale))
  );
}

.result-score {
  display: inline-block;
  margin: 0;
  font-size: clamp(
    calc(160px * var(--ui-scale) * var(--text-scale) * var(--result-fit-scale, 1)),
    calc(34vw * var(--ui-scale) * var(--text-scale) * var(--result-fit-scale, 1)),
    calc(640px * var(--ui-scale) * var(--text-scale) * var(--result-fit-scale, 1))
  );
  line-height: 0.8;
  color: currentColor;
  animation: scoreRise 460ms cubic-bezier(0.17, 0.84, 0.44, 1.04);
  text-align: center;
  white-space: nowrap;
  overflow: visible;
}

.flowers {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.flower {
  position: absolute;
  width: var(--size, 210px);
  aspect-ratio: 1;
  animation: float var(--drift, 9.6s) var(--ease-fluid) infinite alternate,
    pulse var(--pulse, 6.2s) ease-in-out infinite,
    spin var(--spin, 30s) linear infinite,
    driftXY var(--wander, 13s) var(--ease-fluid) infinite;
  transform-origin: center;
  opacity: 1;
  transition: left 820ms var(--ease-glide), top 820ms var(--ease-glide),
    width 820ms var(--ease-glide), opacity 420ms var(--ease-soft),
    filter 420ms var(--ease-soft);
  will-change: left, top, width, filter;
  animation-delay: var(--delay, 0s);
}

#app.state-idle .flower {
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.12));
}

#app.state-running .flower {
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.08));
  opacity: 0.88;
}

.flower.launching {
  opacity: 1;
  filter: none;
}

.flower.launching .flower-image {
  animation: flowerFlash 760ms cubic-bezier(0.2, 0.7, 0.25, 1);
}

.flower-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

@keyframes float {
  0% {
    transform: translateY(-2%) rotate(0deg);
  }
  100% {
    transform: translateY(3%) rotate(5deg);
  }
}

@keyframes pulse {
  0%,
  100% {
    scale: 0.95;
  }
  50% {
    scale: 1.08;
  }
}

@keyframes spin {
  0% {
    rotate: -3deg;
  }
  100% {
    rotate: 3deg;
  }
}

@keyframes driftXY {
  0%,
  100% {
    translate: 0 0;
  }
  30% {
    translate: 0.5vw -0.8vh;
  }
  60% {
    translate: -0.6vw 0.7vh;
  }
}

@keyframes logoFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

@keyframes titlePulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
}

@keyframes floatLetter {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  22% {
    transform: translateY(-0.06em) rotate(-0.8deg);
  }
  50% {
    transform: translateY(-0.095em) rotate(-1.25deg);
  }
  78% {
    transform: translateY(0.045em) rotate(0.8deg);
  }
}

@keyframes qrBreath {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.04);
  }
}

@keyframes numGlow {
  0%,
  100% {
    text-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
  }
  50% {
    text-shadow: 0 16px 34px rgba(0, 0, 0, 0.2);
  }
}

@keyframes scoreRise {
  from {
    transform: translateY(34px) scale(0.92);
    opacity: 0.15;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.screen-home.active .home-head {
  animation: homeRevealTop 760ms var(--ease-glide) 80ms forwards;
}

.screen-home.active .home-center {
  animation: homeRevealCenter 940ms var(--ease-glide) 180ms forwards;
}

.screen-home.active .home-board {
  animation: homeRevealBottom 920ms var(--ease-glide) 300ms forwards;
}

.rank-expanded {
  --rank-panel-top: clamp(
    calc(300px * var(--ui-scale)),
    calc(30vw * var(--ui-scale)),
    calc(520px * var(--ui-scale))
  );
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: var(--rank-panel-top);
  background: #8d80ad;
  border-top: 3px solid rgba(255, 255, 255, 0.16);
  border-radius: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: 1fr auto;
  --rank-scroll-distance: 0px;
  --rank-scroll-duration: 12s;
  opacity: 1;
  transform: translateY(calc(100% + 2px));
  pointer-events: none;
  transition: transform 860ms var(--ease-glide);
  z-index: 5;
}

.rank-expanded-body {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.rank-expanded-top {
  display: grid;
  grid-template-rows: repeat(3, auto);
  position: relative;
  z-index: 2;
}

.rank-expanded-top-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: calc(16px * var(--ui-scale));
  min-width: 0;
  color: var(--yellow);
  border-top: 2px solid rgba(255, 255, 255, 0.17);
  background: #8d80ad;
  padding: clamp(
      calc(14px * var(--ui-scale)),
      calc(1.15vw * var(--ui-scale)),
      calc(20px * var(--ui-scale))
    )
    clamp(
      calc(18px * var(--ui-scale)),
      calc(1.8vw * var(--ui-scale)),
      calc(30px * var(--ui-scale))
    );
  font-size: clamp(
    calc(18px * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale)),
    calc(1.2vw * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale)),
    calc(24px * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale))
  );
  font-weight: 800;
}

.rank-expanded-top-row span,
.rank-expanded-list li span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-expanded-top-row.first {
  background: var(--yellow);
  color: var(--ink);
  border-top: none;
}

.rank-expanded-top strong {
  font-size: clamp(
    calc(14px * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale)),
    calc(1vw * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale)),
    calc(19px * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale))
  );
  white-space: nowrap;
}

.rank-expanded-viewport {
  height: 100%;
  overflow: hidden;
  position: relative;
}

.rank-expanded-viewport::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: calc(24px * var(--ui-scale));
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.22), rgba(0, 0, 0, 0));
  pointer-events: none;
  z-index: 2;
}

.rank-expanded-list {
  list-style: none;
  margin: 0;
  padding: 0;
  transform: translateY(0);
}

.rank-expanded-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: calc(16px * var(--ui-scale));
  min-width: 0;
  color: var(--yellow);
  border-top: 2px solid rgba(255, 255, 255, 0.17);
  padding: clamp(
      calc(14px * var(--ui-scale)),
      calc(1.15vw * var(--ui-scale)),
      calc(20px * var(--ui-scale))
    )
    clamp(
      calc(18px * var(--ui-scale)),
      calc(1.8vw * var(--ui-scale)),
      calc(30px * var(--ui-scale))
    );
  font-size: clamp(
    calc(18px * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale)),
    calc(1.2vw * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale)),
    calc(24px * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale))
  );
  font-weight: 700;
}

.rank-expanded-list li strong {
  font-size: clamp(
    calc(14px * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale)),
    calc(1vw * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale)),
    calc(19px * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale))
  );
  white-space: nowrap;
}

.rank-qr-reminder {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(
    calc(16px * var(--ui-scale)),
    calc(1.5vw * var(--ui-scale)),
    calc(24px * var(--ui-scale))
  );
  padding: clamp(
      calc(12px * var(--ui-scale)),
      calc(1.2vw * var(--ui-scale)),
      calc(18px * var(--ui-scale))
    )
    clamp(
      calc(18px * var(--ui-scale)),
      calc(1.8vw * var(--ui-scale)),
      calc(30px * var(--ui-scale))
    );
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(137, 123, 168, 0.95);
  position: sticky;
  bottom: 0;
}

.rank-qr-reminder p {
  margin: 0;
  color: var(--yellow);
  font-size: clamp(
    calc(14px * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale)),
    calc(1.04vw * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale)),
    calc(20px * var(--ui-scale) * var(--text-scale) * var(--rank-text-scale))
  );
  font-style: italic;
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-qr-reminder-code {
  width: clamp(
    calc(70px * var(--ui-scale)),
    calc(5.8vw * var(--ui-scale)),
    calc(104px * var(--ui-scale))
  );
  aspect-ratio: 1;
  background:
    linear-gradient(90deg, transparent 15%, var(--yellow) 15% 85%, transparent 85%),
    linear-gradient(transparent 15%, var(--yellow) 15% 85%, transparent 85%),
    repeating-linear-gradient(90deg, var(--yellow) 0 4px, transparent 4px 8px),
    repeating-linear-gradient(var(--yellow) 0 4px, transparent 4px 8px);
}

.screen-home.rank-open .rank-expanded {
  transform: translateY(0);
  pointer-events: auto;
}

.screen-home.rank-open .home-center {
  position: absolute;
  left: 50%;
  top: clamp(
    calc(136px * var(--ui-scale)),
    calc(11.2vw * var(--ui-scale)),
    calc(214px * var(--ui-scale))
  );
  width: min(96vw, calc(1100px * var(--ui-scale)));
  margin: 0;
  opacity: 1;
  transform: translateX(-50%) rotate(-9deg);
  transform-origin: center center;
  transition: transform 520ms var(--ease-glide), top 520ms var(--ease-soft);
}

/* Hard override: when both classes coexist during transition, rank-open wins */
.screen-home.rank-open.rank-shifted .home-center {
  top: clamp(
    calc(136px * var(--ui-scale)),
    calc(11.2vw * var(--ui-scale)),
    calc(214px * var(--ui-scale))
  );
  width: min(96vw, calc(1100px * var(--ui-scale)));
  transform: translateX(-50%) rotate(-9deg);
  transform-origin: center center;
}

.screen-home.rank-open .floating-title {
  width: 100%;
  max-width: 100%;
  justify-items: center;
}

.screen-home.rank-open .home-center h1 {
  width: 100%;
  justify-items: center;
}

.screen-home.rank-open .rank-expanded-list {
  animation: rankScroll var(--rank-scroll-duration, 12s) linear 2s forwards;
}

.screen-home.rank-open .rank-expanded-top-row {
  opacity: 0;
  transform: translateY(calc(14px * var(--ui-scale)));
}

.screen-home.rank-open .rank-expanded-top-row:nth-child(1) {
  animation: rankTopRowIn 680ms var(--ease-glide) 160ms forwards;
}

.screen-home.rank-open .rank-expanded-top-row:nth-child(2) {
  animation: rankTopRowIn 680ms var(--ease-glide) 260ms forwards;
}

.screen-home.rank-open .rank-expanded-top-row:nth-child(3) {
  animation: rankTopRowIn 680ms var(--ease-glide) 360ms forwards;
}

.screen-home.rank-open .rank-expanded-viewport {
  animation: rankViewportIn 760ms var(--ease-glide) 220ms both;
}

.screen-home.rank-open .rank-qr-reminder {
  animation: rankReminderIn 780ms var(--ease-glide) 280ms both;
}

.screen-home.rank-shifted .home-center {
  position: absolute;
  left: 50%;
  top: clamp(
    calc(152px * var(--ui-scale)),
    calc(13.6vw * var(--ui-scale)),
    calc(220px * var(--ui-scale))
  );
  width: min(92vw, calc(980px * var(--ui-scale)));
  margin: 0;
  opacity: 1;
  transform: translateX(-50%) rotate(-9deg) scale(0.58);
  transform-origin: top center;
  transition: transform 760ms var(--ease-glide), top 760ms var(--ease-soft);
}

.screen-home.rank-shifted .home-signup,
.screen-home.rank-shifted .home-board {
  opacity: 0;
  transform: translateY(calc(20px * var(--ui-scale)));
  pointer-events: none;
}

@keyframes homeRevealTop {
  from {
    opacity: 0;
    transform: translateY(-18px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes homeRevealCenter {
  from {
    opacity: 0;
    transform: rotate(-8deg) scale(0.94);
  }
  to {
    opacity: 1;
    transform: rotate(-8deg) scale(1);
  }
}

@keyframes homeRevealBottom {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes rankReveal {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes bubbleFlash {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.88);
  }
  12% {
    opacity: 1;
    transform: translateX(-50%) scale(1.06);
  }
  82% {
    opacity: 1;
    transform: translateX(-50%) scale(0.98);
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) scale(0.92);
  }
}

@keyframes boardSheen {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

@keyframes rankPulse {
  0%,
  100% {
    filter: brightness(1);
    transform: scale(1);
  }
  45% {
    filter: brightness(1.08);
    transform: scale(1.02);
  }
}

@keyframes qrBurst {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes rankScroll {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(calc(-1 * var(--rank-scroll-distance, 0px)));
  }
}

@keyframes rankTopRowIn {
  from {
    opacity: 0;
    transform: translateY(calc(14px * var(--ui-scale)));
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes rankViewportIn {
  from {
    opacity: 0.1;
    clip-path: inset(14% 0 0 0);
    transform: translateY(calc(24px * var(--ui-scale)));
  }
  to {
    opacity: 1;
    clip-path: inset(0 0 0 0);
    transform: translateY(0);
  }
}

@keyframes rankReminderIn {
  from {
    opacity: 0;
    transform: translateY(calc(20px * var(--ui-scale)));
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes titleShiftUp {
  from {
    transform: translateY(0) rotate(-9deg);
  }
  to {
    transform: translateY(-11vh) rotate(-9deg);
  }
}

@keyframes titleDock {
  from {
    transform: translateX(-50%) translateY(42px) rotate(-9deg) scale(0.74);
    opacity: 0.88;
  }
  to {
    transform: translateX(-50%) translateY(0) rotate(-9deg) scale(0.58);
    opacity: 1;
  }
}

@keyframes titleSway {
  0%,
  100% {
    transform: rotate(-9deg) translateY(0);
  }
  40% {
    transform: rotate(-8.1deg) translateY(calc(-5px * var(--ui-scale)));
  }
  75% {
    transform: rotate(-9.45deg) translateY(calc(2px * var(--ui-scale)));
  }
}

@keyframes boardLift {
  0% {
    transform: translateY(0);
    filter: brightness(1);
  }
  45% {
    transform: translateY(calc(-9px * var(--ui-scale)));
    filter: brightness(1.06);
  }
  100% {
    transform: translateY(0);
    filter: brightness(1);
  }
}

@keyframes rankPulseSoft {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.08);
  }
}

@keyframes flowerFlash {
  0% {
    scale: 1;
    filter: saturate(1) brightness(1);
  }
  42% {
    scale: 1.17;
    filter: saturate(1.15) brightness(1.04);
  }
  100% {
    scale: 1;
    filter: saturate(1) brightness(1);
  }
}

@keyframes timerWave {
  0%, 100% { transform: scale(var(--count-scale, 1)); }
  50% { transform: scale(calc(var(--count-scale, 1) * 1.06)); }
}

@keyframes timerPop {
  0% { transform: scale(calc(var(--count-scale, 1) * 0.92)); }
  60% { transform: scale(calc(var(--count-scale, 1) * 1.08)); }
  100% { transform: scale(var(--count-scale, 1)); }
}

@keyframes timerTilt {
  0%, 100% { transform: scale(var(--count-scale, 1)) rotate(0deg); }
  30% { transform: scale(var(--count-scale, 1)) rotate(-2.2deg); }
  70% { transform: scale(var(--count-scale, 1)) rotate(2deg); }
}

@keyframes resultGlow {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(255,255,255,0)); }
  50% { filter: drop-shadow(0 0 16px rgba(255,255,255,0.32)); }
}

@keyframes resultBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@media (max-aspect-ratio: 9/16) {
  .home-center h1 {
    font-size: clamp(
      calc(44px * var(--ui-scale) * var(--text-scale)),
      calc(12vw * var(--ui-scale) * var(--text-scale)),
      calc(120px * var(--ui-scale) * var(--text-scale))
    );
  }

  .count-value {
    font-size: clamp(
      calc(140px * var(--ui-scale) * var(--text-scale)),
      calc(30vw * var(--ui-scale) * var(--text-scale)),
      calc(420px * var(--ui-scale) * var(--text-scale))
    );
  }
}

.screen-ready {
  place-items: center;
  text-align: center;
  background: var(--yellow);
  color: var(--violet);
}

.ready-wrap {
  padding: clamp(18px, 3vw, 36px);
  display: grid;
  gap: clamp(10px, 2vw, 18px);
  justify-items: center;
}

.ready-label {
  margin: 0;
  font-size: clamp(20px, 2.8vw, 36px);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.ready-player-name {
  margin: 0;
  font-size: clamp(46px, 7.4vw, 120px);
  line-height: 0.92;
  font-style: italic;
  font-weight: 900;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

.ready-hint {
  margin: 0;
  font-size: clamp(16px, 2vw, 30px);
  font-weight: 700;
}
