:root {
  --ink: #2f3150;
  --muted: #6b6d86;
  --accent: #e0607e;
  --accent-ink: #ffffff;
  --card: rgba(255, 255, 255, 0.92);
  --line: #ece6f0;
}

* {
  box-sizing: border-box;
}

/* `hidden` must win over display rules like `button { display: block }` */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'M PLUS Rounded 1c', system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #fde8ee 0%, #f3ecfb 55%, #e6f1ee 100%);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  display: block;
}

#hud {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 16px);
  left: 20px;
  pointer-events: none;
}

#score {
  font-size: 56px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

#platforms {
  margin-top: 4px;
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
}

#best {
  margin-top: 4px;
  font-size: 14px;
  color: var(--muted);
}

#mute {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 16px);
  right: 16px;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  background: rgba(255, 255, 255, 0.75);
}

#toast {
  position: fixed;
  top: 28%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

#toast.show {
  animation: pop 900ms ease-out;
}

@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.8); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
  70% { opacity: 1; transform: translate(-50%, -6px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -16px) scale(1); }
}

.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(340px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  overflow-y: auto;
  padding: 28px 24px 22px;
  border-radius: 24px;
  background: var(--card);
  box-shadow: 0 18px 50px rgba(47, 49, 80, 0.18);
  text-align: center;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

h1 {
  margin: 0 0 8px;
  font-size: 40px;
  font-weight: 800;
  color: var(--accent);
}

h1 small {
  font-size: 14px;
  color: var(--muted);
}

.hint,
.sub {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--muted);
}

.room {
  margin: 0 0 16px;
  padding: 8px 12px;
  border-radius: 12px;
  background: #fff1f4;
  color: var(--accent);
  font-size: 13px;
}

label {
  display: block;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--muted);
  text-align: left;
}

input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: #fff;
  -webkit-user-select: text;
  user-select: text;
}

button {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 13px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

.label {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.big {
  margin: 0;
  font-size: 64px;
  font-weight: 800;
  line-height: 1.1;
}

.board {
  list-style: none;
  margin: 8px 0 8px;
  padding: 0;
  text-align: left;
}

.board li {
  display: flex;
  gap: 10px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.board li.me {
  color: var(--accent);
  font-weight: 800;
}

.board .rank {
  width: 1.6em;
  color: var(--muted);
  text-align: right;
}

.board .who {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.legal {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.legal a {
  color: var(--muted);
}

/* Result panel needs 300px of inner width for the rectangle ad */
#over {
  width: min(340px, calc(100% - 24px));
  padding: 24px 16px 18px;
}

.ad-slot {
  width: 300px;
  max-width: 100%;
  height: 250px;
  margin: 12px auto 20px; /* keep clear of the buttons to avoid accidental taps */
}

.ad-placeholder {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border: 1.5px dashed #c9c3d4;
  border-radius: 8px;
  background: #f4f2f7;
  color: #9a96a6;
  font-size: 14px;
  line-height: 1.6;
}

.ad-label {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  background: #9a96a6;
  color: #fff;
  font-size: 11px;
}

.ad-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 16px;
  background: rgba(20, 20, 30, 0.88);
  color: #fff;
}

.ad-full {
  width: min(320px, 100%);
  height: min(480px, 60vh);
  font-size: 18px;
}

.ad-countdown {
  margin: 0;
  font-size: 15px;
}

.ad-close {
  width: auto;
  min-width: 160px;
  min-height: 48px; /* large, obvious close button: small or hidden ones count as accidental-click bait */
  margin: 0;
  background: #fff;
  color: var(--ink);
}

/* ---------- daily challenge, rankings, guide ---------- */

button.daily {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border-color: #c9a227;
  background: #fff8e1;
  color: #7a5a00;
}

button.daily small {
  font-size: 12px;
  font-weight: 500;
  color: #8f7a3d;
}

.text-btn {
  width: auto;
  margin: 10px auto 0;
  padding: 6px 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: underline;
}

.row {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.ranks {
  margin: 4px 0 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: #fff1f4;
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
}

#mode-tag {
  display: inline-block;
  margin-bottom: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fff8e1;
  color: #7a5a00;
  font-size: 12px;
  font-weight: 800;
}

#guide-hint {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 28px);
  transform: translateX(-50%);
  width: min(340px, calc(100% - 32px));
  margin: 0;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(47, 49, 80, 0.88);
  color: #fff;
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
  pointer-events: none;
}

#guide-hint .gold {
  color: #ffc83d;
  font-weight: 800;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 22px;
}

.tabs {
  display: flex;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.tabs button {
  flex: 1;
  margin: 0;
  padding: 8px 4px;
  border: 0;
  border-radius: 0;
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
}

.tabs button[aria-selected='true'] {
  background: var(--accent);
  color: var(--accent-ink);
}

#ranking-period {
  margin: 8px 0 0;
}

#ranking-list {
  max-height: min(52vh, 420px);
  overflow-y: auto;
}

.board .empty {
  justify-content: center;
  color: var(--muted);
  border-bottom: 0;
}

/* My own rank, pinned under the scrolling leaderboard */
.me-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff1f4;
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
  text-align: left;
}

.me-row .rank {
  min-width: 1.6em;
  text-align: right;
}

.me-row .who {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.me-row .pts {
  font-variant-numeric: tabular-nums;
}

.me-row.none {
  justify-content: center;
  background: #f6f4f8;
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
}

/* ---------- perfect-landing callout ---------- */

.perfect {
  position: fixed;
  z-index: 5;
  transform: translate(-50%, -100%);
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  animation: perfect-life 1150ms ease-out forwards;
}

.perfect-word {
  display: inline-block;
  font-size: 42px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: 0.02em;
  background: linear-gradient(180deg, #ff7aa2 0%, #e23e6b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 2px #fff;
  paint-order: stroke fill;
  /* dark offset shadow instead of a white glow: stays readable on the pale background */
  filter: drop-shadow(0 4px 0 rgba(47, 49, 80, 0.55)) drop-shadow(0 0 2px rgba(47, 49, 80, 0.35));
  animation: perfect-pop 1150ms cubic-bezier(0.2, 0.9, 0.3, 1.2) forwards;
}

.perfect-sub {
  display: table;
  margin: 2px auto 0;
  padding: 2px 10px;
  border-radius: 999px;
  background: #2f3150;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
  animation: perfect-sub 1150ms ease-out forwards;
}

.tier-2 .perfect-word {
  font-size: 46px;
  background-image: linear-gradient(180deg, #ffb340 0%, #ff6a1f 100%);
}

.tier-3 .perfect-word {
  font-size: 50px;
  background-image: linear-gradient(180deg, #ffe066 0%, #ffb800 50%, #e08600 100%);
}

.tier-4 .perfect-word,
.tier-5 .perfect-word,
.tier-6 .perfect-word {
  font-size: 54px;
  background-image: linear-gradient(90deg, #ff3d6e, #ff9f1c, #ffd60a, #2ec27e, #3a86ff, #9b5de5, #ff3d6e);
  background-size: 300% 100%;
  animation:
    perfect-pop 1150ms cubic-bezier(0.2, 0.9, 0.3, 1.2) forwards,
    perfect-rainbow 900ms linear infinite;
}

.tier-6 .perfect-word {
  font-size: 60px;
}

.spark {
  position: absolute;
  left: 50%;
  top: 45%;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: #ffc83d;
  color: #ffc83d;
  font-size: 16px;
  line-height: 8px;
  text-align: center;
  opacity: 0;
  animation: spark 700ms ease-out var(--delay, 0ms) forwards;
}

.spark:nth-child(3n) {
  background: transparent; /* the ★ ones */
  color: #ffb800;
  font-size: 20px;
  text-shadow: 0 1px 0 rgba(47, 49, 80, 0.45);
}

.spark:nth-child(3n + 1) {
  background: #ff5c8a;
}

.spark:nth-child(3n + 2) {
  background: #fff;
  box-shadow: 0 0 6px #ffc83d;
}

@keyframes perfect-life {
  0%,
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, calc(-100% - 36px));
  }
}

@keyframes perfect-pop {
  0% {
    transform: scale(0.2) rotate(-14deg);
  }
  16% {
    transform: scale(1.3) rotate(5deg);
  }
  30% {
    transform: scale(0.92) rotate(-2deg);
  }
  44% {
    transform: scale(1.06) rotate(0deg);
  }
  56%,
  100% {
    transform: scale(1);
  }
}

@keyframes perfect-sub {
  0%,
  15% {
    opacity: 0;
    transform: translateY(8px);
  }
  30%,
  100% {
    opacity: 1;
    transform: none;
  }
}

@keyframes perfect-rainbow {
  to {
    background-position: 300% 0;
  }
}

@keyframes spark {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1.4);
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.2);
  }
}

@media (prefers-reduced-motion: reduce) {
  .perfect,
  .perfect-word,
  .perfect-sub {
    animation: perfect-fade 1000ms ease-out forwards;
  }
  @keyframes perfect-fade {
    0%,
    70% {
      opacity: 1;
    }
    100% {
      opacity: 0;
    }
  }
}

/* Platforms cleared on the result screen; highlighted when it's a new personal record */
.platforms-line {
  margin: 2px 0 0;
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
}

.platforms-line.record {
  display: inline-block;
  padding: 2px 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #fff1c2, #ffe08a);
  color: #7a5a00;
  animation: record-pop 600ms ease-out 500ms;
}

/* Size only: if the animation ever stalls, the badge is still fully readable */
@keyframes record-pop {
  0% {
    transform: scale(0.85);
  }
  60% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .platforms-line.record {
    animation: none;
  }
}

/* Special-platform bonus callouts */
.bonus .perfect-word {
  font-size: 40px;
}

.bonus-taiko .perfect-word {
  font-size: 56px;
  background-image: linear-gradient(180deg, #ff6b4a 0%, #c81e1e 100%);
}

.bonus-matcha .perfect-word {
  font-size: 34px;
  background-image: linear-gradient(180deg, #a6d36a 0%, #4f8a2b 100%);
}

/* ---------- characters ---------- */

.char-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 8px;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
}

.char-btn img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #f6f1fb;
}

.char-btn span:nth-of-type(1) {
  flex: 1;
}

.char-btn .chev {
  color: var(--muted);
  font-size: 20px;
}

.char-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.char-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: 0;
  padding: 10px 6px;
  border-radius: 16px;
  font-weight: 800;
}

.char-card img {
  width: 80px;
  height: 80px;
}

.char-card.selected {
  border-color: var(--accent);
  background: #fff1f4;
}

.char-card.locked img {
  filter: grayscale(1) brightness(0.35);
  opacity: 0.7;
}

.char-card:disabled {
  opacity: 1;
  cursor: default;
}

.char-name {
  font-size: 15px;
}

.char-status {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.char-card.selected .char-status {
  color: var(--accent);
  font-weight: 800;
}

.unlock {
  margin: 8px 0 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: linear-gradient(90deg, #f3e8ff, #ffe8f1);
  color: #6b2fd6;
  font-size: 13px;
  font-weight: 800;
}

/* ---------- sharing outside LINE ---------- */

.image-btn {
  border-color: #c9b8f5;
  background: #f6f1ff;
  color: #5b2fc4;
}

.share-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  background: rgba(20, 20, 30, 0.88);
  color: #fff;
  text-align: center;
}

.share-overlay img {
  max-width: 100%;
  max-height: 62vh;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  -webkit-touch-callout: default; /* allow long-press to save, which the game otherwise blocks */
  -webkit-user-select: auto;
  user-select: auto;
}

.share-overlay p {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
}

.share-actions {
  display: flex;
  gap: 10px;
  width: min(340px, 100%);
}

.share-overlay .btn {
  flex: 1;
  display: block;
  margin: 0;
  padding: 12px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.share-overlay .btn.x {
  background: #000;
  color: #fff;
  border: 1.5px solid #fff;
}

.share-overlay .btn.ghost {
  flex: none;
  width: min(340px, 100%);
  background: transparent;
  color: #fff;
  border: 1.5px solid rgba(255, 255, 255, 0.6);
}

/* Offer to add the official account for "record beaten" notifications */
.notify {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 0;
  padding: 8px 8px 8px 12px;
  border-radius: 12px;
  background: #eafaf0;
  color: #1e7a3c;
  font-size: 13px;
  font-weight: 800;
  text-align: left;
}

.notify span {
  flex: 1;
}

.notify button {
  width: auto;
  margin: 0;
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: #06c755; /* LINE green */
  color: #fff;
  font-size: 13px;
}
