:root {
  --pink: #ff6397;
  --pink-deep: #e33d77;
  --pink-soft: #ffc3d6;
  --cream: #fff8f1;
  --ink: #19222e;
  --glass: rgba(18, 30, 43, 0.38);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: radial-gradient(95% 62% at 50% 0%, #9ab1c7 0%, #71899f 36%, #4d6379 68%, #324555 100%);
  color: var(--cream);
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.game {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.4dvh, 14px);
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 16px);
}

/* ---------- HUD ---------- */

.hud {
  width: min(100%, 520px);
  margin-inline: auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding-top: 2px;
}

.chip {
  display: flex;
  align-items: baseline;
  gap: 6px;
  justify-self: start;
  padding: 7px 12px;
  min-width: 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.chip.score {
  justify-self: end;
}

.chip-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.13em;
  color: rgba(255, 248, 241, 0.6);
}

.chip-value {
  font-size: 19px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.chip.best .chip-value {
  color: var(--pink-soft);
}

.chip.score .chip-value {
  font-size: 21px;
  color: #fff;
}

.timer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  text-align: center;
}

.timer-value {
  font-size: clamp(28px, 8.4vw, 40px);
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.28);
}

.timer-track {
  width: clamp(86px, 26vw, 150px);
  height: 6px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.16);
}

.timer-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffe4ec, var(--pink));
  transform-origin: left center;
  will-change: transform;
}

.timer.low .timer-value {
  color: var(--pink-soft);
}

.timer.low {
  animation: throb 0.8s ease-in-out infinite;
}

@keyframes throb {
  50% {
    transform: scale(1.06);
  }
}

/* ---------- Photo stage ---------- */

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.4dvh, 14px);
}

.photo-wrap {
  position: relative;
  width: min(92vw, max(210px, calc((100dvh - 250px) * 0.8333)), 470px);
  aspect-ratio: 1145 / 1374;
  overflow: hidden;
  isolation: isolate;
  border-radius: clamp(22px, 7vw, 34px);
  background: #2b3b4c;
  box-shadow:
    0 24px 60px rgba(9, 16, 25, 0.5),
    0 6px 16px rgba(9, 16, 25, 0.35),
    inset 0 0 0 2px rgba(255, 255, 255, 0.22);
  cursor: pointer;
  touch-action: none;
  transition: filter 0.35s ease;
}

.photo-wrap:active {
  filter: brightness(1.06);
}

.photo-wrap.done {
  cursor: default;
  filter: saturate(0.72) brightness(0.88);
}

.photo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(var(--grin, 1));
  transform-origin: 50% 59%;
  transition: transform 0.5s cubic-bezier(0.2, 0.85, 0.25, 1.05);
  pointer-events: none;
  -webkit-user-drag: none;
}

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

.flash {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  background: radial-gradient(58% 46% at 50% 60%, rgba(255, 214, 228, 0.6), rgba(255, 150, 185, 0) 72%);
}

.flash.on {
  animation: flash 0.7s ease-out;
}

@keyframes flash {
  0% {
    opacity: 0;
  }
  22% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* ---------- Tap effects ---------- */

.kiss-mark {
  position: absolute;
  width: 46px;
  height: 30px;
  pointer-events: none;
  filter: drop-shadow(0 3px 6px rgba(70, 8, 28, 0.4));
  animation: kiss-pop 0.95s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}

.kiss-mark svg {
  display: block;
  width: 100%;
  height: 100%;
}

@keyframes kiss-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--tilt)) scale(0.25);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(var(--tilt)) scale(1.15);
  }
  62% {
    opacity: 0.95;
    transform: translate(-50%, -50%) rotate(var(--tilt)) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -58%) rotate(var(--tilt)) scale(0.9);
  }
}

.points {
  position: absolute;
  width: 44px;
  margin-left: -22px;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fff;
  text-shadow: 0 2px 10px rgba(150, 20, 60, 0.7);
  pointer-events: none;
  animation: float-up 0.8s ease-out forwards;
}

@keyframes float-up {
  0% {
    opacity: 0;
    transform: translateY(6px) scale(0.8);
  }
  25% {
    opacity: 1;
    transform: translateY(-8px) scale(1.05);
  }
  100% {
    opacity: 0;
    transform: translateY(-52px) scale(0.95);
  }
}

.grin-toast {
  position: absolute;
  top: 11%;
  left: 50%;
  z-index: 2;
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(255, 93, 147, 0.94);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 8px 22px rgba(80, 10, 30, 0.4);
  animation: grin-toast 1.1s ease-out forwards;
}

@keyframes grin-toast {
  0% {
    opacity: 0;
    transform: translate(-50%, 8px) scale(0.9);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
  75% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -10px) scale(1);
  }
}

/* ---------- Hint ---------- */

.hint {
  margin: 0;
  min-height: 18px;
  text-align: center;
  font-size: clamp(12px, 3.4vw, 14px);
  font-weight: 600;
  color: rgba(255, 248, 241, 0.78);
}

/* ---------- End screen ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(var(--safe-top) + 24px);
  padding-bottom: calc(var(--safe-bottom) + 24px);
  background: rgba(24, 35, 48, 0.55);
  backdrop-filter: blur(12px) saturate(0.9);
  -webkit-backdrop-filter: blur(12px) saturate(0.9);
  transition: opacity 0.25s ease;
}

.overlay[hidden] {
  display: none;
}

.card {
  width: min(86vw, 340px);
  padding: 26px 22px 22px;
  border-radius: 30px;
  background: linear-gradient(180deg, #fff8f1, #ffe9dd);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 30px 80px rgba(5, 10, 18, 0.55);
  animation: card-in 0.45s cubic-bezier(0.2, 0.9, 0.25, 1.15) both;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.kicker {
  margin: 0 0 10px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--pink-deep);
}

.end-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-size: 24px;
  line-height: 1;
}

#endScore {
  font-size: clamp(64px, 20vw, 84px);
  line-height: 0.85;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.unit {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: rgba(25, 34, 46, 0.55);
}

.end-copy {
  margin: 13px 0 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.45;
  color: rgba(25, 34, 46, 0.66);
}

.best-line {
  margin: 14px 0 20px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(25, 34, 46, 0.5);
}

.best-line strong {
  font-size: 16px;
  color: var(--ink);
}

.again {
  appearance: none;
  border: 0;
  width: 100%;
  min-height: 56px;
  border-radius: 18px;
  background: linear-gradient(180deg, #ff7aa6, #e83f78);
  color: #fff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow:
    0 12px 24px rgba(200, 40, 90, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

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

.again:focus-visible {
  outline: 3px solid rgba(227, 61, 119, 0.45);
  outline-offset: 3px;
}

@media (max-width: 359px) {
  .game {
    padding-left: 12px;
    padding-right: 12px;
  }

  .chip {
    padding: 6px 9px;
  }

  .chip-label {
    font-size: 8px;
    letter-spacing: 0.08em;
  }
}
