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

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

body {
  min-height: 100dvh;
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  font-size: 16px;
  line-height: 1.25;
  background-color: var(--ak-bg);
  background-image: var(--ak-bg-art);
  background-size: var(--ak-bg-size);
}

button {
  font-family: inherit;
  color: inherit;
  touch-action: manipulation;
  cursor: pointer;
}

img {
  -webkit-user-drag: none;
}

[hidden] {
  display: none !important;
}

.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;
  gap: 6px;
  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-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;
}

.mute {
  position: absolute;
  top: var(--pad-top);
  right: max(8px, env(safe-area-inset-right, 0px));
  z-index: 10;
  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: 22px;
  height: 22px;
}

.mute-icon .slash {
  display: none;
}

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

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

.hud {
  position: relative;
  z-index: 9;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 6px 6px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: color-mix(in srgb, var(--ak-surface) 88%, transparent);
  box-shadow: var(--ak-shadow);
}

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

.play-logo {
  display: block;
  width: auto;
  height: 36px;
  max-width: 38%;
  object-fit: contain;
}

.turn {
  flex: 1 1 auto;
  min-width: 0;
}

.turn-who,
.turn-sub,
.voice,
.goal,
.why,
.trip-word,
.bank-name,
.pilot,
.result-says,
.result-score {
  margin: 0;
}

.turn-who {
  font-family: var(--ak-font-display);
  font-size: 28px;
  font-weight: var(--ak-title-weight);
  line-height: 0.9;
  color: var(--ak-ink);
}

.turn-sub {
  font-size: 12px;
  color: var(--ak-ink-muted);
  white-space: nowrap;
}

.trips {
  display: grid;
  justify-items: end;
  flex: 0 0 auto;
  margin: 0;
  line-height: 1;
  color: var(--ak-accent);
}

.trip-count {
  font-family: var(--ak-font-display);
  font-size: 32px;
  font-weight: var(--ak-title-weight);
}

.trip-word {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.trips.is-hot {
  color: var(--ak-bg);
  background: var(--ak-accent-2);
  box-shadow: 0 0 12px var(--ak-glow);
  padding: 0 4px;
}

.voice {
  min-height: 1.3em;
  font-size: 15px;
  font-weight: 600;
  color: var(--ak-ink);
}

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

.goal {
  font-size: 12px;
  color: var(--ak-ink-muted);
}

.why {
  font-size: 15px;
  font-weight: 600;
  color: var(--ak-accent-2);
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  touch-action: manipulation;
}

.bezel {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(128px, 0.78fr) minmax(0, 1.02fr);
  height: 100%;
  min-height: 0;
  border: 3px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: transparent;
  box-shadow: var(--ak-shadow), inset 0 0 24px color-mix(in srgb, var(--ak-bg) 55%, transparent);
  overflow: hidden;
}

.led {
  position: absolute;
  top: 6px;
  right: 8px;
  z-index: 8;
  width: 10px;
  height: 10px;
  background: var(--ak-accent-2);
  box-shadow: 0 0 8px var(--ak-accent-2);
}

.bank {
  position: relative;
  z-index: 2;
  min-height: 0;
  overflow: hidden;
  background: var(--ak-bg);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--ak-outline) 55%, transparent);
}

.bank.is-tied {
  box-shadow: inset 0 0 0 3px var(--ak-accent), 0 0 16px color-mix(in srgb, var(--ak-glow) 55%, transparent);
}

.bank.is-over {
  box-shadow: inset 0 0 0 3px var(--ak-accent-2);
}

.dock-img {
  display: none;
}

.bank-near,
.bank-far {
  background-image: url("./art/docks.png");
  background-repeat: no-repeat;
  background-size: 230% auto;
  background-position: 28% 80%;
}

.bank-far {
  background-size: 200% auto;
  background-position: 64% 84%;
}

.bank::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    var(--ak-bg) 0%,
    color-mix(in srgb, var(--ak-bg) 92%, transparent) 34%,
    transparent 62%
  );
}

.bank-name {
  position: absolute;
  z-index: 4;
  top: 4px;
  left: 4px;
  padding: 1px 6px;
  font-family: var(--ak-font-display);
  font-size: 20px;
  line-height: 1;
  color: var(--ak-ink);
  background: color-mix(in srgb, var(--ak-surface) 86%, transparent);
  border: 2px solid var(--ak-outline);
}

.row {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  height: 100%;
  min-height: 0;
  padding: 26px 4px 6px;
}

.token {
  position: relative;
  flex: 1 1 48px;
  width: clamp(48px, 18%, 72px);
  max-width: 72px;
  min-width: 48px;
  height: min(100%, 124px);
  min-height: 48px;
  padding: 0;
  overflow: hidden;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-bg);
  box-shadow: var(--ak-shadow);
}

.token.is-lift {
  opacity: 0.35;
}

.token.is-point,
.btn-go.is-point,
.seat.is-point {
  box-shadow: 0 0 0 3px var(--ak-accent-2), 0 0 14px var(--ak-glow);
}

.face,
.plate {
  position: relative;
  display: block;
  width: 100%;
  overflow: hidden;
}

.face {
  height: 72%;
}

.plate {
  height: 28%;
}

.token.is-aboard .plate {
  display: none;
}

.token.is-aboard .face {
  height: 100%;
}

.face img,
.plate img {
  position: absolute;
  max-width: none;
  pointer-events: none;
}

.river {
  position: relative;
  z-index: 2;
  min-height: 0;
}

.ferry {
  position: absolute;
  left: 50%;
  top: 0;
  z-index: 3;
  width: min(236px, 84%);
  height: min(108px, 74%);
  overflow: hidden;
  transform: translate(-50%, 0);
}

.ferry-img {
  position: absolute;
  width: 168%;
  height: auto;
  left: 50%;
  top: 54%;
  transform: translate(-50%, -46%);
  pointer-events: none;
}

.pilot {
  position: absolute;
  z-index: 4;
  left: 8%;
  bottom: 18%;
  font-family: var(--ak-font-display);
  font-size: 22px;
  line-height: 1;
  color: var(--ak-btn-ink);
  background: var(--ak-accent);
  padding: 2px 6px;
  box-shadow: 0 0 10px var(--ak-glow);
}

.seats {
  position: absolute;
  z-index: 4;
  left: 30%;
  right: 14%;
  top: 34%;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.seats[data-count="1"] {
  justify-content: flex-start;
  padding-left: 2%;
}

.seat {
  position: relative;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  outline: none;
}

.seat.is-over {
  box-shadow: inset 0 0 0 3px var(--ak-accent-2);
}

.seat .token {
  width: 48px;
  height: 48px;
  min-width: 0;
  max-width: none;
  min-height: 0;
}

.cursor {
  position: absolute;
  left: 14px;
  top: 10px;
  width: 14px;
  height: 22px;
  background: var(--ak-accent);
  box-shadow: 0 0 10px var(--ak-glow);
}

.seat.is-filled .cursor {
  display: none;
}

.seat.is-coach::before {
  content: "";
  position: absolute;
  left: 16px;
  top: -14px;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 12px solid var(--ak-accent-2);
  filter: drop-shadow(0 0 6px var(--ak-glow));
}

.shutter {
  position: absolute;
  z-index: 3;
  right: 16%;
  top: 32%;
  width: 22%;
  height: 30%;
  background: var(--ak-bg);
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--ak-outline) 40%, transparent);
}

.wake {
  position: absolute;
  z-index: 2;
  left: 6%;
  bottom: 30%;
  width: 36px;
  height: 28px;
  opacity: 0;
}

.wake i {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--ak-accent);
  box-shadow: 0 0 6px var(--ak-glow);
}

.wake i:nth-child(2) {
  left: 12px;
  top: 8px;
}

.wake i:nth-child(3) {
  left: 4px;
  top: 16px;
}

.wake i:nth-child(4) {
  left: 20px;
  top: 4px;
}

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

.link-seg {
  position: absolute;
  left: 0;
  top: 0;
  height: 12px;
  transform-origin: left center;
  background-image: url("./art/clash-link.png");
  background-repeat: no-repeat;
  background-size: 256% 942%;
  background-position: 51% 50%;
  filter: drop-shadow(0 0 4px var(--ak-glow));
}

.link-seg.is-tight {
  height: 16px;
}

.link-seg.is-slack {
  height: 10px;
  opacity: 0.82;
}

.link-seg.is-yank {
  height: 18px;
  filter: brightness(1.45) drop-shadow(0 0 8px var(--ak-accent-2));
}

.scan,
.glass {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
}

.scan {
  opacity: 0.45;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(255, 176, 32, 0.16) 0px,
    rgba(255, 176, 32, 0.16) 1px,
    transparent 1px,
    transparent 4px
  );
  background-size: 100% 8px;
}

.glass {
  background: radial-gradient(ellipse at center, transparent 58%, color-mix(in srgb, var(--ak-bg) 48%, transparent) 100%);
}

.keycap {
  position: absolute;
  left: 14%;
  bottom: -16px;
  z-index: 1;
  width: 54px;
  height: 34px;
  border: 2px solid var(--ak-outline);
  background: var(--ak-surface);
  box-shadow: inset 0 3px 0 var(--ak-ink), var(--ak-shadow);
}

.actions {
  position: relative;
  z-index: 7;
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
}

.btn-go,
.btn-alt {
  min-height: 48px;
  min-width: 48px;
  padding: 8px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  font-size: 16px;
  font-weight: 600;
}

.btn-go {
  flex: 1.3 1 auto;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-size: 32px;
  font-weight: var(--ak-title-weight);
  line-height: 1;
}

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

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

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

.bit {
  position: absolute;
  top: 30%;
  left: 50%;
  width: 10px;
  height: 14px;
  background: var(--ak-accent);
  box-shadow: 0 0 8px var(--ak-glow);
}

.bit.is-b {
  background: var(--ak-accent-2);
}

.bit.is-c {
  background: var(--ak-ink);
}

.result {
  position: absolute;
  z-index: 8;
  left: max(8px, env(safe-area-inset-left, 0px));
  right: max(8px, env(safe-area-inset-right, 0px));
  bottom: calc(8px + var(--pad-bot));
}

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

.result-says {
  font-family: var(--ak-font-display);
  font-size: clamp(20px, 5vw, 28px);
  font-weight: var(--ak-title-weight);
  line-height: 1.05;
  color: var(--ak-ink);
}

.result-score {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ak-accent);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.result-actions .btn-go,
.result-actions .btn-alt {
  flex: 1 1 140px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.is-ghost {
  position: fixed;
  z-index: 40;
  margin: 0;
  pointer-events: none;
  opacity: 0.92;
}

.bank-far.is-glow::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--ak-glow) 70%, transparent), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
}

@media (prefers-reduced-motion: no-preference) {
  .mute:active,
  .btn-go:active,
  .btn-alt:active,
  .token:active {
    transform: scale(0.96);
  }

  .seat .token:active {
    transform: none;
  }

  .ferry {
    transition: transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .ferry.is-still {
    transition: none;
  }

  .turn.is-cue {
    animation: turnpop 0.42s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .led {
    animation: led 2.4s ease-in-out infinite;
  }

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

  .voice.is-invite::after {
    content: "▍";
    margin-left: 4px;
    color: var(--ak-accent);
    animation: blink 1s steps(1) infinite;
  }

  .seat.is-coach::before {
    animation: bob 0.8s ease-in-out infinite;
  }

  .row .token.is-idle {
    animation: idle 2.8s ease-in-out infinite;
  }

  .row .token:nth-child(2).is-idle {
    animation-delay: 0.25s;
  }

  .row .token:nth-child(3).is-idle {
    animation-delay: 0.45s;
  }

  .row .token:nth-child(4).is-idle {
    animation-delay: 0.15s;
  }

  .row .token:nth-child(5).is-idle {
    animation-delay: 0.55s;
  }

  .token.is-land {
    animation: squash 0.42s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .token.is-hop {
    animation: hop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .token.is-step {
    animation: stepin 0.48s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .trips.is-tick .trip-count {
    animation: tickblink 0.42s steps(1) 2;
  }

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

  .bezel.is-fast .scan {
    animation-duration: 1.1s;
  }

  .ferry.is-push .wake {
    animation: wake 0.7s ease-out;
  }

  .link-seg.is-yank {
    animation: yank 0.35s ease-in-out 3;
  }

  .bank-far.is-glow::after {
    animation: chase 1.8s linear infinite;
  }

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

  .is-ghost {
    transform: scale(1.06, 0.94);
  }

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

  @keyframes led {
    0%, 100% { opacity: 0.65; }
    50% { opacity: 1; }
  }

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

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

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

  @keyframes squash {
    0% { transform: scale(0.86, 1.16); }
    55% { transform: scale(1.12, 0.8); }
    100% { transform: scale(1, 1); }
  }

  @keyframes hop {
    0% { transform: translateY(0) scale(1, 1); }
    40% { transform: translateY(-16px) scale(0.92, 1.1); }
    100% { transform: translateY(0) scale(1, 1); }
  }

  @keyframes stepin {
    0% { transform: translateY(-24px) scale(0.94, 1.08); }
    100% { transform: translateY(0) scale(1, 1); }
  }

  @keyframes tickblink {
    0%, 40% { opacity: 1; }
    50%, 80% { opacity: 0.15; }
    100% { opacity: 1; }
  }

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

  @keyframes wake {
    0% { opacity: 0; transform: translateX(8px); }
    30% { opacity: 1; }
    100% { opacity: 0; transform: translateX(-18px); }
  }

  @keyframes yank {
    0%, 100% { filter: brightness(1.15) drop-shadow(0 0 6px var(--ak-accent-2)); }
    50% { filter: brightness(2.1) drop-shadow(0 0 12px var(--ak-glow)); }
  }

  @keyframes chase {
    from { background-position: -40% 0; }
    to { background-position: 140% 0; }
  }

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

@media (min-width: 800px) {
  body {
    display: grid;
    place-items: center;
  }

  .play {
    height: min(100dvh, 900px);
    border-left: 2px solid var(--ak-outline);
    border-right: 2px solid var(--ak-outline);
    box-shadow: var(--ak-shadow);
  }
}
