:root {
  --domino-ink: #3d3226;
  --domino-wood: #8a552c;
  --domino-gold: #d9a62e;
  --domino-sage: #879a63;
  --domino-amber: #b96819;
  --domino-focus: #174a7e;
  --domino-tile-width: 104px;
  --domino-tile-height: 64px;
  --domino-terminal-width: 64px;
}

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

body {
  height: 100dvh;
  overflow: hidden;
  color: var(--domino-ink);
  background: #6d4529;
}

#activity-root {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

button {
  font: inherit;
}

.domino-game {
  position: relative;
  display: flex;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 0;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: clamp(4px, 1vmin, 8px);
  padding: clamp(2px, 0.8vmin, 7px);
  color: var(--domino-ink);
}

.domino-instruction {
  margin: 0;
  color: var(--domino-ink);
  font-family: "Fredoka", sans-serif;
  font-size: clamp(18px, 2.7vmin, 27px);
  font-weight: 600;
  line-height: 1.06;
  text-align: center;
  text-wrap: balance;
}

.domino-direction {
  margin: -1px 0 0;
  color: #634d39;
  font-size: clamp(12px, 1.7vmin, 14px);
  line-height: 1.2;
  text-align: center;
}

.domino-chain-line,
.domino-serpentine {
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  margin: 0 auto;
}

.domino-line-layout {
  display: flex;
  width: 100%;
  max-width: 100%;
  flex-direction: column;
  align-items: center;
  gap: clamp(3px, 0.8vmin, 7px);
}

.domino-chain-line {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(2px, 0.7vmin, 7px);
}

.domino-chain {
  display: flex;
  min-width: 0;
  flex: 0 1 auto;
  align-items: center;
  justify-content: center;
  gap: clamp(2px, 0.6vmin, 6px);
  margin: 0;
  padding: 2px;
}

.domino-serpentine {
  display: grid;
  max-width: 540px;
  gap: 2px;
}

.domino-chain-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(2px, 0.6vmin, 6px);
}

.domino-turn-row {
  position: relative;
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
}

.domino-place {
  position: relative;
  display: flex;
  flex: 0 0 var(--domino-tile-width);
  width: var(--domino-tile-width);
  min-width: 0;
}

.domino-place::before {
  position: absolute;
  z-index: 4;
  top: 1px;
  left: calc(50% - 10px);
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border: 2px solid var(--domino-wood);
  border-radius: 50%;
  color: var(--domino-ink);
  background: #f3e4c5;
  box-shadow: 0 1px 3px rgba(70, 42, 19, 0.2);
  content: attr(data-position);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}

.domino-tile {
  position: relative;
  display: grid;
  box-sizing: border-box;
  width: var(--domino-tile-width);
  height: var(--domino-tile-height);
  min-width: 100px;
  min-height: 60px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: center;
  padding: 0 2px;
  touch-action: none;
  border: 0;
  border-radius: 12px;
  color: var(--domino-ink);
  background-color: transparent;
  background-image: url("./assets/domino-tile.webp");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 135%;
  cursor: grab;
  filter: drop-shadow(0 2px 2px rgba(70, 42, 19, 0.16));
  transition: transform 150ms ease, filter 150ms ease, outline-color 150ms ease;
}

.domino-tile:hover {
  outline: 2px solid rgba(104, 64, 32, 0.42);
  outline-offset: 1px;
  filter: drop-shadow(0 3px 3px rgba(70, 42, 19, 0.24));
}

.domino-tile:active,
.domino-tile.is-dragging {
  cursor: grabbing;
}

.domino-tile.is-dragging {
  z-index: 8;
  pointer-events: none;
}

.domino-tile.is-selected {
  outline: 4px solid rgba(23, 74, 126, 0.72);
  outline-offset: 2px;
  box-shadow: inset 0 0 0 3px rgba(23, 74, 126, 0.58);
}

.domino-tile.is-drop-target {
  outline: 5px solid rgba(135, 154, 99, 0.78);
  outline-offset: 2px;
  box-shadow: inset 0 0 0 3px rgba(135, 154, 99, 0.58);
}

.domino-half {
  position: relative;
  display: grid;
  height: 100%;
  min-width: 0;
  place-items: center;
  border-radius: 6px;
}

.domino-half img {
  display: block;
  width: 78%;
  height: 82%;
  max-width: none;
  max-height: none;
  object-fit: contain;
  pointer-events: none;
  filter: none;
}

.domino-half.is-mismatch {
  outline: 3px solid var(--domino-amber);
  outline-offset: -3px;
  background: rgba(243, 209, 154, 0.32);
  box-shadow: inset 0 0 0 1px rgba(108, 53, 7, 0.38);
}

.domino-half.is-demo-match {
  outline: 3px solid var(--domino-gold);
  outline-offset: -2px;
  background: rgba(255, 244, 184, 0.3);
  box-shadow: inset 0 0 0 1px rgba(111, 78, 8, 0.22);
}

.domino-divider {
  display: none;
}

.domino-tile[data-chain-direction="rtl"] .domino-half[data-half="left"] {
  grid-column: 2;
  grid-row: 1;
}

.domino-tile[data-chain-direction="rtl"] .domino-half[data-half="right"] {
  grid-column: 1;
  grid-row: 1;
}

.chain-arrow {
  display: grid;
  width: clamp(17px, 2vmin, 20px);
  height: clamp(17px, 2vmin, 20px);
  flex: 0 0 clamp(17px, 2vmin, 20px);
  align-self: center;
  place-items: center;
  border: 0;
  border-radius: 0;
  color: #6e5138;
  background: transparent;
  font-size: clamp(14px, 2vmin, 18px);
  font-weight: 600;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(255, 249, 236, 0.9);
}

.chain-arrow.is-mismatch {
  width: 24px;
  height: 24px;
  flex-basis: 24px;
  color: #6c3507;
  background: transparent;
  font-size: 22px;
  font-weight: 700;
}

.chain-arrow.is-demo-match,
.chain-arrow.is-whole-match {
  color: #a46f00;
  font-weight: 700;
  text-shadow: 0 0 2px #fff9ec, 0 0 5px rgba(217, 166, 46, 0.78);
}

.chain-turn-arrow {
  position: absolute;
  top: 50%;
  right: calc(var(--domino-tile-width) / 4 - 11px);
  left: auto;
  min-width: 22px;
  font-size: 18px;
  pointer-events: none;
  transform: translateY(-50%);
}

.domino-end {
  position: relative;
  display: flex;
  width: var(--domino-terminal-width);
  min-height: 78px;
  flex: 0 0 var(--domino-terminal-width);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  text-align: center;
}

.domino-end-symbol {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  border-radius: 50%;
  background-image: url("./assets/domino-medallion.webp");
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
}

.domino-end-symbol img {
  display: block;
  width: 48px;
  height: 48px;
  max-width: 48px;
  max-height: 48px;
  object-fit: contain;
  filter: none;
}

.domino-end-label {
  display: block;
  min-height: 12px;
  color: #5d422d;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.05;
}

.domino-end.is-mismatch .domino-end-symbol,
.domino-end.is-whole-match .domino-end-symbol {
  outline: 3px solid var(--domino-amber);
  outline-offset: 1px;
}

.domino-end.is-whole-match .domino-end-symbol {
  outline-color: var(--domino-gold);
}

.domino-actions {
  display: flex;
  min-height: 52px;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
}

.domino-turn-row .domino-actions {
  z-index: 3;
  min-height: 48px;
}

.domino-action {
  box-sizing: border-box;
  min-width: 124px;
  min-height: 48px;
  padding: 7px 15px;
  border: 2px solid #7d5537;
  border-radius: 12px;
  color: #4c3625;
  background: #fff8e8;
  font-size: clamp(13px, 1.7vmin, 15px);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.domino-turn {
  display: inline-flex;
  box-sizing: border-box;
  min-width: 108px;
  min-height: 48px;
  padding: 0 8px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  color: #4c2e1a;
  background: transparent;
  box-shadow: none;
  font-size: clamp(15px, 1.8vmin, 17px);
  font-weight: 700;
}

.domino-turn .domino-turn-icon {
  display: block;
  width: 48px;
  height: 48px;
  max-width: none;
  max-height: none;
  flex: 0 0 48px;
  object-fit: contain;
}

.domino-turn-label {
  line-height: 1;
}

.domino-action:hover:not(:disabled) {
  border-color: var(--domino-focus);
  background: #f1eadb;
}

.domino-action:disabled {
  border-color: #b8a58d;
  color: #74634f;
  background: #eee4d3;
  cursor: not-allowed;
}

.domino-turn:hover:not(:disabled) {
  color: #392414;
  background: transparent;
}

.domino-turn:disabled {
  color: #4c3625;
  background: transparent;
  opacity: 0.6;
  filter: none;
}

.domino-feedback {
  min-height: 1.35em;
  margin: 0;
  color: #5f4631;
  font-size: clamp(12px, 1.65vmin, 14px);
  line-height: 1.22;
  text-align: center;
}

.domino-feedback[data-feedback="CONNECTION_MISMATCH"],
.domino-feedback[data-feedback="START_MISMATCH"],
.domino-feedback[data-feedback="END_MISMATCH"],
.domino-feedback[data-feedback="MISSING_TILES"] {
  color: #6c3507;
  font-weight: 600;
}

.domino-feedback.is-success {
  color: #5f501c;
  font-weight: 600;
}

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

.domino-tile:focus-visible,
.domino-action:focus-visible {
  outline: 4px solid var(--domino-focus);
  outline-offset: 3px;
}

.domino-tile:focus-visible {
  box-shadow: inset 0 0 0 3px rgba(23, 74, 126, 0.62);
}

.domino-hand {
  position: absolute;
  z-index: 80;
  top: 0;
  left: 0;
  width: clamp(44px, 7vw, 62px);
  height: auto;
  pointer-events: none;
  filter: drop-shadow(2px 4px 3px rgba(51, 31, 15, 0.28));
  transition: transform 700ms ease;
}

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

.domino-leaf {
  position: absolute;
  top: -22px;
  left: calc(14% + var(--leaf-index) * 18%);
  width: 27px;
  height: 27px;
  object-fit: contain;
  opacity: 0;
  animation: domino-leaf-fall 1000ms ease-out forwards;
  animation-delay: calc(var(--leaf-index) * 55ms);
}

.domino-glint {
  position: absolute;
  top: calc(28% + var(--glint-index) * 18%);
  left: calc(22% + var(--glint-index) * 27%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--domino-gold);
  box-shadow: 0 0 0 4px rgba(217, 166, 46, 0.2);
  opacity: 0;
  animation: domino-glint 700ms ease-out 160ms forwards;
}

@keyframes domino-leaf-fall {
  0% { opacity: 0; transform: translateY(-10px) rotate(-24deg) scale(0.75); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translateY(190px) rotate(190deg) scale(1); }
}

@keyframes domino-glint {
  0% { opacity: 0; transform: scale(0.5); }
  35% { opacity: 1; transform: scale(1.2); }
  100% { opacity: 0; transform: scale(0.7); }
}

.domino-load-error {
  box-sizing: border-box;
  max-width: 42rem;
  min-height: 100%;
  margin: 0 auto;
  padding: 2rem 1rem;
  color: #4c2f1f;
  background: #fff8e6;
  font: 600 1rem/1.4 "Fredoka", sans-serif;
  text-align: center;
}

.domino-level-celebration {
  position: fixed;
  z-index: 200;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.domino-reward-leaf,
.domino-reward-gold {
  position: absolute;
  top: -5vh;
  left: calc(5vw + var(--reward-index) * 6.1vw);
  width: clamp(12px, 2.4vw, 25px);
  height: clamp(18px, 3.4vw, 35px);
  border-radius: 80% 10% 80% 10%;
  background: #e3a933;
  opacity: 0;
  animation: domino-reward-fall 1900ms ease-in forwards;
  animation-delay: calc(var(--reward-index) * 45ms);
}

.domino-reward-leaf:nth-child(3n + 2) {
  background: #8ca05e;
}

.domino-reward-gold {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #f6d36b;
  box-shadow: 0 0 0 5px rgba(246, 211, 107, 0.24);
}

.domino-level-celebration.is-final .domino-reward-leaf {
  width: clamp(15px, 2.8vw, 30px);
  height: clamp(22px, 4vw, 42px);
}

@keyframes domino-reward-fall {
  0% {
    opacity: 0;
    transform: translateY(-20px) rotate(-35deg) scale(0.7);
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(108vh) rotate(420deg) scale(1);
  }
}

@media (min-width: 601px) and (max-width: 999px) and (min-height: 650px) {
  .domino-game {
    container-type: inline-size;
    --domino-tile-width: clamp(136px, calc((100cqw - 174px) / 2), 180px);
    --domino-tile-height: clamp(78px, calc(var(--domino-tile-width) * 0.58), 104px);
  }

  .domino-game[data-tile-count="3"],
  .domino-game[data-tile-count="4"] {
    --domino-tile-width: clamp(136px, calc((100cqw - 106px) / 2), 180px);
  }

  .domino-serpentine {
    max-width: calc(var(--domino-tile-width) * 2 + 174px);
  }
}

@media (min-width: 1000px) and (min-height: 650px) {
  :root {
    --domino-tile-width: clamp(160px, 15vw, 180px);
    --domino-tile-height: clamp(92px, 12vh, 104px);
  }

  .domino-serpentine {
    max-width: 540px;
  }
}

@media (max-width: 600px) {
  :root {
    --domino-tile-width: 104px;
    --domino-tile-height: 64px;
    --domino-terminal-width: 40px;
  }

  .domino-game {
    gap: 3px;
    padding-inline: 1px;
  }

  .domino-serpentine {
    max-width: 286px;
  }

  .domino-chain-line {
    padding-top: 57px;
  }

  .domino-chain-line > .domino-end {
    position: absolute;
    top: 0;
  }

  .domino-chain-line > .domino-end[data-end-marker="start"] {
    left: 0;
  }

  .domino-chain-line > .domino-end[data-end-marker="end"] {
    right: 0;
  }

  .domino-chain,
  .domino-chain-row {
    gap: 2px;
  }

  .domino-end {
    width: 40px;
    min-height: 52px;
    flex-basis: 40px;
  }

  .domino-end-symbol {
    width: 40px;
    height: 40px;
  }

  .domino-end-symbol img {
    width: 32px;
    height: 32px;
    max-width: 32px;
    max-height: 32px;
  }

  .domino-actions {
    min-height: 48px;
  }

  .domino-action {
    min-width: 122px;
    padding-inline: 10px;
  }

  .domino-turn {
    min-width: 108px;
  }

  .chain-arrow {
    width: 13px;
    height: 13px;
    flex-basis: 13px;
    border-width: 1px;
    font-size: 11px;
  }

  .chain-arrow.is-mismatch {
    width: 22px;
    height: 22px;
    flex-basis: 22px;
    font-size: 19px;
  }

  .chain-turn-arrow {
    width: 17px;
    height: 17px;
    min-width: 17px;
    right: calc(var(--domino-tile-width) / 4 - 11px);
    left: auto;
  }
}

@media (max-height: 640px) {
  .domino-game {
    gap: 1px;
    padding-block: 0;
  }

  .domino-turn-row {
    min-height: 48px;
  }

  .domino-actions {
    min-height: 48px;
  }
}

@media (min-width: 601px) and (max-height: 640px) {
  :root {
    --domino-tile-width: 100px;
    --domino-tile-height: 60px;
    --domino-terminal-width: 40px;
  }

  .domino-serpentine {
    max-width: 330px;
  }

  .domino-end {
    width: 40px;
    min-height: 52px;
    flex-basis: 40px;
  }

  .domino-end-symbol {
    width: 40px;
    height: 40px;
  }

  .domino-end-symbol img {
    width: 32px;
    height: 32px;
    max-width: 32px;
    max-height: 32px;
  }
}

@media (max-width: 370px) {
  .domino-serpentine {
    max-width: 278px;
  }

  .domino-turn-row {
    padding-right: 0;
  }
}

@media (max-width: 600px) and (max-height: 700px) {
  .domino-game {
    gap: 0;
    padding-block: 0;
  }

  .domino-turn-row {
    min-height: 48px;
  }

  .chain-turn-arrow {
    line-height: 1;
  }

  .domino-actions {
    min-height: 48px;
  }

  .domino-action {
    box-sizing: border-box;
    min-height: 48px;
    padding-block: 0;
  }

  .domino-place::before {
    top: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .domino-tile,
  .domino-hand {
    transition: none;
  }

  .domino-leaf,
  .domino-glint,
  .domino-reward-leaf,
  .domino-reward-gold {
    animation: none;
    opacity: 0.85;
    transform: none;
  }

  .domino-leaf {
    top: 15%;
  }

  .domino-reward-leaf,
  .domino-reward-gold {
    top: calc(12vh + var(--reward-index) * 9vh);
  }
}
