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

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

body {
  min-height: 100dvh;
  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(2px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  --cream: #f8f3e0;
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "top"
    "voice"
    "tip"
    "stage"
    "why"
    "result";
  gap: 4px;
  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);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.top { grid-area: top; }
.voice { grid-area: voice; }
.tip { grid-area: tip; }
.stage { grid-area: stage; }
.why { grid-area: why; }
.result { grid-area: result; }

.mute {
  position: absolute;
  top: var(--pad-top);
  right: max(4px, env(safe-area-inset-right, 0px));
  z-index: 9;
  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 {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding-right: 52px;
}

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

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

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

.turn-who {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 22px;
  line-height: 0.9;
  letter-spacing: 0.02em;
}

.turn-sub {
  font-size: 14px;
  line-height: 1.15;
  color: var(--ak-btn-ink);
}

.voice,
.tip,
.why,
.result-card,
.hint,
.btn-go,
.btn-alt {
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
}

.voice,
.tip,
.why {
  position: relative;
  z-index: 2;
  margin: 0;
  background: var(--ak-surface);
  color: var(--ak-ink);
}

.voice {
  padding: 6px 8px;
  font-size: 15px;
  line-height: 1.2;
}

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

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

.tip {
  padding: 4px 8px;
  font-size: 13px;
  line-height: 1.2;
  font-weight: 600;
}

.stage {
  position: relative;
  z-index: 1;
  align-self: end;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 6px;
  height: auto;
  max-height: 100%;
  min-height: 0;
  padding: 22px 1px 6px;
  background: color-mix(in srgb, var(--ak-ink) 84%, transparent);
  border: 3px solid var(--ak-accent);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  overflow: hidden;
}

.play.is-locked .stage {
  pointer-events: none;
}

.tableau {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  min-height: 0;
  height: auto;
  max-height: 100%;
  align-items: stretch;
}

.column {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-width: 0;
  min-height: 0;
  height: auto;
}

.column.is-hot {
  z-index: 3;
}

.lane-empty {
  width: 100%;
  aspect-ratio: 156 / 220;
  border: 2px dashed var(--ak-accent);
  border-radius: 10%;
  opacity: 0.8;
}

.face {
  --sheet-w: 374;
  --sheet-h: 384;
  --crop-x: 214;
  --crop-y: 158;
  --crop-w: 156;
  --crop-h: 220;
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 156 / 220;
  padding: 0;
  border: 0;
  border-radius: 10%;
  overflow: visible;
  background: transparent;
  color: var(--ak-ink);
  box-shadow: 2px 3px 0 var(--ak-outline);
  flex: 0 0 auto;
}

button.face {
  cursor: pointer;
  appearance: none;
  font: inherit;
  text-align: left;
}

.column .face + .face {
  margin-top: -48px;
}

.column .face:not(.near) {
  filter: saturate(0.92) brightness(0.97);
}

.paint {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 10%;
  background: var(--cream);
  pointer-events: none;
}

.paint::before {
  content: "";
  position: absolute;
  width: calc(var(--sheet-w) / var(--crop-w) * 100%);
  height: calc(var(--sheet-h) / var(--crop-h) * 100%);
  left: calc(var(--crop-x) / var(--crop-w) * -100%);
  top: calc(var(--crop-y) / var(--crop-h) * -100%);
  background: url("./art/rank-card.png") 0 0 / 100% 100% no-repeat;
}

.idx {
  position: absolute;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 1px;
  background: var(--cream);
  color: inherit;
  line-height: 1;
}

.idx b {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 16px;
  letter-spacing: -0.03em;
  text-shadow: 0.45px 0 0 currentColor, -0.45px 0 0 currentColor;
}

.face.is-ten .idx b {
  font-size: 13px;
}

.idx svg {
  width: 11px;
  height: 11px;
  display: block;
}

.idx-top {
  top: 4%;
  left: 7%;
  width: 58%;
  height: 32%;
  align-items: flex-start;
  padding-top: 0;
}

.idx-mid {
  left: 50%;
  top: 54%;
  width: 52%;
  height: 34%;
  transform: translate(-50%, -50%);
  justify-content: center;
}

.idx-mid svg {
  width: 78%;
  height: 78%;
}

.idx-bot {
  right: 4%;
  bottom: 3%;
  width: 42%;
  height: 28%;
  justify-content: flex-end;
  align-items: flex-end;
}

.idx-bot .flip {
  display: flex;
  align-items: center;
  gap: 1px;
  transform: rotate(180deg);
}

.face.is-red {
  color: var(--ak-accent-2);
}

.face.is-black {
  color: var(--ak-ink);
}

.near.is-fit {
  z-index: 2;
}

.near.is-fit::after,
.draw.is-ready::after {
  content: "";
  position: absolute;
  inset: -3px;
  border: 3px solid var(--ak-accent);
  box-shadow: 0 0 12px 3px var(--ak-accent), var(--ak-glow);
  pointer-events: none;
  z-index: 2;
  border-radius: inherit;
}

.badge {
  position: absolute;
  left: 50%;
  top: -16px;
  transform: translateX(-50%);
  z-index: 6;
  padding: 2px 3px;
  background: var(--ak-accent);
  color: var(--ak-ink);
  border: 2px solid var(--ak-outline);
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.pit {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 14px;
  min-height: 48px;
}

.slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.ring {
  position: relative;
  perspective: 520px;
  display: grid;
  place-items: center;
  width: min(112px, 30vw);
  height: min(112px, 30vw);
  border-radius: 50%;
  border: 7px solid var(--ak-accent);
  background:
    radial-gradient(circle at 50% 42%, color-mix(in srgb, var(--ak-accent) 28%, var(--ak-ink)) 0%, var(--ak-ink) 68%);
  box-shadow:
    0 0 0 3px var(--ak-outline),
    0 0 16px color-mix(in srgb, var(--ak-accent) 75%, transparent),
    var(--ak-glow);
}

.ring .face {
  width: 58%;
  border-radius: 10%;
  box-shadow: 2px 3px 0 var(--ak-ink);
}

.wink {
  position: absolute;
  inset: -8%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.95), transparent 62%);
  opacity: 0;
  pointer-events: none;
}

.slot-label {
  margin: 0;
  padding: 2px 8px;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  border: 2px solid var(--ak-accent);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}

.draw {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  width: 108px;
  min-width: 48px;
  min-height: 48px;
  padding: 2px 4px 4px;
  border: 2px solid var(--ak-accent);
  border-radius: var(--ak-radius);
  background: transparent;
  color: var(--ak-btn-ink);
  cursor: pointer;
}

.draw img {
  width: 96px;
  height: 64px;
  object-fit: contain;
}

.draw.is-empty img {
  opacity: 0.28;
}

.draw.is-point::before {
  content: attr(data-badge);
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -120%);
  z-index: 5;
  padding: 2px 4px;
  background: var(--ak-accent);
  color: var(--ak-ink);
  border: 2px solid var(--ak-outline);
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
}

.draw-count {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 22px;
  line-height: 0.85;
  color: var(--ak-accent);
}

.draw-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--ak-btn-ink);
}

.why {
  padding: 8px;
  font-size: 16px;
  line-height: 1.25;
  background: var(--ak-choice-bg);
}

.result {
  position: relative;
  z-index: 4;
  margin: 0;
}

.result-card {
  padding: 10px 10px 8px;
  background: var(--ak-surface);
  color: var(--ak-ink);
}

.result.is-win .result-card {
  border-color: var(--ak-accent);
  box-shadow: var(--ak-shadow), 0 0 0 3px var(--ak-accent);
}

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

.result-says {
  margin: 0 0 4px;
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: clamp(22px, 6vw, 30px);
  line-height: 0.95;
}

.result-draws {
  margin: 0 0 8px;
  font-size: 15px;
}

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

.btn-go,
.btn-alt,
.hint {
  min-height: 48px;
  padding: 8px 6px;
  cursor: pointer;
}

.btn-go {
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 22px;
  letter-spacing: 0.02em;
}

.btn-alt,
.hint {
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  border-color: var(--ak-choice-border);
  font-size: 15px;
  font-weight: 700;
}

.hint {
  top: calc(var(--pad-top) + 54px);
  right: max(4px, env(safe-area-inset-right, 0px));
  z-index: 8;
  min-width: 48px;
}

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

.near:active,
.draw:active,
.mute:active,
.hint:active,
.btn-go:active,
.btn-alt:active {
  filter: brightness(1.12);
}

.sweep {
  position: absolute;
  top: 0;
  bottom: 34%;
  left: 0;
  width: 42%;
  background: linear-gradient(
    90deg,
    transparent,
    color-mix(in srgb, var(--ak-accent) 88%, white),
    transparent
  );
  transform: translateX(-130%);
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}

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

.fx i {
  position: absolute;
  width: 8px;
  height: 14px;
  opacity: 0;
}

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

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

  .ring {
    animation: ring-idle 3s ease-in-out infinite;
  }

  .ring.is-win {
    animation: chase 0.8s linear 3;
  }

  .near.is-fit::after,
  .draw.is-ready::after {
    animation: fit-glow 1.15s ease-in-out infinite;
  }

  .near.is-point,
  .draw.is-point {
    animation: point-bob 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) infinite;
  }

  .face.is-land {
    animation: land 520ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .face.is-flip {
    animation: flip 440ms ease;
  }

  .face.is-drop {
    animation: drop 380ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .near.is-shake,
  .draw.is-shake {
    animation: shake 420ms ease;
  }

  .ring.is-wink .wink {
    animation: wink 420ms ease;
  }

  .sweep.is-on {
    animation: sweep 720ms ease;
  }

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

  .near:active,
  .draw:active,
  .mute:active,
  .btn-go:active,
  .btn-alt:active,
  .hint:active {
    transform: scale(0.94);
  }

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

@keyframes logo-idle {
  0%,
  100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-2px) rotate(1deg); }
}

@keyframes turn-cue {
  0% { transform: scale(1); }
  40% { transform: scale(1.08, 0.94); }
  100% { transform: scale(1); }
}

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

@keyframes chase {
  0% { box-shadow: 0 0 0 3px var(--ak-outline), 0 0 18px var(--ak-accent), var(--ak-glow); }
  50% { box-shadow: 0 0 0 3px var(--ak-accent-2), 0 0 22px var(--ak-btn-ink), var(--ak-glow); }
  100% { box-shadow: 0 0 0 3px var(--ak-outline), 0 0 18px var(--ak-accent), var(--ak-glow); }
}

@keyframes fit-glow {
  0%,
  100% { opacity: 0.45; }
  50% { opacity: 1; }
}

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

@keyframes land {
  0% { transform: translate(var(--dx, 0px), var(--dy, 0px)) scale(0.88); }
  58% { transform: translate(0, 0) scale(1.08, 0.9); }
  78% { transform: translate(0, -6px) scale(0.97, 1.06); }
  100% { transform: translate(0, 0) scale(1); }
}

@keyframes flip {
  0% { transform: rotateY(86deg) scale(0.9); filter: brightness(1.7); }
  68% { transform: rotateY(-8deg) scale(1.05, 0.94); filter: brightness(1.05); }
  100% { transform: none; filter: none; }
}

@keyframes drop {
  0% { transform: translateY(-18px) scale(1.06, 0.9); }
  70% { transform: translateY(3px) scale(0.98, 1.05); }
  100% { transform: none; }
}

@keyframes shake {
  0%,
  100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-6px) rotate(-2deg); }
  40% { transform: translateX(6px) rotate(2deg); }
  60% { transform: translateX(-3px) rotate(-1deg); }
  80% { transform: translateX(2px) rotate(1deg); }
}

@keyframes wink {
  0% { opacity: 0; }
  30% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes sweep {
  0% { opacity: 0.15; transform: translateX(-40%); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translateX(280%); }
}

@keyframes burst {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: 0; transform: translate(var(--x), var(--y)) rotate(var(--r)); }
}

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

@media (max-width: 359px) {
  .play {
    width: 100%;
  }
}
