@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600;700&family=Nunito:wght@600;700;800&display=swap');

:root {
  --ink: #5c607d;
  --deep-ink: #464b6c;
  --steel-1: #fffaf3;
  --steel-2: #d7e7ee;
  --steel-3: #afc9d6;
  --steel-4: #809aae;
  --aqua: #7ddbd3;
  --aqua-dark: #5aafaf;
  --red: #ed8da1;
  --yellow: #f5d887;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% 10%, #fff5d7 0 8%, transparent 30%),
    radial-gradient(circle at 85% 90%, #dfd7f3 0 7%, transparent 28%),
    linear-gradient(145deg, #c9eaf0, #f5dfea 52%, #d9e7f7);
  color: var(--ink);
  font-family: 'Nunito', 'Trebuchet MS', sans-serif;
  padding: 22px 14px;
}

.celebration-layer {
  position: fixed;
  z-index: 20;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

button {
  font: inherit;
}

.cabinet {
  position: relative;
  width: min(100%, 500px);
  padding: 24px clamp(16px, 5vw, 29px) 20px;
  border: 2px solid #a8bdcb;
  border-radius: 18px;
  background:
    linear-gradient(115deg, transparent 20%, rgba(255,255,255,.36) 21%, transparent 23% 47%, rgba(255,255,255,.2) 48%, transparent 51%),
    linear-gradient(180deg, #f5f1f4, #d7e8ef 52%, #c5dce8);
  background-size: 230px 100%, auto;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.9),
    inset 0 -2px 0 rgba(112,145,163,.22),
    0 18px 38px rgba(95,104,145,.2),
    0 4px 0 #9eb7c5;
}

.cabinet::after {
  content: '';
  position: absolute;
  inset: 8px;
  pointer-events: none;
  border: 1px solid rgba(255,255,255,.55);
  border-radius: 13px;
}

.cabinet-rivets {
  position: absolute;
  inset: 10px 12px auto;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.cabinet-rivets i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #a2c1cc 48%, #7895a7 88%);
  box-shadow: 0 1px 1px #fff;
}

.header {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 19px;
}

h1 {
  margin: 0;
  color: #59628b;
  font-family: 'Fredoka', 'Trebuchet MS', sans-serif;
  font-size: clamp(1.3rem, 6vw, 1.9rem);
  font-weight: 700;
  letter-spacing: .04em;
  line-height: .9;
  text-align: center;
  text-shadow: 0 2px 0 #fff, 0 3px 0 rgba(112,124,168,.18);
  white-space: nowrap;
}

h1 em {
  display: block;
  color: #7a83a8;
  font-size: .7em;
  font-style: normal;
  letter-spacing: .11em;
  margin-top: 5px;
}

.levels {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin: 0 0 12px;
  padding: 3px;
  border: 1px solid #aec5d2;
  border-radius: 10px;
  background: rgba(255, 255, 255, .3);
}

.level-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  padding: 6px 3px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #697292;
  cursor: pointer;
  background: transparent;
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .06em;
  line-height: 1;
}

.level-button:hover {
  color: #59628b;
  background: rgba(255, 255, 255, .55);
}

.level-button.active {
  border-color: #78bdbb;
  color: #fff;
  background: #84c9c5;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 2px 4px rgba(87,157,161,.2);
}

.level-number {
  color: #95a6b3;
  font-size: .52rem;
}

.level-button.active .level-number {
  color: #eafff6;
}

.badge {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #76819e;
  font-size: .57rem;
  font-weight: 700;
  letter-spacing: .08em;
}

.badge.right {
  justify-content: flex-end;
}

.badge-star {
  color: #e8a9bb;
  font-size: .9rem;
}

.control-strip {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 52px 1fr;
  align-items: center;
  gap: 18px;
  min-height: 74px;
  padding: 10px 16px;
  border: 3px solid #a5bdcd;
  border-radius: 13px;
  background: #d6e6ef;
  box-shadow:
    inset 0 2px 3px rgba(104,139,157,.18),
    inset 0 -1px 0 rgba(255,255,255,.8),
    0 3px 0 rgba(116,157,175,.25);
}

.counter {
  min-width: 0;
}

.counter:last-child {
  text-align: right;
}

.counter-label {
  display: block;
  overflow: hidden;
  color: #71829a;
  font-size: .58rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.counter strong {
  display: block;
  margin-top: 3px;
  color: var(--red);
  font-size: clamp(1.35rem, 6vw, 1.9rem);
  font-family: 'Fredoka', 'Trebuchet MS', sans-serif;
  font-weight: 600;
  letter-spacing: .08em;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(255,255,255,.7);
}

.reset {
  width: 45px;
  height: 45px;
  justify-self: center;
  padding: 0;
  border: 2px solid #d99aa8;
  border-radius: 50%;
  color: #d2788d;
  cursor: pointer;
  background: linear-gradient(145deg, #fff9dd, #f5c7bc);
  box-shadow: inset 0 1px 1px rgba(255,255,255,.85), 0 3px 0 #c797a6;
}

.reset:active {
  transform: translateY(2px);
  box-shadow: inset 0 1px 2px rgba(150,91,110,.24);
}

.reset span:not(.sr-only) {
  display: inline-block;
  font-size: 1.2rem;
  line-height: 1;
  transform: rotate(-18deg);
}

.reset:hover {
  border-color: #d889a0;
}

.game-frame {
  position: relative;
  z-index: 1;
  margin-top: 17px;
  padding: 8px;
  border: 2px solid #a0b8ca;
  border-radius: 13px;
  background: #b7d0df;
  box-shadow: inset 0 2px 3px rgba(91,126,150,.24), 0 3px 0 rgba(255,255,255,.75);
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--grid-size, 9), 1fr);
  aspect-ratio: 1;
  gap: 3px;
  padding: 4px;
  border: 2px solid #91afc2;
  border-radius: 8px;
  background: #8fb3ca;
  box-shadow: inset 0 0 0 1px #cce0e8;
}

.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 1px solid #acc3d0;
  border-radius: 5px;
  color: var(--aqua);
  cursor: pointer;
  background:
    linear-gradient(135deg, rgba(255,255,255,.56), transparent 40%),
    linear-gradient(145deg, #fff0d9, #d9eaf2);
  box-shadow: inset 1px 1px 0 rgba(255,255,255,.8), inset -1px -1px 0 rgba(112,145,163,.22);
  font-family: 'Fredoka', 'Trebuchet MS', sans-serif;
  font-size: clamp(.78rem, 4.5vw, 1.35rem);
  line-height: 1;
  text-shadow: 0 1px 0 rgba(255,255,255,.7);
  transition: filter .12s, transform .12s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cell:hover:not(.revealed):not(.flagged) {
  filter: brightness(1.06) saturate(1.08);
}

.cell:focus-visible {
  z-index: 2;
  outline: 3px solid #f0a7ba;
  outline-offset: 1px;
}

.cell:active:not(.revealed) {
  transform: scale(.93);
}

.cell.revealed {
  cursor: default;
  border-color: #c1b9d1;
  background: #f3eef5;
  box-shadow: inset 1px 1px 2px rgba(119,105,143,.16);
  text-shadow: 0 1px 0 #fff;
}

.cell.flagged::before {
  content: '';
  position: absolute;
  left: 47%;
  top: 27%;
  width: 2px;
  height: 53%;
  background: #7787a9;
  box-shadow: 1px 0 0 rgba(255,255,255,.55);
}

.cell.flagged::after {
  content: '';
  position: absolute;
  left: 28%;
  top: 20%;
  width: 46%;
  height: 31%;
  border: 1px solid #d97991;
  border-radius: 2px 7px 2px 2px;
  background: linear-gradient(135deg, #ffadbd, #e77a96);
  clip-path: polygon(0 0, 100% 15%, 0 100%);
}

.cell.flagged {
  color: transparent;
}

.cell[data-number="1"] { color: #5eb8b5; }
.cell[data-number="2"] { color: #dbad4f; }
.cell[data-number="3"] { color: #e77d91; }
.cell[data-number="4"] { color: #9a79c7; }
.cell[data-number="5"] { color: #db8b62; }
.cell[data-number="6"] { color: #53ad82; }
.cell[data-number="7"] { color: #c09c48; }
.cell[data-number="8"] { color: #7885a3; }

.cell.balloon {
  overflow: visible;
  border-color: #d5b6c6;
  background: #fff0f4;
  animation: balloon-pop .8s cubic-bezier(.2,.85,.35,1.35) both;
}

.balloon-glyph {
  position: relative;
  display: block;
  width: 58%;
  height: 64%;
  min-width: 10px;
  min-height: 10px;
  margin: 8% auto 0;
  border: 1px solid var(--balloon-dark);
  border-radius: 52% 52% 48% 48% / 58% 58% 42% 42%;
  background:
    radial-gradient(circle at 27% 20%, rgba(255,255,255,.95) 0 9%, transparent 10% 100%),
    linear-gradient(110deg, var(--balloon-light) 0 20%, var(--balloon-main) 53%, var(--balloon-dark) 100%);
  box-shadow: 1px 2px 0 rgba(94,105,145,.24), inset -2px -2px 2px rgba(94,105,145,.12);
  animation: balloon-bob .65s ease-out both;
}

.balloon-glyph.flying {
  z-index: 4;
  animation: balloon-fly-away 3.8s cubic-bezier(.2,.72,.3,1) forwards;
}

.balloon-glyph.departing {
  opacity: 0;
}

.sky-balloon {
  position: fixed;
  z-index: 21;
  display: block;
  margin: 0;
  transform-origin: 50% 92%;
  animation: sky-balloon-float var(--sky-duration, 6s) cubic-bezier(.22,.58,.27,1) both;
}

.balloon-knot {
  position: absolute;
  z-index: 1;
  left: 39%;
  top: 91%;
  width: 23%;
  height: 17%;
  background: var(--balloon-dark);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.balloon-string {
  position: absolute;
  left: 50%;
  top: 101%;
  width: 1px;
  height: 39%;
  background: #b6a7b4;
  box-shadow: 1px 0 0 rgba(255,255,255,.65);
  transform: rotate(4deg);
  transform-origin: top;
}

.balloon-red {
  --balloon-light: #ffc0c7;
  --balloon-main: #f28fa4;
  --balloon-dark: #c76e87;
}

.balloon-yellow {
  --balloon-light: #fff4ba;
  --balloon-main: #f6d985;
  --balloon-dark: #d1ae5e;
}

.balloon-blue {
  --balloon-light: #c7f0fa;
  --balloon-main: #8dcfe2;
  --balloon-dark: #63a8c0;
}

.balloon-green {
  --balloon-light: #d4f6c9;
  --balloon-main: #9bd8a1;
  --balloon-dark: #6eae7c;
}

.balloon-purple {
  --balloon-light: #ecd7ff;
  --balloon-main: #c2a0e3;
  --balloon-dark: #9877bf;
}

.balloon-orange {
  --balloon-light: #ffe3b6;
  --balloon-main: #f4b47e;
  --balloon-dark: #d28d61;
}

.cell.popped {
  color: #e4b85c;
  background: #fff5de;
}

.cell.popped .balloon-glyph:not(.flying) {
  opacity: 0;
}

.burst {
  position: absolute;
  inset: 5%;
  pointer-events: none;
}

.burst::before,
.burst::after {
  content: '✦';
  position: absolute;
  color: var(--yellow);
  font-family: sans-serif;
  font-size: .8rem;
  animation: sparkle .58s ease-out both;
}

.burst::before { left: 2%; top: 2%; }
.burst::after { right: 0; bottom: 0; color: #e89ab0; animation-delay: .06s; }

.status-line {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 10px 3px 0;
  color: #66718f;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .08em;
}

.led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--aqua);
  box-shadow: 0 0 8px rgba(125,219,211,.7);
}

.led.danger {
  background: var(--red);
  box-shadow: 0 0 8px rgba(237,141,161,.7);
}

.led.win {
  background: var(--yellow);
  box-shadow: 0 0 8px rgba(245,216,135,.7);
}

.status-mark {
  margin-left: auto;
  color: #96a5b5;
  font-weight: 700;
}

.touch-tools {
  display: none;
  position: relative;
  z-index: 1;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 7px;
}

.tool-button {
  padding: 7px 4px;
  border: 1px solid #a9c1cd;
  border-radius: 9px;
  color: #657391;
  background: rgba(255,255,255,.42);
  cursor: pointer;
  font-size: .62rem;
  letter-spacing: .1em;
}

.tool-button.active {
  color: #fff;
  border-color: #78bdbb;
  background: #84c9c5;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.6);
}

.footer {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
  color: #7784a0;
  font-weight: 800;
  font-size: .51rem;
  letter-spacing: .06em;
  white-space: nowrap;
}

.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 balloon-pop {
  0% { transform: scale(.5); opacity: .3; }
  65% { transform: scale(1.12); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes balloon-bob {
  0% { transform: translateY(7px) scale(.75); }
  75% { transform: translateY(-2px) scale(1.05); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes balloon-fly-away {
  0% {
    opacity: 1;
    transform: translate(0, 0) rotate(0deg) scale(1);
  }
  18% {
    transform: translate(calc(var(--fly-x) * .25), -12px) rotate(calc(var(--fly-rotate) * .35)) scale(1.04);
  }
  100% {
    opacity: 0;
    transform: translate(var(--fly-x), -145px) rotate(var(--fly-rotate)) scale(.8);
  }
}

@keyframes sky-balloon-float {
  0% {
    opacity: 0;
    transform: translate3d(0, 26px, 0) rotate(calc(var(--sky-rotate) * -.7)) scale(.82);
  }
  10% {
    opacity: 1;
    transform: translate3d(calc(var(--sky-sway) * .15), 0, 0) rotate(calc(var(--sky-rotate) * .55)) scale(1);
  }
  25% {
    opacity: 1;
    transform: translate3d(calc(var(--sky-x) * .1 - var(--sky-sway)), -17vh, 0) rotate(calc(var(--sky-rotate) * -.4)) scale(1.04);
  }
  42% {
    transform: translate3d(calc(var(--sky-x) * .25 + var(--sky-sway)), -37vh, 0) rotate(calc(var(--sky-rotate) * .7)) scale(.99);
  }
  60% {
    opacity: .94;
    transform: translate3d(calc(var(--sky-x) * .43 - var(--sky-sway)), -61vh, 0) rotate(calc(var(--sky-rotate) * -.65)) scale(1.01);
  }
  78% {
    opacity: .78;
    transform: translate3d(calc(var(--sky-x) * .7 + var(--sky-sway)), -88vh, 0) rotate(calc(var(--sky-rotate) * .35)) scale(.94);
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--sky-x), -124vh, 0) rotate(var(--sky-rotate)) scale(.78);
  }
}

@keyframes sparkle {
  0% { opacity: 1; transform: scale(.3) translate(0, 0); }
  100% { opacity: 0; transform: scale(1.5) translate(8px, -8px); }
}

@media (max-width: 420px) {
  body { padding: 11px 7px; }
  .cabinet { padding-inline: 13px; }
  .header { gap: 5px; }
  .badge { font-size: .48rem; }
  .control-strip { gap: 8px; padding-inline: 10px; }
  .footer { font-size: .45rem; }
}

@media (pointer: coarse) {
  .touch-tools { display: grid; }
  .footer span:nth-child(2) { display: none; }
}
