/* 点灯大作战 —— 深色主题样式 */
:root {
  --bg: #0b1220;
  --bg-soft: #101a2e;
  --card: #16223a;
  --card-hi: #1d2c4a;
  --line: rgba(148, 163, 184, 0.14);
  --text: #e2e8f0;
  --muted: #8ea0bd;
  --accent: #fbbf24;
  --accent-2: #60a5fa;
  --danger: #f87171;
  --ok: #34d399;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;
  background: radial-gradient(1200px 600px at 70% -10%, #1b2a4d 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

main {
  max-width: 620px;
  margin: 0 auto;
  padding: 16px 14px calc(24px + env(safe-area-inset-bottom));
}

.screen {
  display: none;
  flex-direction: column;
  gap: 14px;
  animation: fadein 0.18s ease;
}

.screen.active {
  display: flex;
}

@keyframes fadein {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- 首页 ---------- */

.home-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 2px;
  background: linear-gradient(100deg, #fde047, #fb923c 55%, #f472b6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.head-btns {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--card-hi);
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}

.chip b {
  color: var(--text);
  margin-left: 4px;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(160deg, var(--card), var(--bg-soft));
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: transform 0.15s, border-color 0.15s;
}

.mode-card:hover {
  transform: translateY(-2px);
  border-color: rgba(251, 191, 36, 0.5);
}

.mode-icon {
  font-size: 26px;
}

.mode-name {
  font-size: 16px;
  font-weight: 700;
}

.mode-sub {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* ---------- 子页面 ---------- */

.sub-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.sub-head h2 {
  margin: 0;
  font-size: 20px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel h4 {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.panel p {
  margin: 0;
  line-height: 1.7;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.center {
  text-align: center;
}

.row-btns {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.btn {
  padding: 10px 22px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card-hi);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  transition: filter 0.15s;
}

.btn:hover {
  filter: brightness(1.15);
}

.btn.primary {
  background: linear-gradient(120deg, #f59e0b, #fbbf24);
  border-color: transparent;
  color: #1c1917;
  font-weight: 700;
}

.seg-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.seg {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 13.5px;
  cursor: pointer;
  transition: all 0.15s;
}

.seg.on {
  background: rgba(96, 165, 250, 0.18);
  border-color: var(--accent-2);
  color: var(--text);
  font-weight: 600;
}

/* ---------- 关卡列表 ---------- */

.level-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.level-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, transform 0.15s;
}

.level-card:hover {
  border-color: rgba(251, 191, 36, 0.5);
  transform: translateX(3px);
}

.level-card.locked {
  opacity: 0.45;
  cursor: default;
}

.level-card.locked:hover {
  border-color: var(--line);
  transform: none;
}

.level-no {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 800;
  color: var(--accent);
  flex-shrink: 0;
}

.level-name {
  font-weight: 700;
  font-size: 15px;
}

.level-meta {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 3px;
}

.level-best {
  font-size: 12px;
  color: var(--accent-2);
  margin-top: 2px;
}

.daily-done {
  font-size: 18px;
  font-weight: 700;
  color: var(--ok);
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--card-hi);
  margin: 0 3px;
  vertical-align: middle;
}

.dot.on {
  background: var(--ok);
  box-shadow: 0 0 6px rgba(52, 211, 153, 0.6);
}

/* ---------- 对局 ---------- */

.hud {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hud-mid {
  flex: 1;
  min-width: 120px;
}

#hud-title {
  font-size: 14px;
  font-weight: 700;
}

#hud-progress {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

#hud-hearts {
  display: flex;
  gap: 3px;
  font-size: 18px;
}

.heart {
  transition: filter 0.3s, transform 0.3s;
}

.heart.lost {
  filter: grayscale(1) brightness(0.45);
  transform: scale(0.85);
}

#hud-timer {
  font-variant-numeric: tabular-nums;
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  min-width: 52px;
  text-align: center;
}

.hud-btn {
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}

.hud-btn span {
  font-size: 12px;
  color: var(--muted);
  margin-left: 3px;
}

.hud-btn.brush-on {
  background: rgba(96, 165, 250, 0.22);
  border-color: var(--accent-2);
}

.hud-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 2px;
}

.switch {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: var(--card-hi);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: all 0.2s;
}

.switch.on {
  background: rgba(96, 165, 250, 0.35);
  border-color: var(--accent-2);
}

.switch.on::after {
  left: 22px;
  background: var(--accent-2);
}

.attack-bar {
  display: flex;
  gap: 18px;
  justify-content: center;
  padding: 8px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 13.5px;
  color: var(--muted);
}

.attack-bar b {
  color: var(--accent);
  font-size: 16px;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--n, 6), 1fr);
  grid-template-rows: repeat(var(--n, 6), 1fr); /* 显式行轨道：行高恒定，内容不再撑动格子 */
  width: min(92vw, 460px, calc(100dvh - 250px));
  aspect-ratio: 1;
  margin: 4px auto;
  border-radius: 8px;
  overflow: hidden;
  touch-action: manipulation;
}

.board.brushing {
  touch-action: none; /* 刷选滑动不触发页面滚动 */
  cursor: crosshair;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0; /* grid 轨道内不被内容撑开 */
  cursor: pointer;
}

/* 灯泡/✕ 全部绝对定位，彻底脱离布局流，保证格子尺寸稳定 */
.cell.lit::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 56%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffbeb 0%, #fde047 45%, #f59e0b 100%);
  box-shadow: 0 0 14px 4px rgba(253, 224, 71, 0.5), 0 0 3px 1px rgba(255, 255, 255, 0.4) inset;
  animation: pop 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop {
  from {
    transform: scale(0.3);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.cell.note::after,
.cell.wrong::after {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(12px, 4.5vw, 22px);
  font-weight: 800;
  pointer-events: none;
}

.cell.note::after {
  content: '✕';
  color: rgba(226, 232, 240, 0.45);
}

.cell.wrong {
  background: rgba(239, 68, 68, 0.32) !important;
}

.cell.wrong::after {
  content: '✕';
  color: #fecaca;
  animation: pop 0.2s ease;
}

.cell:not(.lit):not(.wrong):not(.note):hover {
  filter: brightness(1.35);
}

.board.shake {
  animation: shake 0.35s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

.tip-line {
  font-size: 12px;
}

/* ---------- 成长档案 ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat b {
  font-size: 20px;
  color: var(--accent);
}

.stat span {
  font-size: 12px;
  color: var(--muted);
}

#screen-stats h4 {
  margin: 10px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
}

.stats-table th,
.stats-table td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.stats-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  background: var(--bg-soft);
}

/* ---------- 弹窗 / 提示 ---------- */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(4, 9, 20, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.18s;
  z-index: 50;
}

.modal-mask.show {
  opacity: 1;
}

.modal {
  width: min(92vw, 400px);
  background: linear-gradient(165deg, var(--card-hi), var(--card));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  transform: translateY(12px) scale(0.97);
  transition: transform 0.18s;
}

.modal-mask.show .modal {
  transform: none;
}

.modal h3 {
  margin: 0 0 10px;
  font-size: 19px;
}

.modal-body {
  font-size: 14.5px;
  line-height: 1.8;
  color: var(--text);
}

.modal-body b {
  color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
  justify-content: flex-end;
}

.rules {
  margin: 0;
  padding-left: 18px;
}

.rules li {
  margin-bottom: 8px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%) translateY(16px);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  z-index: 60;
  white-space: pre-wrap;
  max-width: 86vw;
  text-align: center;
}

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

.hidden {
  display: none !important;
}

@media (max-width: 400px) {
  h1 {
    font-size: 25px;
  }
  .mode-grid {
    grid-template-columns: 1fr;
  }
  .board {
    width: min(94vw, calc(100dvh - 250px));
  }
}
