:root {
  color-scheme: light;
  --blue: #2f7cf6;
  --green: #2fbf71;
  --yellow: #ffd95a;
  --pink: #ff7fa3;
  --ink: #1f2a44;
  --muted: #69758e;
  --paper: #ffffff;
  --bg: #f6f9ff;
  --line: rgba(31, 42, 68, 0.12);
  font-family: ui-rounded, "SF Pro Rounded", "Hiragino Sans GB", "PingFang SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
}

body {
  min-height: 100svh;
  touch-action: manipulation;
}

button {
  border: 0;
  font: inherit;
  color: inherit;
}

.app {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 217, 90, 0.42), transparent 28%),
    radial-gradient(circle at 88% 4%, rgba(127, 209, 255, 0.45), transparent 28%),
    linear-gradient(180deg, #fbfdff 0%, #eef6ff 100%);
}

.topbar {
  min-height: 72px;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  align-items: center;
  gap: 10px;
}

#homeBtn {
  grid-column: 1;
}

.topbar > div {
  grid-column: 2;
}

#soundBtn {
  grid-column: 3;
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 7vw, 34px);
  line-height: 1.05;
  letter-spacing: 0;
  text-align: center;
}

#subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
}

.icon-btn,
.pill {
  min-height: 48px;
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 8px 20px rgba(31, 42, 68, 0.1);
}

.icon-btn {
  width: 52px;
  font-size: 28px;
  display: grid;
  place-items: center;
}

.pill {
  padding: 0 18px;
  font-weight: 800;
  color: #fff;
  background: var(--blue);
}

.home {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-content: center;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
}

.game-card {
  min-height: 168px;
  border-radius: 28px;
  padding: 18px 12px;
  display: grid;
  place-items: center;
  gap: 6px;
  background: var(--paper);
  box-shadow: 0 14px 34px rgba(31, 42, 68, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.8);
}

.game-card .big {
  width: 82px;
  height: 82px;
  display: grid;
  place-items: center;
  border-radius: 26px;
  font-size: 46px;
  background: rgba(255, 255, 255, 0.62);
}

.game-card strong {
  font-size: 24px;
  line-height: 1;
}

.game-card small {
  color: var(--muted);
  font-size: 14px;
}

.game-card.puzzle { background: linear-gradient(145deg, #fff3b5, #ffffff); }
.game-card.shadow { background: linear-gradient(145deg, #dff4ff, #ffffff); }
.game-card.match { background: linear-gradient(145deg, #e7ffd8, #ffffff); }
.game-card.memory { background: linear-gradient(145deg, #ffe2ed, #ffffff); }

.play {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress {
  min-height: 42px;
  padding: 10px 16px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  font-weight: 800;
}

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 12px;
}

.board {
  min-height: 0;
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.8), 0 12px 30px rgba(31, 42, 68, 0.1);
  padding: 12px;
}

.target-grid,
.tile-grid {
  display: grid;
  gap: 10px;
}

.puzzle-wrap {
  grid-template-rows: minmax(240px, 1fr) auto;
}

.target-grid {
  height: 100%;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(72px, 1fr));
}

.slot,
.tile,
.choice,
.card {
  user-select: none;
  touch-action: none;
}

.slot {
  min-height: 72px;
  border: 3px dashed rgba(47, 124, 246, 0.28);
  border-radius: 22px;
  display: grid;
  place-items: center;
  font-size: clamp(34px, 11vw, 58px);
  color: rgba(31, 42, 68, 0.18);
  background: rgba(255, 255, 255, 0.54);
}

.slot.done {
  border-style: solid;
  border-color: rgba(47, 191, 113, 0.55);
  background: #f2fff7;
  color: var(--ink);
}

.tile-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(76px, 1fr);
  gap: 10px;
  overflow-x: auto;
  padding: 4px 2px 8px;
}

.tile,
.choice,
.card {
  min-height: 76px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  font-size: clamp(36px, 12vw, 58px);
  background: #fff;
  box-shadow: 0 8px 18px rgba(31, 42, 68, 0.12);
  border: 2px solid rgba(31, 42, 68, 0.08);
}

.tile.dragging,
.choice.dragging {
  position: fixed;
  z-index: 20;
  width: 86px;
  height: 86px;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.06);
  box-shadow: 0 18px 34px rgba(31, 42, 68, 0.24);
}

.tile.selected,
.choice.selected {
  outline: 5px solid rgba(255, 217, 90, 0.9);
  transform: translateY(-3px);
}

.shadow-wrap,
.match-wrap {
  grid-template-rows: 1fr auto;
}

.drop-zone {
  min-height: 230px;
  display: grid;
  place-items: center;
}

.shadow-target {
  width: min(58vw, 280px);
  aspect-ratio: 1;
  border-radius: 34px;
  display: grid;
  place-items: center;
  font-size: min(28vw, 132px);
  color: rgba(31, 42, 68, 0.18);
  background: #e8edf6;
  box-shadow: inset 0 0 0 4px rgba(31, 42, 68, 0.06);
}

.shadow-target.done {
  color: var(--ink);
  background: #f0fff5;
}

.choice-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

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

.match-slot {
  min-height: 96px;
  border-radius: 24px;
  border: 3px dashed rgba(47, 124, 246, 0.24);
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  justify-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.match-slot .cue {
  font-size: 52px;
}

.match-slot .answer {
  width: 66px;
  height: 66px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: rgba(31, 42, 68, 0.07);
  color: rgba(31, 42, 68, 0.18);
  font-size: 42px;
}

.match-slot.done {
  border-style: solid;
  border-color: rgba(47, 191, 113, 0.58);
}

.memory-grid {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-content: center;
}

.card {
  min-height: 0;
  aspect-ratio: 1;
  background: linear-gradient(145deg, #2f7cf6, #8bd7ff);
  color: transparent;
  font-size: clamp(34px, 11vw, 58px);
}

.card.revealed,
.card.matched {
  background: #fff;
  color: var(--ink);
}

.card.matched {
  background: #effff5;
  border-color: rgba(47, 191, 113, 0.5);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  min-width: 168px;
  padding: 14px 22px;
  border-radius: 24px;
  color: #fff;
  background: rgba(31, 42, 68, 0.9);
  text-align: center;
  font-size: 22px;
  font-weight: 900;
  box-shadow: 0 14px 30px rgba(31, 42, 68, 0.22);
}

.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 30;
}

.hidden {
  display: none !important;
}

@media (orientation: landscape) and (max-height: 560px) {
  .app {
    padding-top: 8px;
  }

  .topbar {
    min-height: 54px;
  }

  h1 {
    font-size: 24px;
  }

  #subtitle {
    display: none;
  }

  .home {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .game-card {
    min-height: 126px;
  }

  .game-card .big {
    width: 58px;
    height: 58px;
    font-size: 34px;
  }

  .puzzle-wrap,
  .shadow-wrap,
  .match-wrap {
    grid-template-columns: 1fr minmax(260px, 0.55fr);
    grid-template-rows: 1fr;
  }

  .tile-row {
    grid-auto-flow: row;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-columns: unset;
    overflow: visible;
    align-content: center;
  }
}
