*,
*::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,
input {
  font-family: inherit;
  touch-action: manipulation;
}

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

[hidden] {
  display: none !important;
}

.play {
  --pad-top: max(4px, env(safe-area-inset-top, 0px));
  --pad-bot: max(6px, env(safe-area-inset-bottom, 0px));
  --pad-x: max(8px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  position: relative;
  display: flex;
  flex-direction: column;
  gap: min(6px, 0.7dvh);
  width: min(100%, 430px);
  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;
}

.play::before {
  content: "";
  position: absolute;
  left: -58px;
  bottom: max(72px, 14dvh);
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, var(--ak-btn-ink), var(--ak-accent) 46%, var(--ak-ink) 74%);
  box-shadow: inset 0 -10px 0 var(--ak-outline), var(--ak-shadow);
  pointer-events: none;
  z-index: 0;
}

.play > * {
  position: relative;
  z-index: 1;
}

.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 {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding-right: 48px;
  flex-shrink: 0;
}

.play-logo {
  display: block;
  width: auto;
  height: min(44px, 6dvh);
  max-width: min(58%, 220px);
  object-fit: contain;
  filter: drop-shadow(0 2px 0 var(--ak-outline));
}

.turn {
  margin-left: auto;
  min-width: 0;
  text-align: right;
}

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

.turn-who {
  font-family: var(--ak-font-display);
  font-size: clamp(20px, 5vw, 28px);
  font-weight: var(--ak-title-weight);
  line-height: 0.9;
  letter-spacing: 0.02em;
}

.turn-sub {
  color: var(--ak-ink-muted);
  font-size: 13px;
  font-weight: 700;
}

.voice,
.why,
.offer,
.coach {
  margin: 0;
  flex-shrink: 0;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
  color: var(--ak-ink);
  text-align: center;
}

.voice,
.why {
  padding: 6px 8px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
}

.voice {
  min-height: 34px;
}

.voice.is-fault,
.why {
  border-color: var(--ak-accent);
}

.voice.is-fault {
  border-color: var(--ak-accent-2);
}

.offer,
.coach {
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}

.coach::after {
  content: "";
  display: block;
  width: 0;
  height: 0;
  margin: 3px auto 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 8px solid var(--ak-accent);
}

.card-scene {
  flex: 1 1 auto;
  min-height: 132px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.card {
  position: relative;
  container-type: size;
  height: min(100%, 340px);
  width: auto;
  max-width: 100%;
  aspect-ratio: 324 / 384;
}

.face {
  position: absolute;
  inset: 0;
}

.face img {
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.face-back {
  display: none;
}

.card.is-flipped .face-front {
  display: none;
}

.card.is-flipped .face-back {
  display: block;
}

.face-copy {
  position: absolute;
  left: 14%;
  right: 16%;
  top: 24%;
  bottom: 22%;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 2px 4px;
  background: var(--ak-choice-bg);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: min(22px, 12cqh);
  font-weight: var(--ak-title-weight);
  line-height: 0.95;
  text-align: center;
}

.story-copy {
  font-family: var(--ak-font-body);
  font-size: min(15px, 7.5cqh);
  font-weight: 700;
  line-height: 1.15;
}

.rungs {
  position: relative;
  flex: 0 0 auto;
  height: calc(52px * 4 + 12px);
  min-height: calc(48px * 4 + 12px);
  display: grid;
  grid-template-rows: repeat(4, minmax(48px, 1fr));
  gap: 4px;
}

.rungs::before,
.rungs::after {
  content: "";
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 10px;
  background: var(--ak-accent);
  border: 2px solid var(--ak-outline);
  box-shadow: var(--ak-shadow);
  pointer-events: none;
  z-index: 0;
}

.rungs::before {
  left: 8%;
}

.rungs::after {
  right: 8%;
}

.rung {
  position: relative;
  z-index: 1;
  min-height: 48px;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  perspective: 700px;
}

.rung:disabled,
.check:disabled {
  opacity: 1;
  cursor: default;
}

.rung-inner {
  display: block;
  position: relative;
  width: min(78%, 320px);
  height: calc(100% - 4px);
  margin: 2px auto;
}

.rung-front,
.rung-back {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.rung-back {
  display: none;
}

.rung.is-open .rung-front {
  display: none;
}

.rung.is-open .rung-back {
  display: grid;
}

.rung-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.rung-back {
  place-items: center;
  padding: 2px 10px;
  background: var(--ak-choice-bg);
  border: 2px solid var(--ak-accent);
  box-shadow: var(--ak-shadow);
  color: var(--ak-ink);
}

.rung-copy {
  display: block;
  max-height: 100%;
  overflow: hidden;
  font-size: clamp(12px, 3vw, 15px);
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
}

.latch {
  position: absolute;
  z-index: 2;
  top: 50%;
  right: calc(14% + 4px);
  width: 14px;
  height: 18px;
  margin-top: -9px;
  border: 2px solid var(--ak-outline);
  border-radius: 2px;
  background: var(--ak-btn-ink);
  box-shadow: var(--ak-shadow);
}

.rung.is-open .latch {
  opacity: 0;
}

.rung.is-next .rung-inner {
  outline: 3px solid var(--ak-btn-ink);
  outline-offset: 1px;
  box-shadow: 0 0 0 3px var(--ak-accent), 0 0 16px var(--ak-glow);
}

.rung-inner.is-no {
  outline: 3px solid var(--ak-accent-2);
  outline-offset: 1px;
}

.rung:focus-visible,
.check:focus-visible,
.btn-go:focus-visible,
.btn-alt:focus-visible,
.mute:focus-visible,
.answer-input:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 3px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.well {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 48px;
  background: var(--ak-ink);
  box-shadow: var(--ak-shadow);
}

.well img {
  width: 100%;
  height: auto;
  pointer-events: none;
}

.well.is-wrong {
  outline: 3px solid var(--ak-accent-2);
  outline-offset: 2px;
}

.answer-input {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 50%;
  height: 48px;
  margin-top: -24px;
  padding: 0 8px;
  border: 0;
  border-radius: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  text-align: left;
  user-select: text;
  -webkit-user-select: text;
}

.answer-input:placeholder-shown {
  text-align: center;
}

.answer-input::placeholder {
  color: var(--ak-ink-muted);
  font-weight: 600;
}

.answer-input:disabled {
  opacity: 1;
  color: var(--ak-ink);
  -webkit-text-fill-color: var(--ak-ink);
}

.check {
  width: 76px;
  height: 76px;
  flex: 0 0 auto;
  padding: 0;
  border: 3px solid var(--ak-outline);
  border-radius: 50%;
  overflow: hidden;
  background: var(--ak-accent);
  box-shadow: var(--ak-shadow), 0 0 12px var(--ak-glow);
  cursor: pointer;
}

.check img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.16);
  pointer-events: none;
}

.check:active,
.rung:active,
.btn-go:active,
.btn-alt:active,
.mute:active {
  box-shadow: 0 0 0 var(--ak-outline);
}

.lip {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
  min-height: 28px;
  padding: 6px 12px;
  background: var(--ak-ink);
  border: 2px solid var(--ak-accent);
  box-shadow: var(--ak-shadow);
}

.lamp {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ak-ink-muted);
  box-shadow: inset 0 0 0 2px var(--ak-outline);
}

.lamp.is-lit {
  opacity: 1;
  background: var(--ak-btn-ink);
  box-shadow: 0 0 8px var(--ak-accent), 0 0 14px var(--ak-glow), inset 0 0 0 2px var(--ak-outline);
}

.why {
  border-color: var(--ak-accent);
}

.result {
  flex-shrink: 0;
}

.result-card {
  padding: 8px;
  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: clamp(16px, 4.4vw, 22px);
  font-weight: var(--ak-title-weight);
  line-height: 1.05;
  text-align: center;
  color: var(--ak-ink);
}

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

.btn-go,
.btn-alt {
  min-height: 48px;
  width: 100%;
  padding: 8px 12px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  font-family: var(--ak-font-display);
  font-size: clamp(18px, 5vw, 26px);
  font-weight: var(--ak-title-weight);
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: var(--ak-shadow);
}

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

.btn-alt {
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
}

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

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

.play.is-example .rungs,
.play.is-example .offer,
.play.is-example .coach,
.play.is-ending .voice,
.play.is-result .rungs,
.play.is-result .controls,
.play.is-result .offer,
.play.is-result .coach {
  display: none;
}

.card.is-flipped,
.rung.is-open .rung-inner {
  transform: none;
}

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

  .play-logo {
    height: 30px;
  }

  .voice,
  .why {
    padding: 4px 6px;
    font-size: 13px;
  }

  .card-scene {
    min-height: 148px;
  }

  .face-copy {
    font-size: 15px;
    top: 20%;
    bottom: 18%;
  }

  .story-copy {
    font-size: 13px;
  }

  .offer,
  .coach {
    padding: 2px 6px;
    font-size: 12px;
  }

  .coach::after {
    display: none;
  }

  .rungs {
    height: calc(48px * 4 + 6px);
    gap: 2px;
  }

  .check {
    width: 64px;
    height: 64px;
  }

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

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

  .play::before {
    animation: dome 3.4s ease-in-out infinite;
  }

  .card .face-front img {
    animation: idle-card 3.6s ease-in-out infinite;
  }

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

  .well.is-ready {
    animation: ready 1.8s ease-in-out infinite;
  }

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

  .rung.is-next .rung-inner {
    animation: pulse 1.35s ease-in-out infinite;
  }

  .rung-inner,
  .latch,
  .card,
  .lamp {
    transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.35s ease, box-shadow 0.35s ease;
  }

  .rung.is-open .latch {
    transform: translate(12px, -18px) rotate(28deg);
  }

  .card.is-flipped {
    animation: card-flip 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .rung.is-open .rung-inner {
    animation: rung-flip 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

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

  .check.is-press img {
    animation: press 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .check:active,
  .rung:active,
  .btn-go:active,
  .btn-alt:active,
  .mute:active {
    transform: translateY(2px) scale(0.96, 0.92);
  }

  .well.is-wrong {
    animation: shake 0.42s ease;
  }

  .rung-inner.is-no {
    animation: shake 0.42s ease;
  }

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

  .play.is-celebrate .card.is-flipped {
    animation: card-flip 0.55s cubic-bezier(0.34, 1.56, 0.64, 1), glow-chase 0.7s ease 3 0.55s;
  }

  .play.is-celebrate .lamp.is-lit {
    animation: lamp-chase 0.55s ease 3;
  }

  .play.is-celebrate .lamp.is-lit:nth-child(2) {
    animation-delay: 0.1s;
  }

  .play.is-celebrate .lamp.is-lit:nth-child(3) {
    animation-delay: 0.2s;
  }

  .play.is-celebrate .lamp.is-lit:nth-child(4) {
    animation-delay: 0.3s;
  }

  .result-card.is-in {
    animation: rise 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .why.is-in {
    animation: rise 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .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 dome {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
  }

  @keyframes idle-card {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.1) saturate(1.06); }
  }

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

  @keyframes ready {
    0%, 100% { box-shadow: var(--ak-shadow); }
    50% { box-shadow: var(--ak-shadow), 0 0 12px var(--ak-accent); }
  }

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

  @keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 3px var(--ak-accent), 0 0 8px var(--ak-glow); }
    50% { box-shadow: 0 0 0 4px var(--ak-btn-ink), 0 0 18px var(--ak-accent); }
  }

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

  @keyframes press {
    0% { transform: scale(1.16); filter: brightness(1); }
    35% { transform: scale(1.02, 0.96); filter: brightness(1.35); }
    100% { transform: scale(1.16); filter: brightness(1); }
  }

  @keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-7px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(2px); }
  }

  @keyframes spark {
    0%, 100% { filter: brightness(1); }
    40% { filter: brightness(1.45) drop-shadow(0 0 10px var(--ak-accent)); }
  }

  @keyframes glow-chase {
    0%, 100% { filter: drop-shadow(0 0 0 transparent); }
    50% { filter: drop-shadow(0 0 12px var(--ak-accent)); }
  }

  @keyframes lamp-chase {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.28); box-shadow: 0 0 16px var(--ak-accent); }
  }

  @keyframes rise {
    0% { transform: translateY(14px) scale(0.96); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
  }

  @keyframes card-flip {
    0% { transform: scaleX(1); }
    42% { transform: scaleX(0.06) scaleY(1.04); }
    100% { transform: scaleX(1) scaleY(1); }
  }

  @keyframes rung-flip {
    0% { transform: scaleX(1); }
    40% { transform: scaleX(0.08) scaleY(1.06); }
    100% { transform: scaleX(1) scaleY(1); }
  }

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