:root {
  --bg: #101820;
  --panel: #192531;
  --panel-2: #243443;
  --text: #fbfff7;
  --muted: #b5c4bd;
  --accent: #ffcc4d;
  --accent-2: #43d8c9;
  --danger: #ff6b6b;
  --leaf: #92e46d;
  --berry: #ff7a90;
  --tile: 52px;
  --gap: 6px;
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(255, 204, 77, 0.08) 0 18%, transparent 18% 100%),
    linear-gradient(215deg, rgba(67, 216, 201, 0.12) 0 22%, transparent 22% 100%),
    linear-gradient(155deg, #102127 0%, #18313a 42%, #101820 100%);
  overflow-x: hidden;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 480px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto auto 1fr auto auto;
  gap: 11px;
  user-select: none;
  -webkit-user-select: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 2px 0;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 9vw, 42px);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
}

.scorebox,
.stats-row > div {
  border: 1px solid rgba(255, 255, 255, 0.13);
  background: linear-gradient(180deg, rgba(35, 55, 65, 0.92), rgba(21, 33, 43, 0.92));
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.scorebox {
  min-width: 98px;
  padding: 10px 12px;
  border-radius: 8px;
  text-align: right;
  border-color: rgba(255, 204, 77, 0.32);
}

.scorebox span,
.stats-row span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.scorebox strong {
  font-size: 24px;
  color: var(--accent);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stats-row > div {
  min-height: 58px;
  padding: 9px 10px;
  border-radius: 8px;
}

.stats-row strong {
  display: block;
  margin-top: 2px;
  font-size: 20px;
  color: #ffffff;
}

.power-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.power-button {
  width: 78px;
  min-height: 42px;
  display: grid;
  grid-template-columns: 24px 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 4px;
  padding: 6px 7px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(180deg, rgba(40, 61, 72, 0.96), rgba(27, 42, 53, 0.96));
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.power-button.active {
  outline: 2px solid var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 204, 77, 0.14), 0 8px 16px rgba(0, 0, 0, 0.14);
}

.power-button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.power-button.depleted {
  background: linear-gradient(180deg, rgba(255, 204, 77, 0.22), rgba(32, 49, 61, 0.94));
}

.power-icon {
  grid-row: 1 / 3;
  font-size: 21px;
}

.power-button span:not(.power-icon) {
  min-width: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.power-button strong {
  font-size: 13px;
  text-align: left;
}

.ad-power {
  background: linear-gradient(180deg, rgba(67, 216, 201, 0.28), rgba(27, 42, 53, 0.96));
}

.board-wrap {
  position: relative;
  width: 100%;
  min-width: 0;
  display: grid;
  place-items: center;
  min-height: 352px;
  touch-action: manipulation;
}

.board {
  width: min(100%, calc(100vw - 32px), calc(var(--tile) * 7 + var(--gap) * 6 + 18px));
  max-width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--gap);
  padding: 10px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.04)),
    linear-gradient(145deg, rgba(65, 97, 79, 0.45), rgba(23, 39, 50, 0.9));
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow:
    0 18px 34px rgba(0, 0, 0, 0.28),
    inset 0 2px 0 rgba(255, 255, 255, 0.13),
    inset 0 -8px 0 rgba(0, 0, 0, 0.15);
  touch-action: manipulation;
}

.tile {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  display: block;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.1)),
    linear-gradient(145deg, #3d5664, #263947);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.2),
    inset 0 -5px 0 rgba(0, 0, 0, 0.18),
    0 6px 12px rgba(0, 0, 0, 0.18);
  font-size: clamp(24px, 8vw, 38px);
  line-height: 1;
  transform: translateZ(0);
  transition: transform 140ms ease, outline-color 140ms ease, opacity 180ms ease, filter 140ms ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.animal-face {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  line-height: 1;
  padding: 0 0 1px;
  transform: translate(var(--face-x, 0), var(--face-y, -2px)) scale(var(--face-scale, 0.9));
  transform-origin: center;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.22));
  pointer-events: none;
}

.tile.special-bomb {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.08)),
    linear-gradient(145deg, rgba(255, 122, 144, 0.68), rgba(116, 44, 62, 0.9));
}

.tile.special-row,
.tile.special-column {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.44), rgba(255, 255, 255, 0.08)),
    linear-gradient(145deg, rgba(67, 216, 201, 0.58), rgba(28, 82, 84, 0.92));
}

.tile.special-rainbow {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.38), rgba(255, 255, 255, 0.06)),
    conic-gradient(from 0deg, #ff6b6b, #ffcc4d, #43d8c9, #9d7cff, #ff6b6b);
}

.tile.tool-target {
  outline: 3px dashed var(--accent-2);
  outline-offset: -4px;
}

.special-mark {
  position: absolute;
  right: 3px;
  bottom: 3px;
  z-index: 2;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(16, 24, 32, 0.82);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
  font-size: 12px;
  line-height: 1;
}

.tile:focus-visible {
  outline: 3px solid var(--accent-2);
  outline-offset: 2px;
}

.tile.selected {
  outline: 3px solid var(--accent);
  filter: brightness(1.12);
  transform: translateY(-3px) scale(1.04);
}

.tile.hint {
  animation: hintPulse 700ms ease-in-out 3;
}

.tile.clearing {
  opacity: 0;
  transform: scale(0.2) rotate(12deg);
}

.combo-pop {
  position: absolute;
  top: 12px;
  left: 50%;
  translate: -50% 0;
  min-height: 28px;
  color: var(--accent);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.22);
  font-weight: 900;
  pointer-events: none;
}

.combo-pop.show {
  animation: floatUp 900ms ease forwards;
}

.tool-row {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  gap: 10px;
}

.icon-button,
.primary-button,
.dialog-actions button {
  min-height: 48px;
  border-radius: 8px;
  background: linear-gradient(180deg, #2c4251, #20313d);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.icon-button {
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 24px;
  font-weight: 900;
}

.primary-button,
.dialog-actions button {
  background: linear-gradient(180deg, #ffe283, #f1ad2c);
  color: #1f1b10;
  font-weight: 900;
}

.ad-slot {
  min-height: 44px;
  display: grid;
  place-items: center;
  border: 1px dashed rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.055);
  font-size: 13px;
  overflow: hidden;
}

.ad-slot.ready {
  border-style: solid;
  color: var(--text);
}

.result-dialog {
  width: min(92vw, 390px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  background: var(--panel);
}

.result-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.result-dialog form {
  padding: 22px;
}

.result-dialog h2 {
  font-size: 30px;
}

.result-dialog p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.55;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

#rewardButton {
  background: #253845;
  color: var(--text);
}

.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;
}

@keyframes hintPulse {
  50% {
    transform: scale(1.1);
    outline: 3px solid var(--accent-2);
  }
}

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

@media (max-width: 380px) {
  :root {
    --gap: 5px;
  }

  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .scorebox {
    min-width: 84px;
  }

  .dialog-actions {
    grid-template-columns: 1fr;
  }
}
