*,
*::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));
  container-type: size;
  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);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

.art-frame {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 0;
  width: 100%;
  height: 100%;
  width: max(100cqw, calc(100cqh * 0.7467));
  height: max(100cqh, calc(100cqw * 1.3393));
  transform: translateX(-50%);
  pointer-events: none;
  container-type: size;
}

.clock {
  position: absolute;
  left: 50%;
  top: 18%;
  width: min(86vw, 44dvh);
  width: calc(100cqh * 0.44);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
}

.play.is-ended .clock {
  width: min(62vw, 30dvh);
  width: calc(100cqh * 0.32);
}

.dial {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
}

.dial.is-mirror {
  transform: scaleX(-1);
}

.dial.is-turn {
  transform: rotate(90deg);
}

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

.cream {
  position: absolute;
  left: 50%;
  top: 51%;
  width: 60%;
  height: 60%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #faebcc;
}

.marks {
  position: absolute;
  inset: 8%;
  z-index: 2;
  overflow: visible;
}

.marks text {
  font-family: var(--ak-font-display);
  font-weight: 800;
  font-size: 8px;
  fill: var(--ak-ink);
}

.marks.is-roman text {
  font-size: 4.5px;
}

.marks text.is-twelve {
  font-size: 9px;
}

.marks.is-roman text.is-twelve {
  font-size: 5px;
}

.marks .tick {
  stroke: var(--ak-ink);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.marks .tick-twelve {
  stroke: var(--ak-accent);
  stroke-width: 2.4;
}

.hand {
  position: absolute;
  z-index: 3;
  left: 32.17%;
  top: 31.52%;
  width: 42%;
  aspect-ratio: 384 / 260;
  height: auto;
  object-fit: fill;
  transform-origin: 42.45% 65%;
  pointer-events: none;
}

.hand-hour {
  z-index: 3;
  clip-path: inset(0 52% 0 0);
}

.hand-minute {
  z-index: 4;
  clip-path: inset(0 0 0 38%);
}

.hub {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 50%;
  width: 8%;
  height: 8%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--ak-accent-2);
  border: 2px solid var(--ak-surface);
  box-shadow: 0 0 0 2px var(--ak-outline);
}

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

.flakes i {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ak-surface);
  opacity: 0.85;
}

.flakes i:nth-child(1) { left: 8%; top: 12%; }
.flakes i:nth-child(2) { left: 88%; top: 18%; width: 4px; height: 4px; }
.flakes i:nth-child(3) { left: 14%; top: 46%; width: 5px; height: 5px; }
.flakes i:nth-child(4) { left: 78%; top: 42%; }
.flakes i:nth-child(5) { left: 50%; top: 8%; width: 4px; height: 4px; }

.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);
  transform: rotate(-35deg);
}

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

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

.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,
.face-line,
.voice,
.stamp {
  margin: 0;
}

.turn-who {
  font-family: var(--ak-font-display);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--ak-ink);
}

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

.spacer {
  flex: 1 1 auto;
  min-height: 0;
}

.lower {
  position: relative;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.face-line {
  padding: 6px 10px;
  font-family: var(--ak-font-display);
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  color: var(--ak-ink);
}

.voice {
  min-height: 44px;
  padding: 8px 10px;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  color: var(--ak-ink);
}

.btn-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: 16px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

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

.tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  position: relative;
}

.tiles::after {
  content: "";
  position: absolute;
  left: -2%;
  right: -2%;
  bottom: 1px;
  height: 10px;
  border-radius: 40%;
  background: color-mix(in srgb, var(--ak-surface) 88%, var(--ak-accent-2));
  pointer-events: none;
  z-index: 2;
}

.tile {
  position: relative;
  z-index: 1;
  min-width: 0;
  min-height: 64px;
  padding: 14px 2px 16px;
  border: none;
  background-color: transparent;
  background-image: url("./art/time-tile.png");
  background-repeat: no-repeat;
  background-size: 400% 100%;
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: clamp(16px, 5cqw, 22px);
  font-weight: 800;
  letter-spacing: -0.02em;
  text-shadow: 0 1px 0 var(--ak-surface);
  cursor: pointer;
  touch-action: manipulation;
}

.tile:active {
  filter: brightness(0.94);
}

.tile.is-worked,
.tile.is-right {
  box-shadow: 0 0 0 4px var(--ak-accent);
  border-radius: 12px;
}

.tile.is-wrong {
  border-radius: 12px;
}

.stamp {
  padding: 8px 10px;
  font-family: var(--ak-font-display);
  font-size: 20px;
  font-weight: 800;
  text-align: center;
  color: var(--ak-ink);
}

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

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

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

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

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

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

.play.is-ended .lower {
  padding: 8px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: color-mix(in srgb, var(--ak-surface) 94%, var(--ak-bg));
  box-shadow: var(--ak-shadow);
}

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

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

.fx i,
.fx .puff {
  position: absolute;
  opacity: 0;
}

.fx i {
  top: 16%;
  width: 8px;
  height: 12px;
  border-radius: 2px;
}

.fx .puff {
  width: 10px;
  height: 10px;
  margin-left: -5px;
  border-radius: 50%;
  background: var(--ak-surface);
  box-shadow: 0 0 0 2px var(--ak-accent);
}

@media (hover: hover) {
  .btn-go:hover {
    background: var(--ak-btn-hover);
  }

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

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

  .voice {
    min-height: 0;
    padding: 6px 8px;
    font-size: 14px;
  }

  .face-line {
    font-size: 13px;
    padding: 4px 8px;
  }

  .tile {
    min-height: 56px;
    padding-top: 10px;
  }

  .result-says,
  .stamp {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .flakes i {
    animation: drift 4.8s ease-in-out infinite;
  }

  .flakes i:nth-child(2) { animation-delay: -1.2s; }
  .flakes i:nth-child(3) { animation-delay: -2s; }
  .flakes i:nth-child(4) { animation-delay: -3s; }
  .flakes i:nth-child(5) { animation-delay: -0.6s; }

  .clock.is-idle {
    animation: idle-bob 3.4s ease-in-out infinite;
  }

  .clock.is-pop {
    animation: clock-pop 640ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }

  .clock.is-slide {
    animation: clock-slide 520ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  .clock.is-sink {
    animation: clock-sink 280ms ease-in both;
  }

  .clock.is-chase::after {
    content: "";
    position: absolute;
    inset: -3%;
    border-radius: 50%;
    background: conic-gradient(from 0deg, transparent, var(--ak-accent), var(--ak-accent-2), transparent 42%);
    animation: chase 1.1s linear infinite;
    pointer-events: none;
  }

  .hand {
    transition: transform 720ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

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

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

  .tile.is-worked {
    animation: worked 1.2s ease-in-out infinite;
  }

  .tile.is-right {
    animation: glow 700ms ease-in-out 2;
  }

  .tile.is-wrong {
    animation: shake 420ms ease-in-out 1;
  }

  .tile:active {
    transform: translateY(6px) scale(0.96, 0.88);
  }

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

  .stamp.is-on {
    animation: stamp 480ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }

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

  .fx .puff {
    animation: puff 620ms ease-out forwards;
  }
}

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

@keyframes idle-bob {
  0%, 100% { transform: translate(-50%, -50%) rotate(-0.7deg); }
  50% { transform: translate(-50%, -53%) rotate(0.7deg); }
}

@keyframes clock-pop {
  0% { transform: translate(-50%, -30%) scale(0.62); opacity: 0; }
  58% { transform: translate(-50%, -50%) scale(1.06, 0.92); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes clock-slide {
  0% { transform: translate(28%, -50%) scale(0.86); opacity: 0; }
  70% { transform: translate(-52%, -50%) scale(1.04, 0.95); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes clock-sink {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -8%) scale(0.8); opacity: 0; }
}

@keyframes chase {
  to { transform: rotate(360deg); }
}

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

@keyframes invite {
  0%, 100% { box-shadow: var(--ak-shadow); }
  50% { box-shadow: var(--ak-shadow), 0 0 0 4px color-mix(in srgb, var(--ak-accent) 35%, transparent); }
}

@keyframes worked {
  0%, 100% { box-shadow: 0 0 0 3px var(--ak-accent); }
  50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--ak-accent) 45%, transparent); }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px) rotate(-2deg); }
  75% { transform: translateX(7px) rotate(2deg); }
}

@keyframes stamp {
  0% { transform: scale(1.6) rotate(-8deg); opacity: 0; }
  60% { transform: scale(0.94) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(-2deg); opacity: 1; }
}

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

@keyframes puff {
  0% { transform: translate(0, 0) scale(0.4); opacity: 1; }
  100% { transform: translate(var(--dx, 0px), var(--dy, -28px)) scale(1.2); opacity: 0; }
}
