:root {
  --bg: #fff6e0;
  --ink: #4a3b2a;
  --font-ui: ui-rounded, "SF Pro Rounded", "PingFang SC", "Microsoft YaHei", sans-serif;
  /* 楷体的笔画最接近手写，适合认字 */
  --font-kai: "Kaiti SC", "STKaiti", "KaiTi", "楷体", serif;
}

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

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  cursor: pointer;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  max-width: 1100px;
  margin: 0 auto;
}

/* ---------- 通用按钮 ---------- */

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

.topbar h1 {
  margin: 0;
  font-size: 28px;
}

.round-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #fff;
  font-size: 28px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .12);
  flex: none;
}

.round-btn.ghost {
  visibility: hidden;
}

.round-btn:active,
.pill:active,
.tile:active,
.cell:active,
.game-tile:active,
.bubble:active,
.nav-btn:active,
.ask-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .12);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  margin: 16px 0;
}

.pill {
  background: var(--c);
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  padding: 14px 32px;
  border-radius: 999px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .15);
}

/* ---------- 首页 ---------- */

.home {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.logo {
  font-size: clamp(40px, 9vw, 72px);
  margin: 0;
}

.tagline {
  font-size: 24px;
  margin: 8px 0 32px;
  opacity: .7;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 280px));
  justify-content: center;
  gap: 20px;
  width: 100%;
}

@media (orientation: landscape) {
  .tiles {
    grid-template-columns: repeat(4, minmax(0, 240px));
  }
}

.tile {
  aspect-ratio: 1;
  background: var(--c);
  color: #fff;
  border-radius: 36px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, .15);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.tile-icon {
  font-size: clamp(48px, 13vw, 84px);
  font-weight: 800;
  line-height: 1.1;
}

.tile:first-child .tile-icon {
  font-family: var(--font-kai);
}

.tile-title {
  font-size: clamp(22px, 6vw, 34px);
  font-weight: 700;
}

/* ---------- 卡片总览 ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 14px;
  padding-bottom: 16px;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  background: var(--c);
  border-radius: 20px;
  font-size: 48px;
  font-weight: 700;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .12);
}

.cell.hanzi,
.card.hanzi .card-main,
.option.hanzi {
  font-family: var(--font-kai);
}

.cell-star {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 18px;
}

/* ---------- 单张卡片 ---------- */

/* 卡片固定 3:4，宽度 --w 由屏幕宽高一起决定；
   卡片里所有字号都按 --w 的比例算，所以任何屏幕上版式都一样、不会溢出 */
.stage {
  --vh: 100vh;
  --w: min(600px, calc(100vw - 210px), calc((var(--vh) - 130px) * .75));
  flex: 1;
  display: grid;
  grid-template-columns: auto auto auto;
  grid-template-areas: "prev card next";
  align-items: center;
  justify-content: center;
  align-content: center;
  gap: 12px;
  padding: 12px 0;
}

@supports (height: 100dvh) {
  .stage {
    --vh: 100dvh;
  }
}

/* 竖屏：翻页按钮挪到卡片下面，把宽度都留给卡片 */
@media (orientation: portrait) and (max-width: 700px) {
  .stage {
    --w: min(calc(100vw - 32px), calc((var(--vh) - 230px) * .75));
    grid-template-columns: auto auto;
    grid-template-areas:
      "card card"
      "prev next";
    gap: 16px 48px;
  }
}

.nav-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #fff;
  font-size: 32px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .12);
  justify-self: center;
}

.nav-btn:first-child {
  grid-area: prev;
}

.nav-btn:last-child {
  grid-area: next;
}

.card {
  grid-area: card;
  position: relative;
  width: var(--w);
  height: calc(var(--w) * 4 / 3);
  background: var(--c);
  border-radius: calc(var(--w) * .08);
  border: calc(var(--w) * .015) solid #fff;
  box-shadow: 0 10px 0 rgba(0, 0, 0, .12);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--w) * .01);
  padding: calc(var(--w) * .05);
  overflow: hidden;
  white-space: nowrap;
}

.card-top {
  font-size: calc(var(--w) * .085);
  line-height: 1.2;
  opacity: .75;
}

.card-top:empty {
  display: none;
}

.card-main {
  font-size: calc(var(--w) * .56);
  font-weight: 700;
  line-height: 1.05;
}

/* “Ww” 两个字母并排最宽，字号要小一些 */
.card.letters .card-main {
  font-size: calc(var(--w) * .4);
  line-height: 1.2;
}

.card-pic {
  font-size: calc(var(--w) * .19);
  line-height: 1.2;
  min-height: 1.2em;
}

/* 数字卡片：图案每行 5 个，方便数数 */
.card.numbers .card-pic {
  font-size: calc(var(--w) * .085);
  line-height: 1.3;
  min-height: 2.6em;
  width: 6.6em;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
}

.card.numbers .card-pic i {
  width: 1.3em;
  font-style: normal;
  text-align: center;
}

.card-label {
  font-size: calc(var(--w) * .085);
  font-weight: 700;
  line-height: 1.2;
}

.card-sound {
  position: absolute;
  top: calc(var(--w) * .03);
  right: calc(var(--w) * .04);
  font-size: calc(var(--w) * .06);
  opacity: .6;
}

.bounce {
  animation: bounce .45s ease;
}

@keyframes bounce {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.06); }
  70% { transform: scale(.98); }
}

/* ---------- 找一找 ---------- */

.stars {
  text-align: center;
  font-size: 32px;
  margin: 12px 0 8px;
  letter-spacing: 6px;
}

.star-empty {
  filter: grayscale(1);
  opacity: .3;
}

.ask-btn {
  align-self: center;
  background: #ba68c8;
  color: #fff;
  font-size: clamp(22px, 5.5vw, 30px);
  font-weight: 700;
  padding: 14px 32px;
  border-radius: 999px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .15);
  margin: 8px 0 20px;
}

.options {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: center;
  justify-content: center;
  gap: 20px;
}

.option {
  flex: 1 1 96px;
  max-width: 260px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--c);
  border: 6px solid #fff;
  border-radius: 32px;
  font-size: clamp(48px, 14vw, 130px);
  font-weight: 700;
  box-shadow: 0 8px 0 rgba(0, 0, 0, .12);
}

/* 4 个选项时排成 2×2 */
.options.four .option {
  flex: 0 1 calc(50% - 10px);
  max-width: 200px;
}

.option.right {
  background: #a5d6a7;
  animation: bounce .45s ease 2;
}

.option.wrong {
  opacity: .35;
  animation: shake .4s ease;
}

.shake {
  animation: shake .4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

.finish {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.finish-emoji {
  font-size: 120px;
  animation: bounce .8s ease infinite;
}

.finish h2 {
  font-size: 48px;
  margin: 8px 0;
}

/* ---------- 游戏列表 ---------- */

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  margin-top: 16px;
  padding-bottom: 16px;
}

.game-tile {
  aspect-ratio: 1;
  background: var(--c);
  color: #fff;
  border-radius: 28px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .15);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.game-icon {
  font-size: clamp(48px, 12vw, 64px);
  line-height: 1.1;
}

.game-title {
  font-size: 24px;
  font-weight: 700;
}

/* ---------- 游戏：题目和选项里的图 ---------- */

.prompt {
  text-align: center;
  font-size: clamp(56px, 13vh, 110px);
  line-height: 1.2;
}

/* 一堆图案：选项里每行 3 个，题目里每行 5 个 */
.group {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  width: 3.9em;
  font-size: .32em;
  line-height: 1.3;
  vertical-align: middle;
}

.group i {
  width: 1.3em;
  font-style: normal;
  text-align: center;
}

.prompt .group {
  width: 6.6em;
  font-size: min(.5em, 11vw);
}

/* 选项里的一堆图案跟着选项框的大小走，框越大图案越大 */
.option {
  container-type: inline-size;
}

@supports (width: 1cqw) {
  .option .group {
    font-size: 19cqw;
  }
}

.seq {
  display: inline-block;
  font-size: min(.5em, 9vw);
  font-weight: 700;
}

.seq.long {
  font-size: min(.42em, 6.5vw);
}

.shadow {
  display: inline-block;
  filter: brightness(0);
  opacity: .75;
}

.blob {
  width: 64%;
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, .12);
}

.shape {
  width: 68%;
  height: auto;
}

/* ---------- 游戏：排排队 ---------- */

.bubbles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 18px;
  max-width: 620px;
  margin: 8px auto;
}

.bubble {
  width: clamp(76px, 20vw, 130px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--c);
  font-size: clamp(36px, 10vw, 64px);
  font-weight: 700;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .12);
}

.bubble.done {
  background: #a5d6a7;
  opacity: .55;
}

/* ---------- 游戏：戳气球 ---------- */

.balloons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  justify-items: center;
  gap: 24px 12px;
  width: min(100%, 420px, 52vh);
  margin: 8px auto;
}

.balloon {
  position: relative;
  width: 74%;
  aspect-ratio: 5 / 6;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .6) 0 8%, transparent 9%), var(--c);
  box-shadow: inset -6px -8px 0 rgba(0, 0, 0, .1);
  transition: transform .2s, opacity .2s;
}

/* 气球嘴 */
.balloon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  border: 7px solid transparent;
  border-bottom-color: var(--c);
  transform: translate(-50%, -9px);
}

.balloon.popped {
  transform: scale(0);
  opacity: 0;
}

/* ---------- 游戏：翻翻乐 ---------- */

.mem-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: min(100%, 560px);
  margin: 8px auto;
}

.mem-card {
  aspect-ratio: 1;
  background: #ba68c8;
  border-radius: 20px;
  font-size: clamp(36px, 11vw, 72px);
  box-shadow: 0 5px 0 rgba(0, 0, 0, .15);
}

.mem-card::before {
  content: "❓";
}

.mem-face {
  display: none;
}

.mem-card.open {
  background: #fff;
}

.mem-card.open::before {
  content: none;
}

.mem-card.open .mem-face {
  display: inline;
}

.mem-card.done {
  background: #a5d6a7;
}

/* ---------- 游戏：走迷宫 ---------- */

.maze {
  --mw: min(calc(100vw - 32px), 44vh, 520px);
  width: var(--mw);
  height: var(--mw);
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  margin: 0 auto;
  background: #fff;
  border: 4px solid #8d6e63;
  border-radius: 12px;
  font-size: calc(var(--mw) / var(--n) * .55);
  overflow: hidden;
}

.maze-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid transparent;
  line-height: 1;
}

.maze-cell.wt { border-top-color: #8d6e63; }
.maze-cell.wr { border-right-color: #8d6e63; }
.maze-cell.wb { border-bottom-color: #8d6e63; }
.maze-cell.wl { border-left-color: #8d6e63; }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 60px);
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.dpad [data-d="0"] { grid-area: 1 / 2; }
.dpad [data-d="3"] { grid-area: 2 / 1; }
.dpad [data-d="2"] { grid-area: 2 / 2; }
.dpad [data-d="1"] { grid-area: 2 / 3; }
