:root {
  --ink: #151319;
  --muted: #8d8899;
  --violet: #8b5cf6;
  --deep: #6d28d9;
  --lav: #c4b5fd;
  --bg: #f4f1fb;
  --glass: rgba(255, 255, 255, 0.62);
  --edge: rgba(255, 255, 255, 0.9);
}

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

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  padding: calc(16px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

/* thin vertical guide lines, like the poster */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(90deg, rgba(21, 19, 25, 0.05) 0 1px, transparent 1px 28px);
  -webkit-mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.25) 55%, transparent 88%);
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.25) 55%, transparent 88%);
}

/* soft violet wash at the bottom */
body::after {
  content: "";
  position: fixed;
  left: -25%;
  right: -25%;
  bottom: -18%;
  height: 58%;
  pointer-events: none;
  background:
    radial-gradient(55% 65% at 18% 62%, rgba(139, 92, 246, 0.38), transparent 72%),
    radial-gradient(50% 60% at 82% 68%, rgba(167, 139, 250, 0.38), transparent 72%),
    radial-gradient(45% 55% at 52% 92%, rgba(109, 40, 217, 0.30), transparent 72%);
  filter: blur(14px);
  opacity: 0.5;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
}

.screen { width: 100%; }
.screen.is-hidden { display: none; }
.screen:not(.is-hidden) { animation: screenIn 0.28s ease both; }

@keyframes screenIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.screen--menu {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 2px;
}

.screen--menu > *:not(.deco) { position: relative; z-index: 1; }

.screen--menu > *:not(.deco) {
  animation: rise 0.46s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}

.screen--menu > .head { animation-delay: 0.02s; }
.screen--menu > .preview { animation-delay: 0.06s; }
.screen--menu > .tabs { animation-delay: 0.1s; }
.screen--menu > .mode-card { animation-delay: 0.14s; }
.screen--menu > .play-big {
  animation:
    rise 0.46s cubic-bezier(0.2, 0.8, 0.2, 1) 0.18s backwards,
    playPulse 3.8s ease-in-out 1s infinite;
}
.screen--menu > .chips { animation-delay: 0.22s; }
.screen--menu > .hint { animation-delay: 0.26s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* floating glass tiles in the menu */
.deco {
  position: absolute;
  inset: -24px;
  z-index: 0;
  pointer-events: none;
}

.deco-tile {
  position: absolute;
  border-radius: 20px;
  background: linear-gradient(140deg, rgba(196, 181, 253, 0.9), rgba(139, 92, 246, 0.75));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 20px 40px -20px rgba(109, 40, 217, 0.8);
  opacity: 0.3;
  filter: blur(0.5px);
  animation: float 13s ease-in-out infinite;
}

.d1 { top: 36px; right: -30px; width: 84px; height: 84px; }
.d2 { top: 168px; left: -38px; width: 68px; height: 68px; opacity: 0.22; animation-delay: -4s; }
.d3 { bottom: 70px; right: -22px; width: 94px; height: 94px; opacity: 0.26; animation-delay: -7s; }
.d4 { bottom: -26px; left: -18px; width: 64px; height: 64px; opacity: 0.24; animation-delay: -2s; }

@keyframes float {
  50% { transform: translateY(-14px) rotate(4deg); }
}

.head-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #a49dae;
}

.brand-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: linear-gradient(140deg, #a78bfa, #6d28d9);
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.14);
  animation: pulseDot 2.6s ease-in-out infinite;
}

@keyframes pulseDot {
  50% { box-shadow: 0 0 0 8px rgba(139, 92, 246, 0.05); }
}

.played {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.62);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #8d8899;
  font-variant-numeric: tabular-nums;
}

.played[hidden] { display: none; }

.title {
  position: relative;
  margin: 8px 0 0;
  font-size: 48px;
  line-height: 0.92;
  font-weight: 800;
  letter-spacing: -0.045em;
}

.bang { color: var(--violet); }

.spark {
  position: absolute;
  top: -2px;
  margin-left: 8px;
  font-size: 22px;
  color: var(--violet);
  transform: rotate(8deg);
}

.sub {
  margin: 9px 0 0;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--muted);
}

/* ---------- live preview ---------- */

.preview {
  position: relative;
  height: 172px;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid var(--edge);
  background:
    radial-gradient(70% 80% at 50% 62%, rgba(196, 181, 253, 0.34), transparent 72%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(238, 231, 255, 0.78));
  box-shadow: 0 24px 44px -28px rgba(76, 29, 149, 0.65), inset 0 1px 0 #fff;
}

.preview::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 42%, rgba(109, 40, 217, 0.05));
}

.preview canvas { display: block; width: 100%; height: 100%; }

/* ---------- mode tabs ---------- */

.tabs {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 4px;
  border-radius: 16px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.55);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 24px -20px rgba(76, 29, 149, 0.75), inset 0 1px 0 #fff;
}

.tabs-pill {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc((100% - 8px) / 3);
  border-radius: 12px;
  pointer-events: none;
  background: linear-gradient(140deg, #8b5cf6, #6d28d9);
  box-shadow: 0 10px 18px -10px rgba(109, 40, 217, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: transform 0.3s cubic-bezier(0.3, 0.9, 0.25, 1);
}

.tab {
  position: relative;
  z-index: 1;
  padding: 9px 4px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #7b7489;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  transition: color 0.22s ease, transform 0.12s ease;
}

.tab.is-active { color: #fff; }
.tab:active { transform: scale(0.97); }

/* ---------- selected mode card ---------- */

.mode-card {
  --accent: #a78bfa;
  --accent-deep: #6d28d9;
  padding: 12px 14px 11px;
  border-radius: 18px;
  border: 1px solid var(--edge);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.94), rgba(241, 235, 255, 0.94));
  box-shadow: 0 18px 32px -24px rgba(76, 29, 149, 0.95), inset 0 1px 0 #fff;
}

.mode-card.swap { animation: swapIn 0.32s ease; }

@keyframes swapIn {
  from { opacity: 0.5; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.mode-row {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 12px;
}

.mode-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  font-size: 17px;
  color: #fff;
  background: linear-gradient(140deg, var(--accent), var(--accent-deep));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 8px 16px -9px var(--accent-deep);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.mode-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mode-name { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.mode-desc { font-size: 11.5px; line-height: 1.3; color: var(--muted); }

.mode-best { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.mode-best span {
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: #a49dae;
}
.mode-best b {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--accent-deep);
  font-variant-numeric: tabular-nums;
  transition: color 0.3s ease;
}

.mode-tip {
  margin: 9px 0 0;
  padding-top: 9px;
  border-top: 1px dashed rgba(139, 92, 246, 0.22);
  font-size: 11.5px;
  line-height: 1.4;
  color: #8d8899;
}

/* ---------- big play button ---------- */

.play-big {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  padding: 16px;
  border: 0;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9 72%);
  color: #fff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
  box-shadow: 0 20px 36px -18px rgba(109, 40, 217, 1), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  animation: playPulse 3.8s ease-in-out infinite;
}

.play-big:active { transform: translateY(1px) scale(0.995); }

@keyframes playPulse {
  50% {
    box-shadow: 0 24px 46px -16px rgba(109, 40, 217, 1), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  }
}

.play-big::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 32%, rgba(255, 255, 255, 0.28) 50%, transparent 68%);
  transform: translateX(-120%);
  animation: shine 4.6s ease-in-out infinite;
}

@keyframes shine {
  0%, 62% { transform: translateX(-120%); }
  100% { transform: translateX(120%); }
}

.play-spark { font-size: 15px; opacity: 0.9; }

.play-label { font-size: 17px; font-weight: 800; }

.play-mode {
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.18);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: rgba(255, 255, 255, 0.94);
}

/* ---------- chips ---------- */

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 18px -14px rgba(76, 29, 149, 0.8);
  color: #6b6478;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
}

.chip i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #cfc9da;
}

.chip.is-on {
  color: var(--deep);
  background: rgba(255, 255, 255, 0.82);
  border-color: rgba(139, 92, 246, 0.4);
}

.chip.is-on i {
  background: linear-gradient(140deg, #a78bfa, #6d28d9);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.16);
}

.hint {
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: #a49dae;
}

/* ---------- game screen ---------- */

.screen--game { display: flex; flex-direction: column; gap: 10px; }

.hud {
  display: grid;
  grid-template-columns: 40px 1fr 1fr 40px;
  gap: 8px;
  align-items: stretch;
}

.icon-btn {
  width: 40px;
  min-height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--edge);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.6);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 20px -14px rgba(76, 29, 149, 0.8), inset 0 1px 0 #fff;
  color: var(--deep);
  font-family: inherit;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.icon-btn:active { transform: scale(0.95); }

.stat {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 6px 12px 7px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--edge);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 20px -16px rgba(76, 29, 149, 0.8), inset 0 1px 0 #fff;
}

.stat-label {
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: #a49dae;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-value.bump { animation: bump 0.32s ease; }

@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.16); }
  100% { transform: scale(1); }
}

.timerbar {
  height: 5px;
  border-radius: 999px;
  background: rgba(139, 92, 246, 0.14);
  overflow: hidden;
}

.timerbar[hidden] { display: none; }

.timerbar i {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #a78bfa, #6d28d9);
  transition: width 0.12s linear;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 26px;
  overflow: hidden;
  background:
    radial-gradient(80% 60% at 50% 105%, rgba(139, 92, 246, 0.22), transparent 70%),
    linear-gradient(180deg, #fbfaff, #efe8ff);
  border: 1px solid var(--edge);
  box-shadow: 0 26px 52px -26px rgba(76, 29, 149, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

canvas { display: block; width: 100%; height: 100%; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(244, 241, 251, 0.5);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: opacity 0.24s ease, visibility 0.24s ease;
}

.overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.panel {
  width: 100%;
  max-width: 276px;
  padding: 20px 20px 14px;
  text-align: center;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--edge);
  box-shadow: 0 22px 44px -22px rgba(76, 29, 149, 0.6), inset 0 1px 0 #fff;
}

.mark { font-size: 22px; line-height: 1; color: var(--violet); }

.panel h2 {
  margin: 8px 0 0;
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.panel p {
  margin: 7px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.big {
  margin-top: 10px;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--deep);
  font-variant-numeric: tabular-nums;
}

.big[hidden] { display: none; }

.panel .note {
  margin: 6px 0 0;
  font-size: 12px;
  font-weight: 600;
  color: #8d8899;
}

.panel .note[hidden] { display: none; }

.play {
  margin-top: 16px;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: #fff;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  box-shadow: 0 14px 26px -12px rgba(109, 40, 217, 0.95);
}

.play:active { transform: translateY(1px) scale(0.99); }

.ghost {
  margin-top: 6px;
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
}

.ghost:active { color: var(--deep); }

/* ---------- arrow pad ---------- */

.pad {
  width: 100%;
  max-width: 260px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.key {
  height: 54px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 16px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.6);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--deep);
  font-family: inherit;
  font-size: 23px;
  font-weight: 600;
  box-shadow: 0 10px 20px -14px rgba(76, 29, 149, 0.8), inset 0 1px 0 #fff;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.key.is-current {
  border-color: rgba(139, 92, 246, 0.5);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 20px -14px rgba(76, 29, 149, 0.8), inset 0 0 0 2px rgba(139, 92, 246, 0.16);
}

.key:active {
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: #fff;
}

/* ---------- small screens ---------- */

@media (max-height: 780px) {
  body { padding-top: calc(10px + env(safe-area-inset-top)); }
  .screen--menu { gap: 10px; }
  .title { font-size: 42px; }
  .sub { display: none; }
  .preview { height: 148px; }
  .mode-card { padding: 10px 12px 9px; }
  .mode-icon { width: 38px; height: 38px; border-radius: 12px; }
  .mode-desc { font-size: 11px; }
  .mode-tip { margin-top: 7px; padding-top: 7px; }
  .play-big { padding: 14px; }
  .key { height: 46px; }
  .hint { display: none; }
}

@media (max-height: 700px) {
  .screen--menu { max-width: 340px; margin: 0 auto; }
  .title { font-size: 34px; }
  .spark { font-size: 17px; }
  .preview { height: 122px; border-radius: 18px; }
  .mode-card { padding: 8px 11px 8px; }
  .mode-tip { display: none; }
  .mode-desc { display: none; }
  .mode-icon { width: 34px; height: 34px; font-size: 15px; }
  .play-big { padding: 12px; font-size: 16px; }
  .chip { padding: 7px 12px; font-size: 11.5px; }
  .key { height: 42px; border-radius: 14px; }
  .pad { gap: 6px; }
  .stat-value { font-size: 19px; }
}
