:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --primary: #007AFF;
  --text: #1d1d1f;
  --border: #e5e5ea;
  --success: #34c759;
  --warn: #ff9500;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px;
  transition: opacity 0.3s;
  background: var(--bg);
}

.screen.hidden {
  opacity: 0;
  pointer-events: none;
  z-index: -1;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  z-index: 1;
}

.btn-primary {
  padding: 14px 24px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 25px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,122,255,0.25);
}

.btn-sec {
  padding: 10px 18px;
  background: #e5e5ea;
  color: var(--text);
  border: none;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
}

.btn-primary:active,
.btn-sec:active {
  transform: scale(0.96);
}

/* ========== 顶部信息栏（固定置顶）========== */
#game-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: rgba(242,242,247,0.98);
  backdrop-filter: blur(8px);
  padding: 12px 15px 10px;
  z-index: 100;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

#item-display {
  font-size: 28px;
  font-weight: bold;
  height: 36px;
  transition: opacity 0.2s;
}

#progress-bar {
  height: 4px;
  background: #ddd;
  border-radius: 2px;
  overflow: hidden;
  margin: 6px 0;
}

/* 🔹 新增：整体进度条（显示 36 题总进度） */
#overall-progress {
  height: 3px;
  background: #e5e5ea;
  border-radius: 2px;
  overflow: hidden;
  margin: 4px 0 0;
}

#overall-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.3s ease;
}

#timer-display {
  font-size: 13px;
  color: #666;
}

/* ========== 游戏主屏 ========== */
#screen-game {
  padding-top: 110px;
  justify-content: flex-start;
}

#grid-preview {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  width: 100%;
  max-width: 380px;
  aspect-ratio: 1;
  background: var(--card);
  padding: 6px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.g-cell {
  background: #fafafa;
  border-radius: 4px;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #999;
  position: relative;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}

.g-cell.active {
  border-color: var(--primary);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%,100% { border-color: var(--primary); }
  50% { border-color: #5ac8fa; }
}

/* ========== 全屏画板层（优化布局）========== */
#draw-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #fff;
  display: flex;
  flex-direction: column;
  /* 🔹 关键优化：上下留白，不遮挡顶部信息 + 底部工具栏 */
  padding-top: 105px;
  padding-bottom: 75px;
  transform: translateY(100%);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

#draw-overlay.active {
  transform: translateY(0);
  opacity: 1;
}

#main-canvas {
  flex: 1;
  width: 100%;
  background: #fafafa;
  border-radius: 8px;
  cursor: crosshair;
  touch-action: none;
  /* 🔹 防止画板撑满屏幕，留出工具栏空间 */
  max-height: calc(100vh - 180px);
}

/* 🔹 关键优化：工具栏固定底部，悬浮样式 */
#draw-toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255,255,255,0.98);
  backdrop-filter: blur(8px);
  padding: 10px 15px;
  border-top: 1px solid var(--border);
  z-index: 60;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tool-group {
  display: flex;
  gap: 8px;
}

.tool-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid #eee;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: #fff;
}

.tool-btn.active {
  border-color: var(--primary);
  background: #f0f7ff;
  transform: scale(1.1);
}

/* ========== 通用卡片 & 其他页面 ========== */
.card-box {
  background: var(--card);
  padding: 20px;
  border-radius: 12px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.q-text {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 15px;
}

.opt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.opt-btn {
  padding: 14px;
  background: #f2f2f7;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
}

.opt-btn:active {
  background: #e5e5ea;
}

.sub-text {
  font-size: 12px;
  color: #999;
}

.recall-canvas {
  width: 180px;
  height: 180px;
  margin: 0 auto 15px;
  border: 2px dashed #ddd;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #fff;
}

.recall-canvas img {
  max-width: 100%;
  max-height: 100%;
}

#recall-input {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
}

.fb-text {
  height: 24px;
  margin-top: 8px;
  font-weight: bold;
}

.stats-box {
  background: var(--card);
  padding: 15px;
  border-radius: 10px;
  margin: 10px 0 20px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  width: 90%;
  max-width: 360px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 3px;
  width: 100%;
  max-width: 400px;
  margin-bottom: 20px;
  max-height: 60vh;
  overflow-y: auto;
}

.res-cell {
  background: var(--card);
  border-radius: 4px;
  padding: 2px;
  text-align: center;
  font-size: 9px;
  position: relative;
}

.res-cell img {
  width: 100%;
  height: auto;
  border-radius: 2px;
}

.res-cell .res-name {
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.res-mark {
  position: absolute;
  top: 0;
  right: 0;
  font-size: 12px;
  background: rgba(255,255,255,0.9);
  padding: 0 2px;
  border-radius: 4px;
}

.mark-ok { color: var(--success); }
.mark-fail { color: var(--warn); }