/* Clusters: glossy tiles that pop and tumble. */

:root {
  --c0: #e5483b;
  --c1: #f2c230;
  --c2: #2fb36a;
  --c3: #2f7de0;
  --c4: #9a5ad8;
  --c5: #f28a2e;
}
:root[data-theme='hallows'] {
  --c0: #d8402c;
  --c1: #f0b03c;
  --c2: #5fae52;
  --c3: #4a6fd0;
  --c4: #8a4fd0;
  --c5: #f08a24;
}
:root[data-theme='hallows'] .hw-candle {
  display: none;
}
:root[data-theme='hallows'] .title-main {
  font-family: var(--font-display);
  letter-spacing: 0;
}

body {
  min-height: var(--app-height);
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}
#announce {
  margin: 0;
  top: 0;
}
.app {
  display: flex;
  flex-direction: column;
  height: calc(var(--app-height) - var(--safe-top) - var(--safe-bottom));
  min-height: 460px;
  max-width: 640px;
  margin: 0 auto;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px 6px;
}
.title-btn {
  appearance: none;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 12px;
  color: var(--text);
  min-width: 0;
}
.title-btn:hover {
  background: var(--accent-soft);
}
.title-btn:focus-visible {
  outline: 3px solid var(--accent);
}
.title-main {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.title-main::after {
  content: ' ▾';
  font-size: 0.7em;
  color: var(--text-muted);
}
.title-sub {
  display: block;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.score {
  display: flex;
  gap: 8px;
}
.chip {
  min-width: 64px;
  text-align: center;
  padding: 6px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.chip small {
  display: block;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.chip b {
  display: block;
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.chip.bump b {
  animation: bump 0.25s ease;
}
.chip.over b {
  color: var(--danger);
}
@keyframes bump {
  40% {
    transform: scale(1.25);
  }
}
.challenge {
  margin: 2px auto 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: center;
}
.challenge[hidden] {
  display: none;
}
.status {
  margin: 2px 16px 0;
  min-height: 2.6em;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  text-wrap: balance;
}

/* ---------- Board ---------- */

.stage {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px 14px;
  container-type: size;
}
.loading {
  color: var(--text-muted);
  font-weight: 600;
}
.board {
  --size: min(100cqw / var(--cols), 100cqh / var(--rows), 56px);
  position: relative;
  width: calc(var(--size) * var(--cols));
  height: calc(var(--size) * var(--rows));
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 14px 30px -14px rgba(0, 0, 0, 0.35);
  touch-action: manipulation;
}
.tile {
  appearance: none;
  border: 0;
  background: none;
  margin: 0;
  -webkit-tap-highlight-color: transparent;
  position: absolute;
  left: 0;
  top: 0;
  width: var(--size);
  height: var(--size);
  padding: 2px;
  transform: translate(calc(var(--c) * var(--size)), calc(var(--r) * var(--size)));
  transition: transform 0.24s cubic-bezier(0.3, 1.3, 0.5, 1);
  cursor: pointer;
}
.tile i {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 28%;
  font-style: normal;
  font-size: calc(var(--size) * 0.42);
  color: transparent;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18), inset 0 3px 0 rgba(255, 255, 255, 0.3);
  transition: transform 0.12s ease, filter 0.12s ease;
}
.symbols .tile i {
  color: rgba(0, 0, 0, 0.38);
}
.tile.c0 i { background: var(--c0); }
.tile.c1 i { background: var(--c1); }
.tile.c2 i { background: var(--c2); }
.tile.c3 i { background: var(--c3); }
.tile.c4 i { background: var(--c4); }
.tile.lit i {
  transform: scale(0.9);
  filter: brightness(1.15) saturate(1.1);
  box-shadow: 0 0 0 2px var(--text), inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}
.tile.gone {
  pointer-events: none;
}
.tile.gone i {
  animation: vanish 0.26s ease forwards;
}
@keyframes vanish {
  30% {
    transform: scale(1.15);
  }
  100% {
    transform: scale(0);
    opacity: 0;
  }
}
.floater {
  position: absolute;
  pointer-events: none;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--text);
  text-shadow: 0 1px 0 var(--surface), 0 0 8px var(--surface);
  transform: translate(-50%, -50%);
  animation: rise 0.9s ease-out forwards;
  z-index: 2;
}
@keyframes rise {
  to {
    transform: translate(-50%, -160%);
    opacity: 0;
  }
}
.board.over .tile i {
  filter: grayscale(0.6) opacity(0.7);
}
.chip.ahead b {
  color: var(--accent);
}
@media (prefers-reduced-motion: reduce) {
  .tile {
    transition: none;
  }
  .tile.gone i,
  .floater {
    animation: none;
    opacity: 0;
  }
}

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 8px 8px 12px;
}
.tool {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 64px;
  min-height: 52px;
  padding: 6px 8px;
  border-radius: 14px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}
.tool svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool:hover:not(:disabled) {
  background: var(--accent-soft);
}
.tool:disabled {
  opacity: 0.38;
  cursor: default;
}
.tool:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Menus ---------- */

.menu-list {
  display: grid;
  gap: 10px;
}
.menu-card {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.menu-card:active {
  transform: scale(0.98);
}
.menu-card:focus-visible {
  outline: 3px solid var(--accent);
}
.menu-card .menu-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
}
.menu-card b {
  display: block;
  font-size: 1.05rem;
}
.menu-card small {
  color: var(--text-muted);
}
.menu-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.menu-row .btn {
  flex: 1;
  padding-inline: 0.8em;
  white-space: nowrap;
}
.level-picker {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}
.level-picker input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1.1rem;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.help ul {
  padding-left: 1.2em;
}

