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

body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background-color: var(--ak-bg);
  background-image: var(--ak-bg-art);
  background-size: var(--ak-bg-size);
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
}

button,
.cell {
  font: inherit;
  color: inherit;
}

.play {
  position: relative;
  box-sizing: border-box;
  width: min(100%, 430px);
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(120px, 1fr) minmax(108px, 0.7fr) auto auto;
  gap: 4px;
  overflow: hidden;
  padding:
    calc(6px + env(safe-area-inset-top))
    calc(8px + env(safe-area-inset-right))
    calc(6px + env(safe-area-inset-bottom))
    calc(8px + env(safe-area-inset-left));
  background-image: var(--ak-backdrop-layer);
  background-size: cover;
  background-position: center top;
  touch-action: manipulation;
}

.play[hidden] {
  display: none !important;
}

.steam {
  position: absolute;
  width: 84px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--ak-btn-ink) 60%, transparent), transparent 68%);
  pointer-events: none;
  z-index: 1;
}

.steam-a {
  left: -20px;
  bottom: 18%;
}

.steam-b {
  right: -24px;
  top: 8%;
}

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

.mute {
  position: absolute;
  z-index: 8;
  top: calc(4px + env(safe-area-inset-top));
  right: calc(4px + env(safe-area-inset-right));
  width: 48px;
  height: 48px;
  padding: 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);
}

.mute svg {
  width: 32px;
  height: 32px;
  display: block;
  margin: 0 auto;
}

.mute .cross {
  display: none;
}

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

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

.top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding-right: 52px;
}

.logo {
  width: 72px;
  height: 36px;
  object-fit: contain;
  object-position: left center;
}

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

.turn-who,
.turn-sub,
.goal,
.voice,
.tip,
.why,
.clock-read,
.rail-name,
.result-says {
  margin: 0;
}

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

.turn-sub {
  color: var(--ak-ink-muted);
  font-size: 13px;
  line-height: 1.1;
}

.clock {
  width: 48px;
  height: 48px;
  position: relative;
  justify-self: end;
}

.clock svg {
  width: 48px;
  height: 48px;
  display: block;
  filter: drop-shadow(0 2px 0 var(--ak-accent-2));
}

.clock line {
  transform-box: view-box;
  transform-origin: 32px 32px;
  stroke-linecap: round;
}

.face-ring {
  fill: var(--ak-surface);
  stroke: var(--ak-outline);
  stroke-width: 3;
}

.face-hub {
  fill: var(--ak-accent);
}

.hand-min {
  stroke: var(--ak-ink);
  stroke-width: 3;
}

.hand-sec {
  stroke: var(--ak-accent);
  stroke-width: 2;
}

.clock-read {
  position: absolute;
  left: 50%;
  bottom: -2px;
  transform: translateX(-50%);
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 11px;
  line-height: 1;
  background: var(--ak-surface);
  border: 1px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  padding: 0 3px;
}

.clock.is-quiet .clock-read {
  visibility: hidden;
}

.copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.goal {
  font-size: 13px;
  line-height: 1.2;
  color: var(--ak-ink);
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  padding: 2px 8px;
}

.voice,
.why {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 18px;
  line-height: 1.15;
}

.tip {
  color: var(--ak-ink-muted);
  font-size: 13px;
  line-height: 1.2;
}

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

.tray {
  min-width: 0;
  min-height: 0;
  display: flex;
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  padding: 4px;
  overflow: hidden;
}

.board {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  overflow: clip;
  touch-action: none;
  position: relative;
  cursor: grab;
}

.board::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 18px color-mix(in srgb, var(--ak-ink) 40%, transparent);
}

.grid {
  --cell: 48px;
  width: calc(var(--cell) * 15);
  height: calc(var(--cell) * 15);
  display: grid;
  grid-template-columns: repeat(15, var(--cell));
  grid-template-rows: repeat(15, var(--cell));
  transform-origin: 0 0;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background-color: transparent;
  background-image: url('./art/cream-square.png');
  background-position: center;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  min-width: 0;
  min-height: 0;
}

.cell.is-black {
  background-image: url('./art/black-square.png');
}

.num {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: calc(var(--cell) * 0.22);
  line-height: 1;
  color: var(--ak-ink-muted);
  pointer-events: none;
}

.glyph {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: calc(var(--cell) * 0.5);
  line-height: 1;
  pointer-events: none;
}

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

.cell.is-pick {
  z-index: 1;
  box-shadow: var(--ak-glow), inset 0 0 0 2px var(--ak-accent);
}

.cell.is-bad {
  box-shadow: var(--ak-glow), inset 0 0 0 2px var(--ak-accent);
}

.cell.is-ok .glyph {
  color: var(--ak-btn-fill);
}

.rails {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.rail {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  container-type: inline-size;
}

.rail-name {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 14px;
  line-height: 1;
}

.rail-list {
  min-height: 0;
  min-width: 0;
  overflow-x: hidden;
  overflow-x: clip;
  overflow-y: auto;
  overflow-anchor: none;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 4px;
  touch-action: manipulation;
}

.ticket {
  box-sizing: border-box;
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 48px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  padding: 34px 12px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background-color: var(--ak-surface);
  background-image: url('./art/clue-ticket.png');
  background-repeat: no-repeat;
  background-size: 100% auto;
  background-position: center -64px;
  box-shadow: var(--ak-shadow);
  overflow: hidden;
}

@supports (width: 1cqw) {
  .ticket {
    padding: calc(100cqw * 0.2) 12px 10px;
    background-position: center calc(100cqw * -0.43);
  }
}

.ticket-n {
  flex: 0 0 auto;
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 16px;
  line-height: 1.3;
}

.ticket-clue {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: anywhere;
}

.ticket.is-on {
  box-shadow: var(--ak-glow), var(--ak-shadow), inset 0 0 0 2px var(--ak-accent);
}

.ticket.is-lit .ticket-clue {
  color: var(--ak-btn-fill);
}

.keys {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.key {
  min-height: 48px;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: var(--ak-radius);
  background-color: transparent;
  background-image: url('./art/letter-key.png');
  background-position: center;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 16px;
  line-height: 1;
}

.key-erase {
  grid-column: span 2;
  font-size: 14px;
}

.check,
.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-weight: var(--ak-title-weight);
  font-size: 18px;
}

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

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

.result {
  display: none;
  pointer-events: none;
}

.result[hidden] {
  display: none !important;
}

.result.is-open {
  display: grid;
  pointer-events: auto;
  position: absolute;
  z-index: 6;
  left: calc(8px + env(safe-area-inset-left));
  right: calc(8px + env(safe-area-inset-right));
  bottom: calc(8px + env(safe-area-inset-bottom));
  gap: 8px;
  padding: 10px;
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
}

.result-says {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 20px;
  line-height: 1.2;
}

.result-actions {
  display: grid;
  gap: 6px;
}

button:focus-visible,
.cell:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 1px;
}

button:active,
.cell:active {
  transform: translateY(1px);
}

@media (prefers-reduced-motion: no-preference) {
  .steam {
    animation: curl 7s ease-in-out infinite;
  }

  .steam-b {
    animation-delay: -3s;
  }

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

  .cell.is-pick {
    animation: flutter 1.1s ease-in-out infinite;
  }

  .cell.is-stamp .glyph {
    animation: stamp 0.22s ease-out;
  }

  .cell.is-shake {
    animation: shake 0.28s ease-in-out;
  }

  .cell.is-shine::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg, transparent 20%, var(--ak-btn-ink) 50%, transparent 80%);
    animation: shine 0.7s ease;
    pointer-events: none;
  }

  .turn.is-cue {
    animation: squish 0.32s ease;
  }

  .clock.is-hero {
    position: absolute;
    left: 50%;
    top: 38%;
    width: 120px;
    height: 120px;
    transform: translate(-50%, -50%);
    z-index: 5;
    animation: pop 0.45s ease;
  }

  .clock.is-hero svg {
    width: 120px;
    height: 120px;
  }

  .clock.is-hero .clock-read {
    font-size: 22px;
    bottom: 8px;
  }

  .key.is-tap,
  .ticket.is-tap,
  .check.is-tap,
  .mute.is-tap {
    animation: squish 0.18s ease;
  }

  .bit {
    position: absolute;
    left: 50%;
    top: 34%;
    width: 8px;
    height: 12px;
    border-radius: 2px;
    animation: burst 0.9s ease-out forwards;
    animation-delay: var(--d, 0s);
  }
}

@keyframes curl {
  0%,
  100% {
    transform: translateY(0) scale(1);
    opacity: 0.35;
  }
  50% {
    transform: translateY(-18px) scale(1.08);
    opacity: 0.7;
  }
}

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

@keyframes swing {
  from {
    transform: rotate(-1.1deg);
  }
  to {
    transform: rotate(1.1deg);
  }
}

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

@keyframes stamp {
  0% {
    transform: scale(1.4) rotate(-6deg);
  }
  100% {
    transform: scale(1) rotate(0);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(-3px);
  }
  70% {
    transform: translateX(3px);
  }
}

@keyframes shine {
  from {
    transform: translateX(-80%);
  }
  to {
    transform: translateX(80%);
  }
}

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

@keyframes pop {
  0% {
    transform: translate(-50%, -50%) scale(0.6);
  }
  60% {
    transform: translate(-50%, -50%) scale(1.08);
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes burst {
  to {
    transform: translate(var(--x), var(--y)) rotate(160deg);
    opacity: 0;
  }
}
