/* ============================================================
 *  猜数字 — 样式
 *  1A2B 数字 + Mastermind 颜色 双模式推理破译游戏
 * ============================================================ */

:root {
  --bg-0: #0a0e1a;
  --bg-1: #0d1117;
  --bg-2: #161b22;
  --bg-3: #21262d;
  --line: #30363d;
  --line-2: #4c5563;
  --text: #ffffff;
  --text-dim: #8b949e;
  --text-mute: #6e7681;
  --primary: #00E5FF;
  --primary-2: #2A5CAA;
  --accent: #6A00FF;
  --success: #5cdb95;
  --warn: #ffb454;
  --error: #ff4d6d;

  --c-red: #ef4444;
  --c-orange: #fb923c;
  --c-yellow: #fde047;
  --c-green: #22c55e;
  --c-blue: #3b82f6;
  --c-purple: #a855f7;
}

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

html, body {
  background: radial-gradient(ellipse at top, #0f1729 0%, var(--bg-0) 60%);
  color: var(--text);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 12px 80px;
}

/* ========== 顶部栏 ========== */
.top-bar {
  width: 100%;
  max-width: 600px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 4px 8px;
  font-size: 1rem;
}

.home-back {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 6px 10px;
  border-radius: 8px;
  transition: color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.home-back:hover {
  color: var(--primary);
  background: rgba(0, 229, 255, 0.1);
}

.page-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

/* ========== 容器 ========== */
.container {
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ========== 模式 Tab ========== */
.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--bg-2);
  border-radius: 14px;
  border: 1px solid var(--line);
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: var(--bg-3);
  color: var(--primary);
  box-shadow: inset 0 0 0 1px rgba(0, 229, 255, 0.2);
}

.tab-icon {
  font-size: 1.05rem;
  filter: saturate(1.1);
}

/* ========== 难度 + 新局 ========== */
.control-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.difficulty {
  flex: 1;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-2);
  border-radius: 12px;
  border: 1px solid var(--line);
}

.diff-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 8px 4px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  min-width: 0;
}

.diff-btn:hover {
  color: var(--text);
}

.diff-btn.active {
  background: var(--bg-3);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.diff-label {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.1;
}

.diff-meta {
  font-size: 0.68rem;
  color: var(--text-mute);
  font-weight: 400;
  white-space: nowrap;
}

.diff-btn.active .diff-meta {
  color: var(--text-dim);
}

.new-btn {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  white-space: nowrap;
}

.new-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(0, 229, 255, 0.08);
}

/* ========== 状态 ========== */
.status-row {
  display: flex;
  gap: 8px;
}

.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-mute);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  font-family: 'JetBrains Mono', 'SF Mono', 'Menlo', monospace;
  line-height: 1.2;
  margin-top: 2px;
}

/* ========== 图例 ========== */
.legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  font-size: 0.78rem;
  color: var(--text-dim);
  padding: 4px 0;
  flex-wrap: wrap;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-item[hidden] {
  display: none;
}

.legend-item b {
  color: var(--text);
  font-weight: 700;
  margin: 0 2px;
  font-family: 'JetBrains Mono', monospace;
}

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

.dot.a {
  background: var(--success);
  box-shadow: 0 0 6px rgba(92, 219, 149, 0.5);
}

.dot.b {
  background: var(--warn);
  box-shadow: 0 0 6px rgba(255, 180, 84, 0.45);
}

.dot.x {
  background: var(--bg-3);
  border: 1px solid var(--line-2);
}

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

.peg-dot.black {
  background: #ffffff;
  box-shadow: 0 0 4px rgba(255, 255, 255, 0.5);
}

.peg-dot.white {
  background: #d1d5db;
  border: 1px solid #ffffff;
}

.peg-dot.empty {
  background: transparent;
  border: 1px solid var(--line-2);
}

/* ========== 棋盘 ========== */
.board {
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  min-height: 280px;
  max-height: 360px;
}

.history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 2px;
  margin-bottom: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}

.history::-webkit-scrollbar { width: 6px; }
.history::-webkit-scrollbar-track { background: transparent; }
.history::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: 3px;
}

.history-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-mute);
  font-size: 0.88rem;
  text-align: center;
  padding: 20px;
  font-style: italic;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.history-row .slots {
  display: flex;
  gap: 6px;
}

.feedback {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.fb-text {
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  min-width: 54px;
  text-align: right;
}

.fb-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.fb-dots .dot {
  width: 12px;
  height: 12px;
}

.peg-row {
  display: flex;
  gap: 3px;
  padding: 5px;
  background: var(--bg-3);
  border-radius: 6px;
  flex-wrap: wrap;
  max-width: 80px;
}

.peg-row .peg-dot {
  width: 12px;
  height: 12px;
}

/* ========== 当前输入 ========== */
.current-input {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 10px 0 2px;
  border-top: 1px dashed var(--line);
}

/* ========== 槽位 ========== */
.slot {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-weight: 700;
  font-size: 1.4rem;
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
  border: 2px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  transition: all 0.2s ease;
}

.slot.empty {
  border-style: dashed;
  background: transparent;
  color: var(--text-mute);
  opacity: 0.5;
}

.slot.filled.digit {
  background: var(--bg-3);
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: inset 0 0 12px rgba(0, 229, 255, 0.15);
}

.slot.filled.peg {
  font-size: 1.1rem;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  border-color: rgba(255, 255, 255, 0.2);
}

.history-row .slot {
  width: 36px;
  height: 36px;
  font-size: 1.05rem;
  border-radius: 8px;
  border-width: 1.5px;
}

/* ========== 输入面板 ========== */
.keypad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 12px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.keypad.mode-mastermind {
  grid-template-columns: repeat(3, 1fr);
}

.digit-key {
  padding: 14px 0;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 10px;
  font-size: 1.4rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.digit-key:hover:not(:disabled) {
  background: var(--bg-3);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

.digit-key:active:not(:disabled) {
  transform: translateY(0) scale(0.96);
}

.digit-key.used {
  opacity: 0.25;
  cursor: not-allowed;
  color: var(--text-mute);
  background: var(--bg-2);
}

.color-key {
  padding: 12px 6px;
  border: 2px solid var(--line);
  background: var(--bg-2);
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 1.5rem;
  transition: all 0.15s ease;
  font-family: inherit;
  color: var(--text);
}

.color-key:hover {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, var(--bg-2));
  transform: translateY(-1px);
}

.color-key:active {
  transform: translateY(0) scale(0.96);
}

.color-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-weight: 500;
}

/* ========== 操作 ========== */
.controls {
  display: flex;
  gap: 8px;
}

.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.ctrl-btn .ico {
  font-size: 1.2rem;
}

.ctrl-btn.delete {
  flex: 1;
}

.ctrl-btn.delete:hover {
  border-color: var(--warn);
  color: var(--warn);
  background: rgba(255, 180, 84, 0.08);
}

.ctrl-btn.submit {
  flex: 2;
  background: linear-gradient(135deg, var(--primary-2), var(--accent));
  border-color: transparent;
  color: white;
}

.ctrl-btn.submit:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(106, 0, 255, 0.3);
}

.ctrl-btn.submit:disabled {
  background: var(--bg-3);
  color: var(--text-mute);
  cursor: not-allowed;
  border-color: var(--line);
  box-shadow: none;
  transform: none;
}

/* ========== 提示 ========== */
.hint {
  text-align: center;
  font-size: 0.74rem;
  color: var(--text-mute);
  padding: 4px 0 0;
  line-height: 1.7;
}

.hint kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
  font-size: 0.74rem;
  color: var(--text-dim);
  margin: 0 1px;
}

/* ========== 弹窗 ========== */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-mask.show {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 24px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  transform: scale(0.9);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-mask.show .modal {
  transform: scale(1);
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.modal-subtitle {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-bottom: 20px;
}

.answer-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg-0);
  border-radius: 12px;
  border: 1px solid var(--line);
}

.answer-row .slot {
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
}

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

.modal-btn {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.modal-btn:hover {
  background: var(--line);
}

.modal-btn.primary {
  background: linear-gradient(135deg, var(--primary-2), var(--accent));
  border-color: transparent;
  color: white;
  font-weight: 600;
}

.modal-btn.primary:hover {
  background: linear-gradient(135deg, var(--primary), var(--accent));
}

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 20px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.9rem;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
  max-width: 80vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  border-color: var(--error);
  color: var(--error);
}

/* ========== 移动端 ========== */
@media (max-width: 480px) {
  .slot {
    width: 42px;
    height: 42px;
    font-size: 1.2rem;
  }
  .history-row .slot {
    width: 30px;
    height: 30px;
    font-size: 0.92rem;
  }
  .answer-row .slot {
    width: 38px;
    height: 38px;
    font-size: 1.05rem;
  }
  .diff-meta {
    font-size: 0.62rem;
  }
  .tab-label {
    font-size: 0.85rem;
  }
  .stat-value {
    font-size: 1.15rem;
  }
  .keypad {
    gap: 6px;
    padding: 10px;
  }
  .digit-key {
    padding: 12px 0;
    font-size: 1.25rem;
  }
  .color-key {
    padding: 10px 4px;
    font-size: 1.3rem;
  }
  .feedback {
    gap: 6px;
  }
  .fb-text {
    font-size: 0.9rem;
    min-width: 46px;
  }
  .peg-row {
    max-width: 70px;
    padding: 4px;
  }
}

@media (max-width: 360px) {
  .tab-label {
    display: none;
  }
  .diff-btn {
    padding: 6px 2px;
  }
  .diff-meta {
    display: none;
  }
  .new-btn {
    padding: 0 10px;
    font-size: 0.8rem;
  }
  .answer-row .slot {
    width: 32px;
    height: 32px;
    font-size: 0.95rem;
  }
}
