:root {
  --navy: #24304f;
  --lavender: #a995d6;
  --mint: #77d2bd;
  --peach: #ffbe9d;
  --cream: #fff8ee;
  --gold: #ffc43d;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  color: var(--navy);
  background: #8c79c6;
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", Arial, sans-serif;
}
button { font: inherit; }

.game-shell {
  min-height: 100vh;
  position: relative;
  overflow: hidden;
  padding: clamp(10px, 3vw, 42px);
  background-image:
    linear-gradient(rgba(137, 112, 193, .35), rgba(255, 190, 157, .18)),
    url("images/background.webp");
  background-position: center;
  background-size: cover;
}
.game-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, transparent 20%, rgba(53, 38, 92, .18));
  pointer-events: none;
}
.sparkles i {
  position: absolute;
  z-index: 0;
  color: #ffe89a;
  font-style: normal;
  text-shadow: 0 0 12px #fff5c3;
  animation: twinkle 2.8s ease-in-out infinite;
}
.sparkles i:nth-child(1) { left: 3%; top: 10%; font-size: 28px; }
.sparkles i:nth-child(2) { left: 17%; bottom: 5%; font-size: 20px; animation-delay: -.8s; }
.sparkles i:nth-child(3) { right: 8%; top: 8%; font-size: 34px; animation-delay: -1.4s; }
.sparkles i:nth-child(4) { right: 3%; bottom: 20%; font-size: 22px; animation-delay: -.4s; }
.sparkles i:nth-child(5) { left: 2%; top: 52%; font-size: 18px; animation-delay: -1.8s; }

.game {
  width: min(1440px, 100%);
  min-height: calc(100vh - clamp(20px, 6vw, 84px));
  margin: auto;
  position: relative;
  z-index: 1;
  padding: clamp(14px, 2.4vw, 34px);
  border: 2px solid rgba(255,255,255,.76);
  border-radius: 34px;
  background: rgba(255, 249, 245, .84);
  box-shadow: 0 28px 70px rgba(55,35,96,.28), inset 0 1px 0 #fff;
  backdrop-filter: blur(10px);
}
.topbar,.board-card,.palette-wrap { position: relative; z-index: 2; }
.side-art { display: none; position: absolute; z-index: 1; pointer-events: none; }
.side-art img { display: block; width: 100%; height: auto; }
.artists-art { left: 12px; bottom: 4px; width: clamp(190px,17vw,250px); }
.starling-art { right: 14px; bottom: 8px; width: clamp(185px,16vw,235px); text-align: center; }
.brand-mark {
  margin-top: -28px;
  color: #5d4a86;
  font-size: clamp(18px,1.8vw,27px);
  font-weight: 900;
  letter-spacing: .02em;
  text-shadow: 0 2px 0 #fff, 0 0 10px rgba(255,255,255,.9);
}
.finish-actions { position: relative; z-index: 4; margin: 20px auto 0; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; width: min(640px,100%); animation: popIn .4s cubic-bezier(.2,.9,.3,1.2); }
.finish-actions:not([hidden]) { display: grid; }
.finish-title { grid-column: 1/-1; color: #6954a4; font-size: 20px; font-weight: 900; text-align: center; text-shadow: 0 2px #fff; }
.finish-title span { color: var(--gold); }
.finish-button { min-height: 72px; display: flex; align-items: center; justify-content: center; gap: 9px; padding: 9px 12px; border: 4px solid #fff; border-radius: 24px; color: var(--navy); font-size: 14px; font-weight: 900; line-height: 1.12; cursor: pointer; box-shadow: 0 7px 0 rgba(51,40,78,.16),0 10px 22px rgba(51,40,78,.16); transition: transform .16s,box-shadow .16s; }
.finish-button b { flex: 0 0 auto; font-size: 29px; line-height: 1; }
.finish-button:hover { transform: translateY(-4px); }
.finish-button:active { transform: translateY(1px); }
.finish-button.result { background: var(--gold); }
.finish-button.scheme { background: var(--mint); }
.finish-button.again { background: #e9dcf7; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 18px; }
.title-group { display: flex; align-items: center; gap: 16px; min-width: 0; }
.title-star {
  width: 60px; height: 60px; display: grid; place-items: center; flex: 0 0 auto;
  color: #fff; font-size: 31px; background: var(--gold); border: 4px solid #fff3b9;
  border-radius: 20px; transform: rotate(-7deg); box-shadow: 0 7px 18px rgba(211,145,26,.26);
}
h1 { margin: 0; color: var(--navy); font-size: clamp(29px, 4vw, 56px); line-height: 1; letter-spacing: -.045em; text-shadow: 0 2px #fff; }
.title-group p { margin: 8px 0 0; color: #6c5c83; font-size: clamp(14px, 1.35vw, 19px); font-weight: 700; }
.controls { display: flex; align-items: center; justify-content: flex-end; gap: 11px; flex: 0 0 auto; }
.progress-card { width: 185px; padding: 11px 14px; border: 2px solid rgba(169,149,214,.28); border-radius: 18px; background: rgba(255,255,255,.9); box-shadow: 0 6px 16px rgba(62,46,100,.12); }
.progress-copy { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 7px; font-size: 16px; font-weight: 700; }
.progress-copy strong { color: #6954a4; }
.progress-track { height: 10px; overflow: hidden; border-radius: 999px; background: #e9e2ed; box-shadow: inset 0 1px 3px rgba(51,42,73,.15); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg,var(--mint),#61cbb2); transition: width .3s ease; }
.control-button { height: 52px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; border: 2px solid; border-radius: 16px; background: rgba(255,255,255,.93); font-size: 16px; font-weight: 800; cursor: pointer; box-shadow: 0 5px 14px rgba(47,36,75,.12); transition: transform .16s, box-shadow .16s; }
.control-button:hover { transform: translateY(-2px); box-shadow: 0 8px 17px rgba(47,36,75,.17); }
.control-button:active { transform: translateY(1px) scale(.98); }
.control-button b { font-size: 23px; }
.reset-button { color: #a74f54; border-color: #e4a3a1; }
.sound-button { color: #52766d; border-color: #95cdbc; }
.sound-button.is-on { background: #e8fbf4; }

.board-card { width: min(100%, 810px); margin: auto; padding: clamp(8px,1.3vw,16px); border: 3px solid rgba(255,255,255,.94); border-radius: 25px; background: rgba(255,255,255,.76); box-shadow: 0 12px 32px rgba(60,43,89,.17); }
.board { box-sizing: content-box; display: grid; grid-template-columns: repeat(25,minmax(0,1fr)); grid-template-rows: repeat(25,minmax(0,1fr)); margin: auto; overflow: hidden; border: 3px solid var(--navy); border-radius: 10px; background: #fffdf7; user-select: none; touch-action: none; }
.cell { position: relative; width: 100%; height: 100%; min-width: 0; min-height: 0; display: grid; place-items: center; padding: 0; border: 0; border-right: 1px solid rgba(36,48,79,.8); border-bottom: 1px solid rgba(36,48,79,.8); color: var(--navy); background: #fffdf7; font-size: clamp(7px,.95vw,14px); font-weight: 900; cursor: pointer; transition: background-color .1s; }
.cell:nth-child(25n) { border-right: 0; }
.cell:nth-last-child(-n+25) { border-bottom: 0; }
.cell:hover:not(.painted) { background: #f5effb; box-shadow: inset 0 0 0 3px rgba(169,149,214,.45); }
.cell.painted { animation: none; cursor: default; }
.cell.wrong { z-index: 2; background: #ffe6e2; animation: wrongCell .3s ease; }
.cell:focus-visible { z-index: 3; outline: 4px solid #7054b6; outline-offset: -4px; }
.palette-wrap { text-align: center; }
.palette-hint { min-height: 18px; position: relative; z-index: 4; margin: 12px 0 25px; color: #66567c; font-size: 15px; font-weight: 700; }
.palette { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: clamp(9px,1.6vw,20px); }
.color-button { position: relative; width: clamp(52px,6vw,76px); height: clamp(52px,6vw,76px); display: grid; place-items: center; border: 5px solid #fff; border-radius: 50%; color: #fff; font-size: clamp(24px,2.7vw,36px); font-weight: 900; cursor: pointer; box-shadow: 0 7px 0 rgba(51,40,78,.17),0 10px 22px rgba(51,40,78,.18); text-shadow: 0 2px 3px rgba(30,25,43,.5); transition: transform .17s, box-shadow .17s; }
.color-button:hover { transform: translateY(-4px); }
.color-button.selected { transform: translateY(-7px) scale(1.07); box-shadow: 0 0 0 5px #fff3b3,0 0 0 10px var(--gold),0 11px 25px rgba(84,58,113,.28); }
.color-button.selected::before,.color-button.selected::after { content: "✦"; position: absolute; color: var(--gold); font-size: 20px; text-shadow: 0 0 8px #fff; animation: twinkle 1.7s ease-in-out infinite; }
.color-button.selected::before { top: -18px; right: -12px; }
.color-button.selected::after { bottom: -15px; left: -10px; animation-delay: -.8s; }
.color-button:focus-visible,.control-button:focus-visible { outline: 4px solid #fff; box-shadow: 0 0 0 7px #6a51aa; }

@keyframes fillCell { from { transform: scale(.78); opacity: .45; } to { transform: scale(1); opacity: 1; } }
@keyframes wrongCell { 0%,100% { transform: translateX(0); } 30% { transform: translateX(-5px); } 65% { transform: translateX(5px); } }
@keyframes twinkle { 0%,100% { transform: scale(.75) rotate(-5deg); opacity: .65; } 50% { transform: scale(1.15) rotate(7deg); opacity: 1; } }
@keyframes popIn { from { transform: scale(.72); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes floatConfetti { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(18px) rotate(3deg); } }

@media (max-width: 980px) {
  .topbar { align-items: flex-start; flex-direction: column; gap: 16px; }
  .controls { width: 100%; justify-content: stretch; }
  .progress-card { flex: 1; width: auto; }
}
@media (min-width: 1180px) {
  .side-art { display: block; }
  .finish-actions { position: absolute; right: 18px; bottom: clamp(280px,30vw,355px); width: clamp(190px,16vw,235px); margin: 0; grid-template-columns: 1fr; gap: 9px; }
  .finish-title { grid-column: auto; }
  .finish-button { min-height: 64px; border-radius: 22px; }
}
@media (max-width: 640px) {
  .game-shell { padding: 8px; overflow-y: auto; }
  .game { min-height: calc(100vh - 16px); padding: 14px 9px 20px; border-radius: 23px; }
  .title-group { align-items: flex-start; gap: 10px; }
  .title-star { width: 44px; height: 44px; border-radius: 14px; font-size: 23px; }
  h1 { font-size: clamp(26px,8vw,40px); }
  .title-group p { line-height: 1.3; margin-top: 6px; }
  .controls { display: grid; grid-template-columns: 1fr 1fr; }
  .progress-card { grid-column: 1/-1; }
  .control-button { height: 46px; padding: 0 10px; font-size: 14px; }
  .board-card { padding: 5px; border-radius: 14px; }
  .board { border-width: 2px; border-radius: 6px; }
  .cell { font-size: clamp(7px,2.2vw,10px); }
  .palette { gap: clamp(7px,2.7vw,15px); }
  .color-button { width: clamp(50px,15vw,70px); height: clamp(50px,15vw,70px); border-width: 3px; font-size: 25px; }
  .color-button.selected { box-shadow: 0 0 0 3px #fff3b3,0 0 0 6px var(--gold),0 8px 17px rgba(84,58,113,.25); }
  .finish-actions { grid-template-columns: 1fr; width: min(330px,100%); }
}
@media (prefers-reduced-motion: reduce) {
  *,*::before,*::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
