:root {
  color-scheme: light;
  --page: #f5f2ea;
  --ink: #241d17;
  --muted: #71665b;
  --panel: #fffdf7;
  --line: rgba(63, 44, 26, 0.16);
  --wood-a: #d7a760;
  --wood-b: #f2d39a;
  --wood-c: #a96f32;
  --accent: #1f7a75;
  --danger: #b74949;
  --shadow: rgba(59, 39, 18, 0.22);
  --tower-width: clamp(54px, 10vw, 86px);
  --block-height: clamp(36px, 8vw, 54px);
  --slot-gap: 5px;
  --capacity: 5;
  --tower-count: 7;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 22% 12%, rgba(31, 122, 117, 0.16), transparent 28%),
    linear-gradient(135deg, #f8f1df 0%, #eef3ee 48%, #f6eee5 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.game-shell {
  width: min(1120px, calc(100vw - 24px));
  min-height: min(760px, calc(100vh - 24px));
  display: grid;
  grid-template-rows: auto auto 1fr auto auto auto;
  gap: 18px;
  padding: clamp(16px, 3vw, 30px);
}

.topbar,
.settings,
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.25rem, 7vw, 5rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.score-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: clamp(0.9rem, 2vw, 1rem);
}

.score-strip span {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.7);
  padding: 7px 11px;
  white-space: nowrap;
}

.score-strip strong {
  margin-left: 6px;
  color: var(--ink);
}

.settings {
  justify-content: center;
  flex-wrap: wrap;
}

.settings label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.72);
  padding: 6px 8px 6px 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.settings select {
  min-height: 30px;
  border: 1px solid rgba(36, 29, 23, 0.14);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  padding: 3px 28px 3px 8px;
}

.game-area {
  position: relative;
  min-height: 0;
  display: grid;
  align-items: end;
  padding-top: 12px;
  overflow: hidden;
}

.board {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: calc((var(--block-height) + var(--slot-gap)) * var(--capacity) + 120px);
  display: grid;
  grid-template-columns: repeat(var(--tower-count), minmax(42px, 1fr));
  gap: clamp(5px, 1.5vw, 18px);
  align-items: end;
  padding: 20px clamp(8px, 2vw, 22px) 42px;
}

.board::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  height: 34px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.28), transparent 18%, rgba(108, 62, 24, 0.16) 72%, transparent),
    linear-gradient(180deg, var(--wood-b), var(--wood-a) 62%, var(--wood-c));
  box-shadow: 0 18px 28px var(--shadow), inset 0 1px rgba(255, 255, 255, 0.6);
}

.tower {
  position: relative;
  z-index: 1;
  width: 100%;
  height: calc((var(--block-height) + var(--slot-gap)) * var(--capacity) + 76px);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  border: 0;
  border-radius: 8px;
  background: transparent;
  padding: 0 0 30px;
  cursor: pointer;
  touch-action: manipulation;
}

.tower::before {
  content: "";
  position: absolute;
  bottom: 28px;
  width: min(14px, 30%);
  height: calc(100% - 24px);
  border-radius: 999px 999px 4px 4px;
  background:
    linear-gradient(90deg, rgba(119, 70, 30, 0.16), rgba(255, 240, 203, 0.72) 42%, rgba(143, 86, 35, 0.18)),
    linear-gradient(180deg, #f6d8a3, #d2944a);
  box-shadow: 0 2px 7px rgba(65, 38, 14, 0.25);
}

.tower::after {
  content: "";
  position: absolute;
  bottom: 22px;
  width: min(62px, 88%);
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, #f6d9a2, #bf7d35);
  box-shadow: 0 4px 7px rgba(91, 53, 18, 0.25);
}

.tower:focus-visible {
  outline: 3px solid rgba(31, 122, 117, 0.52);
  outline-offset: 3px;
}

.stack {
  width: var(--tower-width);
  min-width: 42px;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--slot-gap);
  align-items: center;
  pointer-events: none;
}

.block {
  position: relative;
  width: 100%;
  height: var(--block-height);
  border-radius: 999px / 44%;
  background:
    radial-gradient(ellipse at 50% 17%, rgba(255, 255, 255, 0.52), transparent 34%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.16), transparent 15%, rgba(255, 255, 255, 0.3) 45%, transparent 74%, rgba(0, 0, 0, 0.14)),
    var(--block-color);
  box-shadow:
    inset 0 -8px 10px rgba(0, 0, 0, 0.12),
    inset 0 4px 6px rgba(255, 255, 255, 0.28),
    0 4px 8px rgba(45, 30, 18, 0.18);
  transform: translateY(0);
  transition: transform 170ms ease, box-shadow 170ms ease, filter 170ms ease;
}

.block::before {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  top: 4px;
  height: 30%;
  border-radius: 999px / 50%;
  background: rgba(255, 255, 255, 0.16);
}

.tower.selected .block:last-child {
  transform: translateY(-18px);
  box-shadow:
    inset 0 -8px 10px rgba(0, 0, 0, 0.12),
    inset 0 4px 6px rgba(255, 255, 255, 0.28),
    0 14px 20px rgba(45, 30, 18, 0.24);
}

.tower.hint-source .block:last-child,
.tower.hint-target::after {
  animation: pulse 720ms ease-in-out infinite alternate;
}

.tower.legal-target::after {
  box-shadow: 0 0 0 5px rgba(31, 122, 117, 0.18), 0 4px 7px rgba(91, 53, 18, 0.25);
}

.tower.invalid {
  animation: shake 220ms ease-in-out 1;
}

.controls {
  justify-content: center;
  flex-wrap: wrap;
}

.controls button {
  min-width: 92px;
  min-height: 44px;
  border: 1px solid rgba(36, 29, 23, 0.14);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 8px 20px rgba(60, 42, 24, 0.1);
  cursor: pointer;
}

.controls button:hover {
  border-color: rgba(31, 122, 117, 0.44);
}

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

.controls button:disabled {
  cursor: not-allowed;
  color: #958c83;
  background: rgba(255, 253, 247, 0.48);
  box-shadow: none;
}

.controls button.is-running {
  background: #143f3d;
  color: #ffffff;
}

.ad-panel {
  width: min(728px, 100%);
  min-height: 90px;
  display: grid;
  place-items: center;
  justify-self: center;
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.58);
  color: var(--muted);
  overflow: hidden;
}

.ad-panel span {
  position: absolute;
  top: 8px;
  left: 10px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.ad-panel .adsbygoogle {
  display: block;
  width: 100%;
  min-height: 90px;
}

.ad-panel.is-placeholder::after {
  content: "Ad space";
  color: rgba(113, 102, 91, 0.72);
  font-weight: 700;
}

.ad-panel.is-placeholder .adsbygoogle {
  display: none;
}

.site-footer,
.policy-links {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.92rem;
}

.site-footer a,
.policy-links a,
.policy-page a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

.site-footer a:hover,
.policy-links a:hover,
.policy-page a:hover {
  text-decoration: underline;
}

.policy-page {
  width: min(820px, calc(100vw - 28px));
  margin: 0 auto;
  padding: clamp(18px, 4vw, 42px);
}

.policy-page header,
.policy-page section {
  border-bottom: 1px solid var(--line);
  padding: 18px 0;
}

.policy-page h1,
.policy-page h2,
.policy-page p {
  margin: 0;
}

.policy-page h1 {
  margin-top: 6px;
  font-size: clamp(2.2rem, 8vw, 4.6rem);
  line-height: 0.92;
}

.policy-page h2 {
  font-size: clamp(1.2rem, 3vw, 1.55rem);
  letter-spacing: 0;
}

.policy-page p {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.6;
}

.policy-links {
  justify-content: flex-start;
  padding-top: 18px;
}

.win-panel {
  width: min(720px, 100%);
  margin: -8px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid rgba(31, 122, 117, 0.28);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.92), rgba(255, 253, 247, 0.76)),
    var(--panel);
  box-shadow: 0 16px 34px rgba(60, 42, 24, 0.14);
  padding: 14px 16px;
}

.win-panel[hidden] {
  display: none;
}

.win-panel h2,
.win-panel p {
  margin: 0;
}

.win-panel h2 {
  font-size: clamp(1.25rem, 3vw, 1.65rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.win-panel #win-summary {
  margin-top: 5px;
  color: var(--muted);
}

.win-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.win-actions button {
  min-height: 40px;
  border: 1px solid rgba(36, 29, 23, 0.14);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}

.win-actions button:first-child {
  background: #143f3d;
  color: #ffffff;
}

.reward-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  overflow: hidden;
}

.reward-layer.is-active::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 58px;
  width: min(540px, 92%);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.78);
  box-shadow:
    0 0 0 12px rgba(255, 222, 92, 0.12),
    0 0 46px rgba(242, 138, 46, 0.35),
    inset 0 0 34px rgba(32, 182, 165, 0.22);
  opacity: 0;
  transform: translateX(-50%) scale(0.22);
  animation: reward-ring 1200ms ease-out both;
}

.reward-block,
.reward-spark {
  position: absolute;
  left: var(--start-x);
  top: var(--start-y);
  pointer-events: none;
}

.reward-block {
  width: clamp(24px, 4vw, 42px);
  height: clamp(17px, 3vw, 28px);
  border-radius: 999px / 44%;
  background:
    radial-gradient(ellipse at 50% 17%, rgba(255, 255, 255, 0.58), transparent 35%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.16), transparent 18%, rgba(255, 255, 255, 0.34) 50%, transparent 76%, rgba(0, 0, 0, 0.12)),
    var(--block-color);
  box-shadow:
    inset 0 -6px 8px rgba(0, 0, 0, 0.12),
    inset 0 3px 5px rgba(255, 255, 255, 0.28),
    0 10px 18px rgba(45, 30, 18, 0.18);
  animation: reward-block-flight var(--duration) cubic-bezier(0.16, 0.78, 0.2, 1) var(--delay) both;
}

.reward-spark {
  width: var(--spark-size);
  height: var(--spark-size);
  border-radius: 50%;
  background: var(--block-color);
  box-shadow:
    0 0 10px var(--block-color),
    0 0 22px rgba(255, 255, 255, 0.72);
  animation: reward-spark-flight var(--duration) ease-out var(--delay) both;
}

.moving-block {
  position: fixed;
  left: var(--start-left);
  top: var(--start-top);
  z-index: 8;
  width: var(--move-width);
  height: var(--move-height);
  pointer-events: none;
  border-radius: 999px / 44%;
  background:
    radial-gradient(ellipse at 50% 17%, rgba(255, 255, 255, 0.58), transparent 35%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.16), transparent 18%, rgba(255, 255, 255, 0.34) 50%, transparent 76%, rgba(0, 0, 0, 0.12)),
    var(--block-color);
  box-shadow:
    inset 0 -8px 10px rgba(0, 0, 0, 0.12),
    inset 0 4px 6px rgba(255, 255, 255, 0.28),
    0 16px 24px rgba(45, 30, 18, 0.22);
  animation: moving-block-flight 360ms cubic-bezier(0.18, 0.8, 0.22, 1) both;
}

.block.is-drop-ghost {
  visibility: hidden;
}

.is-won .block {
  animation: settle 540ms ease both;
}

@keyframes pulse {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.2);
  }
}

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

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

@keyframes reward-ring {
  0% {
    opacity: 0.88;
    transform: translateX(-50%) scale(0.16);
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) scale(1.15);
  }
}

@keyframes reward-block-flight {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) translate(0, 0) rotate(0deg) scale(0.7);
  }
  10% {
    opacity: 1;
  }
  45% {
    opacity: 1;
    transform: translate(-50%, -50%) translate(var(--mid-x), var(--mid-y)) rotate(var(--mid-spin)) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) translate(var(--end-x), var(--end-y)) rotate(var(--end-spin)) scale(0.48);
  }
}

@keyframes reward-spark-flight {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) translate(0, 0) scale(0.2);
  }
  12% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) translate(var(--end-x), var(--end-y)) scale(0.06);
  }
}

@keyframes moving-block-flight {
  0% {
    transform: translate(0, 0);
  }
  34% {
    transform: translate(0, var(--lift-y));
  }
  72% {
    transform: translate(var(--move-x), var(--lift-y));
  }
  100% {
    transform: translate(var(--move-x), var(--move-y));
  }
}

@media (max-width: 760px) {
  .game-shell {
    min-height: 100vh;
    width: 100%;
    padding: 14px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .score-strip {
    width: 100%;
    max-width: none;
    justify-content: flex-start;
  }

  .settings {
    justify-content: flex-start;
  }

  .settings label {
    flex: 1 1 145px;
    justify-content: space-between;
  }

  .score-strip span {
    min-height: 32px;
    padding: 6px 8px;
  }

  .win-panel {
    align-items: flex-start;
    flex-direction: column;
  }

  .win-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .board {
    --row-height: calc((var(--block-height) + var(--slot-gap)) * var(--capacity) + 78px);
    grid-template-columns: repeat(5, minmax(48px, 1fr));
    grid-auto-rows: var(--row-height);
    align-items: end;
    min-height: auto;
    padding-bottom: 30px;
  }

  .board::after {
    height: 34px;
    top: auto;
    bottom: 8px;
    background:
      linear-gradient(90deg, rgba(255, 255, 255, 0.28), transparent 18%, rgba(108, 62, 24, 0.16) 72%, transparent),
      linear-gradient(180deg, var(--wood-b), var(--wood-a) 62%, var(--wood-c));
  }

  .board::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: calc(var(--row-height) - 34px);
    height: 34px;
    border-radius: 8px;
    background:
      linear-gradient(90deg, rgba(255, 255, 255, 0.28), transparent 18%, rgba(108, 62, 24, 0.16) 72%, transparent),
      linear-gradient(180deg, var(--wood-b), var(--wood-a) 62%, var(--wood-c));
    box-shadow: 0 18px 28px var(--shadow), inset 0 1px rgba(255, 255, 255, 0.6);
  }

  .board.is-single-row::before {
    display: none;
  }
}

@media (max-width: 560px) {
  :root {
    --tower-width: 50px;
    --block-height: 32px;
    --slot-gap: 4px;
  }

  .settings label {
    flex: 0 0 100%;
    justify-content: flex-start;
  }

  .settings select {
    width: 128px;
    max-width: 58%;
  }

  .controls button {
    width: calc(50% - 8px);
  }

  .ad-panel {
    min-height: 74px;
  }

  .ad-panel .adsbygoogle {
    min-height: 74px;
  }

  .win-actions button {
    flex: 1 1 130px;
  }
}
