/* ====== 全局重置 ====== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f8f9fa;
  --card: #ffffff;
  --text: #333333;
  --text-light: #888888;
  --primary: #4A90D9;
  --primary-hover: #3a7bc8;
  --success: #52C41A;
  --danger: #FF4D4F;
  --warning: #FAAD14;
  --border: #e8e8e8;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ====== 导航栏 ====== */
#navbar {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-btn {
  flex: 1;
  padding: 14px 8px;
  border: none;
  background: none;
  font-size: 1rem;
  color: var(--text-light);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  min-height: 44px;
}
.nav-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}
.nav-btn.disabled {
  color: #ccc;
  cursor: not-allowed;
}

/* ====== 标签页切换 ====== */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ====== 屏幕切换 ====== */
.screen { display: none; }
.screen.active { display: block; }

/* ====== 按钮 ====== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 44px;
  font-family: inherit;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-large { padding: 16px 48px; font-size: 1.2rem; border-radius: var(--radius); }
.btn-sm { padding: 8px 16px; font-size: 0.9rem; }
.btn-pause {
  display: block;
  margin: 12px auto 0;
  padding: 10px 32px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-light);
  font-size: 0.9rem;
  cursor: pointer;
  min-height: 44px;
  font-family: inherit;
}

/* ====== 主页 ====== */
.home-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  min-height: 80dvh;
  padding: 24px;
  text-align: center;
  gap: 16px;
}
.game-title { font-size: 2rem; font-weight: 700; color: var(--text); }
.game-subtitle { font-size: 1rem; color: var(--text-light); max-width: 300px; }

/* ====== 阶段一：画画 ====== */
#screen-draw {
  display: none;
  flex-direction: column;
  height: calc(100vh - 49px);
  height: calc(100dvh - 49px);
}
#screen-draw.active { display: flex; }

.draw-header {
  display: flex;
  justify-content: space-between;
  padding: 8px 16px;
  font-size: 0.85rem;
  color: var(--text-light);
}
.draw-score { font-weight: 600; color: var(--primary); }

.prompt-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px;
}
.prompt-text {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}
#prompt-word { color: var(--primary); }
.timer-text {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 40px;
  text-align: center;
}
.timer-ring { flex-shrink: 0; }

.canvas-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}
#draw-canvas {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: crosshair;
  touch-action: none;
  box-shadow: var(--shadow);
}

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

.color-picker, .width-picker {
  display: flex;
  gap: 6px;
  align-items: center;
}
.color-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.color-btn.active { border-color: var(--primary); transform: scale(1.15); }
.width-btn {
  padding: 6px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  font-size: 0.8rem;
  min-height: 36px;
  font-family: inherit;
}
.width-btn.active { border-color: var(--primary); background: #e8f0fe; color: var(--primary); }
.tool-btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  min-height: 36px;
  font-family: inherit;
}

/* ====== 阶段二：干扰题 ====== */
#screen-quiz {
  display: none;
  min-height: calc(100vh - 49px);
  min-height: calc(100dvh - 49px);
  background: #fff;
}
#screen-quiz.active { display: flex; flex-direction: column; }

.quiz-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 24px;
  gap: 20px;
}
.quiz-header {
  font-size: 0.9rem;
  color: var(--text-light);
}
.quiz-question {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  padding: 20px;
  min-height: 60px;
}

/* 数字键盘 */
.number-input-display {
  font-size: 2.5rem;
  font-weight: 700;
  min-height: 60px;
  min-width: 150px;
  text-align: center;
  border-bottom: 3px solid var(--primary);
  padding: 4px 16px;
  letter-spacing: 4px;
}
.number-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 280px;
  width: 100%;
}
.keypad-btn {
  padding: 16px;
  font-size: 1.4rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  min-height: 56px;
  font-family: inherit;
  transition: all 0.15s;
}
.keypad-btn:active { background: #eee; transform: scale(0.93); }
.keypad-btn.keypad-back { color: var(--danger); font-size: 1rem; }
.keypad-btn.keypad-confirm { background: var(--primary); color: #fff; border-color: var(--primary); }

/* 选项网格 */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 400px;
}
.option-btn {
  padding: 16px 12px;
  font-size: 1.1rem;
  font-weight: 500;
  border: 3px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  min-height: 56px;
  font-family: inherit;
  transition: all 0.15s;
}
.option-btn:active { transform: scale(0.95); }
.option-btn.correct { border-color: var(--success); background: #f0fff0; color: var(--success); }
.option-btn.wrong { border-color: var(--danger); background: #fff0f0; color: var(--danger); animation: shake 0.4s; }

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

.quiz-feedback {
  font-size: 1rem;
  color: var(--danger);
  min-height: 28px;
  text-align: center;
}

/* ====== 阶段三：含义选择 ====== */
#screen-meaning {
  display: none;
  min-height: calc(100vh - 49px);
  min-height: calc(100dvh - 49px);
  background: #fff;
}
#screen-meaning.active { display: flex; flex-direction: column; }

.meaning-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  padding: 20px;
  gap: 14px;
}
.meaning-header {
  font-size: 0.9rem;
  color: var(--text-light);
}
.meaning-drawing {
  max-width: 80vw;
  max-height: 40vh;
}
.meaning-drawing img {
  max-width: 100%;
  max-height: 40vh;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
.meaning-prompt {
  font-size: 1.2rem;
  font-weight: 600;
}
.meaning-feedback {
  font-size: 1rem;
  min-height: 28px;
  text-align: center;
  font-weight: 600;
}

/* ====== 结算 ====== */
#screen-settlement { display: none; }
#screen-settlement.active { display: block; }
.settlement-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.settlement-card {
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  text-align: center;
}
.settlement-card h2 {
  font-size: 1.3rem;
  margin-bottom: 16px;
}
.settle-section {
  margin: 12px 0;
  font-size: 0.95rem;
  color: var(--text-light);
}
.settle-label { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.settle-detail { line-height: 1.6; }
.settle-divider {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}
.settle-group-score {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
}
.settle-total-score {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 8px 0 20px;
}
.settle-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ====== 题库管理 ====== */
.bank-container {
  display: flex;
  min-height: calc(100vh - 49px);
  min-height: calc(100dvh - 49px);
}
.bank-sidebar {
  width: 90px;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 4px;
}
.bank-type-btn {
  padding: 12px 6px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  min-height: 44px;
}
.bank-type-btn.active { background: var(--primary); color: #fff; }
.bank-main { flex: 1; padding: 12px; overflow-y: auto; }
.bank-toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.bank-list { display: flex; flex-direction: column; gap: 8px; }
.bank-del-btn {
  float: right;
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 12px;
  color: #999;
  cursor: pointer;
  line-height: 1;
}
.bank-del-btn:hover { color: var(--danger); border-color: var(--danger); }
.bank-item {
  background: #fff;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}
.bank-item:hover { border-color: var(--primary); }
.bank-item .bi-question { font-weight: 600; }
.bank-item .bi-answer { color: var(--success); font-size: 0.8rem; }
.bank-item .bi-id { color: #ccc; font-size: 0.7rem; float: right; }
.bank-editor textarea {
  width: 100%;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  resize: vertical;
}
.bank-editor-buttons { display: flex; gap: 8px; margin-top: 8px; }

/* ====== 联机预留 ====== */
.online-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  color: var(--text-light);
}

/* ====== 响应式：PC端 ====== */
@media (min-width: 768px) {
  .home-container { padding: 48px; }
  .game-title { font-size: 2.5rem; }
  .quiz-container { max-width: 600px; margin: 0 auto; }
  .meaning-container { max-width: 600px; margin: 0 auto; }
  .bank-sidebar { width: 120px; }
  #navbar { justify-content: center; }
  .nav-btn { flex: 0 0 auto; padding: 14px 32px; }
  .canvas-wrapper { padding: 16px; }
}
