:root {
  color-scheme: dark;
  --red-950: #190306;
  --red-900: #2b0509;
  --red-800: #4b080e;
  --red-700: #74121a;
  --gold-100: #fff5bd;
  --gold-300: #f9d568;
  --gold-500: #e8aa22;
  --gold-700: #9d5c08;
  --ink: #170b08;
  --cream: #fff6d9;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #100104;
  font-family: "STKaiti", "KaiTi", "Noto Serif SC", serif;
  touch-action: manipulation;
}

button {
  font: inherit;
}

.app-shell {
  position: relative;
  width: min(100vw, 520px);
  height: 100dvh;
  min-height: 620px;
  margin: 0 auto;
  overflow: hidden;
  background: var(--red-950);
  box-shadow: 0 0 60px #000;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  overflow: hidden;
}

.screen.is-active {
  display: flex;
}

.home-screen {
  align-items: center;
  flex-direction: column;
  padding: calc(var(--safe-top) + 50px) 28px calc(var(--safe-bottom) + 24px);
  background:
    linear-gradient(180deg, rgb(0 0 0 / 20%), rgb(19 1 3 / 72%)),
    url("./assets/backgrounds/altar.png") center / cover;
  isolation: isolate;
}

.home-screen::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(circle at 50% 50%, transparent 0 30%, rgb(5 0 1 / 60%) 78%);
  content: "";
}

.home-glow {
  position: absolute;
  top: 19%;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(255 216 92 / 34%), transparent 68%);
  filter: blur(8px);
  animation: breathe 2.8s ease-in-out infinite;
}

.brand {
  z-index: 1;
  margin-top: 5vh;
  text-align: center;
  text-shadow: 0 4px 2px #250000, 0 0 26px #b83b16;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold-300);
  font-family: system-ui, sans-serif;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

.brand h1 {
  margin: 0;
  color: var(--cream);
  font-size: clamp(66px, 20vw, 104px);
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 0.82;
}

.brand h1 span {
  color: var(--gold-300);
}

.tagline {
  margin: 22px 0 0;
  color: #fff5de;
  font-size: 17px;
  letter-spacing: 0.12em;
}

.primary-button,
.secondary-button {
  min-height: 52px;
  border-radius: 999px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.primary-button {
  width: min(100%, 340px);
  border: 1px solid #fff0a6;
  color: #3b1600;
  background: linear-gradient(180deg, #fff3a2, #efb92e 52%, #c37a0d);
  box-shadow: inset 0 2px 0 rgb(255 255 255 / 66%), 0 8px 25px rgb(0 0 0 / 42%), 0 0 22px rgb(231 165 27 / 30%);
  font-size: 19px;
}

.primary-button:active:not(:disabled) {
  transform: translateY(2px) scale(0.985);
}

.primary-button:disabled {
  opacity: 0.45;
  filter: grayscale(0.5);
}

.home-note,
.result-note {
  margin: 14px 0 0;
  color: rgb(255 242 215 / 58%);
  font-family: system-ui, sans-serif;
  font-size: 11px;
}

.home-screen > .primary-button {
  margin-top: auto;
}

.select-screen {
  flex-direction: column;
  padding: calc(var(--safe-top) + 18px) 18px calc(var(--safe-bottom) + 18px);
  background:
    radial-gradient(circle at 50% 0, rgb(170 54 30 / 34%), transparent 42%),
    linear-gradient(160deg, #31070c, #160205 75%);
}

.screen-header,
.game-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.screen-header h2 {
  margin: 0;
  color: var(--cream);
  font-size: 25px;
}

.screen-header .eyebrow {
  margin-bottom: 2px;
}

.icon-button,
.game-sound {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid rgb(248 210 104 / 36%);
  border-radius: 50%;
  place-items: center;
  color: var(--gold-100);
  background: rgb(20 0 3 / 38%);
  font-family: system-ui, sans-serif;
  font-size: 26px;
}

.sound-toggle.is-muted {
  color: #9d8a7a;
}

.select-hint {
  margin: 15px 0 14px;
  color: rgb(255 245 218 / 68%);
  font-size: 14px;
  text-align: center;
}

.target-grid {
  display: grid;
  width: min(100%, 360px);
  min-height: 0;
  flex: 1;
  align-self: center;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: clamp(130px, 18vh, 160px);
  gap: 8px;
  overflow-y: auto;
  padding: 2px 2px 112px;
  scrollbar-width: none;
}

.target-grid::-webkit-scrollbar {
  display: none;
}

.target-card {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgb(240 193 77 / 25%);
  border-radius: 18px;
  color: #fff6db;
  background: #2a0709;
  box-shadow: 0 8px 20px rgb(0 0 0 / 25%);
  transition: transform 160ms ease, border-color 160ms ease, filter 160ms ease;
}

.target-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.78) brightness(0.72);
  pointer-events: none;
}

.target-card::after {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, transparent 52%, rgb(25 0 4 / 88%));
  content: "";
}

.target-card span {
  position: absolute;
  right: 10px;
  bottom: 10px;
  left: 10px;
  z-index: 1;
  font-size: 15px;
  font-weight: 900;
  text-shadow: 0 2px 4px #000;
}

.target-card.is-selected {
  border-color: var(--gold-300);
  box-shadow: 0 0 0 2px rgb(244 202 79 / 22%), 0 10px 24px rgb(0 0 0 / 34%);
  transform: translateY(-3px) scale(1.015);
}

.target-card.is-selected img {
  filter: saturate(1.08) brightness(0.95);
}

.target-card.is-selected::before {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: grid;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  place-items: center;
  color: #492000;
  background: var(--gold-300);
  content: "✓";
  font-family: system-ui, sans-serif;
  font-weight: 900;
}

.select-footer {
  position: absolute;
  right: 18px;
  bottom: calc(var(--safe-bottom) + 18px);
  left: 18px;
  z-index: 4;
  padding-top: 40px;
  background: linear-gradient(180deg, transparent, #180204 38%);
}

.selected-copy {
  margin: 0 0 10px;
  color: var(--gold-100);
  font-size: 14px;
  text-align: center;
}

.select-footer .primary-button {
  width: 100%;
}

.game-screen {
  background: #180205;
  user-select: none;
}

.game-background,
.game-vignette {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.game-background {
  object-fit: cover;
}

.game-vignette {
  background: linear-gradient(180deg, rgb(0 0 0 / 62%), transparent 25%, transparent 69%, rgb(10 0 2 / 45%));
}

.game-hud {
  position: absolute;
  top: calc(var(--safe-top) + 18px);
  right: 16px;
  left: 16px;
  z-index: 5;
  align-items: flex-start;
}

.hud-block {
  display: grid;
  width: 74px;
  color: var(--cream);
  line-height: 1;
}

.hud-block span,
.hud-block small,
.target-chip span {
  color: rgb(255 244 217 / 70%);
  font-family: system-ui, sans-serif;
  font-size: 10px;
}

.hud-block strong {
  margin-top: 2px;
  color: #fff9dc;
  font-family: system-ui, sans-serif;
  font-size: 35px;
  font-variant-numeric: tabular-nums;
}

.hud-block small {
  justify-self: end;
  margin-top: -11px;
}

.align-right {
  text-align: right;
}

.target-chip {
  max-width: 180px;
  padding: 7px 15px;
  border: 1px solid rgb(246 209 105 / 38%);
  border-radius: 999px;
  text-align: center;
  background: rgb(39 2 7 / 70%);
  backdrop-filter: blur(8px);
}

.target-chip span {
  display: block;
}

.target-chip strong {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: var(--gold-100);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.time-track {
  position: absolute;
  top: calc(var(--safe-top) + 92px);
  right: 24px;
  left: 24px;
  z-index: 5;
  height: 3px;
  overflow: hidden;
  border-radius: 3px;
  background: rgb(255 255 255 / 22%);
}

.time-track span {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #d48912, #fff09c);
  transform-origin: left;
}

.game-sound {
  position: absolute;
  top: calc(var(--safe-top) + 108px);
  left: 16px;
  z-index: 6;
  width: 36px;
  height: 36px;
  font-size: 20px;
}

.playfield {
  position: absolute;
  inset: 16% 0 8%;
  z-index: 2;
  cursor: pointer;
}

.character-image {
  position: absolute;
  bottom: 3%;
  left: 50%;
  width: min(99%, 470px);
  max-width: none;
  transform: translateX(-50%);
  transform-origin: 50% 78%;
  clip-path: inset(0 0 4% 0);
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.character-image.is-striking {
  animation: strike 120ms ease-out;
}

.hit-effects {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.hit-particle {
  position: absolute;
  z-index: 8;
  color: #fff1a2;
  font-size: 28px;
  font-weight: 900;
  text-shadow: 0 0 8px #ff9d00, 0 2px 3px #4b0b00;
  animation: particle 650ms ease-out forwards;
}

.combo-label {
  position: absolute;
  top: 18%;
  left: 50%;
  z-index: 6;
  color: #fff2a3;
  font-family: system-ui, sans-serif;
  font-size: 18px;
  font-weight: 900;
  opacity: 0;
  text-shadow: 0 2px 10px #bb2b00;
  transform: translateX(-50%) scale(0.8);
  transition: 120ms ease;
}

.combo-label.is-visible {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.hit-button {
  position: absolute;
  top: 72%;
  left: calc(50% - 58px);
  z-index: 8;
  display: grid;
  width: 116px;
  height: 116px;
  border: 5px solid #fff1a0;
  border-radius: 50%;
  place-content: center;
  color: #4e1600;
  background: radial-gradient(circle at 38% 28%, #fff7a0, #f5bd27 42%, #bd6506 76%);
  box-shadow: inset 0 -10px 16px rgb(108 41 0 / 25%), 0 8px 0 #7b3400, 0 13px 24px rgb(0 0 0 / 52%), 0 0 34px rgb(255 189 41 / 44%);
  transition: top 1.65s ease-in-out, left 1.65s ease-in-out;
  touch-action: manipulation;
  will-change: top, left, transform;
}

.hit-button span {
  font-size: 33px;
  font-weight: 900;
  line-height: 1;
}

.hit-button small {
  margin-top: 6px;
  font-family: system-ui, sans-serif;
  font-size: 10px;
  font-weight: 800;
}

.hit-button:active,
.hit-button.is-pressed {
  box-shadow: inset 0 -4px 10px rgb(108 41 0 / 28%), 0 3px 0 #7b3400, 0 7px 18px rgb(0 0 0 / 45%);
  transform: translateY(5px) scale(0.97);
}

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

.reward-drop {
  position: absolute;
  top: -80px;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  filter: drop-shadow(0 4px 5px rgb(42 7 0 / 50%));
  animation: reward-fall var(--fall-duration) linear var(--fall-delay) forwards;
}

.reward-drop.is-ingot {
  min-width: 48px;
  padding: 5px 10px 7px;
  border: 2px solid #fff1a0;
  border-radius: 50% 50% 42% 42% / 38% 38% 62% 62%;
  color: #6c2800;
  background: radial-gradient(ellipse at 50% 22%, #fff7aa 0 14%, #f5c52c 34%, #bc6705 76%);
  box-shadow: inset 0 -5px 5px rgb(102 39 0 / 28%), 0 0 12px rgb(255 199 46 / 70%);
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 15px !important;
  font-weight: 900;
  text-align: center;
}

.achievement-banner {
  position: absolute;
  top: 21%;
  left: 50%;
  z-index: 18;
  width: min(84%, 360px);
  padding: 14px 22px;
  border: 2px solid #fff1a0;
  border-radius: 16px;
  color: #491700;
  background: linear-gradient(110deg, #f9c83c, #fff3a0 48%, #e69a16);
  box-shadow: 0 0 35px rgb(255 191 36 / 80%), 0 10px 24px rgb(0 0 0 / 38%);
  opacity: 0;
  text-align: center;
  transform: translateX(-50%) scale(0.45);
  pointer-events: none;
}

.achievement-banner small,
.achievement-banner strong {
  display: block;
}

.achievement-banner small {
  font-family: system-ui, sans-serif;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.3em;
}

.achievement-banner strong {
  margin-top: 3px;
  font-size: 22px;
}

.achievement-banner.is-visible {
  animation: achievement-pop 2.8s ease both;
}

.countdown {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--gold-100);
  background: rgb(18 0 3 / 42%);
  font-family: system-ui, sans-serif;
  font-size: 116px;
  font-weight: 1000;
  text-shadow: 0 4px 0 #8f2804, 0 0 40px #ee9e1d;
  backdrop-filter: blur(2px);
}

.countdown.is-visible {
  display: flex;
}

.pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: rgb(12 0 2 / 82%);
  backdrop-filter: blur(7px);
}

.pause-overlay.is-visible {
  display: flex;
}

.pause-card {
  width: 100%;
  padding: 28px 22px;
  border: 1px solid rgb(245 205 91 / 32%);
  border-radius: 24px;
  text-align: center;
  background: linear-gradient(160deg, #4b0c13, #1c0306);
}

.pause-card h2 {
  margin: 0 0 24px;
  color: var(--cream);
}

.result-screen {
  align-items: center;
  flex-direction: column;
  padding: calc(var(--safe-top) + 42px) 22px calc(var(--safe-bottom) + 18px);
  color: var(--cream);
  background:
    radial-gradient(circle at 50% 25%, rgb(250 190 43 / 23%), transparent 34%),
    linear-gradient(165deg, #4f0b12, #170205 72%);
  text-align: center;
}

.result-rays {
  position: absolute;
  top: 2%;
  left: 50%;
  width: 380px;
  height: 380px;
  background: repeating-conic-gradient(from 0deg, rgb(255 212 87 / 9%) 0 7deg, transparent 7deg 15deg);
  animation: rotate 28s linear infinite;
  transform: translateX(-50%);
}

.result-screen > *:not(.result-rays) {
  z-index: 1;
}

.rank-badge {
  display: grid;
  width: 112px;
  height: 112px;
  margin: 10px 0 6px;
  border: 4px double var(--gold-300);
  border-radius: 50%;
  place-items: center;
  color: #3b0b06;
  background: radial-gradient(circle, #fff2a1, #d78d12);
  box-shadow: 0 0 35px rgb(245 190 57 / 36%);
  font-family: system-ui, sans-serif;
  font-size: 64px;
  font-weight: 1000;
}

.result-screen h2 {
  margin: 4px 0 4px;
  color: var(--gold-100);
  font-size: 35px;
}

.result-subtitle {
  margin: 0 0 16px;
  color: rgb(255 242 215 / 70%);
  font-size: 13px;
}

.result-card {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid rgb(246 208 100 / 24%);
  border-radius: 18px;
  background: rgb(15 0 2 / 35%);
}

.result-card div {
  padding: 16px 5px;
}

.result-card div + div {
  border-left: 1px solid rgb(246 208 100 / 16%);
}

.result-card span {
  display: block;
  color: rgb(255 242 215 / 58%);
  font-family: system-ui, sans-serif;
  font-size: 11px;
}

.result-card strong {
  display: block;
  margin-top: 5px;
  color: var(--gold-100);
  font-family: system-ui, sans-serif;
  font-size: 28px;
}

blockquote {
  width: 100%;
  margin: 16px 0;
  padding: 13px 18px;
  border: 0;
  border-radius: 12px;
  color: #57220d;
  background: linear-gradient(100deg, #f8e4ad, #fff7dd);
  font-size: 15px;
}

.result-actions {
  display: grid;
  width: 100%;
  gap: 9px;
}

.secondary-button {
  width: 100%;
  border: 1px solid rgb(247 210 104 / 52%);
  color: var(--gold-100);
  background: rgb(87 12 19 / 45%);
  font-size: 16px;
}

.text-button {
  min-height: 34px;
  border: 0;
  color: rgb(255 242 215 / 68%);
  background: none;
  text-decoration: underline;
}

.share-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  color: white;
  background: rgb(4 0 1 / 88%);
}

.share-overlay.is-visible {
  display: block;
}

.share-arrow {
  position: absolute;
  top: calc(var(--safe-top) + 14px);
  right: 22px;
  color: var(--gold-300);
  font-family: system-ui, sans-serif;
  font-size: 68px;
  transform: rotate(-12deg);
}

.share-guide {
  position: absolute;
  top: 25%;
  right: 25px;
  left: 25px;
  text-align: center;
}

.share-guide h2 {
  color: var(--gold-100);
  font-size: 30px;
}

.share-guide p {
  margin-bottom: 28px;
  font-family: system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.8;
}

.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 28px);
  left: 50%;
  z-index: 120;
  max-width: 80vw;
  padding: 10px 18px;
  border-radius: 999px;
  color: white;
  background: rgb(0 0 0 / 78%);
  font-family: system-ui, sans-serif;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes breathe {
  50% { opacity: 0.62; transform: scale(1.08); }
}

@keyframes strike {
  45% { transform: translateX(-50%) translateY(10px) scale(1.025); }
}

@keyframes particle {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.5) rotate(-8deg); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -90px) scale(1.15) rotate(8deg); }
}

@keyframes reward-fall {
  0% { opacity: 0; transform: translate3d(0, -40px, 0) rotate(0deg) scale(0.75); }
  8% { opacity: 1; }
  92% { opacity: 1; }
  100% { opacity: 0; transform: translate3d(var(--drift), calc(100dvh + 120px), 0) rotate(var(--spin)) scale(1.05); }
}

@keyframes achievement-pop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.45); }
  12% { opacity: 1; transform: translateX(-50%) scale(1.08); }
  20%, 78% { opacity: 1; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-28px) scale(0.92); }
}

@keyframes rotate {
  to { transform: translateX(-50%) rotate(360deg); }
}

@media (max-height: 700px) {
  .brand { margin-top: 1vh; }
  .brand h1 { font-size: 64px; }
  .target-grid { grid-auto-rows: 124px; }
  .rank-badge { width: 84px; height: 84px; font-size: 48px; }
  .result-screen { padding-top: calc(var(--safe-top) + 20px); }
  .result-screen h2 { font-size: 28px; }
  blockquote { margin: 10px 0; }
}

@media (min-width: 521px) {
  body { background: radial-gradient(circle, #4b1117, #100104 70%); }
}

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