:root {
  color-scheme: light;
  --design-w: 720;
  --design-h: 1280;
  --ink: #17120f;
  --paper: #fffaf2;
  --cream: #f9f0dd;
  --sun: #ffd563;
  --orange: #ff9f3f;
  --teal: #2eb7ad;
  --rose: #f05d5e;
  --violet: #7057d2;
  --green: #6bbf59;
  --shadow: rgba(23, 18, 15, 0.24);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: #050505;
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", ui-rounded, system-ui, sans-serif;
  letter-spacing: 0;
  touch-action: none;
  user-select: none;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.app {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-width: 0;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  display: grid;
  place-items: center;
  background: #050505;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.stage-shell {
  position: relative;
  width: 56.25vh;
  height: 100vh;
  max-width: 100vw;
  max-height: 177.7778vw;
  width: min(100vw, calc(100vh * 9 / 16));
  height: min(100vh, calc(100vw * 16 / 9));
  width: min(100vw, calc(100dvh * 9 / 16));
  height: min(100dvh, calc(100vw * 16 / 9));
  max-width: 720px;
  max-height: 1280px;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 0 0 9999px #050505;
  transform: translateZ(0);
}

.fx-canvas,
.screen {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
}

.boot-guard {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2147483647;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #fffaf2;
  color: #17120f;
  font-size: 20px;
  font-weight: 800;
  text-align: center;
}

.boot-guard.is-hidden {
  display: none;
}

.fx-canvas {
  z-index: 2;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.screen {
  z-index: 1;
  display: flex;
  flex-direction: column;
  padding: 42px 38px;
  background: var(--paper);
}

.screen.is-hidden {
  display: none;
}

.loading-screen {
  z-index: 10;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background:
    linear-gradient(90deg, rgba(23, 18, 15, 0.06) 1px, transparent 1px) 0 0 / 34px 34px,
    linear-gradient(0deg, rgba(23, 18, 15, 0.06) 1px, transparent 1px) 0 0 / 34px 34px,
    #fff7e8;
}

.loading-screen h1,
.game-title {
  margin: 0;
  color: transparent;
  background: linear-gradient(90deg, #f05d5e 0%, #ff9f3f 33%, #ffd563 58%, #2eb7ad 100%);
  background-clip: text;
  -webkit-background-clip: text;
  font-size: clamp(54px, 13vw, 118px);
  font-weight: 950;
  line-height: 0.95;
  text-align: center;
  text-shadow:
    4px 4px 0 rgba(23, 18, 15, 0.88),
    10px 12px 0 rgba(23, 18, 15, 0.12);
  transform: rotate(-3deg);
}

.loading-screen p,
.menu-status,
.panel-copy {
  margin: 0;
  color: rgba(23, 18, 15, 0.7);
  font-size: clamp(15px, 2.9vw, 22px);
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
}

.menu-screen {
  justify-content: space-between;
  background:
    radial-gradient(circle at 16% 22%, rgba(255, 213, 99, 0.38), transparent 20%),
    radial-gradient(circle at 84% 72%, rgba(46, 183, 173, 0.26), transparent 24%),
    linear-gradient(180deg, #fffaf2 0%, #f5efe1 100%);
}

.menu-top {
  display: grid;
  gap: 24px;
  padding-top: 32px;
}

.menu-cats {
  position: relative;
  min-height: 360px;
}

.menu-cats img {
  position: absolute;
  bottom: 4px;
  width: 47%;
  max-width: 310px;
  filter: drop-shadow(0 18px 0 rgba(23, 18, 15, 0.12));
}

.menu-cats img:first-child {
  left: 3%;
  transform: rotate(-4deg);
}

.menu-cats img:last-child {
  right: 2%;
  transform: rotate(-4deg);
}

.menu-cats img.is-flipped:first-child {
  transform: scaleX(-1) rotate(-4deg);
}

.menu-cats img.is-flipped:last-child {
  transform: scaleX(-1) rotate(-4deg);
}

.main-menu,
.result-actions {
  display: grid;
  gap: 18px;
}

.big-button,
.small-button,
.back-button,
.action-button,
.rank-tabs button {
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  box-shadow: 7px 8px 0 var(--shadow);
  color: var(--ink);
  font-weight: 950;
  transition:
    transform 100ms ease,
    box-shadow 100ms ease,
    filter 120ms ease;
}

.big-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 92px;
  padding: 0 28px;
  text-align: left;
}

.big-button span {
  color: rgba(23, 18, 15, 0.62);
  font-size: clamp(18px, 3.5vw, 26px);
}

.big-button strong {
  font-size: clamp(30px, 6.7vw, 52px);
  line-height: 1;
}

.big-button.is-primary {
  background: var(--sun);
}

.big-button:active,
.small-button:active,
.back-button:active,
.action-button:active,
.rank-tabs button:active {
  box-shadow: 2px 3px 0 rgba(23, 18, 15, 0.82);
  transform: translate(5px, 5px);
}

.menu-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.small-button {
  min-height: 58px;
  padding: 0 16px;
  background: #fff;
  font-size: clamp(15px, 3vw, 20px);
}

.battle-screen {
  padding: 28px 28px 30px;
  background: #fff;
}

.battle-screen.has-custom-bg {
  background-position: center;
  background-size: cover;
}

.battle-hud {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  z-index: 3;
  margin-top: 64px;
}

.fighter-card {
  min-width: 0;
  padding: 12px;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.94);
  box-shadow: 5px 6px 0 rgba(23, 18, 15, 0.12);
}

.fighter-card span,
.fighter-card em {
  display: block;
  overflow: hidden;
  font-style: normal;
  font-weight: 900;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fighter-card span {
  font-size: clamp(13px, 2.8vw, 18px);
}

.fighter-card strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(20px, 4.8vw, 34px);
  line-height: 1;
}

.fighter-card em {
  margin-top: 5px;
  color: var(--violet);
  font-size: clamp(12px, 2.6vw, 17px);
}

.bar {
  height: 18px;
  margin-top: 9px;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #ffe3e3;
}

.bar i {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--green), #b8ec69);
  transform-origin: left center;
  transition: transform 150ms ease;
}

.fighter-card.is-enemy .bar i {
  background: linear-gradient(90deg, var(--rose), #ff9f3f);
}

.battle-field {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 16px 0 10px;
}

.cat-sprite {
  --flip: 1;
  --hit-x: 0px;
  --act-y: 0px;
  --tilt: 0deg;
  position: absolute;
  top: 38%;
  width: min(42%, 300px);
  transform-origin: 50% 88%;
  transform: scaleX(var(--flip)) translateX(var(--hit-x)) translateY(var(--act-y)) rotate(var(--tilt));
  filter: drop-shadow(0 22px 0 rgba(23, 18, 15, 0.12));
  transition:
    opacity 850ms ease,
    transform 170ms ease;
  will-change: transform, opacity;
}

.cat-sprite.is-player {
  left: 4%;
}

.cat-sprite.is-enemy {
  right: 4%;
}

.cat-sprite.is-hit.is-player {
  --hit-x: -18px;
  --tilt: -4deg;
}

.cat-sprite.is-hit.is-enemy {
  --hit-x: 18px;
  --tilt: 4deg;
}

.cat-sprite.is-acting.is-player {
  --act-y: -10px;
  --tilt: -2deg;
}

.cat-sprite.is-acting.is-enemy {
  --act-y: -10px;
  --tilt: 2deg;
}

.cat-sprite.is-flipped {
  --flip: -1;
}

.cat-sprite.is-defeated {
  opacity: 0;
}

.battle-log {
  z-index: 3;
  min-height: 44px;
  margin: 0 0 12px;
  color: var(--ink);
  font-size: clamp(16px, 3.5vw, 24px);
  font-weight: 900;
  line-height: 1.25;
  text-align: center;
}

.cooldown-ring {
  position: absolute;
  right: 32px;
  bottom: 214px;
  z-index: 4;
  width: 46px;
  height: 46px;
  border: 4px solid rgba(23, 18, 15, 0.18);
  border-top-color: var(--violet);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}

.cooldown-ring.is-active {
  opacity: 1;
  animation: spin 0.9s linear infinite;
}

.action-panel {
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
}

.action-button {
  display: grid;
  min-height: 86px;
  align-content: center;
  gap: 5px;
  padding: 8px 10px;
  background: var(--cream);
}

.action-button:nth-child(1) {
  background: #dff8f2;
}

.action-button:nth-child(2) {
  background: #ffe7ca;
}

.action-button:nth-child(3) {
  background: #fff0a8;
}

.action-button:nth-child(4) {
  background: #dff2ff;
}

.action-button span {
  font-size: clamp(17px, 3.6vw, 25px);
  line-height: 1.05;
}

.action-button em {
  color: rgba(23, 18, 15, 0.58);
  font-size: clamp(12px, 2.4vw, 16px);
  font-style: normal;
}

.action-button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.45);
  opacity: 0.58;
}

.back-button {
  position: absolute;
  top: max(24px, env(safe-area-inset-top));
  left: max(24px, env(safe-area-inset-left));
  z-index: 5;
  min-width: 92px;
  min-height: 48px;
  background: #fff;
  font-size: 18px;
}

.battle-screen .back-button {
  min-width: 78px;
  min-height: 42px;
  border-width: 3px;
  box-shadow: 4px 5px 0 var(--shadow);
  font-size: 16px;
}

.panel-screen {
  z-index: 6;
  align-items: center;
  justify-content: flex-start;
  gap: 22px;
  overflow-y: auto;
  padding-top: 108px;
  background:
    linear-gradient(90deg, rgba(23, 18, 15, 0.055) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(0deg, rgba(23, 18, 15, 0.055) 1px, transparent 1px) 0 0 / 32px 32px,
    #fffaf2;
  touch-action: pan-y;
}

.panel-screen h2,
.result-screen h2 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(36px, 8vw, 62px);
  font-weight: 950;
  line-height: 1;
  text-align: center;
}

.cat-select-grid,
.unlock-grid {
  display: grid;
  width: 100%;
  gap: 16px;
}

.select-card,
.unlock-card {
  display: grid;
  min-height: 150px;
  gap: 8px;
  align-items: center;
  padding: 16px;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  box-shadow: 6px 7px 0 var(--shadow);
  text-align: center;
}

.select-card {
  grid-template-columns: 110px 1fr;
  text-align: left;
}

.select-card img {
  width: 110px;
  height: 110px;
  object-fit: contain;
}

.select-card strong,
.unlock-card strong {
  display: block;
  font-size: clamp(24px, 5vw, 34px);
  font-weight: 950;
}

.select-card span,
.unlock-card span {
  display: block;
  margin-top: 6px;
  color: rgba(23, 18, 15, 0.62);
  font-size: clamp(15px, 3vw, 20px);
  font-weight: 850;
}

.select-card.is-selected {
  background: var(--sun);
}

.select-card.is-locked {
  filter: grayscale(0.45);
  opacity: 0.72;
}

.range-row {
  display: grid;
  width: 100%;
  gap: 14px;
  padding: 18px;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  box-shadow: 6px 7px 0 var(--shadow);
}

.range-row span {
  font-size: clamp(20px, 4vw, 28px);
  font-weight: 950;
}

.range-row input {
  width: 100%;
  accent-color: var(--teal);
}

.rank-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: 100%;
  gap: 8px;
}

.target-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  gap: 10px;
}

.target-tabs button {
  min-height: 54px;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  box-shadow: 5px 6px 0 var(--shadow);
  color: var(--ink);
  font-size: clamp(16px, 3.2vw, 22px);
  font-weight: 950;
}

.target-tabs button.is-active {
  background: var(--sun);
}

.rank-tabs button {
  min-height: 50px;
  font-size: clamp(13px, 2.6vw, 18px);
}

.rank-tabs button.is-active {
  background: var(--sun);
}

.rank-list {
  display: grid;
  width: 100%;
  gap: 10px;
  margin: 0;
  padding: 0 0 24px;
  list-style: none;
}

.rank-list li {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 68px;
  padding: 10px 14px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  box-shadow: 4px 5px 0 rgba(23, 18, 15, 0.14);
  font-weight: 900;
}

.rank-list .empty-rank {
  grid-template-columns: 1fr;
  text-align: center;
}

.rank-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-score {
  color: var(--violet);
  font-size: 24px;
}

.unlock-card .small-button {
  margin-top: 8px;
  background: var(--sun);
}

.result-screen {
  z-index: 7;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 213, 99, 0.38), transparent 24%),
    #fffaf2;
  text-align: center;
}

.result-screen p {
  margin: 0;
  color: rgba(23, 18, 15, 0.72);
  font-size: clamp(20px, 4vw, 30px);
  font-weight: 900;
}

.result-actions {
  width: 100%;
  margin-top: 12px;
}

.damage-pop {
  position: absolute;
  z-index: 8;
  color: var(--rose);
  font-size: clamp(22px, 5vw, 36px);
  font-weight: 950;
  pointer-events: none;
  text-shadow: 2px 2px 0 #fff;
  animation: floatPop 680ms ease-out forwards;
}

.damage-pop.is-interrupt {
  color: #c00000;
  font-size: clamp(32px, 7vw, 54px);
  text-shadow:
    3px 3px 0 #fff,
    0 0 14px rgba(192, 0, 0, 0.24);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes floatPop {
  from {
    opacity: 0;
    transform: translate(-50%, 12px) scale(0.92);
  }
  20% {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translate(-50%, -52px) scale(1.08);
  }
}

@media (pointer: fine) and (hover: hover) {
  .big-button:hover,
  .small-button:hover,
  .back-button:hover,
  .action-button:hover:not(:disabled),
  .rank-tabs button:hover {
    filter: brightness(1.04);
  }
}

@media (max-height: 720px) {
  .menu-cats {
    min-height: 260px;
  }

  .action-button {
    min-height: 72px;
  }
}

/* Compact phone menu: the embedded Toy viewport is often shorter than the
   device screen because of the app header and bottom action bar. */
@media (max-width: 767px) {
  .menu-screen {
    padding: 20px 18px 16px;
    overflow-y: auto;
    touch-action: pan-y;
  }

  .menu-top {
    gap: 8px;
    padding-top: 0;
  }

  .menu-cats {
    min-height: clamp(150px, 25dvh, 220px);
  }

  .menu-cats img {
    width: 45%;
  }

  .main-menu {
    gap: 10px;
  }

  .big-button {
    min-height: 68px;
    padding: 0 16px;
  }

  .big-button span {
    font-size: clamp(16px, 3.8vw, 22px);
  }

  .big-button strong {
    font-size: clamp(27px, 7vw, 40px);
  }

  .menu-footer {
    gap: 8px;
  }

  .small-button {
    min-height: 48px;
    padding: 0 8px;
    font-size: clamp(13px, 3vw, 17px);
  }
}

@media (max-width: 767px) and (max-height: 760px) {
  .menu-screen {
    justify-content: flex-start;
    gap: 8px;
    padding: 12px 14px;
  }

  .game-title {
    font-size: 48px;
  }

  .menu-status {
    font-size: 14px;
  }

  .menu-cats {
    flex: 1 1 110px;
    min-height: 110px;
    max-height: 150px;
  }

  .main-menu {
    flex: 0 0 auto;
    gap: 6px;
  }

  .big-button {
    height: 58px;
    min-height: 58px;
    max-height: 58px;
  }

  .menu-footer {
    flex: 0 0 44px;
  }

  .small-button {
    height: 44px;
    min-height: 44px;
    max-height: 44px;
  }
}

/* Tablet and desktop: use the available landscape space instead of leaving a
   fixed portrait canvas surrounded by black bars. */
@media (min-width: 768px) and (min-height: 560px) {
  .stage-shell {
    width: min(calc(100vw - 32px), 1120px);
    height: min(calc(100dvh - 32px), 760px);
    aspect-ratio: auto;
  }

  .screen {
    padding: 32px 48px;
  }

  .menu-screen {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    column-gap: 48px;
    align-items: center;
  }

  .menu-top {
    grid-column: 1 / -1;
    padding-top: 0;
  }

  .menu-cats {
    min-height: 0;
    height: 100%;
  }

  .menu-cats img {
    width: 48%;
    max-width: 360px;
  }

  .main-menu {
    align-self: center;
  }

  .menu-footer {
    grid-column: 1 / -1;
  }

  .battle-screen {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    column-gap: 24px;
  }

  .battle-hud {
    grid-column: 1 / -1;
    margin-top: 32px;
  }

  .battle-field {
    grid-column: 1;
    grid-row: 2;
    margin: 16px 0 10px;
  }

  .battle-log {
    grid-column: 1;
    grid-row: 3;
    margin-bottom: 0;
  }

  .action-panel {
    grid-column: 2;
    grid-row: 2 / 4;
    align-self: end;
    padding-bottom: 0;
  }

  .cooldown-ring {
    right: 344px;
    bottom: 32px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
