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

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

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  font-family: var(--ak-font-body);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ak-ink);
  background-color: var(--ak-bg);
  background-image: var(--ak-bg-art);
  background-size: var(--ak-bg-size);
}

button {
  font-family: inherit;
  touch-action: manipulation;
}

img {
  display: block;
  max-width: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

[hidden] {
  display: none !important;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.play {
  --pad-top: max(6px, env(safe-area-inset-top, 0px));
  --pad-bot: max(8px, env(safe-area-inset-bottom, 0px));
  --pad-x: max(10px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  --close: 0;
  --rise: 0;
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
  gap: 6px;
  width: min(100%, 440px);
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding: var(--pad-top) var(--pad-x) var(--pad-bot);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  background-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

.mute {
  position: absolute;
  top: var(--pad-top);
  right: max(4px, env(safe-area-inset-right, 0px));
  z-index: 8;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  color: var(--ak-ink);
  box-shadow: var(--ak-shadow);
  cursor: pointer;
}

.mute-icon {
  width: 22px;
  height: 22px;
}

.mute.is-muted .wave {
  display: none;
}

.mute.is-muted::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 3px;
  background: var(--ak-accent-2);
  transform: rotate(-35deg);
}

.top,
.voice,
.stage,
.streak-row,
.lower,
.result {
  position: relative;
  z-index: 2;
  min-width: 0;
}

.top { grid-row: 1; }
.voice { grid-row: 2; }
.stage { grid-row: 3; }
.streak-row { grid-row: 4; }
.lower { grid-row: 5; }
.result { grid-row: 6; }

.top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding-right: 52px;
}

.play-logo {
  height: 44px;
  width: auto;
  max-width: 46%;
  object-fit: contain;
  filter: drop-shadow(0 2px 0 var(--ak-outline));
}

.turn {
  min-width: 0;
  min-height: 48px;
  padding: 4px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
}

.turn-who,
.turn-sub {
  margin: 0;
}

.turn-who {
  font-family: var(--ak-font-display);
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  color: var(--ak-ink);
}

.turn-sub {
  margin-top: 2px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ak-accent-2);
}

.voice {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  margin: 0;
  padding: 8px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
  color: var(--ak-ink);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
}

.stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  container-type: size;
}

.glow {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 0;
  z-index: 0;
  height: 34%;
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--ak-accent) 55%, transparent), transparent 72%);
  pointer-events: none;
}

.nudge {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 4;
  width: 0;
  height: 0;
  margin-left: -9px;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-top: 14px solid var(--ak-accent-2);
  filter: drop-shadow(0 0 6px var(--ak-glow));
  pointer-events: none;
}

.pair {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  gap: max(2px, calc(10px - var(--close) * 8px));
}

.card {
  --tilt: 0deg;
  position: relative;
  flex: 0 1 auto;
  width: min(44cqw, calc(86cqh * 258 / 347), 230px);
  height: auto;
  aspect-ratio: var(--card-ratio, 258 / 347);
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  transform: rotate(var(--tilt));
  transform-origin: 50% 0%;
  cursor: pointer;
  touch-action: manipulation;
}

.card-left {
  --tilt: calc(-6deg + var(--close) * 4deg);
}

.card-right {
  --tilt: calc(5deg - var(--close) * 3deg);
}

.card:disabled {
  cursor: default;
}

.card-body {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
}

.card-face {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(3px 4px 0 var(--ak-bg));
}

.place-name {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 47%;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 15%;
  margin: 0;
  padding: 1px 3px 2px;
  border: 2px solid var(--ak-accent);
  border-radius: 2px;
  background: var(--ak-bg);
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  font-size: clamp(11px, 2.9vw, 15px);
  font-weight: 700;
  line-height: 1.05;
  text-align: center;
}

.place-name.is-long {
  font-size: clamp(10px, 2.5vw, 13px);
}

.ribbon {
  position: absolute;
  left: 10%;
  right: 34%;
  top: 63.5%;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 11%;
  border: 2px solid var(--ak-outline);
  border-radius: 2px 2px 8px 8px;
  background: var(--ak-surface);
  color: var(--ak-accent-2);
  box-shadow: var(--ak-shadow);
  font-size: clamp(11px, 2.8vw, 14px);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.seal {
  position: absolute;
  right: 8%;
  bottom: 6%;
  z-index: 4;
  width: 28%;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 36%, var(--ak-accent-2) 0 9%, transparent 10%),
    radial-gradient(circle at 50% 58%, var(--ak-accent) 0 64%, var(--ak-bg) 66%);
  box-shadow: 0 0 0 2px var(--ak-outline);
  opacity: 0;
}

.plate {
  position: absolute;
  right: 2%;
  bottom: 5%;
  z-index: 4;
  width: 34%;
  aspect-ratio: 384 / 378;
  opacity: 0;
}

.plate img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.digits {
  position: absolute;
  inset: 16%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--ak-accent);
  color: var(--ak-bg);
  text-align: center;
}

.digits .main {
  font-family: var(--ak-font-body);
  font-size: clamp(12px, 3.6vw, 20px);
  font-weight: 700;
  line-height: 0.95;
}

.digits .unit {
  max-width: 100%;
  font-size: clamp(8px, 2vw, 11px);
  font-weight: 700;
  line-height: 1.05;
}

.card.is-open .plate {
  opacity: 1;
  transform: scale(1);
}

.card.is-open .seal {
  opacity: 0;
}

.eye,
.tag {
  position: absolute;
  pointer-events: none;
}

.eye {
  left: 38%;
  top: 24%;
  z-index: 2;
  width: 22%;
  height: 12%;
  border-radius: 50%;
  background: var(--ak-accent-2);
  box-shadow: 0 0 10px var(--ak-glow);
  opacity: 0;
}

.tag {
  top: 10%;
  left: 50%;
  z-index: 5;
  padding: 2px 6px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  transform: translateX(-50%);
  opacity: 0;
}

.tag-big {
  color: var(--ak-accent-2);
}

.tag-small {
  color: var(--ak-ink-muted);
}

.card.is-wink .tag-big,
.card.is-smaller .tag-small {
  opacity: 1;
}

.card.is-smaller .card-face {
  filter: brightness(0.45) drop-shadow(3px 4px 0 var(--ak-bg));
}

.streak-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 64px;
}

.candle-wrap {
  position: relative;
  flex: 0 0 auto;
  width: 76px;
  height: 80px;
}

.candle-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 0 8px color-mix(in srgb, var(--ak-accent) 55%, transparent));
}

.flame {
  position: absolute;
  left: 44%;
  top: 4%;
  width: 20%;
  height: 22%;
  border-radius: 50% 50% 46% 46%;
  background: radial-gradient(circle at 50% 70%, var(--ak-accent-2), transparent 68%);
  filter: drop-shadow(0 0 6px var(--ak-glow));
  transform: translateY(calc(var(--rise) * -4px));
}

.streak-copy {
  margin: 0;
}

.streak-num {
  display: block;
  font-family: var(--ak-font-body);
  font-size: 40px;
  font-weight: 700;
  line-height: 0.85;
  color: var(--ak-accent);
}

.streak-word {
  display: block;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ak-ink-muted);
}

.btn-hint,
.btn-go,
.btn-alt {
  min-height: 48px;
  width: 100%;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  font-family: var(--ak-font-display);
  font-size: 18px;
  font-weight: 400;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.btn-hint,
.btn-go {
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
}

.btn-alt {
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  font-size: 16px;
  font-weight: 700;
}

.why {
  margin: 0;
  padding: 8px 10px;
  border: 2px solid var(--ak-accent);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
  color: var(--ak-ink);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
}

.result-card {
  padding: 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
}

.result-says {
  margin: 0 0 8px;
  font-family: var(--ak-font-display);
  font-size: 18px;
  font-weight: 400;
  line-height: 1.25;
  text-align: center;
  color: var(--ak-ink);
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card.is-coach::after {
  content: "";
  position: absolute;
  top: -6px;
  left: 50%;
  z-index: 5;
  margin-left: -8px;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 12px solid var(--ak-accent-2);
  filter: drop-shadow(0 0 5px var(--ak-glow));
}

.card:focus-visible,
.btn-hint:focus-visible,
.btn-go:focus-visible,
.btn-alt:focus-visible,
.mute:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 3px;
}

.play.is-ended .glow {
  opacity: 0.28;
}

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

.fx i {
  position: absolute;
  width: 10px;
  height: 14px;
  border: 2px solid var(--ak-outline);
  opacity: 0;
}

@media (max-height: 700px) {
  .play {
    gap: 4px;
  }

  .play-logo {
    height: 34px;
  }

  .turn-who {
    font-size: 18px;
  }

  .voice {
    min-height: 40px;
    padding: 4px 8px;
    font-size: 14px;
  }

  .candle-wrap {
    width: 56px;
    height: 60px;
  }

  .streak-num {
    font-size: 32px;
  }

  .result-says {
    font-size: 16px;
    margin-bottom: 6px;
  }

  .btn-hint,
  .btn-go,
  .btn-alt {
    min-height: 48px;
  }
}

@media (hover: hover) {
  .card:not(:disabled):hover .card-face {
    filter: brightness(1.06) drop-shadow(3px 4px 0 var(--ak-bg));
  }

  .btn-go:hover,
  .btn-hint:hover {
    background: var(--ak-btn-hover);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .play-logo {
    animation: bob 3.2s ease-in-out infinite;
  }

  .flame {
    animation: flicker 1.3s ease-in-out infinite;
  }

  .glow {
    animation: pulse 2.8s ease-in-out infinite;
  }

  .voice.is-invite {
    animation: invite 1.5s ease-in-out infinite;
  }

  .nudge {
    animation: point 0.7s ease-in-out infinite;
  }

  .pair.is-idle .card {
    animation: sway 3.6s ease-in-out infinite;
  }

  .pair.is-idle .card-right {
    animation-delay: 0.25s;
  }

  .pair.is-glide .card {
    animation: glide 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  .pair.is-glide .card-right {
    animation: glide 0.7s cubic-bezier(0.22, 1, 0.36, 1) 90ms both;
  }

  .card.is-coach::after {
    animation: point 0.7s ease-in-out infinite;
  }

  .card:not(:disabled):active {
    transform: rotate(var(--tilt)) scale(0.96);
  }

  .card.is-tipped .card-body {
    animation: tip 0.46s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .card.is-open .seal {
    opacity: 1;
    animation: seal-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  }

  .card.is-open .plate {
    animation: plate-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .card.is-wink .eye {
    animation: eye-wink 0.55s ease;
  }

  .card.is-wink .card-body {
    animation: chase 0.55s ease 2;
  }

  .card.is-slump .card-body {
    animation: slump 0.55s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }

  .candle-wrap.is-hop .flame {
    animation: hop 0.48s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .play.is-dip .stage {
    animation: dip 0.7s ease;
  }

  .turn.is-cue {
    animation: cue 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .btn-hint:active,
  .btn-go:active,
  .btn-alt:active,
  .mute:active {
    transform: translateY(2px) scale(0.98);
    box-shadow: none;
  }

  .fx i {
    animation: burst 0.9s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }

  @keyframes bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
  }

  @keyframes flicker {
    0%, 100% { transform: translateY(calc(var(--rise) * -4px)) scale(1, 1); opacity: 0.85; }
    50% { transform: translateY(calc(var(--rise) * -4px - 3px)) scale(0.86, 1.16); opacity: 1; }
  }

  @keyframes pulse {
    0%, 100% { opacity: 0.72; }
    50% { opacity: 1; }
  }

  @keyframes invite {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-2px); }
  }

  @keyframes point {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(5px); }
  }

  @keyframes sway {
    0%, 100% { transform: rotate(var(--tilt)) translateY(0); }
    50% { transform: rotate(calc(var(--tilt) + 1.4deg)) translateY(-5px); }
  }

  @keyframes glide {
    0% { opacity: 0; transform: translateX(42%) rotate(11deg) scale(0.84, 1.1); }
    62% { opacity: 1; transform: translateX(-3%) rotate(var(--tilt)) scale(1.06, 0.92); }
    100% { opacity: 1; transform: translateX(0) rotate(var(--tilt)) scale(1); }
  }

  @keyframes tip {
    0% { transform: rotateX(0deg) scale(1, 1); }
    45% { transform: rotateX(14deg) scale(1.06, 0.9); }
    100% { transform: rotateX(6deg) scale(1.02, 0.98); }
  }

  @keyframes seal-pop {
    0% { opacity: 1; transform: translate(0, 0) scale(1) rotate(0deg); }
    100% { opacity: 0; transform: translate(16px, -36px) scale(0.35) rotate(24deg); }
  }

  @keyframes plate-pop {
    0% { opacity: 0; transform: scale(0.2); }
    60% { opacity: 1; transform: scale(1.12); }
    100% { opacity: 1; transform: scale(1); }
  }

  @keyframes eye-wink {
    0% { opacity: 0; transform: scaleY(1); }
    28% { opacity: 1; transform: scaleY(1); }
    46% { opacity: 1; transform: scaleY(0.12); }
    64% { opacity: 1; transform: scaleY(1); }
    100% { opacity: 0; transform: scaleY(1); }
  }

  @keyframes chase {
    0%, 100% { box-shadow: 0 0 0 0 transparent; }
    50% { box-shadow: 0 0 16px 3px var(--ak-glow); }
  }

  @keyframes slump {
    0% { transform: translateY(0) rotate(0deg) scale(1, 1); }
    100% { transform: translateY(16px) rotate(7deg) scale(0.96, 0.9); }
  }

  @keyframes hop {
    0% { transform: translateY(calc(var(--rise) * -4px + 8px)) scale(1, 0.8); }
    45% { transform: translateY(calc(var(--rise) * -4px - 12px)) scale(0.8, 1.28); }
    100% { transform: translateY(calc(var(--rise) * -4px)) scale(1, 1); }
  }

  @keyframes dip {
    0% { filter: brightness(1); }
    40% { filter: brightness(0.55); }
    100% { filter: brightness(0.82); }
  }

  @keyframes cue {
    0% { transform: scale(1); }
    45% { transform: scale(1.06); }
    100% { transform: scale(1); }
  }

  @keyframes burst {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--rot, 20deg)) scale(0.55); }
  }
}
