* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: #fff8f2;
  color: #241c22;
  font-family: Pretendard, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.stage {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: center;
  padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
}

.hud {
  width: min(420px, 100%);
  display: grid;
  justify-items: center;
}

.count {
  margin: 8px 0 0;
  font-size: clamp(64px, 16vw, 128px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
}

.hint {
  margin: 8px 0 0;
  color: #8a7080;
  font-size: 15px;
  font-weight: 700;
}

.hint[hidden] {
  display: none;
}

.cps-rank {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin: 34px 0 0;
}

.cps-ladder {
  display: flex;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cps-ladder li {
  min-width: 28px;
  padding: 3px 6px;
  border-radius: 999px;
  background: #f3e6ee;
  color: #b59aab;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-align: center;
}

.cps-ladder li[data-rank="SS"] {
  min-width: 34px;
}

.cps-ladder li[data-rank="SSS"] {
  min-width: 46px;
}

.cps-ladder li.now {
  transform: scale(1.12);
}

.cps-ladder li[data-rank="C"].now {
  background: #efe4ea;
  color: #6d5a68;
}

.cps-ladder li[data-rank="B"].now {
  background: #d7e8ff;
  color: #1d4f93;
}

.cps-ladder li[data-rank="A"].now {
  background: #d7f6ea;
  color: #0e7a52;
}

.cps-ladder li[data-rank="S"].now {
  background: #ffe7a8;
  color: #8a5a00;
}

.cps-ladder li[data-rank="SS"].now {
  background: #ffd0b4;
  color: #9a3d0c;
}

.cps-ladder li[data-rank="SSS"].now {
  background: #ff4d8a;
  color: #fff;
}

.cps-meta {
  margin: 0;
  color: #8a7080;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.fever {
  width: 100%;
  margin: 14px 0 0;
  text-align: center;
}

.fever-track {
  height: 14px;
  border-radius: 999px;
  background: #f0e4dc;
  overflow: hidden;
}

.fever-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, #c9a6ff, #6a3ec8);
}

.fever-label {
  margin: 5px 0 0;
  color: #8a7080;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-align: center;
}

.fever.on .fever-track {
  box-shadow: 0 0 0 3px #ffe0ea;
}

.fever.on .fever-fill {
  background: linear-gradient(90deg, #ffd36a, #ff4d8d);
}

.fever.on .fever-label {
  color: #fff;
  text-shadow: 0 1px 0 #000, 0 0 6px rgba(0, 0, 0, 0.8);
}

body.fever-on {
  background: #000;
}

body.fever-on .count {
  color: #fff;
  text-shadow: 0 2px 0 #000, 0 0 8px rgba(0, 0, 0, 0.9);
}

body.fever-on .cps-meta {
  color: #fff;
}

body.fever-on .cps-ladder li:not(.now) {
  background: #2a2a2a;
  color: #8d8d8d;
}

.rank-burst {
  position: fixed;
  left: 50%;
  top: 38%;
  z-index: 6;
  margin: 0;
  color: #6d5a68;
  font-size: 96px;
  font-weight: 800;
  letter-spacing: -0.06em;
  line-height: 1;
  pointer-events: none;
  animation: rank-pop 720ms ease-out forwards;
}

.rank-burst.down {
  font-size: 64px;
  animation-duration: 460ms;
}

.rank-burst[data-rank="B"] { color: #3d7ed8; }
.rank-burst[data-rank="A"] { color: #14a56e; }
.rank-burst[data-rank="S"] { color: #e0a000; }
.rank-burst[data-rank="SS"] { color: #ff7a3c; }
.rank-burst[data-rank="SSS"] {
  color: #ff4d8a;
  font-size: 118px;
}

.rank-burst::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 110px;
  height: 110px;
  border: 6px solid currentColor;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0.2);
  animation: rank-ring 720ms ease-out forwards;
}

@keyframes rank-pop {
  0% { opacity: 0; transform: translate(-50%, -46%) scale(0.4); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -78%) scale(1.28); }
}

@keyframes rank-ring {
  0% { opacity: 0.85; transform: translate(-50%, -50%) scale(0.2); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(2.4); }
}


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

.fx[hidden] {
  display: none;
}

.fx-spot {
  position: absolute;
  top: 0;
  left: 50%;
  width: 100vh;
  height: 100vh;
  background-color: #ff2eea;
  clip-path: polygon(43% 0, 57% 0, 82% 100%, 18% 100%);
  transform: translateX(-50%);
  animation: fx-neon 1.2s linear infinite;
}

@keyframes fx-neon {
  0% {
    background-color: #ff2eea;
    filter: drop-shadow(0 0 26px #ff2eea) brightness(1.15);
    animation-timing-function: steps(1, end);
  }
  12.5% {
    background-color: #fff;
    filter: drop-shadow(0 0 40px #fff) brightness(1.7);
    animation-timing-function: steps(1, end);
  }
  25% {
    background-color: #3de4ff;
    filter: drop-shadow(0 0 26px #3de4ff) brightness(1.2);
    animation-timing-function: steps(1, end);
  }
  37.5% {
    background-color: #fff25a;
    filter: drop-shadow(0 0 32px #fff25a) brightness(1.45);
    animation-timing-function: steps(1, end);
  }
  50% {
    background-color: #7d5cff;
    filter: drop-shadow(0 0 26px #7d5cff) brightness(1.15);
    animation-timing-function: steps(1, end);
  }
  62.5% {
    background-color: #fff;
    filter: drop-shadow(0 0 40px #fff) brightness(1.7);
    animation-timing-function: steps(1, end);
  }
  75% {
    background-color: #39ff8a;
    filter: drop-shadow(0 0 26px #39ff8a) brightness(1.25);
    animation-timing-function: steps(1, end);
  }
  87.5% {
    background-color: #ff4d6a;
    filter: drop-shadow(0 0 32px #ff4d6a) brightness(1.4);
    animation-timing-function: steps(1, end);
  }
  100% {
    background-color: #ff2eea;
    filter: drop-shadow(0 0 26px #ff2eea) brightness(1.15);
  }
}

.yarn {
  position: absolute;
  left: 0;
  top: 0;
  width: 84px;
  height: auto;
  will-change: transform;
}

.yarn:nth-of-type(3n) {
  width: 62px;
}

.yarn:nth-of-type(4n) {
  width: 108px;
}

.face {
  align-self: end;
  margin-bottom: 10px;
  width: min(78vw, 520px);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  display: flex;
  justify-content: center;
}

.face:focus-visible {
  outline: 3px solid #7a3dff;
  outline-offset: 8px;
}

#view {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: auto;
}

.board {
  position: fixed;
  z-index: 3;
  left: 0;
  top: 278px;
  width: min(420px, calc(100vw - 28px));
  margin: 0;
  padding: 10px 14px 8px;
  background: rgba(255, 248, 242, 0.96);
  border-radius: 0 16px 16px 0;
}

@media (max-width: 760px) {
  .board {
    top: 214px;
    width: min(420px, calc(100vw - 20px));
  }
}

.board.collapsed {
  width: auto;
  padding: 0;
  background: transparent;
}

.board.collapsed ol,
.board.collapsed .board-refresh {
  display: none;
}

.board-refresh {
  width: 100%;
  min-height: 44px;
  margin: 0 0 10px;
  padding: 8px 14px;
  border: 2px solid #6a3ec8;
  border-radius: 12px;
  background: #fff;
  color: #6a3ec8;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.board-refresh:disabled {
  border-color: #d9c8f5;
  background: #f3eefe;
  color: #9a86c4;
  cursor: default;
}

.board-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  min-height: 64px;
  margin: 0 0 10px;
  padding: 14px 18px;
  border: 0;
  border-radius: 14px;
  background: #6a3ec8;
  color: #fff;
  font: inherit;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.board.collapsed .board-toggle {
  width: auto;
  min-height: 72px;
  margin: 0;
  padding: 18px 22px;
  border-radius: 0 18px 18px 0;
  font-size: 24px;
}

.board-chevron {
  font-size: 34px;
  line-height: 1;
}

.board-chevron::before {
  content: "‹";
}

.board.collapsed .board-chevron::before {
  content: "›";
}

.board-toggle:focus-visible {
  outline: 3px solid #7a3dff;
  outline-offset: 3px;
}

.board ol {
  position: relative;
  list-style: none;
  max-height: min(48vh, 380px);
  margin: 0;
  padding: 0;
  overflow-y: auto;
}

.board li {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 8px;
  align-items: baseline;
  margin: 2px 0;
  padding: 6px 8px;
  border-radius: 8px;
  background: #fff1ea;
  font-size: 15px;
  font-weight: 700;
}

.board li:nth-child(even) {
  background: #ffe0d2;
}

.board li.place-1,
.board li.place-1 .rank {
  background: #ffe08a;
  color: #7a4b00;
}

.board li.place-2,
.board li.place-2 .rank {
  background: #e4e9f4;
  color: #3d4660;
}

.board li.place-3,
.board li.place-3 .rank {
  background: #ffd0b0;
  color: #7a3d16;
}

.board .rank {
  color: #b0909c;
  font-variant-numeric: tabular-nums;
}

.board .score {
  font-variant-numeric: tabular-nums;
}

.board li.me {
  background: #6a3ec8;
  color: #fff;
}

.board li.me .rank,
.board li.me .score {
  background: transparent;
  color: #fff;
}

body.popping .count {
  transform: scale(1.04);
}
