:root {
  --ink: #263344;
  --muted: #718096;
  --paper: #fffdf8;
  --cream: #f8f4ea;
  --line: #e7e2d8;
  --coral: #f4776b;
  --yellow: #f7c948;
  --mint: #60c7a5;
  --sky: #68b8df;
  --violet: #9b86d8;
  --pink: #e994b4;
  --shadow: 0 18px 45px rgba(55, 54, 42, 0.09);
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  color: var(--ink);
  background: var(--cream);
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(circle at 12% 8%, #fff9d9 0, transparent 26rem), var(--cream);
}

button { font: inherit; }

.start-screen {
  width: min(560px, calc(100% - 24px));
  min-height: 100vh;
  display: grid;
  place-items: center;
  margin: 0 auto;
  padding: 32px 0;
}

.start-card {
  width: 100%;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(220, 210, 188, 0.9);
  border-radius: 28px;
  box-shadow: 0 20px 40px rgba(59, 60, 54, 0.08);
  padding: 68px 28px 30px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.start-card .back-button {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  min-width: 54px;
  min-height: 54px;
  padding: 0;
  border-radius: 999px;
  background: #fff4d9;
  color: #a86b12;
  border: 1px solid #f3ddb2;
  text-decoration: none;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(170, 110, 10, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  font-size: 1.5rem;
}

.start-card .back-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(170, 110, 10, 0.12);
}

.start-card::before,
.start-card::after {
  content: "";
  position: absolute;
  width: 170px;
  height: 170px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(244, 119, 107, 0.18), rgba(244, 119, 107, 0));
  pointer-events: none;
}

.start-card::before {
  top: -72px;
  left: -52px;
}

.start-card::after {
  right: -52px;
  bottom: -74px;
}

.start-card .eyebrow {
  position: relative;
  z-index: 1;
}

.start-card h2 {
  position: relative;
  z-index: 1;
  margin: 0 0 18px;
  font-size: clamp(2.2rem, 4vw, 3.2rem);
  letter-spacing: -0.05em;
  color: var(--ink);
}

#start-game-button {
  position: relative;
  z-index: 1;
  border: none;
  width: 88px;
  height: 88px;
  background: linear-gradient(180deg, #f7b35a 0%, #f49555 100%);
  color: white;
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 0;
  border-radius: 28px;
  cursor: pointer;
  box-shadow: 0 16px 26px rgba(244, 149, 85, 0.22);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#start-game-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 30px rgba(244, 149, 85, 0.26);
}

.game-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 44px;
}

.game-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 26px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.back-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  padding: 0;
  border-radius: 999px;
  background: #fff4d9;
  color: #a86b12;
  border: 1px solid #f3ddb2;
  text-decoration: none;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(170, 110, 10, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  font-size: 1.5rem;
}

.back-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(170, 110, 10, 0.12);
}

.eyebrow {
  display: none;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 7px;
  font-family: Georgia, serif;
  font-size: clamp(2.2rem, 5vw, 4.4rem);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 0.95;
}

.subtitle { display: none; }

.round-badge {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 8px 20px rgba(55, 54, 42, 0.06);
  white-space: nowrap;
}

.round-label { display: none; }
.round-badge strong { color: var(--coral); font-size: 1.5rem; }
.round-total { color: var(--muted); font-size: 0.9rem; }

.board { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel, .palette-panel {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 253, 248, 0.88);
  box-shadow: var(--shadow);
}
.panel { min-height: 340px; padding: 23px; }

.panel-heading, .palette-heading { display: flex; align-items: center; gap: 12px; }
.panel-heading { margin-bottom: 23px; }
.panel-heading h2, .palette-heading h2 { margin-bottom: 0; font-size: 1.8rem; line-height: 1; }
.panel-heading p, .palette-heading p { margin-bottom: 0; color: var(--muted); font-size: 0.82rem; }
.step-number {
  display: grid;
  flex: 0 0 31px;
  width: 31px;
  height: 31px;
  place-items: center;
  border-radius: 50%;
  background: #fff1bf;
  color: #9a7414;
  font-size: 0.85rem;
  font-weight: 800;
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(65px, 1fr));
  gap: 17px;
  align-items: center;
  justify-items: center;
}

.shape-slot {
  display: grid;
  width: 100%;
  min-height: 105px;
  place-items: center;
  border-radius: 16px;
  background: rgba(248, 244, 234, 0.7);
}

.shape {
  width: 68px;
  height: 68px;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
}
.shape.circle { border-radius: 50%; }
.shape.square { border-radius: 10px; }
.shape.triangle { width: 0; height: 0; border-right: 36px solid transparent; border-bottom: 68px solid currentColor; border-left: 36px solid transparent; background: transparent !important; }
.shape.diamond { width: 52px; height: 52px; transform: rotate(45deg); border-radius: 8px; }
.shape.star { width: 68px; height: 68px; clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 93%, 50% 71%, 21% 93%, 32% 57%, 2% 35%, 39% 35%); }
.shape.hexagon { width: 72px; height: 62px; clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%); }

.shape.target { border: 4px dashed #cfc8b9; background: transparent; }
.shape.target.triangle { border-top: 0; border-right: 36px solid transparent; border-bottom: 68px solid #d4cdbf; border-left: 36px solid transparent; opacity: 0.72; }
.shape.target.star, .shape.target.hexagon { border: 0; background: #d4cdbf; opacity: 0.72; }
.shape.target.diamond { background: transparent; }
.shape.target.is-filled { border-style: solid; outline: none; opacity: 1; }
.shape.target.is-filled.triangle { border-bottom-color: var(--target-color); }
.shape.target.is-filled.star, .shape.target.is-filled.hexagon { background: var(--target-color); }
.shape.target.is-filled.diamond { background: var(--target-color); }
.shape-slot.is-over .shape.target { transform: scale(1.1); border-color: var(--coral); outline-color: var(--coral); }
.shape-slot.is-over .shape.target.triangle { border-bottom-color: var(--coral); }
.shape-slot.is-wrong { animation: shake 340ms ease; }

.palette-panel { margin-top: 18px; padding: 20px 23px 22px; }
.palette-heading { justify-content: space-between; margin-bottom: 18px; }
.palette-heading > div { display: flex; align-items: center; gap: 12px; }
#game-status { transition: color 160ms ease; font-weight: 700; }
#game-status.success { color: #329b78; font-weight: 800; }
#game-status.error { color: #d96157; font-weight: 800; }
.palette { display: flex; flex-wrap: wrap; justify-content: center; gap: 17px; }
.swatch {
  position: relative;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 5px solid var(--paper);
  border-radius: 50%;
  box-shadow: 0 5px 0 rgba(38, 51, 68, 0.13), 0 7px 12px rgba(38, 51, 68, 0.1);
  cursor: grab;
  touch-action: none;
  transition: transform 140ms ease, box-shadow 140ms ease;
}
.swatch:hover, .swatch:focus-visible { transform: translateY(-4px); box-shadow: 0 8px 0 rgba(38, 51, 68, 0.13), 0 10px 15px rgba(38, 51, 68, 0.12); outline: none; }
.swatch:active { cursor: grabbing; transform: scale(0.94); }
.swatch-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.drag-ghost { position: fixed; z-index: 10; width: 58px; height: 58px; border: 5px solid var(--paper); border-radius: 50%; pointer-events: none; opacity: 0.9; box-shadow: 0 12px 22px rgba(38, 51, 68, 0.22); transform: translate(-50%, -50%) scale(1.08); }

.celebration { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; background: rgba(38, 51, 68, 0.32); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity 220ms ease; }
.celebration.is-visible { opacity: 1; pointer-events: auto; }
.celebration-card { position: relative; width: min(390px, 100%); padding: 34px 28px 30px; border-radius: 28px; background: linear-gradient(180deg, #fffefb 0%, #fff7ee 100%); text-align: center; box-shadow: 0 28px 62px rgba(38, 51, 68, 0.2); border: 1px solid rgba(244, 204, 117, 0.6); transform: translateY(12px) scale(0.96); transition: transform 260ms ease; overflow: hidden; }
.celebration.is-visible .celebration-card { transform: translateY(0) scale(1); }
.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;
}

.celebration-card::before,
.celebration-card::after {
  content: "";
  position: absolute;
  inset: 18px auto auto 18px;
  width: 110px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(247, 201, 73, 0.8), transparent);
  transform: rotate(-9deg);
}
.celebration-card::after {
  inset: auto 18px 16px auto;
  transform: rotate(8deg);
}
.celebration-badges {
  display: flex;
  justify-content: center;
  gap: 12px;
  font-size: 2rem;
  margin-bottom: 10px;
  animation: badge-bounce 0.8s ease-in-out infinite alternate;
}
.celebration-badges span:nth-child(2) { animation-delay: 0.15s; }
.celebration-badges span:nth-child(3) { animation-delay: 0.3s; }
.celebration-spark { display: block; margin-bottom: 10px; color: var(--yellow); font-size: 3rem; line-height: 1; }
.celebration-card h2 { margin-bottom: 18px; font-family: Georgia, serif; font-size: clamp(2.5rem, 4vw, 3rem); }
.celebration-card p { display: none; }
#play-again {
  width: 88px;
  height: 88px;
  padding: 0;
  border: 0;
  border-radius: 28px;
  background: linear-gradient(180deg, #f7b35a 0%, #f49555 100%);
  color: white;
  font-size: 2.2rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 14px 22px rgba(244, 149, 85, 0.22);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#play-again:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 26px rgba(244, 149, 85, 0.26);
}
@keyframes badge-bounce {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-6px) scale(1.06); }
}

@keyframes shake { 25% { transform: translateX(-7px); } 50% { transform: translateX(7px); } 75% { transform: translateX(-4px); } }
@keyframes pop { 50% { transform: scale(1.13); } }
.shape.target.is-filled { animation: pop 260ms ease; }

@media (max-width: 700px) {
  .game-shell { width: min(100% - 20px, 560px); padding-top: 24px; }
  .game-header { align-items: flex-start; }
  .board { grid-template-columns: 1fr; }
  .panel { min-height: 0; padding: 18px; }
  .shape-slot { min-height: 88px; }
  .shape { width: 56px; height: 56px; }
  .shape.triangle { border-right-width: 30px; border-bottom-width: 56px; border-left-width: 30px; }
  .shape.diamond { width: 44px; height: 44px; }
  .shape.target.triangle { border-bottom-width: 56px; }
  .palette-panel { padding: 18px; }
  .palette-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
}

@media (max-width: 420px) {
  h1 { font-size: 2.25rem; }
  .subtitle { font-size: 0.88rem; }
  .round-badge { padding: 9px 12px; }
  .shape-grid { gap: 9px; }
  .shape-slot { min-height: 76px; }
}
