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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  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);
}

[hidden] {
  display: none !important;
}

button {
  font-family: inherit;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}

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

.play {
  --pad-top: max(6px, env(safe-area-inset-top, 0px));
  --pad-right: max(8px, env(safe-area-inset-right, 0px));
  --pad-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  --pad-left: max(8px, env(safe-area-inset-left, 0px));
  --gap: clamp(56px, 18vw, 92px);
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 4px;
  width: min(100%, 420px);
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding: var(--pad-top) var(--pad-right) var(--pad-bottom) var(--pad-left);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  background-image: var(--ak-backdrop-layer);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

.porthole {
  position: absolute;
  top: 7%;
  right: 3%;
  z-index: 0;
  width: min(108px, 26vw);
  aspect-ratio: 1;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle at 40% 40%, var(--ak-surface), transparent 46%),
    radial-gradient(circle, var(--ak-accent-2), transparent 68%);
  box-shadow: 0 0 0 4px var(--ak-accent-2), 0 0 18px var(--ak-accent-2);
  opacity: 0.38;
}

.play.is-win .porthole {
  opacity: 0.9;
}

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

.mute {
  position: absolute;
  top: var(--pad-top);
  right: var(--pad-right);
  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-x {
  display: none;
}

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

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

.top,
.status,
.chart,
.action {
  position: relative;
  z-index: 1;
}

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

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

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

.turn-who {
  margin: 0;
  font-family: var(--ak-font-display);
  font-size: clamp(18px, 5vw, 24px);
  font-weight: var(--ak-title-weight);
  line-height: 1;
  color: var(--ak-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.voice,
.reason {
  margin: 0;
  min-height: 40px;
  padding: 6px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
  font-size: 15px;
  line-height: 1.25;
  color: var(--ak-ink);
}

.voice.is-wrong,
.reason {
  color: var(--ak-accent);
  border-color: var(--ak-accent);
}

.chart {
  min-height: 0;
  height: 100%;
  position: relative;
}

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

.glitter i {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ak-accent-2);
  box-shadow: 0 0 0 1px var(--ak-outline);
  opacity: 0.45;
}

.glitter i:nth-child(1) { top: 4px; left: 6px; }
.glitter i:nth-child(2) { top: 8px; right: 8px; }
.glitter i:nth-child(3) { bottom: 10px; left: 10px; }
.glitter i:nth-child(4) { bottom: 6px; right: 12px; }

.compass {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  color: var(--ak-accent-2);
  pointer-events: none;
}

.rose {
  display: block;
  width: 100%;
  height: 100%;
}

.rose .cross {
  fill: var(--ak-accent);
}

.board,
.demo {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  height: 100%;
  min-height: 0;
  pointer-events: none;
}

.col {
  position: relative;
  display: grid;
  grid-template-rows: repeat(8, minmax(0, 1fr));
  gap: 3px;
  min-height: 0;
  height: 100%;
}

.demo {
  align-items: center;
}

.demo .plaque {
  height: min(112px, 22dvh);
  min-height: 72px;
}

.plaque {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-height: 48px;
  padding: 0 6px;
  border: 0;
  border-radius: 18px;
  background: transparent url('./art/word-plaque.png') center / 100% 100% no-repeat;
  color: var(--ak-accent);
  font-family: var(--ak-font-body);
  font-weight: 700;
  font-size: clamp(13px, 3.4vw, 18px);
  letter-spacing: 0.01em;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
}

.plaque::before {
  content: '';
  position: absolute;
  left: 12%;
  right: 12%;
  top: 22%;
  bottom: 22%;
  border-radius: 999px;
  background: var(--ak-surface);
  pointer-events: none;
}

.plaque-word {
  position: relative;
  z-index: 1;
  max-width: 90%;
  padding: 0 0.15em;
  border-radius: 999px;
  background: var(--ak-surface);
  box-shadow: 0 0 0 0.28em var(--ak-surface);
  line-height: 1;
  white-space: nowrap;
}

.plaque:disabled {
  opacity: 1;
  color: var(--ak-accent);
}

.plaque.is-picked,
.plaque.is-locked {
  outline: 3px solid var(--ak-accent-2);
  outline-offset: -5px;
}

.plaque.is-marked,
.plaque.is-wait {
  outline: 3px solid var(--ak-accent);
  outline-offset: -5px;
}

.plaque:active {
  outline: 3px solid var(--ak-accent-2);
  outline-offset: -5px;
}

.ropes {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.rope {
  position: absolute;
  height: 48px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  transform-origin: 0 50%;
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
}

.rope-art {
  position: absolute;
  left: 0;
  right: 0;
  top: 4px;
  height: 40px;
  overflow: hidden;
  transform-origin: center center;
}

.rope-art img {
  display: block;
  width: 134.7%;
  height: 164px;
  margin-left: -19.3%;
  transform: translateY(-63px);
  object-fit: fill;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(#000, #000), url('./art/ink-line.png');
  -webkit-mask-size: 100% 100%, 100% 100%;
  -webkit-mask-repeat: no-repeat, no-repeat;
  -webkit-mask-position: center, center;
  -webkit-mask-composite: source-out;
  mask-image: linear-gradient(#000, #000), url('./art/ink-line.png');
  mask-size: 100% 100%, 100% 100%;
  mask-repeat: no-repeat, no-repeat;
  mask-position: center, center;
  mask-mode: alpha, luminance;
  mask-composite: subtract;
}

.rope.is-tight .rope-art {
  filter: drop-shadow(0 0 4px var(--ak-accent-2));
}

.rope.is-droop .rope-art {
  transform: translateY(14px) scaleY(1.2);
}

.drop {
  position: absolute;
  left: 50%;
  top: 58%;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  border-radius: 50%;
  background: var(--ak-accent);
  pointer-events: none;
}

.action {
  min-height: 56px;
}

.check {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 56px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ak-ink);
  cursor: pointer;
}

.check img {
  width: 52px;
  height: 52px;
  object-fit: contain;
}

.check-label {
  margin-top: -8px;
  padding: 3px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
  font-family: var(--ak-font-display);
  font-size: clamp(15px, 4vw, 20px);
  font-weight: var(--ak-title-weight);
  line-height: 1.1;
  color: var(--ak-ink);
}

.check.is-ready .check-label {
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
}

.play.is-example .check {
  visibility: hidden;
  pointer-events: none;
}

.play.is-card .check {
  display: none;
}

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

.result-says {
  margin: 0;
  font-family: var(--ak-font-display);
  font-size: clamp(18px, 4.6vw, 26px);
  font-weight: var(--ak-title-weight);
  line-height: 1.15;
  color: var(--ak-ink);
}

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

.btn-go,
.btn-alt {
  flex: 1 1 0;
  min-height: 48px;
  padding: 8px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  font-family: var(--ak-font-display);
  font-size: clamp(14px, 3.6vw, 18px);
  font-weight: var(--ak-title-weight);
  line-height: 1.1;
  cursor: pointer;
}

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

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

.bit {
  position: absolute;
  width: 8px;
  height: 10px;
  border-radius: 2px;
}

.bit.is-ink { background: var(--ak-accent); }
.bit.is-brass { background: var(--ak-accent-2); }
.bit.is-cream {
  background: var(--ak-surface);
  border: 1px solid var(--ak-outline);
}

@media (hover: hover) {
  .plaque:hover {
    outline: 3px solid var(--ak-accent-2);
    outline-offset: -5px;
  }
}

@media (max-height: 700px) {
  .play-logo { height: 28px; }
  .voice,
  .reason {
    min-height: 34px;
    padding: 4px 8px;
    font-size: 14px;
  }
  .check img { width: 44px; height: 44px; }
  .check-label { font-size: 15px; }
  .demo .plaque { min-height: 56px; }
}

@media (prefers-reduced-motion: no-preference) {
  .porthole {
    animation: breathe 5.5s ease-in-out infinite;
  }

  .play.is-win .porthole {
    animation: swell 1.15s ease-out 1;
  }

  .compass {
    animation: spin 16s linear infinite;
  }

  .play.is-win .compass {
    animation-duration: 2.2s;
  }

  .chart {
    animation: rock 5.2s ease-in-out infinite;
  }

  .chart.is-shake {
    animation: shake 0.42s ease-in-out;
  }

  .play.is-win .chart {
    animation: chase 1.2s ease-out 1;
  }

  .glitter i {
    animation: glint 2.8s ease-in-out infinite;
  }

  .glitter i:nth-child(2) { animation-delay: 0.4s; }
  .glitter i:nth-child(3) { animation-delay: 0.9s; }
  .glitter i:nth-child(4) { animation-delay: 1.3s; }

  .plaque-word {
    animation: word-rock 3.4s ease-in-out infinite;
  }

  .plaque.is-invite,
  .plaque.is-marked {
    animation: invite 0.95s ease-in-out infinite;
  }

  .plaque.is-tip {
    animation: tip 0.42s cubic-bezier(0.34, 1.4, 0.64, 1);
  }

  .plaque.is-shake {
    animation: shake 0.36s ease-in-out;
  }

  .plaque.is-flash {
    animation: brass 0.7s ease-out;
  }

  .rope.is-fresh .rope-art {
    animation: rope-snap 0.48s cubic-bezier(0.34, 1.45, 0.64, 1) both;
  }

  .rope.is-slip .rope-art {
    animation: rope-slip 0.62s ease-in forwards;
  }

  .rope.is-drop .drop {
    animation: drip 0.55s ease-in forwards;
  }

  .turn.is-cue {
    animation: turn-cue 0.35s ease-out;
  }

  .check.is-ready img {
    animation: stamp-pulse 1.35s ease-in-out infinite;
  }

  .check:active img {
    transform: scale(0.92) translateY(2px);
  }

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

  .bit {
    animation: burst 900ms ease-out forwards;
  }

  .rope.is-tight .rope-art {
    transition: transform 0.45s cubic-bezier(0.34, 1.4, 0.64, 1);
  }
}

@keyframes breathe {
  0%, 100% { opacity: 0.32; }
  50% { opacity: 0.5; }
}

@keyframes swell {
  0% { transform: scale(1); opacity: 0.4; }
  45% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 0.9; }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes rock {
  0%, 100% { transform: rotate(-0.35deg); }
  50% { transform: rotate(0.35deg); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-4px) rotate(-0.4deg); }
  70% { transform: translateX(4px) rotate(0.4deg); }
}

@keyframes chase {
  0% { box-shadow: inset 0 0 0 0 var(--ak-glow); }
  40% { box-shadow: inset 0 0 22px 3px var(--ak-accent-2); }
  100% { box-shadow: inset 0 0 0 0 var(--ak-glow); }
}

@keyframes glint {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.3); }
}

@keyframes word-rock {
  0%, 100% { transform: rotate(-1.4deg); }
  50% { transform: rotate(1.4deg); }
}

@keyframes invite {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-3px) scale(1.045); }
}

@keyframes tip {
  0% { transform: rotate(0deg) scale(1); }
  40% { transform: rotate(-7deg) scale(1.06, 0.92); }
  100% { transform: rotate(0deg) scale(1); }
}

@keyframes brass {
  0%, 100% { box-shadow: inset 0 0 0 0 var(--ak-accent-2); }
  45% { box-shadow: inset 0 0 0 4px var(--ak-accent-2), 0 0 14px var(--ak-accent-2); }
}

@keyframes rope-snap {
  0% { transform: translateY(16px) scaleY(1.25); }
  58% { transform: translateY(-4px) scaleY(0.88); }
  100% { transform: translateY(0) scaleY(1); }
}

@keyframes rope-slip {
  0% { transform: none; opacity: 1; }
  22% { transform: translateY(5px) rotate(-3deg); }
  48% { transform: translateY(-3px) rotate(3deg); }
  100% { transform: translateY(32px) rotate(8deg); opacity: 0; }
}

@keyframes drip {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(26px) scale(0.7); opacity: 0; }
}

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

@keyframes stamp-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

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