:root {
  --bg: #fff8ee;
  --card: #ffffff;
  --ink: #3d2b1f;
  --ink-soft: #8a7462;
  --line: #f0e2d0;
  --primary: #ff8c42;
  --primary-dark: #f26b1f;
  --green: #5fbf6a;
  --red: #e8635a;
  --blue: #5aa9e6;
  --yellow: #ffc94d;
  --radius: 18px;
  --shadow: 0 6px 20px rgba(180, 120, 60, .10);
}

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

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.6;
  -webkit-user-select: none;
  user-select: none;
}

.hidden { display: none !important; }

button, input { font-family: inherit; font-size: inherit; }
button { cursor: pointer; border: none; outline: none; }

/* ---------- setup ---------- */
.setup-mask {
  position: fixed; inset: 0; z-index: 50;
  background: linear-gradient(160deg, #fff1d6, #ffe8d0);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.setup-card {
  width: 100%; max-width: 420px; background: var(--card);
  border-radius: 24px; padding: 32px 28px; box-shadow: var(--shadow);
  text-align: center;
}
.setup-logo { font-size: 64px; line-height: 1; }
.setup-card h1 { font-size: 24px; margin: 12px 0 4px; }
.setup-sub { color: var(--ink-soft); font-size: 14px; margin: 0 0 22px; }
.setup-card label {
  display: block; text-align: left; font-size: 14px;
  color: var(--ink-soft); margin: 14px 0 6px;
}
.setup-card input {
  width: 100%; padding: 13px 14px; border: 2px solid var(--line);
  border-radius: 12px; font-size: 17px;
}
.setup-card input:focus { border-color: var(--primary); }
.err { color: var(--red); font-size: 13px; min-height: 20px; margin: 10px 0 0; }
.setup-tip { color: var(--ink-soft); font-size: 13px; margin: 16px 0 0; }

/* ---------- buttons ---------- */
.btn-primary {
  background: var(--primary); color: white; font-weight: 700;
  padding: 11px 22px; border-radius: 12px;
  box-shadow: 0 4px 0 var(--primary-dark);
  transition: transform .1s, box-shadow .1s;
}
.btn-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--primary-dark); }
.btn-primary.big { width: 100%; margin-top: 18px; padding: 15px; font-size: 18px; }
.btn-ghost {
  background: #fff4e6; color: var(--primary-dark); font-weight: 600;
  padding: 10px 16px; border-radius: 12px; border: 2px solid #ffe0bd;
}
.btn-ghost:active { background: #ffe9cf; }

/* ---------- layout ---------- */
.app { max-width: 780px; margin: 0 auto; padding-bottom: 40px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 10px;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 800; }
.brand-icon { font-size: 30px; }
.stats { display: flex; gap: 12px; }
.stat {
  background: white; border-radius: 14px; padding: 6px 12px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 5px;
  font-size: 15px;
}
.stat-icon { font-size: 17px; }

.tabs {
  display: flex; gap: 6px; padding: 8px 16px 4px;
  overflow-x: auto;
}
.tab {
  flex: 1; min-width: 78px; background: transparent; color: var(--ink-soft);
  padding: 10px 6px; border-radius: 12px; font-size: 14px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab span { font-size: 20px; }
.tab.active { background: white; color: var(--primary-dark); box-shadow: var(--shadow); }

.main { padding: 12px 16px; }
.view { display: none; }
.view.active { display: block; }

/* ---------- train ---------- */
.level-bar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.lv-btn {
  flex: 1; min-width: 70px; background: white; border: 2px solid var(--line);
  border-radius: 14px; padding: 8px 4px; text-align: center; color: var(--ink-soft);
}
.lv-btn b { display: block; font-size: 15px; }
.lv-btn small { font-size: 11px; }
.lv-btn.active { border-color: var(--primary); background: #fff4e6; color: var(--primary-dark); }
.lv-btn.locked { opacity: .45; }

.train-card {
  background: var(--card); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.train-head { display: flex; justify-content: space-between; align-items: center; }
.q-index { color: var(--primary-dark); font-weight: 700; font-size: 15px; }
.q-hint { font-size: 13px; color: var(--ink-soft); }
.train-tip { color: var(--ink-soft); font-size: 13px; margin: 8px 0 14px; }

.answer-zone {
  min-height: 78px; background: #fffaf2; border: 3px dashed #f3d9b6;
  border-radius: 14px; padding: 10px; display: flex; flex-wrap: wrap;
  gap: 8px; align-content: flex-start;
}
.answer-zone.drag-over { border-color: var(--primary); background: #fff2df; }

.chunk-pool {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 20px;
  min-height: 50px;
}
.chunk {
  background: white; border: 2px solid #e8d5bd; color: var(--ink);
  border-radius: 12px; padding: 9px 14px; font-size: 17px; font-weight: 600;
  box-shadow: 0 3px 0 #e8d5bd; touch-action: none;
}
.chunk:active { transform: translateY(2px); box-shadow: 0 1px 0 #e8d5bd; }
.chunk.in-answer { border-color: var(--primary); background: #fff4e6; box-shadow: 0 3px 0 #ffd4a8; }
.chunk.hint-glow { animation: glow 1s infinite alternate; }
@keyframes glow { to { box-shadow: 0 0 0 4px rgba(255, 201, 77, .6); } }
.chunk.dragging { opacity: .4; }

.train-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.train-actions button { font-size: 14px; padding: 9px 12px; }

.feedback {
  margin-top: 16px; padding: 14px 16px; border-radius: 12px;
  font-size: 16px; font-weight: 600; text-align: center;
}
.feedback.ok { background: #eaf8ec; color: #2e8b3c; }
.feedback.no { background: #fdeceb; color: #b93b33; }

/* ---------- pet ---------- */
.pet-card {
  background: var(--card); border-radius: var(--radius);
  padding: 28px 20px; box-shadow: var(--shadow); text-align: center;
}
.pet-stage-wrap { position: relative; display: inline-block; }
.pet-icon { font-size: 110px; line-height: 1.2; }
.pet-shine { position: absolute; top: 6px; right: -10px; font-size: 28px; }
.pet-card h2 { font-size: 24px; margin: 6px 0 2px; }
.pet-title { color: var(--ink-soft); margin: 0 0 22px; }
.exp-box { text-align: left; margin-bottom: 22px; }
.exp-label { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; }
.exp-track { height: 16px; background: #f5e8d8; border-radius: 10px; overflow: hidden; }
.exp-fill { height: 100%; background: linear-gradient(90deg, var(--yellow), var(--primary)); width: 0; border-radius: 10px; transition: width .5s; }
.pet-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pet-stat { background: #fff8ee; border-radius: 12px; padding: 12px 4px; }
.pet-stat span { display: block; font-size: 12px; color: var(--ink-soft); }
.pet-stat b { font-size: 20px; color: var(--primary-dark); }
.pet-tip { color: var(--ink-soft); font-size: 13px; margin: 22px 0 0; }

/* ---------- map ---------- */
.map-head { text-align: center; margin-bottom: 18px; }
.map-head h2 { font-size: 22px; margin: 0; }
.map-head p { color: var(--ink-soft); font-size: 13px; margin: 4px 0 0; }
.monster-list { display: grid; gap: 12px; }
.monster {
  background: white; border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 14px;
}
.monster.locked { opacity: .55; }
.monster-icon { font-size: 42px; }
.monster-info { flex: 1; }
.monster-info h3 { margin: 0; font-size: 17px; }
.monster-info p { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); }
.monster .btn-primary { font-size: 13px; padding: 8px 14px; }

/* ---------- parent ---------- */
.parent-card {
  background: white; border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow);
}
.parent-card h2 { margin: 0; font-size: 21px; }
.parent-sub { color: var(--ink-soft); font-size: 13px; margin: 4px 0 18px; }
.parent-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.pgrid-item { background: #fff8ee; border-radius: 12px; padding: 12px; }
.pgrid-item span { font-size: 12px; color: var(--ink-soft); display: block; }
.pgrid-item b { font-size: 22px; color: var(--primary-dark); }
.parent-row { display: flex; align-items: end; gap: 12px; margin-top: 20px; }
.parent-row label { font-size: 13px; color: var(--ink-soft); display: block; margin-bottom: 4px; }
.code-chip {
  background: #fff4e6; border: 2px dashed #ffcf9c; border-radius: 10px;
  padding: 8px 14px; font-weight: 700; letter-spacing: 2px;
}
.parent-actions { margin-top: 20px; }

/* ---------- toast / battle ---------- */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: rgba(61, 43, 31, .92); color: white; padding: 10px 20px;
  border-radius: 20px; font-size: 14px; z-index: 60; white-space: nowrap;
}
.battle-fx {
  position: fixed; inset: 0; z-index: 70; background: rgba(61, 43, 31, .6);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.fx-card {
  background: white; border-radius: 24px; padding: 28px; text-align: center;
  width: 100%; max-width: 360px;
}
.fx-title { font-size: 22px; font-weight: 800; margin-bottom: 16px; }
.fx-vs { display: flex; align-items: center; justify-content: center; gap: 18px; font-size: 56px; margin-bottom: 12px; }
.fx-vs b { font-size: 20px; color: var(--ink-soft); }
.fx-card p { color: var(--ink-soft); font-size: 14px; margin-bottom: 20px; }

@media (max-width: 480px) {
  .brand { font-size: 17px; }
  .stat { padding: 5px 8px; font-size: 13px; }
  .tab { font-size: 12px; min-width: 66px; }
  .train-card { padding: 16px; }
  .train-actions button { flex: 1 1 45%; }
  .pet-icon { font-size: 90px; }
}
