:root {
  font-family: Nunito, ui-rounded, "Trebuchet MS", sans-serif;
  color: #1d2b49;
  background: #f3f7fc;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --navy: #1d2b49;
  --blue: #546ef5;
  --mint: #49cdb4;
  --coral: #ff7f79;
  --yellow: #ffc84b;
  --muted: #8190aa;
  --line: #e8edf5;
  --shadow: 0 14px 35px rgba(52, 74, 123, .09);
}

* { box-sizing: border-box; }
html, body { width: 100%; min-width: 320px; min-height: 100%; margin: 0; }
body {
  overflow-x: hidden;
  background:
    radial-gradient(ellipse at 12% 0%, #eaf0ff 0, transparent 36%),
    radial-gradient(ellipse at 100% 100%, #e6fbf6 0, transparent 35%),
    #f5f8fd;
}
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
h1, h2, p { margin: 0; }

.app {
  width: 100%;
  min-height: 100svh;
  padding: clamp(10px, 2vw, 24px) clamp(14px, 3.3vw, 54px);
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2.1vh, 22px);
  position: relative;
}
.app.is-playing {
  height: 100dvh;
  min-height: 520px;
  overflow: hidden;
}

.topbar {
  min-height: 48px;
  flex: 0 0 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--navy);
  text-decoration: none;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.4px;
}
.brand b { color: var(--blue); }
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(145deg, #7587ff, #546ef5);
  box-shadow: 0 5px 13px #546ef544;
  font-size: 21px;
}
.top-actions { display: flex; gap: 10px; align-items: center; }
.sound-button, .fullscreen-button, .fullscreen-exit {
  border: 1px solid #e2e8f2;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px #33456c0c;
  transition: transform .18s, box-shadow .18s;
}
.sound-button:hover, .fullscreen-button:hover { transform: translateY(-1px); box-shadow: 0 7px 16px #33456c18; }
.sound-button { width: 40px; height: 40px; border-radius: 13px; font-size: 20px; color: #697999; }
.sound-button[aria-pressed=false] { opacity: .55; }
.fullscreen-button {
  height: 40px;
  padding: 0 14px;
  border-radius: 13px;
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  font-weight: 800;
  color: #4e6082;
}
.fullscreen-button span:first-child { font-size: 18px; }
.fullscreen-exit {
  display: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: #ef5350;
  color: #fff;
  font-size: 30px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  box-shadow: 0 5px 15px #ef535055;
}
.app:fullscreen { background: #f3f7fc; }
.app:fullscreen .fullscreen-exit { display: flex; }
.app:fullscreen .fullscreen-button { display: none; }

.home-screen {
  max-width: 1120px;
  width: 100%;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: clamp(18px, 4vh, 40px);
  min-height: 0;
  padding: 8px 0 18px;
}
.intro { text-align: center; }
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 1.7px;
  color: #7181a1;
}
.sparkle { color: #ffb837; font-size: 16px; }
.intro h1 {
  font-size: clamp(27px, 4.3vh, 44px);
  line-height: 1.13;
  letter-spacing: -1.7px;
  font-weight: 900;
  margin: 9px 0 7px;
}
.intro h1 em { font-style: normal; color: var(--blue); }
.intro p { font-size: clamp(13px, 1.8vh, 16px); color: #7887a1; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(12px, 2vw, 22px);
}
.category-card {
  position: relative;
  display: flex;
  align-items: center;
  text-align: left;
  gap: clamp(12px, 1.7vw, 20px);
  min-width: 0;
  min-height: clamp(120px, 22vh, 185px);
  padding: clamp(12px, 2vw, 21px);
  border: 2px solid #fff;
  border-radius: 24px;
  background: rgba(255, 255, 255, .89);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .2s, border-color .2s, box-shadow .2s;
}
.category-card:hover { transform: translateY(-4px); box-shadow: 0 17px 35px #344a781c; }
.category-card.selected { border-color: #8b9aff; box-shadow: 0 12px 30px #546ef526; }
.category-art {
  position: relative;
  flex: 0 0 clamp(72px, 10vw, 112px);
  height: clamp(72px, 10vw, 112px);
  border-radius: 21px;
  display: block;
  overflow: hidden;
}
.art-shapes { background: #fff3d8; }
.art-numbers { background: #eaf8f5; }
.art-letters { background: #f1edff; }
.shape { position: absolute; filter: drop-shadow(0 5px 1px #23344b19); }
.shape-circle { width: 39%; aspect-ratio: 1; border-radius: 50%; background: linear-gradient(145deg, #ff9b77, #ff6d70); top: 17%; left: 12%; transform: rotate(-10deg); }
.shape-triangle { width: 45%; height: 44%; background: linear-gradient(145deg, #ffda6e, #ffb83d); clip-path: polygon(50% 0, 100% 100%, 0 100%); right: 7%; top: 14%; transform: rotate(9deg); }
.shape-square { width: 38%; aspect-ratio: 1; border-radius: 8px; background: linear-gradient(145deg, #75a9ff, #6578f6); bottom: 10%; left: 36%; transform: rotate(12deg); }
.number, .letter { position: absolute; font-weight: 900; line-height: 1; filter: drop-shadow(0 5px 1px #23344b16); }
.number-one, .letter-a { font-size: clamp(35px, 5vw, 59px); left: 8%; top: 23%; color: #ff816c; transform: rotate(-9deg); }
.number-five, .letter-b { font-size: clamp(35px, 5vw, 59px); right: 7%; top: 15%; color: #60b8a9; transform: rotate(8deg); }
.number-three, .letter-c { font-size: clamp(35px, 5vw, 59px); left: 36%; bottom: 2%; color: #657bf3; transform: rotate(-3deg); }
.letter-a { color: #8b74ef; }
.letter-b { color: #ff866e; }
.letter-c { color: #62b6a7; }
.category-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.category-text strong { font-size: clamp(17px, 2.2vw, 24px); font-weight: 900; letter-spacing: -.6px; }
.category-text small { font-size: clamp(11px, 1.3vw, 14px); color: #7d8ba4; line-height: 1.25; }
.card-arrow { position: absolute; right: 18px; bottom: 15px; color: #a0abc0; font-size: 19px; font-weight: 900; }
.category-card.selected .card-arrow { color: var(--blue); }
.home-footer { display: flex; align-items: center; justify-content: center; gap: clamp(14px, 3vw, 36px); position: relative; min-height: 56px; }
.age-badge, .how-to { display: inline-flex; align-items: center; gap: 8px; color: #74839d; font-size: 12px; font-weight: 700; }
.age-badge span { color: #f3b83f; }
.how-to span { color: #7386ff; font-size: 16px; }
.play-button {
  border: 0;
  border-radius: 15px;
  background: linear-gradient(135deg, #657bf8, #4c62ec);
  box-shadow: 0 8px 18px #546ef53c;
  color: #fff;
  font-weight: 900;
  font-size: 15px;
  padding: 14px 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 17px;
  cursor: pointer;
  transition: transform .18s, box-shadow .18s;
}
.play-button:hover { transform: translateY(-2px); box-shadow: 0 12px 22px #546ef54d; }
.play-button span { font-size: 19px; }

.game-screen { min-height: 0; flex: 1; display: flex; flex-direction: column; gap: clamp(10px, 1.8vh, 18px); }
.game-toolbar { flex: 0 0 auto; display: flex; align-items: center; gap: clamp(10px, 2vw, 22px); min-height: 54px; }
.back-button, .restart-button, .shuffle-button { border: 1px solid #e6ebf3; background: #fff; display: grid; place-items: center; cursor: pointer; box-shadow: 0 4px 12px #33456c0c; }
.back-button { width: 42px; height: 42px; flex: 0 0 42px; border-radius: 14px; color: #637491; font-size: 24px; }
.game-title { display: flex; align-items: center; gap: 10px; min-width: 150px; }
.game-category-icon { width: auto; min-width: 34px; height: 34px; padding: 0 6px; border-radius: 12px; display: grid; place-items: center; background: #edf0ff; color: #6278f5; font-size: 12px; font-weight: 900; }
.game-title small { display: block; font-size: 8px; font-weight: 900; letter-spacing: 1.3px; color: #929fb6; }
.game-title h1 { font-size: 20px; font-weight: 900; letter-spacing: -.4px; }
.progress-area { width: min(350px, 38vw); margin-left: auto; }
.progress-label { display: block; text-align: right; font-size: 11px; font-weight: 800; color: #7888a2; margin: 0 2px 6px; }
.progress-track { height: 8px; border-radius: 10px; background: #e8edf6; overflow: hidden; }
.progress-track span { display: block; height: 100%; width: 0; border-radius: 10px; background: linear-gradient(90deg, #4cceb0, #75dfb9); transition: width .35s; }
.restart-button { flex: 0 0 42px; width: 42px; height: 42px; border-radius: 14px; font-size: 23px; color: #697996; }

.play-area {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.07fr) minmax(0, .93fr);
  gap: clamp(12px, 2vw, 22px);
}
.targets-panel, .pieces-panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, .96);
  border-radius: 24px;
  background: rgba(255, 255, 255, .83);
  box-shadow: var(--shadow);
  padding: clamp(10px, 1.7vh, 17px) clamp(10px, 1.7vw, 18px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-heading { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; min-height: 38px; margin-bottom: clamp(6px, 1vh, 10px); }
.heading-icon { flex: 0 0 32px; height: 32px; border-radius: 11px; background: #eef1ff; color: #7185f6; display: grid; place-items: center; font-size: 18px; }
.piece-heading-icon { background: #e9faf5; color: #46bba3; }
.panel-heading strong { font-size: 14px; font-weight: 900; display: block; }
.panel-heading small { font-size: 9px; color: #8b98ad; display: block; margin-top: 1px; }

.target-grid, .piece-grid {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: clamp(6px, .9vw, 11px);
  align-content: stretch;
}
.target-slot, .piece-card {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: clamp(11px, 1.25vw, 17px);
  display: grid;
  place-items: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.target-slot { background: #f8faff; border: 2px dashed #ced7e9; transition: border-color .18s, background .18s, transform .18s; }
.target-slot::after { content: ""; position: absolute; inset: 4px; border-radius: 11px; border: 1px solid #eef1f8; pointer-events: none; }
.target-slot.target-over { background: #eefcf7; border-color: #51c9ae; transform: scale(1.025); }
.target-slot.wrong-target { animation: shake .28s; border-color: #ff9991; background: #fff5f4; }
.target-slot.filled { border: 2px solid transparent; background: #eafaf5; }
.slot-shape { width: 100%; height: 100%; display: grid; place-items: center; }
.target-slot svg, .piece-card svg { width: min(72%, 120px); height: min(72%, 120px); overflow: visible; pointer-events: none; }
.target-slot .slot-label { position: absolute; bottom: 3px; font-size: 8px; font-weight: 800; color: #a1acc0; }
.target-slot.filled .slot-label { display: none; }
.piece-card {
  border: 2px solid rgba(255, 255, 255, .95);
  background: var(--tile-bg, #fff4dc);
  box-shadow: 0 4px 0 var(--tile-edge, #eed7a5), 0 7px 14px #33466b12;
  cursor: grab;
  transition: transform .16s, box-shadow .16s, opacity .2s;
  overflow: hidden;
}
.piece-card:hover { transform: translateY(-2px) rotate(-1deg); box-shadow: 0 6px 0 var(--tile-edge, #eed7a5), 0 10px 18px #33466b18; }
.piece-card:active { cursor: grabbing; }
.piece-card.selected { outline: 3px solid #7388ff; outline-offset: 1px; transform: translateY(-2px); }
.piece-card.dragging-source { opacity: .3; }
.piece-card .piece-shape { filter: drop-shadow(0 4px 1px #2636501c); }
.glyph-shape, .outline-glyph { font-family: Nunito, ui-rounded, "Trebuchet MS", sans-serif; font-weight: 900; dominant-baseline: middle; text-anchor: middle; }
.glyph-shape { filter: drop-shadow(0 4px 1px #2636501c); }
.outline-glyph { fill: transparent; stroke: #aab7cc; stroke-width: 2.7px; stroke-linejoin: round; }
.shuffle-button { width: 32px; height: 32px; margin-left: auto; border-radius: 11px; color: #6e7e9b; font-size: 19px; }
.feedback { flex: 0 0 auto; min-height: 29px; margin-top: clamp(5px, .8vh, 8px); display: flex; align-items: center; gap: 8px; padding: 6px 9px; border-radius: 10px; background: #f5f7fb; color: #77859d; font-size: 9px; font-weight: 800; }
.feedback-dot { width: 7px; height: 7px; border-radius: 50%; background: #91a0b8; flex: 0 0 7px; }
.feedback.good { background: #edfbf6; color: #368f7c; }
.feedback.good .feedback-dot { background: #49cdb4; }
.feedback.try { background: #fff5ef; color: #bd8052; }
.feedback.try .feedback-dot { background: #ffb554; }
.drag-ghost { position: fixed; z-index: 30; width: clamp(58px, 7vw, 82px); height: clamp(58px, 7vw, 82px); display: grid; place-items: center; pointer-events: none; border: 2px solid #fff; border-radius: 18px; background: #fff4dc; box-shadow: 0 12px 30px #1c2e4d3a; transform: scale(1.05) rotate(-3deg); }
.drag-ghost svg { width: 70%; height: 70%; }

.win-screen { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; background: #24345475; backdrop-filter: blur(8px); }
.win-screen[hidden], .home-screen[hidden], .game-screen[hidden], .portrait-tip[hidden] { display: none; }
.win-card { width: min(440px, 92vw); position: relative; padding: 32px 34px 28px; border-radius: 28px; background: white; box-shadow: 0 24px 65px #17264645; text-align: center; overflow: hidden; animation: pop .36s cubic-bezier(.2,.9,.3,1.2); }
.win-card h2 { font-size: 32px; font-weight: 900; letter-spacing: -1px; margin: 9px 0 5px; }
.win-card p { font-size: 13px; line-height: 1.5; color: #8290a8; }
.win-stars { position: absolute; top: 13px; left: 0; right: 0; color: #ffc44e; font-size: 20px; }
.win-medal { width: 64px; height: 64px; margin: 12px auto 17px; border-radius: 22px; display: grid; place-items: center; background: linear-gradient(145deg, #58d5b6, #37b997); box-shadow: 0 8px 16px #44c8aa4d; color: #fff; font-size: 35px; font-weight: 900; transform: rotate(-7deg); }
.win-actions { margin-top: 22px; display: grid; gap: 9px; }
.win-actions .play-button { width: 100%; }
.secondary-button { border: 0; background: transparent; color: #7887a0; padding: 10px; font-size: 12px; font-weight: 800; cursor: pointer; }
.portrait-tip { display: none !important; }

@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes pop { from { opacity: 0; transform: scale(.86); } to { opacity: 1; transform: scale(1); } }

@media (max-width: 1024px) {
  .app { padding-left: 18px; padding-right: 18px; }
  .target-grid, .piece-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(0, 1fr)); }
  .targets-panel, .pieces-panel { padding: 10px; }
  .panel-heading small { display: none; }
}

@media (max-width: 720px) {
  .app { padding: 10px 12px; gap: 9px; }
  .app.is-playing { min-height: 480px; padding: 7px 8px; gap: 7px; }
  .topbar { min-height: 40px; flex-basis: 40px; }
  .brand { font-size: 14px; gap: 7px; }
  .brand-mark { width: 31px; height: 31px; border-radius: 10px; }
  .sound-button { width: 36px; height: 36px; }
  .fullscreen-button { height: 36px; padding: 0 9px; font-size: 0; }
  .fullscreen-button span:first-child { font-size: 18px; }
  .fullscreen-exit { width: 36px; height: 36px; }

  .home-screen { gap: 18px; padding-top: 4px; }
  .intro h1 { font-size: clamp(27px, 8vw, 38px); }
  .category-grid { grid-template-columns: 1fr; gap: 10px; }
  .category-card { min-height: 102px; padding: 11px 14px; border-radius: 18px; }
  .category-art { flex-basis: 72px; height: 72px; border-radius: 16px; }
  .category-text strong { font-size: 19px; }
  .category-text small { font-size: 12px; }
  .card-arrow { right: 14px; bottom: 11px; }
  .home-footer { gap: 10px; flex-wrap: wrap; }
  .age-badge, .how-to { font-size: 10px; }
  .play-button { width: min(320px, 100%); font-size: 13px; padding: 12px 16px; }

  .game-screen { gap: 7px; }
  .game-toolbar { min-height: 43px; gap: 7px; }
  .back-button, .restart-button { width: 36px; height: 36px; flex-basis: 36px; border-radius: 12px; }
  .game-title { min-width: 0; gap: 6px; }
  .game-category-icon { min-width: 29px; height: 29px; border-radius: 9px; font-size: 9px; padding: 0 4px; }
  .game-title small { display: none; }
  .game-title h1 { font-size: 15px; white-space: nowrap; }
  .progress-area { width: auto; flex: 1; min-width: 70px; }
  .progress-label { font-size: 8px; margin-bottom: 4px; }
  .progress-track { height: 6px; }

  .play-area { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .targets-panel, .pieces-panel { padding: 6px; border-radius: 15px; }
  .panel-heading { min-height: 31px; gap: 5px; margin-bottom: 5px; }
  .heading-icon { flex-basis: 27px; height: 27px; border-radius: 9px; font-size: 15px; }
  .panel-heading strong { font-size: 10px; line-height: 1.05; }
  .panel-heading small { display: none; }
  .shuffle-button { width: 27px; height: 27px; font-size: 16px; border-radius: 8px; }
  .target-grid, .piece-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(6, minmax(0, 1fr)); gap: 5px; }
  .target-slot, .piece-card { border-radius: 10px; }
  .target-slot::after { inset: 2px; border-radius: 7px; }
  .target-slot svg, .piece-card svg { width: min(70%, 58px); height: min(70%, 58px); }
  .target-slot .slot-label { bottom: 1px; font-size: 7px; }
  .feedback { min-height: 25px; margin-top: 4px; padding: 4px 6px; font-size: 7.5px; line-height: 1.15; gap: 5px; }
  .feedback-dot { width: 5px; height: 5px; flex-basis: 5px; }
}

@media (max-width: 430px) {
  .app.is-playing .brand span:last-child { display: none; }
  .app.is-playing .top-actions { gap: 6px; }
  .game-title h1 { max-width: 64px; overflow: hidden; text-overflow: ellipsis; }
  .progress-label { white-space: nowrap; }
}

@media (max-height: 620px) and (min-width: 721px) {
  .app.is-playing { min-height: 0; padding-top: 7px; padding-bottom: 7px; gap: 7px; }
  .topbar { min-height: 36px; flex-basis: 36px; }
  .brand-mark { width: 30px; height: 30px; }
  .sound-button, .fullscreen-button { height: 32px; }
  .sound-button { width: 32px; }
  .game-screen { gap: 6px; }
  .game-toolbar { min-height: 38px; }
  .back-button, .restart-button { width: 34px; height: 34px; flex-basis: 34px; }
  .targets-panel, .pieces-panel { padding-top: 6px; padding-bottom: 6px; }
  .panel-heading { min-height: 28px; margin-bottom: 4px; }
  .heading-icon { flex-basis: 26px; height: 26px; }
  .feedback { min-height: 22px; margin-top: 3px; padding: 3px 6px; }
}

@media (orientation: landscape) and (max-height: 520px) and (max-width: 950px) {
  .app.is-playing { min-height: 0; height: 100dvh; padding: 5px 7px; gap: 5px; }
  .app.is-playing .topbar { display: none; }
  .game-toolbar { min-height: 36px; }
  .play-area { gap: 6px; }
  .targets-panel, .pieces-panel { padding: 5px; border-radius: 13px; }
  .panel-heading { min-height: 25px; margin-bottom: 3px; }
  .heading-icon { flex-basis: 23px; height: 23px; font-size: 13px; }
  .panel-heading strong { font-size: 10px; }
  .target-grid, .piece-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); gap: 4px; }
  .feedback { min-height: 20px; margin-top: 2px; padding: 2px 5px; font-size: 7px; }
}

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