:root {
  --bg: #FBF4E6;
  --card: #FFFDF8;
  --line: #E8D8BE;
  --ink: #2C241B;
  --muted: #766452;
  --wood: #E6C386;
  --wood-dark: #C49B57;
  --red: #D94F3D;
  --blue: #3572C6;
  --green: #3D9960;
  --gold: #E5A93B;
  --gold-soft: #FFF3D1;
  --shadow: 0 8px 24px rgba(84, 58, 28, 0.08);
  --radius: 22px;
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  touch-action: manipulation;
  overscroll-behavior: none;
}

input, select, button {
  font-family: inherit;
  color: inherit;
}

input {
  -webkit-user-select: text;
  user-select: text;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0;
}

button:active {
  transform: scale(0.97);
}

[hidden] {
  display: none !important;
}

#app {
  min-height: 100dvh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.screen {
  display: none;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  max-width: 1120px;
  margin: 0 auto;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ---------- 首页 ---------- */
.home-head {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}

.home-head h1 {
  margin: 0;
  font-size: clamp(24px, 3.6vw, 34px);
  letter-spacing: 0.5px;
}

.home-head .sub {
  margin: 4px 0 0;
  font-size: 16px;
  color: var(--muted);
}

.star-total {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--gold-soft);
  border: 2px solid #F1CF7C;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 22px;
  font-weight: 700;
  color: #9A640B;
}

.star-ico {
  width: 24px;
  height: 24px;
  display: inline-block;
  background: var(--gold);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

.home-cards {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin: 22px 0;
  align-content: center;
}

.game-card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 26px;
  padding: 26px 20px;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  transition: transform 0.14s ease, border-color 0.14s ease;
}

.game-card:hover {
  border-color: var(--wood-dark);
}

.game-card h2 {
  margin: 4px 0 0;
  font-size: 26px;
}

.game-card p {
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  color: var(--muted);
}

.card-art {
  width: 112px;
  height: 112px;
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.art-gomoku {
  background: linear-gradient(145deg, #EED29B, #DDA95E);
  border: 2px solid #C49147;
  display: grid;
  grid-template-columns: repeat(4, 18px);
  gap: 4px;
  padding: 18px;
  align-content: center;
  justify-content: center;
}

.art-gomoku i {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #666, #141414);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25);
}

.art-gomoku i.w {
  background: radial-gradient(circle at 35% 30%, #fff, #d6d0c4);
}

.art-checkers {
  background: linear-gradient(145deg, #FCE4DF, #F6CBC3);
  border: 2px solid #E9A79B;
}

.art-checkers::before, .art-checkers::after {
  content: "";
  width: 34px;
  height: 34px;
  border-radius: 50%;
  position: absolute;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.18);
}

.art-checkers::before {
  background: radial-gradient(circle at 35% 30%, #ff9a8a, #c9302c);
  transform: translate(-16px, -12px);
}

.art-checkers::after {
  background: radial-gradient(circle at 35% 30%, #9cc8ff, #2862b0);
  transform: translate(16px, 14px);
}

.art-lesson {
  background: linear-gradient(145deg, #DCF3E5, #B5E4C8);
  border: 2px solid #84C9A1;
}

.art-lesson span {
  font-size: 46px;
  font-weight: 800;
  color: #206A40;
}

.home-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px;
  font-size: 16px;
  color: var(--muted);
}

.link-btn {
  font-size: 16px;
  color: var(--muted);
  padding: 10px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
  min-height: 44px;
}

/* ---------- 猫头鹰（CSS绘制） ---------- */
.owl, .owl-big {
  position: relative;
  border-radius: 50% 50% 46% 46%;
  background: #8B6443;
  flex-shrink: 0;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.12);
}

.owl-big {
  width: 66px;
  height: 66px;
}

.owl {
  width: 56px;
  height: 56px;
}

.owl::before, .owl::after, .owl-big::before, .owl-big::after {
  content: "";
  position: absolute;
  top: 26%;
  width: 34%;
  height: 34%;
  border-radius: 50%;
  background: radial-gradient(circle at 52% 52%, #221B15 32%, #FFF9EE 35%);
  border: 2px solid #D9B382;
}

.owl::before, .owl-big::before { left: 13%; }
.owl::after, .owl-big::after { right: 13%; }

.owl.sleepy::before, .owl.sleepy::after {
  height: 8%;
  top: 42%;
  border-radius: 99px;
  background: #2C241B;
  border: 0;
}

/* ---------- 顶部栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.topbar h2 {
  margin: 0;
  font-size: 22px;
  text-align: center;
}

.icon-btn, .act-btn {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 16px;
  background: var(--card);
  border: 2px solid var(--line);
  font-size: 17px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.act-btn.hint {
  background: var(--gold-soft);
  border-color: #E7BC5C;
  color: #875405;
}

.act-btn.danger {
  color: var(--red);
  border-color: #F0B6AF;
}

/* ---------- 对局设置 ---------- */
.setup-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 820px;
  width: 100%;
  margin: 8px auto 0;
}

.setup-body h3 {
  margin: 0;
  font-size: 20px;
}

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

.level-card {
  background: var(--card);
  border: 2.5px solid var(--line);
  border-radius: 22px;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  box-shadow: var(--shadow);
}

.level-card.active {
  border-color: var(--green);
  background: #F2FBF5;
  box-shadow: 0 0 0 4px rgba(61, 153, 96, 0.16);
}

.level-card b {
  font-size: 20px;
}

.level-card small {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.4;
}

.lv-wins {
  font-style: normal;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 99px;
  background: #F5EBDA;
  color: #7D6242;
}

.animal {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  position: relative;
}

.animal.ant {
  background: #F9DFD8;
  border: 2.5px solid #D96B52;
}

.animal.ant::before {
  content: "蚁";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 800;
  color: #B4412B;
}

.animal.rabbit {
  background: #E2EEFD;
  border: 2.5px solid #5990D6;
}

.animal.rabbit::before {
  content: "兔";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 800;
  color: #2B5EA3;
}

.animal.lion {
  background: #FCEBC6;
  border: 2.5px solid #D99726;
}

.animal.lion::before {
  content: "狮";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 800;
  color: #9C5E08;
}

.opt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.opt {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.opt span {
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: #F3E9D7;
  border-radius: 14px;
  padding: 4px;
  gap: 4px;
}

.seg button {
  min-height: 44px;
  border-radius: 11px;
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
}

.seg button.active {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.big-btn {
  min-height: 58px;
  padding: 0 32px;
  border-radius: 20px;
  background: linear-gradient(180deg, #4FB574, #369257);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  box-shadow: 0 6px 0 #266D3F;
  margin-top: auto;
  align-self: center;
  min-width: 240px;
}

.big-btn.sm {
  min-height: 48px;
  min-width: 130px;
  font-size: 18px;
  border-radius: 15px;
  box-shadow: 0 4px 0 #266D3F;
  margin-top: 0;
}

/* ---------- 对局界面（一屏锁定） ---------- */
#screen-game.active {
  height: 100dvh;
  overflow: hidden;
  max-width: 1220px;
}

.game-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.board-wrap {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.board-wrap svg {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.coach {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.turn-box {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
}

.turn-box small {
  margin-left: auto;
  font-weight: 500;
  color: var(--muted);
  font-size: 14px;
}

.dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot.b { background: #1E1E1E; }
.dot.w { background: #fff; border: 2px solid #888; }
.dot.r { background: var(--red); }

.coach-card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 20px;
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  box-shadow: var(--shadow);
}

.coach-card.happy {
  border-color: #88CCA2;
  background: #F4FCF7;
}

.coach-card.warn {
  border-color: #EC9D92;
  background: #FFF5F3;
}

.coach-card.pop {
  animation: popIn 0.24s ease;
}

@keyframes popIn {
  0% { transform: scale(0.98); }
  50% { transform: scale(1.015); }
  100% { transform: scale(1); }
}

.bubble {
  flex: 1;
  min-width: 0;
}

.bubble p {
  margin: 0;
  font-size: 18px;
  line-height: 1.5;
}

.bubble .term {
  color: #B44818;
  background: #FFEBD8;
  padding: 0 5px;
  border-radius: 6px;
}

.replay {
  margin-top: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--blue);
  background: #EEF4FD;
  padding: 6px 12px;
  border-radius: 99px;
  min-height: 36px;
}

.lesson-goal {
  background: var(--gold-soft);
  border: 2px solid #E7BC5C;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 16px;
  font-weight: 700;
  color: #7D4F07;
}

/* ---------- iPad 横屏适配 ---------- */
@media (min-aspect-ratio: 11/10) and (min-width: 760px) {
  .game-body {
    flex-direction: row;
    align-items: stretch;
    gap: 18px;
  }
  .coach {
    width: 340px;
    justify-content: center;
  }
}

/* ---------- 手机/窄屏首页与设置自适应 ---------- */
@media (max-width: 720px) {
  .home-cards, .level-row {
    grid-template-columns: 1fr;
  }
  .topbar h2 {
    font-size: 18px;
  }
  .icon-btn, .act-btn {
    padding: 0 12px;
    font-size: 15px;
  }
  .bubble p {
    font-size: 16px;
  }
}

/* ---------- 五子棋 SVG ---------- */
.g-wood {
  fill: var(--wood);
  stroke: var(--wood-dark);
  stroke-width: 3;
}

.g-grid line {
  stroke: #7F5B28;
  stroke-width: 1.4;
}

.g-star {
  fill: #69491D;
}

.shadow {
  fill: rgba(40, 24, 6, 0.25);
}

.last-dot {
  fill: var(--red);
}

.last-dot.on-black {
  fill: #FFD35C;
}

.win-line {
  stroke: var(--red);
  stroke-width: 7;
  stroke-linecap: round;
  opacity: 0.86;
}

.mk {
  fill: none;
  stroke-width: 4;
  pointer-events: none;
}

.mk-danger {
  stroke: var(--red);
  fill: rgba(217, 79, 61, 0.14);
  animation: pulseRing 1.1s ease-in-out infinite;
}

.mk-hint {
  stroke: var(--gold);
  fill: rgba(229, 169, 59, 0.22);
  animation: pulseRing 1.1s ease-in-out infinite;
}

@keyframes pulseRing {
  0%, 100% { stroke-opacity: 1; stroke-width: 4.5; }
  50% { stroke-opacity: 0.45; stroke-width: 2.5; }
}

/* ---------- 跳棋 SVG ---------- */
.c-star {
  fill: #F3DFB9;
  stroke: #CFA86B;
  stroke-width: 2.5;
  stroke-linejoin: round;
}

.hole {
  fill: #DFC394;
  stroke: #B7945B;
  stroke-width: 1.4;
}

.hole.tgt-me {
  fill: #FAD9D2;
  stroke: #D96B58;
  stroke-width: 2;
}

.hole.tgt-ai {
  fill: #D6E6FA;
  stroke: #6695D4;
  stroke-width: 2;
}

.hit {
  fill: transparent;
  cursor: pointer;
}

.zone-label {
  font-size: 18px;
  font-weight: 700;
  text-anchor: middle;
}

.zone-label.me { fill: #B33928; }
.zone-label.ai { fill: #25589E; }

.piece {
  pointer-events: none;
}

.piece.sel .p-body {
  stroke: var(--gold);
  stroke-width: 4.5;
}

.piece.fresh .p-body {
  stroke: #FFF4B8;
  stroke-width: 3;
}

.dest {
  pointer-events: none;
}

.dest.step circle {
  fill: rgba(61, 153, 96, 0.25);
  stroke: var(--green);
  stroke-width: 2.5;
}

.dest.jump circle {
  fill: rgba(61, 153, 96, 0.38);
  stroke: #217340;
  stroke-width: 3;
}

.dest.best circle {
  fill: rgba(229, 169, 59, 0.45);
  stroke: #C67F0B;
  stroke-width: 3.5;
}

.dest text {
  font-size: 15px;
  font-weight: 800;
  text-anchor: middle;
  fill: #134A28;
}

.c-paths polyline {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.path-best {
  stroke: var(--gold);
  stroke-width: 5;
  stroke-dasharray: 8 6;
}

.path-done {
  stroke: var(--green);
  stroke-width: 4;
  opacity: 0.7;
}

.path-ai {
  stroke: var(--blue);
  stroke-width: 3.5;
  stroke-dasharray: 6 6;
  opacity: 0.55;
}

/* ---------- 技巧小课堂 ---------- */
.lessons-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
  padding-bottom: 20px;
}

.lesson-sec {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 24px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.lesson-sec h3 {
  margin: 0 0 12px;
  font-size: 22px;
}

.lesson-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lesson-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #FAF3E5;
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px;
  text-align: left;
  min-height: 64px;
}

.lesson-item.done {
  background: #F2FBF5;
  border-color: #97D2AD;
}

.ln {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--wood);
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 800;
  flex-shrink: 0;
}

.lt {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lt b { font-size: 18px; }
.lt small { font-size: 14px; color: var(--muted); }

.ls {
  display: flex;
  gap: 4px;
}

.ls i {
  width: 18px;
  height: 18px;
  background: #E0D3BC;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

.ls i.on {
  background: var(--gold);
}

/* ---------- 弹窗与护眼锁 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(34, 24, 14, 0.52);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.overlay.on {
  display: flex;
}

.overlay.lock {
  background: rgba(242, 246, 236, 0.97);
  z-index: 80;
}

.result-card, .lock-card, .parent-card {
  width: min(460px, 100%);
  background: var(--card);
  border: 2.5px solid var(--line);
  border-radius: 28px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  position: relative;
  overflow: hidden;
}

.result-card h2, .lock-card h2, .parent-card h2 {
  margin: 0 0 10px;
  font-size: 28px;
}

.result-card p, .lock-card p, .parent-card p {
  margin: 0 0 18px;
  font-size: 18px;
  line-height: 1.6;
  color: var(--muted);
}

.result-btns, .row-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti i {
  position: absolute;
  top: -12px;
  width: 10px;
  height: 16px;
  border-radius: 3px;
  animation: fall 2.4s linear infinite;
}

@keyframes fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(420px) rotate(360deg); opacity: 0; }
}

.lock-card .owl {
  margin: 0 auto 16px;
  width: 82px;
  height: 82px;
}

.lock-count {
  font-size: 52px;
  font-weight: 800;
  color: var(--green);
  margin: 6px 0 10px;
  font-variant-numeric: tabular-nums;
}

.small {
  font-size: 15px !important;
}

.gate-q {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 14px;
}

#gate-a {
  width: 160px;
  height: 52px;
  font-size: 26px;
  text-align: center;
  border: 2px solid var(--line);
  border-radius: 14px;
  margin-bottom: 18px;
  background: #FAF3E5;
}

.prow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 17px;
}

.prow select {
  min-height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: #FAF3E5;
  font-size: 16px;
  margin-left: auto;
  margin-right: 6px;
}

.pstat {
  margin: 14px 0;
  padding: 12px;
  border-radius: 14px;
  background: #FAF3E5;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
  text-align: left;
}

.parent-card .big-btn.sm {
  margin-top: 14px;
  width: 100%;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: rgba(44, 36, 27, 0.92);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 90;
}

.toast.on {
  opacity: 1;
  transform: translate(-50%, 0);
}
