:root {
  --bg-top: #e0f2fe;
  --bg-bottom: #f8fafc;
  --card-bg: #ffffff;
  --primary: #3b82f6;
  --primary-light: #dbeafe;
  --primary-dark: #1d4ed8;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --text-main: #1e293b;
  --text-sub: #64748b;
  --line: #cbd5e1;
  --tile-size: min(9vw, 46px);
  --cell-gap: 2px;
}

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

body {
  margin: 0;
  padding: 14px 12px 22px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.app-container {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- 顶部栏 ---------- */
.header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: var(--card-bg);
  padding: 10px 14px;
  border-radius: 18px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
}

.level-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 15px;
  color: var(--primary-dark);
}

.level-select {
  border: 2px solid var(--primary-light);
  background: #f8fafc;
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 10px;
  outline: none;
  cursor: pointer;
}

.tool-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.btn-tool {
  border: none;
  border-radius: 12px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.1s, opacity 0.2s;
}

.btn-tool:active {
  transform: scale(0.95);
}

.btn-tool:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-hint {
  background: #fef3c7;
  color: #b45309;
  border: 1.5px solid #fde68a;
}

.btn-reset {
  background: #f1f5f9;
  color: #475569;
}

.btn-account {
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* ---------- 局面信息卡 ---------- */
.info-card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.08);
  border: 2px solid var(--primary-light);
}

.info-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.info-emoji {
  font-size: 36px;
  line-height: 1;
  background: #f8fafc;
  width: 56px;
  height: 56px;
  flex: 0 0 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  border: 1px solid #e2e8f0;
}

.info-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.info-tag {
  align-self: flex-start;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: 999px;
}

.info-main {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-main);
}

.info-sub {
  font-size: 12px;
  color: var(--text-sub);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-pause {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: white;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
  transition: transform 0.1s;
}

.btn-pause:active {
  transform: scale(0.92);
}

/* ---------- 状态栏 ---------- */
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 0 2px;
}

.stat-pill {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  background: rgba(255, 255, 255, 0.8);
  border-radius: 999px;
  padding: 5px 9px;
  white-space: nowrap;
}

.stat-pill b {
  color: var(--text-main);
  font-size: 13px;
}

.note-toggle {
  border: 1.5px solid var(--line);
  background: #f8fafc;
  color: var(--text-sub);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.note-toggle.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}

/* ---------- 棋盘 ---------- */
.board-wrapper {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 12px 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.05);
  overflow-x: auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(9, var(--tile-size));
  gap: var(--cell-gap);
  padding: 2px;
}

.cell {
  width: var(--tile-size);
  height: var(--tile-size);
  border: 1px solid #dbe3ef;
  border-radius: 7px;
  background: #ffffff;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--tile-size) * 0.52);
  font-weight: 900;
  color: var(--primary-dark);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.12s;
}

.cell.box-right {
  border-right: 3px solid #94a3b8;
}

.cell.box-bottom {
  border-bottom: 3px solid #94a3b8;
}

.cell.given {
  color: var(--text-main);
  background: #f8fafc;
}

.cell.peer {
  background: #eff6ff;
}

.cell.same {
  background: #e0f2fe;
}

.cell.selected {
  background: var(--primary-light);
  border-color: var(--primary);
  transform: translateY(-1px);
  z-index: 2;
  box-shadow: 0 3px 0 #93c5fd;
}

.cell.wrong {
  background: var(--danger-light);
  border-color: #f87171;
  color: #b91c1c;
}

.cell.hinted {
  animation: popIn 0.35s ease;
}

.cell.unit-done:not(.selected):not(.wrong) {
  background: var(--success-light);
  border-color: #6ee7b7;
  color: #065f46;
}

@keyframes popIn {
  0% { transform: scale(0.7); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 2px;
  line-height: 1;
}

.notes span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--tile-size) * 0.22);
  font-weight: 700;
  color: #94a3b8;
  opacity: 0;
}

.notes span.on {
  opacity: 1;
  color: #475569;
}

/* ---------- 数字键盘 ---------- */
.keyboard-card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 14px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.05);
}

.keyboard-tip {
  text-align: center;
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 10px;
  font-weight: 600;
}

.number-bank {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
}

.key-btn {
  width: 46px;
  height: 48px;
  border-radius: 12px;
  border: 2px solid #e2e8f0;
  background: #f8fafc;
  font-size: 21px;
  font-weight: 800;
  color: var(--text-main);
  cursor: pointer;
  box-shadow: 0 3px 0 #cbd5e1;
  transition: transform 0.1s, background 0.1s;
}

.key-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #cbd5e1;
  background: var(--primary-light);
}

.key-btn.done {
  color: #94a3b8;
  background: #f1f5f9;
}

.key-erase {
  width: auto;
  padding: 0 13px;
  background: #fee2e2;
  border-color: #fecaca;
  color: #b91c1c;
  font-size: 14px;
  box-shadow: 0 3px 0 #fca5a5;
}

/* ---------- 弹窗 ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.show {
  display: flex;
}

.modal-box {
  background: white;
  border-radius: 26px;
  padding: 26px 22px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  animation: popIn 0.3s ease;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal-stars {
  font-size: 44px;
  margin-bottom: 8px;
}

.modal-title {
  font-size: 22px;
  font-weight: 900;
  color: var(--text-main);
  margin: 0 0 8px;
}

.modal-desc {
  font-size: 14px;
  color: var(--text-sub);
  margin: 0 0 18px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-next {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 15px;
  background: var(--success);
  color: white;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 #059669;
}

.btn-secondary {
  width: 100%;
  padding: 11px;
  border: 2px solid var(--line);
  border-radius: 15px;
  background: #f8fafc;
  color: var(--text-sub);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

/* ---------- 轻提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(12px);
  background: rgba(15, 23, 42, 0.88);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}

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

@media (max-width: 400px) {
  :root {
    --tile-size: min(8.6vw, 40px);
    --cell-gap: 2px;
  }
  .key-btn {
    width: 42px;
    height: 44px;
    font-size: 19px;
  }
  .info-emoji {
    width: 48px;
    height: 48px;
    flex-basis: 48px;
    font-size: 30px;
  }
  .info-main {
    font-size: 14px;
  }
}
