:root {
  --game-board-tile-bg: #efe6ff;
  --game-board-tile-art-bg: #d8c4f5;
  --game-board-tile-selected-bg: #6b46c1;
  --game-board-tile-selected-text: #ffffff;
  --game-board-tile-text: #25133d;
  --game-board-tile-border: #43206d;
  --game-board-tile-letter-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
  --game-surface: rgba(19, 12, 35, 0.78);
  --playable-gold: #f7c955;
  --playable-cyan: #6ee7f9;
  --playable-ink: #f9f6ff;
  --playable-panel: rgba(20, 14, 36, 0.86);
}

* {
  box-sizing: border-box;
}

html,
body,
#playable-root {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #120d21;
  color: var(--playable-ink);
}

button {
  font: inherit;
}

.playable-game {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-height: 480px;
  overflow: hidden;
  isolation: isolate;
  background:
    linear-gradient(180deg, rgba(16, 9, 31, 0.2), rgba(16, 9, 31, 0.62)),
    url("../assets/lobby-magic-crystal-library-phone.webp") center / cover no-repeat;
}

.playable-game::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 18% 12%, rgba(110, 231, 249, 0.24), transparent 32%),
    linear-gradient(90deg, rgba(8, 7, 20, 0.72), rgba(31, 18, 52, 0.24), rgba(8, 7, 20, 0.7));
}

.playable-game__surface {
  width: min(92vw, 400px);
  max-height: min(94vh, 640px);
  display: grid;
  grid-template-rows: auto auto auto auto;
  gap: clamp(10px, 2.8vh, 18px);
  padding: clamp(14px, 3.5vw, 22px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: var(--game-surface);
  box-shadow: 0 20px 60px rgba(4, 3, 12, 0.42);
  backdrop-filter: blur(10px);
}

.playable-game__top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.playable-game__prompt {
  min-width: 0;
  margin: 0;
  font-size: 1.32rem;
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: 0;
  text-wrap: balance;
}

.playable-stars {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-width: 78px;
  justify-content: flex-end;
  color: var(--playable-gold);
  font-size: 1.18rem;
  text-shadow: 0 2px 8px rgba(247, 201, 85, 0.42);
}

.playable-stars .ph {
  color: rgba(255, 255, 255, 0.38);
  text-shadow: none;
}

.playable-board {
  width: 100%;
  max-width: min(82vw, 372px);
  aspect-ratio: 1 / 1;
  align-self: center;
  justify-self: center;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: clamp(4px, 1.4vw, 8px);
}

.playable-tile {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1 / 1;
  border: 0;
  border-radius: clamp(10px, 3vw, 16px);
  background-color: var(--game-board-tile-art-bg);
  background-image: url("../assets/world-tile-magic.png");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 108% 108%;
  box-shadow: 0 6px 0 0 var(--game-board-tile-border), 0 10px 16px rgba(2, 1, 8, 0.22);
  color: var(--game-board-tile-text);
  cursor: pointer;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.playable-tile:active {
  transform: translateY(2px);
  box-shadow: 0 4px 0 0 var(--game-board-tile-border), 0 7px 12px rgba(2, 1, 8, 0.24);
}

.playable-tile__face {
  position: absolute;
  inset: 11%;
  border-radius: clamp(7px, 2vw, 11px);
  background: var(--game-board-tile-selected-bg);
  opacity: 0;
  pointer-events: none;
}

.playable-tile__letter {
  position: relative;
  z-index: 1;
  font-size: 2.1rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  text-shadow: var(--game-board-tile-letter-shadow);
}

.playable-tile--selected {
  color: var(--game-board-tile-selected-text);
}

.playable-tile--selected .playable-tile__face {
  opacity: 0.38;
}

.playable-tile--hinted {
  z-index: 1;
  animation: playableTileHintLift 1.25s ease-in-out infinite;
  animation-delay: calc(var(--playable-hint-order, 0) * 120ms);
}

.playable-tile--hinted::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  pointer-events: none;
  animation: playableTileHint 1.25s ease-in-out infinite;
  animation-delay: calc(var(--playable-hint-order, 0) * 120ms);
}

.playable-tile--hinted .playable-tile__face {
  animation: playableTileHintFace 1.25s ease-in-out infinite;
  animation-delay: calc(var(--playable-hint-order, 0) * 120ms);
  background: radial-gradient(circle, rgba(255, 231, 137, 0.82) 0%, rgba(110, 231, 249, 0.42) 56%, transparent 74%);
  opacity: 0.3;
}

.playable-tile--invalid {
  animation: playableTileInvalid 250ms ease;
  box-shadow:
    0 6px 0 0 var(--game-board-tile-border),
    0 0 0 6px rgba(248, 113, 113, 0.34);
}

.playable-tile:disabled,
.playable-action:disabled {
  opacity: 1;
  cursor: default;
}

.playable-tile--demo-target {
  box-shadow:
    0 6px 0 0 var(--game-board-tile-border),
    0 0 0 3px rgba(255, 226, 122, 0.28),
    0 10px 16px rgba(2, 1, 8, 0.22);
}

.playable-selection {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  gap: 6px;
  padding: 2px 0;
}

.playable-selection__chip {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: #2a1544;
  font-weight: 900;
  box-shadow: 0 4px 0 rgba(30, 13, 52, 0.42);
}

.playable-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.playable-action,
.playable-cta {
  position: relative;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.playable-action--primary,
.playable-cta {
  background: linear-gradient(180deg, #ffe27a, var(--playable-gold));
  color: #2d1b05;
  box-shadow: 0 5px 0 #a8671e, 0 10px 22px rgba(247, 201, 85, 0.22);
}

.playable-action--secondary {
  background: rgba(255, 255, 255, 0.16);
  color: var(--playable-ink);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.playable-score {
  display: grid;
  place-items: center;
  min-width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(110, 231, 249, 0.18);
  color: var(--playable-cyan);
  font-weight: 900;
  box-shadow: inset 0 0 0 1px rgba(110, 231, 249, 0.34);
}

.playable-demo-hand {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  width: clamp(39px, 12vw, 54px);
  height: clamp(39px, 12vw, 54px);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(16, 7, 36, 0.7) 0%, rgba(16, 7, 36, 0.36) 44%, transparent 72%);
  color: #fff7c2;
  font-size: clamp(2.325rem, 10.5vw, 3.225rem);
  filter:
    drop-shadow(0 5px 7px rgba(8, 3, 18, 0.72))
    drop-shadow(0 0 12px rgba(110, 231, 249, 0.68));
  pointer-events: none;
  text-shadow:
    0 0 3px rgba(20, 7, 45, 0.95),
    0 0 16px rgba(255, 231, 137, 0.7);
  animation: playableDemoHandTap 2.4s ease-in-out infinite;
}

.playable-demo-hand--tile {
  right: 6%;
  bottom: 4%;
}

.playable-demo-hand--submit {
  right: 8px;
  bottom: -11px;
}

.playable-outro {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 3, 12, 0.72);
  z-index: 5;
}

.playable-outro__video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.78;
}

.playable-outro__content {
  position: relative;
  width: min(88vw, 360px);
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 22px;
  border-radius: 8px;
  background: rgba(15, 9, 28, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.18);
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
}

.playable-outro__eyebrow,
.playable-outro__subtitle,
.playable-outro__title {
  margin: 0;
}

.playable-outro__eyebrow {
  color: var(--playable-cyan);
  font-size: 0.94rem;
  font-weight: 900;
}

.playable-outro__title {
  font-size: 2.4rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
}

.playable-outro__title--final {
  font-size: clamp(1.55rem, 6vw, 2.05rem);
  line-height: 1.08;
}

.playable-outro__subtitle {
  font-size: 1rem;
  line-height: 1.28;
}

.playable-cta {
  margin-top: 6px;
  width: 100%;
}

@keyframes playableTileHint {
  0%,
  100% {
    opacity: 0.45;
    box-shadow:
      inset 0 0 0 2px rgba(110, 231, 249, 0.34),
      0 0 0 0 rgba(255, 231, 137, 0);
  }
  42% {
    opacity: 1;
    box-shadow:
      inset 0 0 0 4px rgba(255, 231, 137, 0.68),
      0 0 0 8px rgba(255, 231, 137, 0.28),
      0 0 30px rgba(110, 231, 249, 0.76);
  }
}

@keyframes playableTileHintFace {
  0%,
  100% {
    opacity: 0.26;
  }
  42% {
    opacity: 0.72;
  }
}

@keyframes playableTileHintLift {
  0%,
  100% {
    filter: brightness(1);
    box-shadow:
      0 4px 0 0 var(--game-board-tile-border),
      0 7px 12px rgba(2, 1, 8, 0.24),
      0 0 0 rgba(255, 231, 137, 0);
  }
  42% {
    filter: brightness(1.16) saturate(1.12);
    box-shadow:
      0 6px 0 0 var(--game-board-tile-border),
      0 12px 18px rgba(2, 1, 8, 0.32),
      0 0 0 5px rgba(255, 231, 137, 0.24),
      0 0 28px rgba(110, 231, 249, 0.78);
  }
}

@keyframes playableTileInvalid {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-7px);
  }
  40% {
    transform: translateX(5px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(3px);
  }
}

@keyframes playableDemoHandTap {
  0%,
  100% {
    opacity: 0.88;
    transform: translate(8px, 8px) rotate(-12deg) scale(1);
  }
  44% {
    opacity: 1;
    transform: translate(0, 0) rotate(-12deg) scale(0.92);
  }
}

@media (max-height: 520px) {
  .playable-game {
    min-height: 420px;
  }

  .playable-game__surface {
    gap: 8px;
    padding: 12px;
  }

  .playable-selection {
    min-height: 32px;
  }

  .playable-selection__chip {
    width: 28px;
    height: 30px;
  }

  .playable-action,
  .playable-cta {
    min-height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
