:root {
  --ink: #332943;
  --cream: #fff9ed;
  --pink: #ff6f91;
  --purple: #6656c7;
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html, body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  background: #f8dfc2;
  color: var(--ink);
  font-family: ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100svh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 12% 12%, #fff7d1 0 4%, transparent 4.2%),
    radial-gradient(circle at 86% 78%, #efb8c9 0 6%, transparent 6.2%),
    linear-gradient(145deg, #f9e4c8, #edc9bf);
}

.game-shell { width: min(100vw, 640px); padding: 12px; }

.hud {
  height: 76px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 9px;
  align-items: center;
}

.brand { font-size: clamp(20px, 5vw, 27px); font-weight: 900; letter-spacing: -1px; }
.brand-mark { font-size: .85em; margin-right: 3px; }

.score-card, .next-card {
  height: 61px;
  border: 2px solid rgba(51, 41, 67, .12);
  border-radius: 18px;
  background: rgba(255,255,255,.72);
  box-shadow: 0 5px 0 rgba(92, 63, 75, .1);
}

.score-card { min-width: 86px; padding: 8px 15px; display: flex; flex-direction: column; }
.score-card span, .next-card span { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; opacity: .65; }
.score-card strong { font-size: 25px; line-height: 28px; }
.next-card { width: 72px; position: relative; overflow: hidden; }
.next-card span { position: absolute; left: 7px; top: 5px; z-index: 1; }
#next-preview { width: 58px; height: 58px; display: block; margin: 5px auto 0; }

.meta-bar {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 3px 7px;
  font-size: 10px;
  font-weight: 850;
}

#daily-cat { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#round-status { padding: 3px 7px; border-radius: 8px; background: rgba(255,255,255,.6); white-space: nowrap; }
.small-button { padding: 5px 10px; border-radius: 9px; box-shadow: 0 3px 0 #c74264; font-size: 10px; }
.sound-button { padding-inline: 8px; background: var(--purple); box-shadow: 0 3px 0 #40358d; white-space: nowrap; }

.play-area {
  display: flex;
  align-items: stretch;
  gap: 10px;
  height: min(76svh, 720px);
  min-height: 420px;
}

.game-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  border: 5px solid rgba(72, 53, 82, .88);
  border-top: 0;
  border-radius: 8px 8px 30px 30px;
  background:
    linear-gradient(rgba(255,255,255,.14) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.14) 1px, transparent 1px),
    linear-gradient(#9bd8d2, #6ebcb9);
  background-size: 28px 28px, 28px 28px, auto;
  box-shadow: inset 0 -18px 35px rgba(23, 94, 100, .17), 0 12px 30px rgba(80, 50, 57, .18);
}

.cat-scale {
  flex: 0 0 112px;
  display: flex;
  flex-direction: column;
  padding: 9px 7px 8px;
  overflow: hidden;
  border: 2px solid rgba(51, 41, 67, .12);
  border-radius: 20px;
  background: rgba(255,255,255,.64);
  box-shadow: 0 7px 0 rgba(92, 63, 75, .1);
}

.cat-scale h2 {
  margin: 0 0 5px;
  text-align: center;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: .65;
}

.cat-scale-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  min-height: 0;
}

.scale-cat {
  position: relative;
  display: grid;
  grid-template-columns: 40px 1fr;
  align-items: center;
  gap: 4px;
  min-height: 0;
  color: rgba(51, 41, 67, .72);
  font-size: 9px;
  font-weight: 850;
  line-height: 1;
}

.scale-cat::after {
  content: "";
  position: absolute;
  left: 19px;
  bottom: -50%;
  width: 2px;
  height: 55%;
  z-index: 0;
  background: rgba(51, 41, 67, .14);
}

.scale-cat:last-child::after { display: none; }

.scale-portrait {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: var(--portrait-size);
  height: var(--portrait-size);
  margin: auto;
}

.scale-sprite {
  display: block;
  width: 140%;
  height: 140%;
  max-width: none;
  object-fit: contain;
}

.scale-sprite-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 2px solid var(--face-accent);
  border-radius: 50%;
  background: var(--face-color);
  font-size: 7px;
  color: rgba(51, 41, 67, .72);
  font-weight: 900;
  box-shadow: 0 2px 0 rgba(51, 41, 67, .15);
}

.scale-sprite-fallback[hidden] { display: none; }

.scale-cat.reached { color: var(--ink); }
.scale-cat.reached .scale-portrait { filter: drop-shadow(0 0 3px rgba(255,255,255,.95)); }

#game-canvas { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }

.danger-label {
  position: absolute;
  top: 119px;
  left: 9px;
  padding: 3px 7px;
  color: rgba(153, 41, 70, .8);
  background: rgba(255, 244, 229, .75);
  border-radius: 5px;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1px;
  pointer-events: none;
}

.start-hint {
  position: absolute;
  top: 165px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  padding: 8px 12px;
  border-radius: 12px;
  color: rgba(51, 41, 67, .7);
  background: rgba(255,255,255,.65);
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
  transition: opacity .3s;
}

.start-hint.gone { opacity: 0; }
.help { margin: 11px 0 0; text-align: center; font-size: 12px; font-weight: 700; opacity: .68; }

.event-banner, .celebration {
  position: absolute;
  left: 50%;
  z-index: 4;
  transform: translateX(-50%);
  pointer-events: none;
  text-align: center;
  font-weight: 1000;
  letter-spacing: 2px;
}

.event-banner {
  position: fixed;
  top: 12px;
  z-index: 8;
  padding: 7px 15px;
  border: 3px solid rgba(51,41,67,.72);
  border-radius: 13px;
  color: #fff;
  background: #ff657f;
  box-shadow: 0 4px 0 rgba(51,41,67,.25);
  animation: banner-bounce .45s ease-out;
}

.event-banner.laser { background: #cf304c; }
.event-banner.gold { color: #5b3a00; background: #ffd84d; border-color: #9d6900; }
.celebration {
  position: fixed;
  top: max(54px, calc(env(safe-area-inset-top) + 54px));
  width: min(430px, calc(100vw - 24px));
  color: #fff7aa;
  font-size: clamp(18px, 5vw, 31px);
  text-shadow: 0 3px 0 #5d3b96, 0 0 18px #fff;
  animation: divine-pop .7s ease-out;
}
.game-wrap.divine-glow { animation: divine-glow 1.1s ease-out; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(37, 27, 48, .62);
  backdrop-filter: blur(6px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.modal[hidden] { display: none; }
.modal-card {
  position: relative;
  width: min(360px, 100%);
  padding: 27px;
  text-align: center;
  border: 4px solid var(--ink);
  border-radius: 28px;
  background: var(--cream);
  box-shadow: 0 12px 0 rgba(36, 26, 48, .22);
  animation: pop-in .28s ease-out;
  max-height: calc(100svh - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.modal-cat { font-size: 61px; line-height: 1; }
.modal h1 { margin: 11px 0 3px; font-size: 32px; }
.modal p { margin: 0 0 18px; opacity: .7; }
.final-score { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 auto 18px; padding: 12px; border-radius: 14px; background: #f5e8d0; }
.final-score span + span { border-left: 2px solid rgba(51,41,67,.12); }
.final-score strong { display: block; color: var(--purple); font-size: 32px; }
button {
  border: 0;
  border-radius: 14px;
  padding: 13px 23px;
  color: white;
  background: var(--pink);
  box-shadow: 0 5px 0 #c74264;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}
button:active { transform: translateY(3px); box-shadow: 0 2px 0 #c74264; }

.close-button {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  box-shadow: none;
  font-size: 23px;
  line-height: 1;
}

.collection-card { width: min(560px, 100%); max-height: 88svh; overflow: auto; padding: 22px; }
.collection-card h1 { margin-top: 0; }
.collection-card h2 { margin: 20px 0 8px; font-size: 16px; }
.collection-grid, .mystery-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.catdex-item {
  min-height: 76px;
  padding: 7px 4px;
  display: grid;
  place-items: center;
  gap: 3px;
  border: 2px solid rgba(51,41,67,.12);
  border-radius: 13px;
  color: var(--ink);
  background: rgba(255,255,255,.68);
  box-shadow: 0 3px 0 rgba(51,41,67,.12);
  font-size: 9px;
}
.catdex-item.locked { filter: grayscale(1); opacity: .52; background: #d9d2d5; cursor: default; }
.catdex-face { display: grid; place-items: center; width: 36px; height: 36px; border: 2px solid var(--face-accent, #555); border-radius: 50%; background: var(--face-color, #777); font-size: 9px; font-weight: 900; }
.catdex-item.locked .catdex-face { color: #fff; background: #615b67; }
.catdex-sprite { display: block; width: 48px; height: 48px; object-fit: contain; }
.catdex-sprite-fallback { display: grid; place-items: center; width: 36px; height: 36px; border: 2px solid var(--face-accent); border-radius: 50%; background: var(--face-color); font-size: 9px; font-weight: 900; }
.catdex-sprite-fallback[hidden] { display: none; }
.detail-visual { display: grid; place-items: center; width: 94px; height: 94px; margin: 0 auto; }
.detail-face { width: 94px; height: 94px; object-fit: contain; }
.detail-fallback { place-items: center; width: 82px; height: 82px; border: 4px solid var(--face-accent); border-radius: 50%; background: var(--face-color); font-weight: 1000; }
.detail-fallback:not([hidden]) { display: grid; }
.detail-card blockquote { margin: 15px 0; padding: 11px; border-radius: 12px; background: #f5e8d0; font-weight: 900; }
.detail-description { margin-top: 12px !important; }
.instructions-card { width: min(470px, 100%); }
.instructions-copy { margin: 15px 0 20px; text-align: left; }
.instructions-copy p { margin: 10px 0; line-height: 1.35; }
.mode-card { width: min(430px, 100%); }
.mode-card h2 { margin: 18px 0 8px; font-size: 15px; }
.mode-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode-options button { padding-inline: 8px; }
.endless-button { width: 100%; background: var(--purple); box-shadow: 0 5px 0 #40358d; }
.mystery-requirement { display: block; padding: 0 4px; font-size: 7px; line-height: 1.15; }
.rescue-card { width: min(390px, 100%); }
.rescue-actions { display: grid; gap: 10px; }
.secondary-button {
  color: var(--ink);
  background: #f4dfbf;
  box-shadow: 0 5px 0 #d4b98e;
}

.achievement-splash {
  position: fixed;
  top: max(96px, calc(env(safe-area-inset-top) + 96px));
  left: 50%;
  z-index: 9;
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 24px));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0;
  pointer-events: none;
  background: transparent;
  animation: achievement-fade 1.7s ease both;
}
.achievement-splash[hidden] { display: none; }
.achievement-card {
  min-width: min(250px, 76vw);
  padding: 12px 16px;
  text-align: center;
  border: 3px solid var(--ink);
  border-radius: 18px;
  color: var(--ink);
  background: #fff9d9;
  box-shadow: 0 5px 0 rgba(51,41,67,.25), 0 0 20px #fff4a0;
  animation: achievement-pop .48s cubic-bezier(.2,1.5,.5,1);
}
.achievement-card span { display: block; font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: 1.5px; opacity: .65; }
.achievement-card strong { display: block; margin-top: 3px; color: var(--purple); font-size: clamp(22px, 6vw, 34px); }
.achievement-stars { color: #fff4a0; font-size: clamp(16px, 5vw, 28px); letter-spacing: 2px; text-shadow: 0 2px 0 #b57c20, 0 0 14px #fff; animation: stars-dance .55s ease-in-out infinite alternate; }

.launch-splash {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow: hidden;
  background: #f9e4c8;
}
.launch-splash[hidden] { display: none; }
.launch-card {
  position: relative;
  width: 100%;
  height: 100svh;
  overflow: hidden;
}
.splash-layer {
  position: absolute;
  display: block;
  max-width: none;
  user-select: none;
  pointer-events: none;
}
.splash-backdrop {
  left: 50%;
  top: 50%;
  z-index: 0;
  width: max(100vw, calc(100svh * 1.78));
  height: max(100svh, calc(100vw * .5625));
  object-fit: cover;
  object-position: center;
  transform: translate(-50%, -50%);
  animation: splash-backdrop-in 2s ease-out both;
}
.splash-logo {
  left: 50%;
  top: clamp(18px, 5svh, 44px);
  z-index: 5;
  width: min(378px, 61.2vw);
  transform: translate(-50%, -130%);
  filter: drop-shadow(0 8px 0 rgba(51,41,67,.18));
  animation: splash-slide-top .82s .95s cubic-bezier(.2,.9,.25,1) both;
}
.splash-tagline {
  left: 50%;
  top: 184px;
  z-index: 5;
  width: min(340px, 61vw);
  transform: translate(-50%, -160%);
  filter: drop-shadow(0 4px 0 rgba(51,41,67,.14));
  animation: splash-slide-tagline .8s 1.42s cubic-bezier(.2,.9,.25,1) both;
}
.splash-siamese {
  left: 50%;
  top: 45%;
  z-index: 4;
  width: min(230px, 42vw, 34svh);
  transform: translate(-50%, -180%) rotate(-9deg) scale(.9);
  filter: drop-shadow(0 10px 0 rgba(51,41,67,.18));
  animation: splash-siamese-drop .95s 1.88s cubic-bezier(.2,.9,.25,1) both, splash-float 2.6s 3s ease-in-out infinite alternate;
}
.splash-burst {
  left: 50%;
  bottom: -114px;
  z-index: 2;
  width: max(118vw, min(930px, 132svh));
  transform: translate(-50%, 115%) scale(.75) rotate(-12deg);
  filter: drop-shadow(0 8px 0 rgba(51,41,67,.12));
  animation: splash-rise-burst .86s .55s cubic-bezier(.2,.9,.25,1) both;
}
.splash-bucket {
  left: 50%;
  bottom: -12svh;
  z-index: 3;
  width: max(122vw, min(480px, 126svh));
  transform: translate(-50%, 115%);
  filter: drop-shadow(0 12px 0 rgba(51,41,67,.18));
  animation: splash-rise-bucket .86s .62s cubic-bezier(.2,.9,.25,1) both;
}
.play-button {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + clamp(82px, 11svh, 128px));
  z-index: 8;
  min-width: 170px;
  padding: 15px 34px;
  border-radius: 999px;
  font-size: clamp(22px, 7vw, 34px);
  text-transform: uppercase;
  letter-spacing: 1px;
  background: var(--purple);
  box-shadow: 0 7px 0 #40358d;
  transform: translateX(-50%) scale(.88);
  opacity: 0;
  animation: splash-play-in .55s 2.75s cubic-bezier(.18,1.5,.38,1) both;
}
.ploopy-logo {
  position: absolute;
  left: 20%;
  bottom: calc(env(safe-area-inset-bottom) + -13px);
  z-index: 8;
  width: min(350px, 158vw);
  max-height: 128px;
  object-fit: contain;
  opacity: .96;
  transform: translateX(-50%);
  filter:
    drop-shadow(0 0 7px rgba(255,255,255,.98))
    drop-shadow(0 0 18px rgba(255,245,199,.85))
    drop-shadow(0 4px 0 rgba(51,41,67,.22));
}

@keyframes banner-bounce { from { transform: translate(-50%, -20px) scale(.8); opacity: 0; } }
@keyframes divine-pop { from { transform: translate(-50%, 0) scale(.2) rotate(-5deg); opacity: 0; } }
@keyframes divine-glow { 25% { box-shadow: inset 0 0 80px #fff, 0 0 45px #e9c3ff; filter: brightness(1.7); } }
@keyframes achievement-pop { from { transform: scale(.25) rotate(-7deg); opacity: 0; } }
@keyframes achievement-fade { 80% { opacity: 1; } to { opacity: 0; } }
@keyframes stars-dance { to { transform: scale(1.12) rotate(2deg); } }
@keyframes splash-backdrop-in { from { opacity: 0; transform: translate(-50%, -50%) scale(1.06); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes splash-rise-bucket {
  from { transform: translate(-50%, 115%); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
@keyframes splash-rise-burst {
  from { transform: translate(-50%, 115%) scale(.82); opacity: 0; }
  to { transform: translate(-50%, 0) scale(1); opacity: 1; }
}
@keyframes splash-slide-top {
  from { transform: translate(-50%, -130%); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
@keyframes splash-slide-tagline {
  from { transform: translate(-50%, -160%); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
@keyframes splash-siamese-drop {
  from { transform: translate(-50%, -180%) rotate(-7deg) scale(.94); opacity: 0; }
  to { transform: translate(-50%, -50%) rotate(0) scale(1); opacity: 1; }
}
@keyframes splash-float { to { transform: translate(-50%, -54%) rotate(2deg) scale(1.02); } }
@keyframes splash-play-in { to { opacity: 1; transform: translateX(-50%) scale(1); } }

@keyframes pop-in { from { transform: scale(.82); opacity: 0; } }

@media (max-height: 650px) {
  .play-area { height: calc(100svh - 128px); min-height: 350px; }
  .hud { height: 65px; }
  .score-card, .next-card { transform: scale(.88); }
  .help { display: none; }

  /* Compact every dialog for 4-inch phones while retaining internal scrolling
     as a safety net for larger text/accessibility settings. */
  .modal { place-items: center; padding: 8px; }
  .modal-card {
    max-height: calc(100svh - 16px);
    padding: 15px 16px;
    border-width: 3px;
    border-radius: 20px;
    box-shadow: 0 6px 0 rgba(36, 26, 48, .22);
  }
  .modal-cat { font-size: 38px; }
  .instructions-card .modal-cat { display: none; }
  .modal h1 { margin: 4px 0 2px; font-size: 25px; }
  .modal p { margin-bottom: 10px; font-size: 13px; }
  .modal button:not(.close-button) { padding: 10px 16px; }
  .modal .close-button { padding: 0; }
  .instructions-copy { margin: 7px 0 11px; }
  .instructions-copy p { margin: 6px 0; line-height: 1.22; }
  .mode-card h2 { margin: 10px 0 6px; }
  .mode-options { gap: 5px; }
  .final-score { margin-bottom: 11px; padding: 8px; }
  .final-score strong { font-size: 25px; }
  .detail-visual, .detail-face { width: 68px; height: 68px; }
  .detail-card blockquote { margin: 8px 0; padding: 8px; }
  .detail-description { margin-top: 7px !important; }
  .collection-card { max-height: calc(100svh - 16px); }
}

@media (max-width: 560px) {
  .play-area { gap: 6px; }
  .cat-scale { flex-basis: 72px; padding-inline: 4px; }
  .scale-cat { grid-template-columns: 30px 1fr; gap: 2px; font-size: 8px; }
  .scale-cat::after { left: 13px; }
  .scale-portrait { transform: scale(.78); }
  .brand-mark { display: none; }
  .collection-grid, .mystery-grid { grid-template-columns: repeat(3, 1fr); }
  .collection-card { padding: 18px 12px; }
  .meta-bar { gap: 4px; font-size: 8px; }
  #daily-cat { max-width: 115px; }
  #achievement-rank { display: none; }
  #merged-stat { white-space: nowrap; }
  .sound-button { font-size: 0; }
  .sound-button::before { content: attr(data-icon); font-size: 10px; }
  .mode-options { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .splash-backdrop,
  .splash-logo,
  .splash-tagline,
  .splash-siamese,
  .splash-burst,
  .splash-bucket,
  .play-button {
    animation: none;
    opacity: 1;
  }
  .splash-backdrop { transform: translate(-50%, -50%); }
  .splash-logo,
  .splash-tagline,
  .splash-burst,
  .splash-bucket,
  .play-button { transform: translateX(-50%); }
  .splash-siamese { transform: translate(-50%, -50%); }
}
