*,
*::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;
  margin: 0;
  touch-action: manipulation;
  cursor: pointer;
}

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(8px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, 420px);
  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, var(--ak-bg-art));
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

.lamp,
.hearth {
  position: absolute;
  z-index: 0;
  pointer-events: none;
}

.lamp {
  top: 0;
  right: 0;
  width: min(46%, 200px);
  height: min(42%, 320px);
  background: radial-gradient(circle at 78% 18%, color-mix(in srgb, var(--ak-accent-2) 62%, transparent), transparent 68%);
  opacity: 0.42;
}

.hearth {
  left: 0;
  bottom: 8%;
  width: min(36%, 150px);
  height: min(28%, 200px);
  background: radial-gradient(circle at 0 70%, color-mix(in srgb, var(--ak-accent) 48%, transparent), transparent 70%);
  opacity: 0.55;
}

.calc {
  position: absolute;
  z-index: 3;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 26px;
  border: 2px solid var(--ak-outline);
  border-radius: 4px;
  background: linear-gradient(180deg, var(--ak-accent-2), var(--ak-btn-fill));
  box-shadow: var(--ak-shadow);
  pointer-events: none;
  transform: rotate(8deg);
}

.calc-lid {
  display: block;
  height: 7px;
  margin: 3px 3px 0;
  border-radius: 2px;
  background: var(--ak-ink);
  opacity: 0.45;
}

.top,
.prompt,
.stage,
.lip,
.tiles,
.check,
.result {
  position: relative;
  z-index: 1;
}

.mute {
  position: absolute;
  z-index: 7;
  top: var(--pad-top);
  right: var(--pad-x);
  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);
}

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

.slash {
  display: none;
}

.mute.is-muted .slash {
  display: block;
}

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

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

.play-logo {
  height: min(48px, 6dvh);
  width: auto;
  max-width: min(46%, 180px);
  object-fit: contain;
}

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

.turn-who,
.turn-sub,
.kicker,
.num,
.ask,
.voice,
.why,
.result-says {
  margin: 0;
}

.turn-who {
  font-family: var(--ak-font-display);
  font-size: min(22px, 2.6dvh);
  line-height: 1.05;
}

.turn-sub {
  color: var(--ak-ink-muted);
  font-size: 12px;
  letter-spacing: 0.04em;
}

.prompt {
  display: flex;
  align-items: stretch;
  gap: 6px;
  margin-top: 4px;
}

.voice,
.why {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 8px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
  font-size: clamp(12px, 1.7dvh, 15px);
  line-height: 1.3;
}

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

.hint {
  flex: 0 0 auto;
  min-width: 64px;
  min-height: 48px;
  padding: 0 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  box-shadow: var(--ak-shadow);
  font-family: var(--ak-font-display);
  font-size: 16px;
  font-weight: 700;
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 6px;
}

.drawer {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  min-height: 0;
  padding: 4px 6px 8px;
  overflow: hidden;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--ak-accent) 78%, var(--ak-ink)) 0%, color-mix(in srgb, var(--ak-accent) 48%, var(--ak-bg)) 100%);
  box-shadow: var(--ak-shadow), inset 0 0 0 3px color-mix(in srgb, var(--ak-bg) 28%, transparent);
}

.person {
  position: relative;
  z-index: 2;
  align-self: flex-start;
  height: min(84px, 11dvh);
  width: auto;
  aspect-ratio: 384 / 373;
  margin: 0 0 -10px 4px;
  pointer-events: none;
}

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

.ask {
  position: absolute;
  left: 16%;
  right: 16%;
  top: 34%;
  text-align: center;
  font-family: var(--ak-font-display);
  font-size: clamp(11px, 1.6dvh, 15px);
  line-height: 1;
  color: var(--ak-ink);
}

.receipt.is-point {
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--ak-accent-2) 85%, transparent));
}

.lip.is-point::after {
  content: '';
  position: absolute;
  left: 22px;
  top: -7px;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 8px solid var(--ak-accent-2);
}

.receipt {
  position: relative;
  flex: 1 1 auto;
  width: min(86%, 292px);
  min-height: 0;
  display: flex;
  background: url("./art/receipt.png") center / 100% 100% no-repeat;
  padding: 22% 12% 18% 18%;
}

.lines {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  font-size: clamp(11px, 1.55dvh, 14px);
  line-height: 1.15;
}

.line {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  column-gap: 4px;
  align-items: center;
  padding: 0 2px;
  border-radius: 4px;
}

.meta {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 6px;
  min-width: 0;
}

.line.is-ask {
  background: color-mix(in srgb, var(--ak-accent) 12%, transparent);
}

.line.is-fault {
  outline: 2px solid var(--ak-accent-2);
  outline-offset: 1px;
}

.line.is-split {
  border-top: 1px solid color-mix(in srgb, var(--ak-outline) 28%, transparent);
  margin-top: 1px;
  padding-top: 1px;
}

.plate {
  grid-row: 1;
  width: 20px;
  height: auto;
}

.plate-gap {
  grid-row: 1;
  width: 20px;
  height: 1px;
}

.name {
  font-weight: 800;
}

.line.is-extra .name {
  grid-column: 2;
}

.who {
  color: var(--ak-ink-muted);
  font-size: 0.92em;
  font-weight: 600;
}

.who strong {
  color: var(--ak-accent);
  font-weight: 800;
}

.price {
  grid-column: 3;
  grid-row: 1;
  font-family: var(--ak-font-display);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.wax {
  border-radius: 50%;
  background: var(--ak-accent-2);
  border: 2px solid var(--ak-outline);
  box-shadow: 0 0 8px color-mix(in srgb, var(--ak-accent-2) 75%, transparent);
}

.receipt > .wax {
  position: absolute;
  top: 13%;
  left: 46%;
  width: min(18px, 8%);
  aspect-ratio: 1;
  transform: translateX(-50%);
}

.lip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  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);
}

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

.dots {
  display: flex;
  gap: 5px;
  flex: 0 0 auto;
}

.dots i {
  display: block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--ak-outline);
  border-radius: 50%;
  background: color-mix(in srgb, var(--ak-bg) 72%, var(--ak-surface));
}

.dots i.is-lit {
  background: var(--ak-accent-2);
  box-shadow: 0 0 8px color-mix(in srgb, var(--ak-accent-2) 80%, transparent);
}

.amount {
  flex: 1 1 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.kicker {
  color: var(--ak-ink-muted);
  font-size: 12px;
  letter-spacing: 0.04em;
}

.num {
  font-family: var(--ak-font-display);
  font-size: min(36px, 5dvh);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.num.is-blank {
  color: var(--ak-ink-muted);
}

.tiles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin-top: 6px;
}

.tile {
  flex: 0 0 calc((100% - 20px) / 6);
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  padding: 0 0 4px;
  border: 0;
  background: url("./art/number-tile.png") center / 100% 100% no-repeat;
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: clamp(18px, 4.6vw, 24px);
  font-weight: 700;
}

.tile-del {
  font-size: 14px;
  letter-spacing: 0.02em;
}

.tile:disabled {
  opacity: 0.55;
  filter: saturate(0.65);
}

.check,
.btn {
  min-height: 48px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  font-family: var(--ak-font-display);
  font-weight: 700;
}

.check {
  width: 100%;
  margin-top: 6px;
  padding: 8px 12px;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-size: 17px;
}

.play.is-ended .tiles,
.play.is-ended .check {
  opacity: 0.4;
  pointer-events: none;
}

.play.is-card .tiles,
.play.is-card .check {
  display: none;
}

.result {
  margin-top: 6px;
}

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

.play.is-win .result-card {
  border-color: var(--ak-accent-2);
}

.result-says {
  margin-bottom: 8px;
  font-size: clamp(14px, 1.9dvh, 18px);
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
}

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

.btn {
  width: 100%;
  padding: 8px 12px;
  font-size: 17px;
}

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

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

.fan {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.fan-slip {
  position: relative;
  width: min(34%, 120px);
  margin: 0 -3%;
  --rot: 0deg;
  --ty: 0px;
  transform: rotate(var(--rot)) translateY(var(--ty));
}

.fan-slip:nth-child(1) {
  --rot: -16deg;
  --ty: 10px;
}

.fan-slip:nth-child(2) {
  --rot: 0deg;
  --ty: -8px;
  z-index: 1;
}

.fan-slip:nth-child(3) {
  --rot: 16deg;
  --ty: 10px;
}

.fan-slip img {
  width: 100%;
  height: auto;
}

.fan-slip .wax {
  position: absolute;
  top: 12%;
  left: 50%;
  width: 14px;
  height: 14px;
  transform: translateX(-50%);
}

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

.fx i {
  position: absolute;
  top: 12%;
  width: 8px;
  height: 12px;
  opacity: 0;
  background: var(--ak-accent);
}

.mute:focus-visible,
.hint:focus-visible,
.tile:focus-visible,
.check:focus-visible,
.btn:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 2px;
}

.tile:active:not(:disabled),
.check:active,
.btn:active,
.mute:active,
.hint:active {
  filter: brightness(1.12);
}

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .check:hover,
  .btn-go:hover {
    background: var(--ak-btn-hover);
  }

  .hint:hover,
  .btn-alt:hover,
  .mute:hover {
    transform: translateY(-1px);
  }
}

@media (max-height: 700px) {
  .play-logo {
    height: 32px;
  }

  .person {
    height: 48px;
    margin-bottom: -4px;
  }

  .voice,
  .why {
    padding: 4px 6px;
  }

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

  .num {
    font-size: 26px;
  }

  .lines {
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .receipt.is-curl {
    opacity: 1;
    transform: rotate(22deg) translateY(8%) scale(0.78, 0.34);
  }
}

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

  .lamp {
    animation: lamp-idle 4.6s ease-in-out infinite;
  }

  .hearth {
    animation: hearth-idle 3.8s ease-in-out infinite;
  }

  .play.is-win .lamp {
    animation: lamp-win 900ms ease-in-out 3;
  }

  .receipt.is-idle {
    animation: flutter 3.2s ease-in-out infinite;
  }

  .receipt.is-rise {
    animation: rise-slip var(--rise-ms, 620ms) cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }

  .receipt.is-curl {
    animation: curl-away var(--curl-ms, 720ms) cubic-bezier(0.45, 0, 0.7, 0.4) forwards;
  }

  .receipt > .wax.is-pop {
    animation: wax-pop var(--stamp-ms, 680ms) cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }

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

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

  .lip.is-point::after {
    animation: bob 1s ease-in-out infinite;
  }

  .tile.is-bounce {
    animation: tile-pop 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .tile:active:not(:disabled) {
    transform: scale(0.92, 0.82) translateY(2px);
  }

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

  .dots i.is-pop {
    animation: dot-pop 480ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .why.is-on,
  .result.is-on .result-card {
    animation: rise-in 420ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }

  .play.is-win .fan-slip {
    animation: fan-in 640ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
    animation-delay: calc(var(--i) * 90ms);
  }

  .play.is-win .fan-slip .wax {
    animation: glow-chase 680ms ease-in-out 3;
    animation-delay: calc(240ms + var(--i) * 120ms);
  }

  .fx i {
    animation: confetti 980ms ease-out forwards;
  }
}

@keyframes logo-float {
  0%,
  100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

@keyframes lamp-idle {
  0%,
  100% { opacity: 0.34; }
  50% { opacity: 0.62; }
}

@keyframes hearth-idle {
  0%,
  100% { opacity: 0.4; }
  50% { opacity: 0.7; }
}

@keyframes lamp-win {
  0%,
  100% { opacity: 0.55; }
  50% { opacity: 1; }
}

@keyframes flutter {
  0%,
  100% { transform: rotate(-0.5deg) translateY(0); }
  50% { transform: rotate(0.8deg) translateY(-4px); }
}

@keyframes rise-slip {
  0% { opacity: 0; transform: translateY(48%) rotate(-8deg) scale(0.92, 1.08); }
  64% { opacity: 1; transform: translateY(-2%) rotate(1.5deg) scale(1.04, 0.94); }
  100% { opacity: 1; transform: rotate(-0.3deg) scale(1); }
}

@keyframes curl-away {
  0% { transform: rotate(-0.3deg) scale(1); opacity: 1; }
  42% { transform: rotate(-12deg) scale(0.94, 0.72); opacity: 1; }
  100% { transform: rotate(22deg) translateY(8%) scale(0.78, 0.34); opacity: 1; }
}

@keyframes wax-pop {
  0% { transform: translateX(-50%) scale(0.2); opacity: 0; }
  62% { transform: translateX(-50%) scale(1.18); opacity: 1; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

@keyframes cue {
  0% { transform: scale(0.96); }
  55% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

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

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

@keyframes tile-pop {
  0% { transform: scale(1); }
  35% { transform: scale(0.9, 0.78) translateY(3px); }
  70% { transform: scale(1.06, 1.1) translateY(-2px); }
  100% { transform: scale(1) translateY(0); }
}

@keyframes dot-pop {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

@keyframes rise-in {
  0% { opacity: 0; transform: translateY(10px) scale(0.98); }
  100% { opacity: 1; transform: none; }
}

@keyframes fan-in {
  0% { opacity: 0; transform: translateY(36%) rotate(0deg) scale(0.8); }
  100% { opacity: 1; transform: rotate(var(--rot)) translateY(var(--ty)) scale(1); }
}

@keyframes glow-chase {
  0%,
  100% { filter: brightness(1); }
  50% { filter: brightness(1.5); box-shadow: 0 0 12px var(--ak-accent-2); }
}

@keyframes confetti {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(72dvh) rotate(220deg); opacity: 0; }
}
