:root {
  color-scheme: dark;
  font-family: ui-rounded, "Trebuchet MS", system-ui, sans-serif;
  color: #f4fbff;
  background: #193d52;
  --muted: #bddeea;
  --glass: #8bc1e3;
  --panel: #16364a;
  --control: #0c283b;
  --line: #85c0dc66;
  --focus: #ffe39a;
}
* { box-sizing: border-box; }
body {
  min-height: 100dvh;
  margin: 0;
  background: radial-gradient(ellipse at 48% 14%, #28566b 0, #1b4056 48%, #103148 100%);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: url("./candy-shop.svg") center bottom / max(100%, 440px) auto no-repeat;
  opacity: .29;
}
main {
  position: relative;
  width: min(100%, 760px);
  min-height: 100vh;
  min-height: 100dvh;
  margin-inline: auto;
  display: grid;
  grid-template-rows: auto minmax(min-content, 1fr) auto auto;
  padding: max(16px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(27px, calc(env(safe-area-inset-bottom) + 17px)) max(8px, env(safe-area-inset-left));
}
h1, h2, p { margin: 0; }
button { color: inherit; font: inherit; font-weight: 750; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
button:disabled { cursor: default; }
button svg { display: block; width: 100%; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.hud { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding-inline: clamp(9px, 3vw, 20px); }
.hud-button {
  display: grid;
  place-items: center;
  width: clamp(48px, 12vw, 58px);
  aspect-ratio: 1;
  padding: 9px;
  border-radius: 50%;
  color: #f6fcff;
  background: #94bed448;
  border: 1px solid #c8eafa24;
  box-shadow: inset 0 1px #c5edff20;
}
.hud-button:last-child { justify-self: end; }
.hud-button svg { width: 100%; max-width: 34px; }
.level-info { text-align: center; }
h1 { font-size: clamp(1.36rem, 6vw, 1.95rem); line-height: 1.12; letter-spacing: -.035em; }
.moves { margin-top: 4px; color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
.moves strong { color: inherit; }
.arena { position: relative; display: grid; align-items: center; padding-block: 36px 24px; min-width: 0; }
#board {
  --gap: clamp(4px, 1.25vw, 13px);
  --piece: min(clamp(50px, 14.5vw, 72px), calc((100% - (var(--columns) - 1) * var(--gap)) / var(--columns)));
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  column-gap: var(--gap);
  row-gap: clamp(24px, 5vh, 55px);
  isolation: isolate;
}
.tube {
  display: grid;
  position: relative;
  width: var(--piece);
  flex: 0 0 var(--piece);
  min-width: 0;
  padding: 0 2px;
  border: 0;
  background: transparent;
  container-type: inline-size;
}
.glass {
  display: flex;
  position: relative;
  flex-direction: column-reverse;
  align-items: center;
  justify-content: flex-start;
  gap: 4cqw;
  width: calc(100% - 6px);
  margin: 4px auto 0;
  height: calc(325cqw + 6px);
  padding-bottom: 10cqw;
  border: 2px solid var(--glass);
  border-top: 0;
  border-radius: 2px 2px 52% 52% / 2px 2px 15% 15%;
  background: linear-gradient(90deg, #b1dcf013 0, #0a2638a8 13%, #102e41d6 81%, #abd8ed10 100%);
  box-shadow: inset 0 -2px 5px #a7d9f120;
}
.glass::before {
  content: "";
  position: absolute;
  inset: -4px -5px auto;
  height: 7px;
  border: 2px solid var(--glass);
  border-radius: 8px;
  background: #17384d;
}
.ball {
  position: relative;
  z-index: 1;
  width: 65cqw;
  height: 65cqw;
  flex: 0 0 65cqw;
  overflow: hidden;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 23%, #fff6, transparent 40%), radial-gradient(circle at 39% 37%, var(--candy-light) 41%, var(--candy-shade) 100%);
  box-shadow: inset 0 -2px 3px #081b492e, 0 2px 3px #081b4970;
  transition: transform 165ms ease-out;
}
.ball svg { display: block; width: 100%; height: 100%; fill: #fff; opacity: .25; }
.ball::before, .ball::after {
  position: absolute;
  content: "";
  border-radius: 50%;
  background: #fffffff2;
}
.ball::before { inset: 12% auto auto 19%; width: 17%; height: 10%; transform: rotate(-41deg); }
.ball::after { inset: 26% auto auto 12%; width: 7%; height: 7%; }
.tube[aria-pressed="true"], .tube:focus-visible { z-index: 2; }
.tube[aria-pressed="true"] .glass { --glass: #b4effb; box-shadow: 0 0 12px #8fddf45c; }
.tube[aria-pressed="true"] .ball:last-child { transform: translateY(-27cqw); }
.tube[data-complete] .glass { --glass: #88ead1; }
#message { min-height: 2.8em; padding: 0 12px; color: var(--muted); text-align: center; font-size: .9rem; }
.controls { display: flex; justify-content: center; align-items: center; gap: clamp(19px, 6vw, 39px); padding: 12px 0 0; }
.controls button {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(58px, 17vw, 79px);
  aspect-ratio: 1;
  padding: 14px;
  border: 1px solid #92cee821;
  border-radius: 25%;
  background: var(--control);
  box-shadow: 0 3px 0 #0b2436b3, inset 0 1px #a2d4ee14;
}
.controls button:active { translate: 0 2px; }
.controls button[aria-pressed="true"] { border-color: #a9ecf9; box-shadow: 0 0 0 2px #a9ecf94d; }
.controls button:disabled svg { opacity: .36; }
.controls .count {
  position: absolute;
  display: grid;
  place-items: center;
  top: -7px;
  right: -7px;
  width: 25px;
  height: 25px;
  border: 2px solid #244d61;
  border-radius: 50%;
  background: #397696;
  color: #fff;
  font-size: .85rem;
  font-variant-numeric: tabular-nums;
}
#undo .count { color: #092d21; background: #73df64; }
.controls button:disabled .count { filter: saturate(.62); }
#celebration {
  position: absolute;
  z-index: 3;
  inset: 40% 0 auto;
  margin-inline: auto;
  width: max-content;
  max-width: 100%;
  text-align: center;
  pointer-events: none;
  font-size: 1.25rem;
  font-weight: 900;
}
#celebration:not(:empty) { padding: .3em .62em; border-radius: .7em; color: #fff4c1; background: #144455; border: 1px solid #ffe99cba; box-shadow: 0 0 15px #ffca6366; }
#celebration.combo { font-size: clamp(1.6rem, 7vw, 2.75rem); letter-spacing: .045em; text-shadow: 0 0 12px #ffc65a; }
#sparks { position: absolute; z-index: 2; inset: 0; pointer-events: none; overflow: hidden; }
#sparks span { position: absolute; font-size: 1.2rem; text-shadow: 0 0 8px currentColor; }
dialog {
  width: min(92vw, 410px);
  max-height: 85dvh;
  padding: 23px;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 18px 60px #061b2bbf;
}
dialog::backdrop { background: #071c2bc9; }
dialog p, .help-list { color: var(--muted); margin-top: 12px; line-height: 1.5; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
dialog button { min-height: 44px; border: 1px solid var(--line); border-radius: 12px; background: #214f65; }
dialog button:disabled { opacity: .4; }
.close { min-width: 44px; }
.help-list { padding-inline-start: 20px; }
.help-list strong { color: #f4fbff; }
.progress-info { margin-block: 14px; color: var(--muted); }
progress { display: block; width: 100%; height: 7px; margin-top: 7px; overflow: hidden; border: 0; border-radius: 20px; accent-color: #84e5d8; }
progress::-webkit-progress-bar { background: #0d2838; }
progress::-webkit-progress-value { background: #84e5d8; }
.pause-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
#level-grid { margin-top: 16px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
#level-grid button[aria-current] { background: #347d88; }
#win-dialog { text-align: center; }
.win-badge { color: #ffe39a; font-size: 2.5rem; }
.primary { margin-top: 16px; width: 100%; border: 0; background: #a1e6ef; color: #14374a; }
.quiet { margin-top: 5px; border: 0; background: transparent; color: #b8dfea; }
[hidden] { display: none !important; }
@media (min-width: 650px) { body::before { background-size: min(100%, 960px) auto; } }
@media (max-height: 580px) { .arena { padding-block: 30px 16px; } }
@media (prefers-reduced-motion: reduce) { .ball { transition: none; } }
