*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

button { touch-action: manipulation; }

@property --s { syntax: '<number>'; inherits: false; initial-value: 1; }
@property --bg-a { syntax: '<color>'; inherits: true; initial-value: #241436; }
@property --bg-b { syntax: '<color>'; inherits: true; initial-value: #0a0810; }

:root {
  --bg-a: #241436;
  --bg-b: #0a0810;
  --ink: #f4f1ff;
  --dim: rgba(244, 241, 255, 0.55);
  --faint: rgba(244, 241, 255, 0.14);
  --good: #4ade80;
  --bad: #fb7185;
  --gold: #fbbf24;
  --glass: rgba(255, 255, 255, 0.055);
  --stroke: rgba(255, 255, 255, 0.1);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg-b);
  color: var(--ink);
  font-family: 'Segoe UI', system-ui, -apple-system, 'Noto Sans', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 900ms var(--ease);
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: 620px;
  margin: 0 auto;
  overflow: hidden;
}

#backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 80% at 50% -10%, var(--bg-a) 0%, transparent 62%),
    radial-gradient(90% 60% at 12% 108%, rgba(255,255,255,0.07) 0%, transparent 60%),
    linear-gradient(175deg, var(--bg-a) 0%, var(--bg-b) 58%);
  transition: --bg-a 900ms var(--ease), --bg-b 900ms var(--ease);
}

#backdrop::after {
  content: '';
  position: absolute;
  inset: -40%;
  background: conic-gradient(from 0deg, transparent 0 68%, rgba(255,255,255,0.025) 78%, transparent 88%);
  animation: sweep 22s linear infinite;
  pointer-events: none;
}

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

#fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 70;
}

#stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  will-change: transform;
}

#hud { flex: 0 0 auto; z-index: 10; }

.hud-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
}

.badge {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--dim);
  padding: 7px 12px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: var(--glass);
}

.icon-btn {
  width: 44px;
  height: 44px;
  font-size: 18px;
  color: var(--ink);
  background: var(--glass);
  border: 1px solid var(--stroke);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 160ms var(--spring), background 200ms;
}
.icon-btn:active { transform: scale(0.88); }
.icon-btn.is-off { opacity: 0.4; }

.timer {
  position: relative;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
}
.timer svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 3.5; stroke-linecap: round; }
.timer-track { stroke: rgba(255,255,255,0.1); }
.timer-fill {
  stroke: var(--good);
  stroke-dasharray: 119.4;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 200ms linear, stroke 400ms;
}
#timer-text { font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer.is-warn .timer-fill { stroke: var(--gold); }
.timer.is-danger .timer-fill { stroke: var(--bad); }
.timer.is-danger { animation: tick-pulse 700ms ease-in-out infinite; }
@keyframes tick-pulse { 50% { transform: scale(1.12); } }

.target {
  margin-top: 16px;
  padding: 16px 18px;
  border: 1px solid var(--stroke);
  border-radius: 20px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  text-align: center;
  animation: drop-in 620ms var(--spring) both;
}

.target-tag {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--bad);
  margin-bottom: 7px;
}

.target-text {
  font-size: clamp(17px, 5vw, 23px);
  font-weight: 700;
  line-height: 1.32;
  letter-spacing: -0.01em;
}

@keyframes drop-in {
  from { opacity: 0; transform: translateY(-18px) scale(0.96); }
}

.lives {
  display: flex;
  justify-content: center;
  gap: 7px;
  margin-top: 12px;
  min-height: 12px;
}
.life {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 10px rgba(74, 222, 128, 0.6);
  transition: all 300ms var(--spring);
}
.life.is-lost {
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.2);
  box-shadow: none;
  transform: scale(0.75);
}

#board {
  position: relative;
  flex: 1 1 auto;
  margin: 8px 0;
  min-height: 0;
  touch-action: none;
}

.obj {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: grab;
  animation: pop-in 520ms var(--spring) both;
  transition: filter 220ms;
}
.obj.is-static { cursor: default; }
.obj.is-dragging { cursor: grabbing; z-index: 30; }

@keyframes pop-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
}

.obj-glyph {
  font-size: clamp(46px, 14vw, 70px);
  line-height: 1;
  filter: drop-shadow(0 10px 16px rgba(0,0,0,0.55));
  transition: transform 320ms var(--spring), filter 260ms, opacity 320ms, --s 620ms var(--spring);
  animation: float 4.5s ease-in-out infinite;
}
.obj.is-static .obj-glyph { animation-duration: 6s; }
.obj.is-dragging .obj-glyph {
  transform: scale(calc(var(--s, 1) * 1.22)) rotate(-5deg);
  filter: drop-shadow(0 24px 30px rgba(0,0,0,0.6)) brightness(1.14);
  animation: none;
}

@keyframes float {
  0%, 100% { transform: translateY(0) scale(var(--s, 1)); }
  50% { transform: translateY(-8px) scale(var(--s, 1)); }
}

.obj-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--dim);
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,0.45);
  white-space: nowrap;
  transition: color 200ms, background 200ms, opacity 300ms;
}
.obj.is-dragging .obj-name { opacity: 0; }

.obj.is-target::before {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 120px; height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  border: 2px dashed rgba(255,255,255,0.4);
  animation: ring-spin 8s linear infinite, ring-in 260ms var(--spring);
  pointer-events: none;
}
@keyframes ring-spin { to { transform: rotate(360deg); } }
@keyframes ring-in { from { opacity: 0; transform: scale(0.6); } }

.obj.is-hot .obj-glyph {
  animation: none;
  transform: scale(calc(var(--s, 1) * 1.16));
  filter: drop-shadow(0 0 26px var(--gold)) brightness(1.25);
}
.obj.is-hot .obj-name { color: var(--gold); background: rgba(251,191,36,0.16); }

.obj.fx-shake .obj-glyph { animation: fx-shake 420ms ease-out; }
@keyframes fx-shake {
  0%,100% { transform: translateX(0) scale(var(--s, 1)); }
  15% { transform: translateX(-11px) rotate(-7deg) scale(var(--s, 1)); }
  35% { transform: translateX(9px) rotate(6deg) scale(var(--s, 1)); }
  55% { transform: translateX(-6px) rotate(-4deg) scale(var(--s, 1)); }
  78% { transform: translateX(4px) rotate(2deg) scale(var(--s, 1)); }
}

.obj.fx-pulse .obj-glyph { animation: fx-pulse 560ms var(--spring); }
@keyframes fx-pulse {
  0%, 100% { transform: scale(var(--s, 1)); }
  40% { transform: scale(calc(var(--s, 1) * 1.3)); }
}

.obj.fx-impact .obj-glyph { animation: fx-impact 520ms var(--spring); }
@keyframes fx-impact {
  0% { transform: scale(1); }
  22% { transform: scale(1.45) rotate(4deg); }
  48% { transform: scale(0.88) rotate(-3deg); }
}

.obj.fx-launch .obj-glyph {
  animation: fx-launch 1000ms cubic-bezier(0.4, 0, 0.9, 0.1) forwards;
}
@keyframes fx-launch {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  18% { transform: translateY(24px) scale(0.9, 1.12); }
  100% { transform: translateY(-115vh) scale(0.45) rotate(320deg); opacity: 0; }
}

.obj.fx-sink .obj-glyph { animation: fx-sink 700ms var(--ease) forwards; }
@keyframes fx-sink {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(26px) scale(1.16, 0.8); filter: drop-shadow(0 2px 6px rgba(0,0,0,0.8)) brightness(0.75); }
}

.obj.fx-fade .obj-glyph { animation: fx-fade 620ms var(--ease) forwards; }
@keyframes fx-fade {
  100% { opacity: 0; transform: scale(0.5) translateY(-30px); }
}

.obj.fx-launch .obj-name,
.obj.fx-fade .obj-name { opacity: 0; }

.obj.fx-ignite .obj-glyph {
  animation: fx-ignite 900ms var(--spring);
  filter: drop-shadow(0 0 34px #ff9d2b) brightness(1.35) saturate(1.4);
}
@keyframes fx-ignite {
  0% { transform: scale(1); }
  30% { transform: scale(1.34) rotate(-4deg); }
  60% { transform: scale(1.12) rotate(3deg); }
}

.obj.fx-dim .obj-glyph {
  animation: fx-pulse 500ms var(--ease);
  filter: grayscale(0.85) brightness(0.55);
}

.obj.fx-silence .obj-glyph {
  animation: fx-silence 640ms var(--ease);
  filter: grayscale(0.9) brightness(0.6);
}
@keyframes fx-silence {
  0% { transform: scale(1.2); }
  100% { transform: scale(0.9); }
}

.obj.fx-melt .obj-glyph { animation: fx-melt 760ms var(--ease); }
@keyframes fx-melt {
  0%, 100% { transform: scale(var(--s, 1)); }
  45% { transform: scale(calc(var(--s, 1) * 1.2), calc(var(--s, 1) * 0.72)) translateY(12px); }
}

.obj.fx-freeze .obj-glyph {
  animation: fx-freeze 720ms var(--spring);
  filter: drop-shadow(0 0 26px #7dd3fc) brightness(1.2);
}
@keyframes fx-freeze {
  0% { transform: scale(1); }
  35% { transform: scale(0.82); }
  70% { transform: scale(1.18); }
}

.obj.fx-nudge .obj-glyph { animation: fx-nudge 340ms ease-out; }
@keyframes fx-nudge {
  50% { transform: translateY(-14px) scale(1.06); }
}

#footer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 10;
}

.feedback {
  min-height: 40px;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  color: var(--dim);
  padding: 0 8px;
  transition: color 260ms;
}
.feedback.is-good { color: var(--good); }
.feedback.is-bad { color: var(--bad); }
.feedback.is-hint { color: var(--gold); }
.feedback.is-flash { animation: fb-flash 420ms var(--spring); }
@keyframes fb-flash {
  0% { transform: scale(0.9); opacity: 0.3; }
  55% { transform: scale(1.04); }
}

.steps { display: flex; gap: 6px; min-height: 6px; }
.step-dot {
  width: 26px; height: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.16);
  transition: background 400ms, box-shadow 400ms;
}
.step-dot.is-done { background: var(--good); box-shadow: 0 0 10px rgba(74,222,128,0.7); animation: dot-pop 420ms var(--spring); }
@keyframes dot-pop { 45% { transform: scaleX(1.5) scaleY(2.6); } }

.hint-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--ink);
  padding: 13px 22px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  cursor: pointer;
  transition: transform 180ms var(--spring), background 220ms, opacity 220ms;
}
.hint-btn:active { transform: scale(0.94); }
.hint-btn:disabled { opacity: 0.35; cursor: default; }
.hint-icon { font-size: 15px; }
.hint-tag {
  font-size: 9px;
  letter-spacing: 0.14em;
  color: var(--gold);
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(251,191,36,0.15);
}
.hint-btn:disabled .hint-tag { display: none; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(6, 4, 12, 0.82);
  backdrop-filter: blur(14px);
}
.overlay.is-open { display: flex; animation: ov-in 300ms var(--ease); }
@keyframes ov-in { from { opacity: 0; } }

.card {
  width: 100%;
  max-width: 400px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 30px 26px;
  text-align: center;
  border: 1px solid var(--stroke);
  border-radius: 26px;
  background: linear-gradient(165deg, rgba(255,255,255,0.09), rgba(255,255,255,0.03));
  box-shadow: 0 30px 70px rgba(0,0,0,0.6);
  animation: card-in 460ms var(--spring) both;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(26px) scale(0.93); }
}

.card-glyph {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 14px;
  animation: glyph-pop 700ms var(--spring) both 100ms;
}
@keyframes glyph-pop {
  from { opacity: 0; transform: scale(0.2) rotate(-25deg); }
}

.win-title {
  font-size: 27px;
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(100deg, #fbbf24, #f472b6, #a78bfa, #fbbf24);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 18px;
  animation: title-shine 3s linear infinite;
}
@keyframes title-shine { to { background-position: -300% 0; } }

.fail-title { font-size: 23px; font-weight: 800; color: var(--bad); margin-bottom: 12px; }

.rule-label {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--dim);
  margin-bottom: 8px;
}

.rule-text {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--gold);
  margin-bottom: 24px;
}

.intro-card h2 {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}
.intro-glyphs {
  font-size: 21px;
  letter-spacing: 2px;
  white-space: nowrap;
  margin-bottom: 16px;
  animation: glyph-pop 800ms var(--spring) both;
}
.lead { font-size: 15px; font-weight: 700; color: var(--bad); margin-bottom: 14px; }
.body { font-size: 14px; line-height: 1.55; color: var(--dim); margin-bottom: 14px; }
.body b { color: var(--ink); }
.body.dim { font-size: 13px; color: rgba(244, 241, 255, 0.62); }

.primary {
  position: relative;
  overflow: hidden;
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.09em;
  color: #14101c;
  padding: 16px;
  margin-top: 10px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(100deg, #fbbf24, #fb923c);
  box-shadow: 0 12px 26px rgba(251, 146, 60, 0.32);
  cursor: pointer;
  transition: transform 180ms var(--spring), box-shadow 220ms;
}
.primary:active { transform: scale(0.96); }
.primary:disabled { opacity: 0.45; }

.primary::after {
  content: '';
  position: absolute;
  inset: 0;
  transform: translateX(-130%) skewX(-18deg);
  background: linear-gradient(105deg, transparent 42%, rgba(255,255,255,0.45) 50%, transparent 58%);
  animation: sheen 3.2s ease-in-out infinite;
  pointer-events: none;
}
.primary:disabled::after { animation: none; }
@keyframes sheen { 55%, 100% { transform: translateX(130%) skewX(-18deg); } }

.primary.revive {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  background: linear-gradient(100deg, #4ade80, #22d3ee);
  box-shadow: 0 12px 26px rgba(34, 211, 238, 0.28);
}

.ghost {
  width: 100%;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--dim);
  padding: 13px;
  margin-top: 9px;
  border: 1px solid var(--stroke);
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
  transition: color 200ms, border-color 200ms;
}
.ghost:active { color: var(--ink); }

.rules-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 8px 0 20px;
  text-align: left;
}
.rules-list div {
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--dim);
  padding: 9px 12px;
  border-radius: 11px;
  background: rgba(255,255,255,0.045);
}

.ad-overlay { background: rgba(0,0,0,0.9); z-index: 80; }

.ad-frame {
  width: 100%;
  max-width: 400px;
  border: 1px solid var(--stroke);
  border-radius: 20px;
  overflow: hidden;
  background: #12101a;
  box-shadow: 0 30px 70px rgba(0,0,0,0.7);
  animation: card-in 380ms var(--spring) both;
}

.ad-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 15px;
  background: rgba(255,255,255,0.05);
}
.ad-kind { font-size: 9.5px; font-weight: 800; letter-spacing: 0.2em; color: var(--dim); }
.ad-timer { font-size: 11px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }

.ad-body { padding: 30px 20px; }
.ad-fake {
  text-align: center;
  padding: 26px 16px;
  border-radius: 16px;
  background: linear-gradient(150deg, #4c1d95, #831843, #7c2d12);
  background-size: 200% 200%;
  animation: ad-shift 6s ease-in-out infinite;
}
@keyframes ad-shift { 50% { background-position: 100% 100%; } }

.ad-logo { font-size: 46px; animation: ad-bounce 1.4s ease-in-out infinite; }
@keyframes ad-bounce { 50% { transform: translateY(-9px) scale(1.06); } }
.ad-brand { font-size: 17px; font-weight: 900; letter-spacing: 0.04em; margin: 10px 0 5px; }
.ad-stars { font-size: 13px; color: var(--gold); letter-spacing: 3px; }
.ad-cta {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #14101c;
  padding: 9px 20px;
  margin-top: 15px;
  border-radius: 999px;
  background: #fff;
  animation: ad-bounce 1.4s ease-in-out infinite 200ms;
}

.ad-progress { height: 3px; background: rgba(255,255,255,0.09); }
.ad-progress-fill { height: 100%; width: 0; background: var(--gold); transition: width 100ms linear; }

.ad-actions { display: flex; gap: 9px; padding: 13px 15px; }
.ad-close, .ad-claim {
  flex: 1;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 13px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 160ms var(--spring);
}
.ad-close { color: var(--dim); border: 1px solid var(--stroke); background: transparent; }
.ad-claim { color: #14101c; border: none; background: linear-gradient(100deg, #4ade80, #22d3ee); }
.ad-close:active, .ad-claim:active { transform: scale(0.95); }

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