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

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

body {
  min-height: 100dvh;
  height: 100dvh;
  display: flex;
  justify-content: center;
  font-family: var(--ak-font-body);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.25;
  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));
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto auto auto;
  gap: 6px;
  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: transparent;
  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,
.meter,
.keys,
.check,
.hint,
.result {
  position: relative;
  z-index: 2;
  min-width: 0;
}

.top { grid-row: 1; }
.voice { grid-row: 2; }
.stage { grid-row: 3; }
.meter { grid-row: 4; }
.keys { grid-row: 5; }
.check { grid-row: 6; }
.hint { grid-row: 7; }
.result { grid-row: 8; }

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

.logo-slot {
  height: 42px;
  width: min(48vw, 176px);
  overflow: hidden;
  flex: 0 0 auto;
}

.play-logo {
  width: 118%;
  height: 150%;
  max-width: none;
  object-fit: cover;
  object-position: center 42%;
  transform: translate(-8%, -16%);
  filter: drop-shadow(0 0 6px var(--ak-glow));
}

.turn {
  min-width: 0;
  padding: 6px 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,
.voice,
.meter-copy,
.mini-points,
.result-says,
.parade-note {
  margin: 0;
}

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

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

.voice {
  min-height: 44px;
  padding: 8px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  color: var(--ak-ink);
}

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

.monitor {
  position: relative;
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  max-width: 100%;
  max-height: 100%;
}

.bezel {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

.hole {
  position: absolute;
  left: 17%;
  top: 12.5%;
  width: 68%;
  height: 69%;
  overflow: hidden;
  background: var(--ak-bg);
  box-shadow: inset 0 0 18px color-mix(in srgb, var(--ak-glow) 55%, transparent);
}

.flag-bounce,
.flag-fit,
.scan,
.cursor {
  position: absolute;
}

.flag-bounce {
  inset: 0;
}

.flag-fit {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

.flag-fit svg,
.mini-flag svg {
  display: block;
  width: 100%;
  height: 100%;
}

.scan {
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.55;
  background: repeating-linear-gradient(
    to bottom,
    color-mix(in srgb, var(--ak-accent) 42%, transparent) 0 1px,
    transparent 1px 4px
  );
}

.cursor {
  z-index: 3;
  left: 7%;
  top: 8%;
  width: 9px;
  height: 15px;
  background: var(--ak-accent);
  box-shadow: 0 0 8px var(--ak-glow);
  pointer-events: none;
}

.meter {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 4px 8px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
}

.pip-board {
  position: relative;
  width: min(34vw, 128px);
  flex: 0 0 auto;
  aspect-ratio: 384 / 255;
}

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

.lamp {
  position: absolute;
  top: 42.5%;
  width: 11.6%;
  height: 17.5%;
  background: #2c2418;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ak-bg) 70%, black);
}

.lamp[data-i="0"] { left: 17.8%; }
.lamp[data-i="1"] { left: 44.2%; }
.lamp[data-i="2"] { left: 70.4%; }

.lamp.is-lit {
  background: var(--ak-accent);
  box-shadow: 0 0 8px var(--ak-glow);
}

.meter-copy {
  font-family: var(--ak-font-display);
  font-size: clamp(18px, 5vw, 26px);
  line-height: 1;
  color: var(--ak-ink);
}

.waiting,
.score {
  color: var(--ak-accent);
}

.keys {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.key {
  position: relative;
  min-width: 0;
  min-height: 56px;
  height: min(11dvh, 86px);
  padding: 0;
  border: none;
  background: transparent url("./art/country-key.png") center / 100% 100% no-repeat;
  color: var(--ak-btn-ink);
  cursor: pointer;
  touch-action: manipulation;
}

.key-name {
  position: absolute;
  left: 20%;
  right: 20%;
  top: 27%;
  bottom: 25%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  background: var(--ak-ink);
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-size: clamp(16px, 4.8vw, 26px);
  line-height: 0.92;
  text-align: center;
}

.key-name.is-long {
  font-size: clamp(14px, 3.7vw, 20px);
}

.key.is-picked .key-name {
  background: var(--ak-accent);
}

.key.is-right .key-name {
  background: var(--ak-accent-2);
}

.key.is-spent {
  filter: grayscale(0.85) brightness(0.58);
}

.check,
.hint,
.btn-go,
.btn-alt {
  min-height: 48px;
  border-radius: var(--ak-radius);
  border: 2px solid var(--ak-outline);
  box-shadow: var(--ak-shadow);
  font-family: var(--ak-font-display);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

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

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

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

.parade {
  width: 100%;
  padding: 8px;
}

.parade-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px 6px;
  align-items: end;
}

.mini {
  min-width: 0;
}

.mini-flag {
  width: 100%;
  overflow: hidden;
  background: var(--ak-bg);
  border: 1px solid var(--ak-outline);
}

.mini-points {
  font-family: var(--ak-font-display);
  font-size: 18px;
  line-height: 1.1;
  text-align: center;
  color: var(--ak-accent);
}

.mini-points.is-zero {
  color: var(--ak-ink-muted);
}

.result {
  z-index: 7;
}

.result-card {
  padding: 10px;
  border-color: var(--ak-accent);
}

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

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

.btn-go,
.btn-alt {
  width: 100%;
}

.play.is-ended .monitor,
.play.is-ended .meter,
.play.is-ended .keys,
.play.is-ended .check,
.play.is-ended .hint {
  display: none !important;
}

.play.is-ended .stage {
  align-items: center;
  justify-content: center;
}

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

.fx i {
  position: absolute;
  top: 42%;
  width: 8px;
  height: 12px;
  opacity: 0;
}

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

.key.is-coach,
.keys.is-pointing .key,
.check.is-point {
  outline: 3px solid var(--ak-focus);
  outline-offset: 3px;
}

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

.key:active .key-name,
.check:active,
.hint:active,
.btn-go:active,
.btn-alt:active,
.mute:active {
  background-color: var(--ak-btn-active);
}

.hint:active,
.btn-alt:active,
.mute:active {
  background: var(--ak-choice-bg);
}

@media (max-height: 700px) {
  .logo-slot { height: 32px; }
  .turn-who { font-size: 18px; }
  .voice { min-height: 36px; padding: 4px 8px; font-size: 13px; }
  .key { height: 56px; }
  .check,
  .hint,
  .btn-go,
  .btn-alt { min-height: 48px; font-size: 18px; }
  .play { gap: 4px; }
}

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

  .cursor {
    animation: blink 1.05s steps(1) infinite;
  }

  .scan {
    animation: drift 2.6s linear infinite;
  }

  .flag-fit {
    transition:
      left 520ms cubic-bezier(0.22, 1, 0.36, 1),
      top 520ms cubic-bezier(0.22, 1, 0.36, 1),
      width 520ms cubic-bezier(0.22, 1, 0.36, 1),
      height 520ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .flag-fit.is-instant {
    transition: none;
  }

  .keys .key {
    animation: keyglow 2.8s ease-in-out infinite;
  }

  .keys .key:nth-child(2) { animation-delay: 0.15s; }
  .keys .key:nth-child(3) { animation-delay: 0.3s; }
  .keys .key:nth-child(4) { animation-delay: 0.45s; }

  .keys.is-pointing .key,
  .key.is-coach,
  .check.is-point {
    animation: coach 0.9s cubic-bezier(0.34, 1.56, 0.64, 1) infinite;
  }

  .key.is-picked,
  .key.is-spent {
    animation: none;
  }

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

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

  .key.is-shake,
  .check.is-shake {
    animation: shake 380ms ease;
  }

  .key.is-yes {
    animation: yes 480ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .flag-bounce.is-land {
    animation: land 460ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .hole.is-smear {
    animation: smear 480ms ease;
  }

  .scan.is-ripple {
    animation: ripple 700ms linear;
  }

  .cursor.is-hop {
    animation: hop 460ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .lamp.is-land {
    animation: pip 420ms ease;
  }

  .score.is-pop,
  .waiting.is-pop {
    animation: pop 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .parade.is-chase {
    position: relative;
    overflow: hidden;
  }

  .parade.is-chase::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, transparent, var(--ak-glow), transparent);
    animation: chase 900ms ease forwards;
    pointer-events: none;
  }

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

  .key:active {
    transform: translateY(2px) scale(0.97);
  }

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

@keyframes bob {
  0%, 100% { transform: translate(-8%, -16%); }
  50% { transform: translate(-8%, -22%); }
}

@keyframes blink {
  0%, 45% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@keyframes drift {
  from { background-position: 0 0; }
  to { background-position: 0 8px; }
}

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

@keyframes coach {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-4px) scale(1.03, 0.97); }
}

@keyframes invite {
  0%, 100% { box-shadow: var(--ak-shadow); }
  50% { box-shadow: var(--ak-shadow), 0 0 14px var(--ak-glow); }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px) rotate(-1deg); }
  45% { transform: translateX(5px) rotate(1deg); }
  70% { transform: translateX(-3px); }
}

@keyframes yes {
  0% { transform: scale(1); }
  40% { transform: scale(1.08, 0.92); }
  70% { transform: scale(0.96, 1.05); }
  100% { transform: scale(1); }
}

@keyframes land {
  0% { transform: translateX(12%) scale(0.92, 1.06); opacity: 0.2; }
  60% { transform: translateX(0) scale(1.04, 0.96); opacity: 1; }
  100% { transform: none; opacity: 1; }
}

@keyframes smear {
  0% { filter: blur(0); }
  40% { filter: blur(2.5px); }
  100% { filter: blur(0); }
}

@keyframes ripple {
  0% { opacity: 0.35; background-position: 0 0; }
  45% { opacity: 0.9; }
  100% { opacity: 0.55; background-position: 0 14px; }
}

@keyframes hop {
  0% { transform: translateY(0) scale(1, 1); }
  40% { transform: translateY(-12px) scale(0.8, 1.25); }
  100% { transform: translateY(0) scale(1, 1); }
}

@keyframes pip {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  40% { transform: scale(1.2); filter: brightness(1.7); }
}

@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@keyframes chase {
  0% { transform: translateX(-120%); opacity: 0.9; }
  100% { transform: translateX(120%); opacity: 0; }
}

@keyframes burst {
  0% { transform: translate3d(0, 0, 0) scale(0.5) rotate(0deg); opacity: 1; }
  100% { transform: translate3d(var(--dx), 62vh, 0) rotate(var(--spin)); opacity: 0; }
}
