:root {
  color-scheme: light;
  --bg: #fff8ea;
  --ink: #2f2a24;
  --muted: #6d6258;
  --wood: #d9a76c;
  --wood-dark: #b8793f;
  --wood-light: #e8c48e;
  --cream: #fffdf6;
  --green: #5ba86b;
  --blue: #6eb6d9;
  --red: #d65a4a;
  --yellow: #f3c84b;
  --focus: #214f76;
  --shadow: 0 16px 36px rgba(91, 66, 32, .18);
  --soft-shadow: 0 8px 18px rgba(91, 66, 32, .16);
  --radius: 22px;
  font-family: "Trebuchet MS", "Atkinson Hyperlegible", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, .22) 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(180deg, #fff8ea 0%, #f8ecd3 100%);
  color: var(--ink);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 4px solid rgba(33, 79, 118, .45);
  outline-offset: 4px;
}

.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;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.screen {
  width: min(1120px, 100%);
  min-height: calc(100vh - 32px);
  min-height: calc(100dvh - 32px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark,
.mascot {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  background: var(--wood-light);
  box-shadow: inset 0 -6px 0 rgba(122, 75, 28, .13), var(--soft-shadow);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.brand h1,
.screen-title {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2.25rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.brand p,
.lead {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: clamp(.98rem, 2vw, 1.15rem);
  line-height: 1.35;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-button,
.primary-button,
.secondary-button,
.tile {
  min-height: 58px;
  border-radius: 18px;
  color: var(--ink);
  background: var(--cream);
  box-shadow: var(--soft-shadow);
  border: 2px solid rgba(93, 67, 36, .12);
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.icon-button {
  width: 58px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.primary-button,
.secondary-button,
.nav-button {
  padding: 0 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 800;
}

.nav-button {
  min-height: 58px;
  border-radius: 18px;
  color: var(--ink);
  background: var(--cream);
  box-shadow: var(--soft-shadow);
  border: 2px solid rgba(93, 67, 36, .12);
  text-decoration: none;
  white-space: nowrap;
}

.primary-button {
  background: var(--green);
  color: #fffdf6;
  border-color: rgba(20, 91, 49, .18);
}

.secondary-button {
  background: var(--wood-light);
}

.icon-button:hover,
.primary-button:hover,
.secondary-button:hover,
.tile:hover,
.nav-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 26px rgba(91, 66, 32, .2);
}

.icon {
  width: 30px;
  height: 30px;
  display: block;
}

.icon-button > svg {
  width: 30px;
  height: 30px;
  max-width: 30px;
  max-height: 30px;
  display: block;
}

.brand-mark > svg,
.mascot > svg,
.tile-art > svg {
  width: 70%;
  height: 70%;
  max-width: 70%;
  max-height: 70%;
  display: block;
}

.hero-panel,
.settings-panel,
.parent-panel {
  background: rgba(255, 253, 246, .86);
  border: 2px solid rgba(93, 67, 36, .12);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(18px, 3vw, 32px);
}

.home-grid,
.category-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.tile {
  padding: 18px;
  text-align: left;
  display: grid;
  grid-template-columns: 74px 1fr;
  align-items: center;
  gap: 14px;
  min-height: 118px;
}

.tile h2,
.tile h3 {
  margin: 0;
  font-size: clamp(1.1rem, 2vw, 1.45rem);
  letter-spacing: 0;
}

.tile p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.32;
}

.tile-art {
  width: 74px;
  height: 74px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: var(--wood-light);
  box-shadow: inset 0 -8px 0 rgba(122, 75, 28, .12);
}

.mode-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.mode-strip {
  gap: 8px;
  margin-top: 12px;
}

.mode-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(110, 182, 217, .18);
  border: 1px solid rgba(79, 147, 194, .22);
  color: #123245;
  font-size: .92rem;
  font-weight: 900;
  pointer-events: none;
  user-select: none;
}

.game-screen {
  width: min(1180px, 100%);
}

.game-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
}

.game-title {
  min-width: 0;
  text-align: center;
}

.game-title h1 {
  margin: 0;
  font-size: clamp(1.25rem, 3vw, 2rem);
}

.game-title p {
  margin: 4px 0 0;
  color: var(--muted);
}

.stage-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}

.stage {
  position: relative;
  width: min(100%, 1080px);
  aspect-ratio: 16 / 10;
  min-height: 480px;
  border-radius: 30px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(107, 67, 28, .08), transparent 28%, rgba(255, 255, 255, .18) 50%, transparent 74%, rgba(107, 67, 28, .08)),
    var(--wood-light);
  box-shadow: var(--shadow), inset 0 -16px 0 rgba(119, 76, 30, .16);
  border: 3px solid rgba(109, 78, 36, .22);
  touch-action: none;
  user-select: none;
}

.board-label {
  position: absolute;
  left: 50%;
  top: 5%;
  transform: translateX(-50%);
  color: rgba(47, 42, 36, .7);
  font-weight: 900;
  font-size: clamp(1rem, 2vw, 1.3rem);
  pointer-events: none;
}

.slot {
  position: absolute;
  transform: translate(-50%, -50%);
  border-radius: 28px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 42%, rgba(86, 48, 20, .22), rgba(86, 48, 20, .12) 58%, rgba(255, 255, 255, .16));
  box-shadow: inset 0 8px 16px rgba(86, 48, 20, .28), inset 0 -6px 10px rgba(255, 255, 255, .28);
  border: 3px solid rgba(116, 75, 33, .2);
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
}

.slot.near {
  box-shadow: 0 0 0 8px rgba(91, 168, 107, .24), inset 0 8px 16px rgba(86, 48, 20, .25);
}

.slot.filled {
  opacity: .55;
}

.slot svg {
  width: 76%;
  height: 76%;
  opacity: .26;
  filter: grayscale(1);
}

.piece {
  position: absolute;
  transform: translate(-50%, -50%);
  border-radius: 28px;
  display: grid;
  place-items: center;
  background: rgba(255, 253, 246, .12);
  filter: drop-shadow(0 14px 13px rgba(69, 43, 16, .22));
  touch-action: none;
  cursor: grab;
  transition: filter .16s ease;
  will-change: left, top, transform;
}

.piece.dragging {
  cursor: grabbing;
  filter: drop-shadow(0 24px 18px rgba(69, 43, 16, .3));
  z-index: 20;
}

.piece.placed {
  cursor: default;
  filter: drop-shadow(0 5px 6px rgba(69, 43, 16, .14));
}

.piece.hint {
  animation: wiggle 1.1s ease-in-out infinite;
}

.piece svg {
  width: 100%;
  height: 100%;
}

.knob {
  position: absolute;
  left: 50%;
  top: 14%;
  width: 34%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: radial-gradient(circle at 38% 32%, #fff5d6, #dca760 56%, #a96c33);
  box-shadow: 0 6px 9px rgba(69, 43, 16, .28), inset 0 -4px 5px rgba(93, 55, 22, .2);
  border: 2px solid rgba(91, 57, 24, .22);
  pointer-events: none;
}

.piece-label {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, 4px);
  background: rgba(255, 253, 246, .9);
  border-radius: 12px;
  padding: 4px 9px;
  font-size: .86rem;
  font-weight: 900;
  color: var(--ink);
  box-shadow: var(--soft-shadow);
  pointer-events: none;
}

.mascot-card {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: min(250px, 34%);
  min-height: 82px;
  border-radius: 22px;
  background: rgba(255, 253, 246, .86);
  border: 2px solid rgba(93, 67, 36, .12);
  box-shadow: var(--soft-shadow);
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px;
  pointer-events: none;
}

.mascot-card p {
  margin: 0;
  line-height: 1.25;
  font-weight: 800;
}

.hand-hint {
  position: absolute;
  width: 54px;
  height: 54px;
  border-radius: 999px;
  background: rgba(255, 253, 246, .88);
  border: 5px solid rgba(33, 79, 118, .42);
  box-shadow: 0 12px 24px rgba(33, 79, 118, .22);
  z-index: 18;
  pointer-events: none;
}

.celebration {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: grid;
  place-items: center;
  z-index: 40;
}

.spark {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: var(--yellow);
  animation: pop 900ms ease-out forwards;
}

.reward-card {
  width: min(640px, 100%);
  margin: auto;
  text-align: center;
}

.stars {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 18px 0;
}

.star {
  width: 70px;
  height: 70px;
}

.form-grid {
  display: grid;
  gap: 16px;
}

.setting-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 248, 234, .8);
}

.setting-row label,
.stat strong {
  font-weight: 900;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  background: rgba(255, 248, 234, .8);
  border-radius: 16px;
  padding: 16px;
  min-height: 96px;
}

.stat span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.parent-gate {
  display: grid;
  gap: 14px;
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(3, 74px);
  gap: 10px;
  justify-content: center;
}

.number-pad button {
  width: 74px;
  min-height: 64px;
  border-radius: 18px;
  background: var(--wood-light);
  box-shadow: var(--soft-shadow);
  font-weight: 900;
  font-size: 1.25rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(91, 168, 107, .18);
  font-weight: 900;
  color: #244d31;
}

.color-high-contrast {
  --bg: #ffffff;
  --ink: #111111;
  --muted: #333333;
  --wood: #c58b2c;
  --wood-light: #ffd56c;
  --cream: #ffffff;
  --focus: #000000;
}

.color-colorblind .piece svg .pattern-mark {
  opacity: .72;
}

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

@keyframes wiggle {
  0%, 100% {
    transform: translate(-50%, -50%) rotate(0);
  }
  25% {
    transform: translate(-50%, -50%) rotate(-3deg);
  }
  75% {
    transform: translate(-50%, -50%) rotate(3deg);
  }
}

@keyframes pop {
  0% {
    transform: translate(0, 0) scale(.2);
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: translate(var(--dx), var(--dy)) scale(1);
    opacity: 0;
  }
}

@media (max-width: 820px) {
  .screen {
    gap: 12px;
  }

  .app-shell {
    padding: 10px;
  }

  .hero-panel {
    padding: 16px;
  }

  .hero-panel .lead {
    font-size: .98rem;
  }

  .topbar,
  .game-header {
    min-height: auto;
    align-items: center;
  }

  .game-header {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .game-title {
    width: 100%;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .toolbar {
    justify-content: flex-start;
    gap: 8px;
  }

  .icon-button {
    width: 48px;
    min-height: 48px;
    border-radius: 15px;
  }

  .icon-button > svg {
    width: 25px;
    height: 25px;
  }

  .nav-button {
    min-height: 48px;
    border-radius: 15px;
    padding: 0 14px;
    font-size: .95rem;
  }

  .mode-strip {
    margin-top: 10px;
  }

  .mode-chip {
    min-height: 30px;
    padding: 5px 10px;
    font-size: .84rem;
  }

  .home-grid,
  .category-grid,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .tile {
    grid-template-columns: 64px 1fr;
    min-height: 96px;
  }

  .tile-art {
    width: 64px;
    height: 64px;
  }

  .stage {
    aspect-ratio: 9 / 13;
    min-height: 540px;
    border-radius: 24px;
    margin-bottom: 104px;
    overflow: visible;
  }

  .mascot-card {
    width: calc(100% - 28px);
    top: calc(100% + 12px);
    right: 14px;
    bottom: auto;
    min-height: 72px;
  }

  .board-label {
    top: 4%;
  }
}

@media (max-width: 460px) {
  .app-shell {
    padding: 10px;
  }

  .brand-mark,
  .mascot,
  .icon-button {
    width: 54px;
    height: 54px;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .toolbar {
    width: 100%;
    justify-content: flex-start;
  }

  .toolbar .icon-button {
    flex: 0 0 54px;
  }

  .toolbar .nav-button {
    flex: 1 1 128px;
    min-width: 128px;
    padding: 0 14px;
  }
}
