:root {
  color-scheme: light;
  --ink: #3d3a34;
  --muted: #6f6a61;
  --cream: #fff4d6;
  --blue: #4f8fcf;
  --green: #4f9d7e;
  --orange: #e98b45;
  --line: #e5ddce;
  --shadow: 0 14px 35px rgb(90 69 42 / 12%);
}

* {
  box-sizing: border-box;
}

html {
  background: #f8f3e9;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background:
    radial-gradient(circle at 8% 8%, rgb(255 220 184 / 58%) 0 8%, transparent 9%),
    radial-gradient(circle at 93% 16%, rgb(191 232 255 / 62%) 0 7%, transparent 8%),
    #f8f3e9;
  min-height: 100vh;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible,
[role="button"]:focus-visible {
  outline: 4px solid rgb(66 139 202 / 35%);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 30px 0 40px;
}

.hero {
  text-align: center;
  padding: 10px 16px 26px;
}

.eyebrow,
.step-label {
  margin: 0 0 6px;
  color: var(--orange);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .12em;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.2rem);
  letter-spacing: .06em;
}

.hero p:last-child {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: clamp(.95rem, 2vw, 1.12rem);
}

.mode-section,
.game-section {
  padding: 24px;
  border: 1px solid rgb(208 195 174 / 60%);
  border-radius: 28px;
  background: rgb(255 253 248 / 94%);
  box-shadow: var(--shadow);
}

.game-section {
  margin-top: 20px;
}

.section-heading,
.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.section-heading h2,
.game-topbar h2 {
  margin: 0;
  font-size: clamp(1.25rem, 3vw, 1.65rem);
}

.quiet-button {
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-weight: 750;
  cursor: pointer;
}

.quiet-button:hover {
  background: var(--cream);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 18px;
}

.mode-card {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: 2px 12px;
  min-height: 82px;
  padding: 14px 16px;
  text-align: left;
  border: 2px solid transparent;
  border-radius: 20px;
  background: #f7f4ed;
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}

.mode-card:hover {
  transform: translateY(-2px);
}

.mode-card.is-active {
  border-color: var(--green);
  background: #ecfaf4;
  box-shadow: 0 6px 16px rgb(79 157 126 / 15%);
}

.mode-icon {
  grid-row: 1 / 3;
  align-self: center;
  font-size: 2rem;
}

.mode-name {
  align-self: end;
  font-size: 1.05rem;
  font-weight: 850;
}

.mode-summary {
  color: var(--muted);
  font-size: .85rem;
  font-weight: 650;
}

.mode-detail {
  min-height: 24px;
  margin: 14px 4px 0;
  color: var(--muted);
  font-weight: 650;
}

.question-progress {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  gap: 5px;
}

.question-count {
  color: #7d6337;
  font-size: .8rem;
  font-weight: 850;
}

.progress-box {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--cream);
  font-weight: 850;
}

.progress-dots {
  display: flex;
  gap: 5px;
}

.progress-dot {
  width: 12px;
  height: 12px;
  border: 2px solid #d5a358;
  border-radius: 50%;
  background: #fff;
}

.progress-dot.is-done {
  background: #f4b64f;
}

.instruction-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  margin: 18px 0 12px;
  padding: 12px 16px;
  border-radius: 16px;
  background: #edf7ff;
  color: #3d6689;
  font-size: .92rem;
}

.game-board {
  position: relative;
  height: clamp(470px, 62vh, 620px);
  min-height: 470px;
  overflow: hidden;
  border: 3px solid #eadfc9;
  border-radius: 26px;
  background:
    linear-gradient(180deg, #eef9ff 0 54%, #fff6df 54% 100%);
  box-shadow: inset 0 0 0 8px rgb(255 255 255 / 45%);
  user-select: none;
  -webkit-user-select: none;
}

.game-board::before,
.game-board::after {
  position: absolute;
  content: "";
  z-index: 0;
  border-radius: 50%;
  opacity: .6;
}

.game-board::before {
  top: 28px;
  right: 38px;
  width: 72px;
  height: 72px;
  background: #ffe58b;
  box-shadow: -52px 14px 0 -24px #fff;
}

.game-board::after {
  bottom: 18px;
  left: 5%;
  width: 90%;
  height: 24px;
  background: rgb(224 189 119 / 17%);
}

.board-divider {
  position: absolute;
  z-index: 1;
  top: 54%;
  left: 5%;
  width: 90%;
  border-top: 3px dashed rgb(202 175 126 / 55%);
}

.board-label {
  position: absolute;
  z-index: 2;
  left: 18px;
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--muted);
  background: rgb(255 255 255 / 78%);
  font-size: .78rem;
  font-weight: 800;
}

.target-label {
  top: 14px;
}

.piece-label {
  top: calc(54% + 14px);
}

.board-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.shape-target,
.shape-piece {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--piece-size, 88px);
  height: var(--piece-size, 88px);
  transform: translate(-50%, -50%);
}

.shape-target {
  color: #aab8c1;
  opacity: .58;
  filter: grayscale(.4);
}

.shape-target::after {
  position: absolute;
  inset: -10px;
  content: "";
  border: 3px dashed rgb(98 128 147 / 45%);
  border-radius: 24px;
}

.shape-target.is-hint::after {
  border-color: #eea633;
  box-shadow: 0 0 0 9px rgb(255 205 89 / 24%);
  animation: hint-pulse .65s ease-in-out 3;
}

.shape-target.is-solved {
  opacity: .18;
}

.shape-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 5px 6px rgb(56 45 33 / 16%));
}

.shape-target .shape-svg {
  filter: none;
}

.shape-piece {
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: transparent;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-drag: none;
  will-change: left, top, transform;
}

.shape-piece:active {
  cursor: grabbing;
}

.shape-piece.is-selected::after {
  position: absolute;
  inset: -12px;
  content: "";
  border: 4px solid rgb(77 151 205 / 55%);
  border-radius: 25px;
  box-shadow: 0 0 0 7px rgb(168 220 255 / 20%);
}

.shape-piece.is-solved {
  pointer-events: none;
  animation: snap-in .45s cubic-bezier(.2, .8, .25, 1.2);
}

.shape-piece.needs-turn {
  animation: gentle-wiggle .45s ease;
}

.feedback {
  min-height: 52px;
  margin: 12px 0;
  padding: 13px 16px;
  border-radius: 17px;
  color: #46685b;
  background: #eaf8f1;
  font-weight: 750;
  text-align: center;
}

.feedback[data-tone="try"] {
  color: #855d20;
  background: #fff3d3;
}

.feedback[data-tone="success"] {
  color: #2f7257;
  background: #dff6e9;
}

.helper-panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #faf8f3;
}

.selected-piece {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}

.selected-label {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 750;
}

.helper-buttons {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 9px;
}

.helper-buttons button {
  min-height: 58px;
  border: 0;
  border-radius: 15px;
  color: #fff;
  background: var(--blue);
  font-size: 1.5rem;
  font-weight: 850;
  cursor: pointer;
}

.helper-buttons button span {
  display: block;
  margin-top: 2px;
  font-size: .72rem;
}

.helper-buttons button:hover {
  filter: brightness(1.06);
}

.helper-buttons .soft-button {
  color: #675f53;
  background: #ece6db;
}

.helper-note {
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: .78rem;
}

.celebration {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(62 63 56 / 38%);
  backdrop-filter: blur(3px);
}

.celebration-card {
  width: min(390px, 92%);
  padding: 30px 26px;
  text-align: center;
  border: 5px solid #fff;
  border-radius: 28px;
  background: #fff9df;
  box-shadow: 0 20px 55px rgb(55 43 24 / 25%);
  animation: pop-in .42s cubic-bezier(.2, .9, .28, 1.18);
}

.celebration-stars {
  font-size: 2rem;
}

.celebration h3 {
  margin: 10px 0 4px;
  font-size: 1.8rem;
}

.celebration p {
  margin: 0 0 18px;
  color: var(--muted);
}

.celebration button {
  min-height: 52px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: var(--green);
  font-weight: 850;
  cursor: pointer;
}

footer {
  padding: 18px 8px 0;
  color: var(--muted);
  font-size: .78rem;
  text-align: center;
}

@keyframes snap-in {
  0% { transform: translate(-50%, -50%) rotate(var(--rotation)) scale(var(--scale)); }
  55% { transform: translate(-50%, -50%) rotate(var(--rotation)) scale(calc(var(--scale) * 1.14)); }
  100% { transform: translate(-50%, -50%) rotate(var(--rotation)) scale(var(--scale)); }
}

@keyframes gentle-wiggle {
  0%, 100% { margin-left: 0; }
  35% { margin-left: -8px; }
  70% { margin-left: 8px; }
}

@keyframes hint-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(.82); }
  to { opacity: 1; transform: scale(1); }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 16px, 1120px);
    padding-top: 18px;
  }

  .mode-section,
  .game-section {
    padding: 16px;
    border-radius: 22px;
  }

  .mode-card {
    display: flex;
    min-height: 86px;
    padding: 10px 7px;
    align-items: center;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    text-align: center;
  }

  .mode-icon {
    font-size: 1.6rem;
  }

  .mode-name {
    font-size: .92rem;
  }

  .mode-summary {
    font-size: .72rem;
  }

  .game-topbar {
    align-items: flex-start;
  }

  .game-board {
    height: 520px;
  }

  .helper-buttons {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
