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

:root {
  --bg-dark: #fff8f0;
  --bg-card: #fff0e0;
  --accent: #d4372c;
  --accent-glow: #e85040;
  --gold: #c8960c;
  --text: #4a2018;
  --text-dim: #8b6050;
  --connected: #d4372c;
  --connected-glow: rgba(212, 55, 44, 0.25);
  --cell-bg: #ffe8d0;
  --cell-border: #e0c0a0;
  --pipe-color: #c0a080;
  --pipe-connected: #d4372c;
  --source-color: #d4372c;
  --rocket-color: #c8960c;
  --lantern-red: #cc2222;
  --lantern-gold: #daa520;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-dark);
  color: var(--text);
  font-family: -apple-system, "Helvetica Neue", "PingFang SC", "STKaiti", "KaiTi", serif;
}

.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.active {
  display: flex;
}

/* ===== 开始界面 — 中国红金风 ===== */
#start-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(212, 55, 44, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 70%, rgba(200, 150, 12, 0.12) 0%, transparent 50%),
    linear-gradient(180deg, #fff5e8 0%, #ffe0c0 50%, #ffd0a0 100%);
}

/* 装饰灯笼 */
#start-screen::before,
#start-screen::after {
  content: '🏮';
  position: absolute;
  font-size: 2.5rem;
  top: 40px;
  animation: lantern-sway 3s ease-in-out infinite;
  filter: drop-shadow(0 4px 8px rgba(200, 50, 30, 0.3));
}
#start-screen::before { left: 30px; animation-delay: 0s; }
#start-screen::after { right: 30px; animation-delay: 1.5s; }

@keyframes lantern-sway {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}

.start-content {
  text-align: center;
}

.game-title {
  font-size: 2.8rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--lantern-red), var(--lantern-gold), var(--lantern-red));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.3rem;
  text-shadow: none;
  letter-spacing: 0.1em;
}

.game-subtitle {
  font-size: 1rem;
  color: var(--text-dim);
  margin-bottom: 2.5rem;
  letter-spacing: 0.2em;
}

.btn {
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: transform 0.1s, box-shadow 0.1s;
  color: #fff;
  background: #9b7060;
  padding: 0.7rem 1.5rem;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #b02820);
  box-shadow: 0 4px 15px rgba(212, 55, 44, 0.35);
  padding: 0.9rem 2.5rem;
  font-size: 1.2rem;
  border: 2px solid var(--lantern-gold);
}

.btn-small {
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
}

/* ===== 游戏界面 ===== */
#game-screen {
  flex-direction: column;
  background:
    radial-gradient(ellipse at center, rgba(255, 220, 180, 0.5) 0%, transparent 70%),
    linear-gradient(180deg, #fff5e8 0%, #ffe8d0 100%);
}

#top-bar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(90deg, var(--accent), #b02820);
  border-bottom: 2px solid var(--lantern-gold);
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  z-index: 10;
}

#timer {
  color: var(--lantern-gold);
  font-size: 1.1rem;
  text-shadow: 0 0 6px rgba(200, 150, 12, 0.5);
}

#top-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.top-toggle {
  border: 1px solid rgba(255, 240, 224, 0.45);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  padding: 5px 10px;
  white-space: nowrap;
}

.top-toggle.is-off {
  background: rgba(74, 32, 24, 0.24);
  color: rgba(255, 245, 235, 0.78);
  border-color: rgba(255, 240, 224, 0.22);
}

#game-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  overflow: hidden;
  touch-action: none;
}

.side-col {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  width: 32px;
  flex-shrink: 0;
}

.source-icon, .rocket-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  width: 28px;
  height: var(--cell-size, 40px);
  position: relative;
}

.source-icon {
  color: var(--source-color);
}

.source-icon.lit {
  color: #ff6600;
  animation: source-pulse 0.6s ease-out;
}

@keyframes source-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* 火源/火箭旁的颜色标记点 */
.source-color-dot {
  position: absolute;
  bottom: 2px;
  right: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid rgba(120, 60, 30, 0.3);
}

.rocket-icon {
  color: var(--rocket-color);
  opacity: 0.5;
}

.rocket-icon.lit {
  opacity: 1;
  animation: rocket-glow 0.5s ease-out;
}

.rocket-icon.special {
  filter: brightness(1.3);
}

@keyframes rocket-glow {
  0% { transform: scale(1); }
  50% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

/* ===== 棋盘 ===== */
#board {
  display: grid;
  gap: 2px;
  background: linear-gradient(135deg, #e8c8a0, #d4a878);
  border: 3px solid var(--lantern-gold);
  border-radius: 10px;
  padding: 3px;
  box-shadow:
    0 4px 16px rgba(150, 100, 50, 0.3),
    inset 0 0 20px rgba(255, 220, 180, 0.3);
}

.cell {
  width: var(--cell-size, 40px);
  height: var(--cell-size, 40px);
  background: var(--cell-bg);
  border-radius: 5px;
  position: relative;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateZ(0);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
  box-shadow:
    0 2px 4px rgba(150, 100, 50, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  -webkit-transform-style: flat;
  transform-style: flat;
  pointer-events: auto;
  border: 1px solid rgba(200, 160, 100, 0.4);
}

.cell:active {
  transform: scale(0.93);
  box-shadow: 0 1px 2px rgba(150, 100, 50, 0.2);
}

.cell.connected {
  transform: scale(1.02);
  box-shadow:
    0 3px 10px rgba(212, 55, 44, 0.25),
    0 0 6px var(--connected-glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* 旋转动画 */
.cell.rotating {
  animation: cell-rotate-3d 0.18s ease-out;
}

@keyframes cell-rotate-3d {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* 管道SVG */
.cell svg {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  transition: transform 0.15s ease-out;
  overflow: visible;
}

.cell .pipe-line {
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  transition: stroke 0.2s ease, filter 0.2s ease;
}

.cell .pipe-depth {
  stroke: #9e7d5b;
  stroke-width: 11;
  opacity: 0.92;
}

.cell .pipe-core {
  stroke: var(--pipe-color);
  stroke-width: 8;
}

.cell .pipe-highlight {
  stroke: rgba(255, 248, 238, 0.72);
  stroke-width: 3;
  opacity: 0.95;
}

.cell .pipe-dot {
  filter: drop-shadow(0 1px 2px rgba(88, 48, 16, 0.18));
}

/* 立交桥方块 */
.cell.bridge-cell {
  background: #fce0c0;
}

.cell.bridge-cell.connected {
  background: rgba(212, 55, 44, 0.08);
}

#bottom-bar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 10px 16px;
  background: linear-gradient(90deg, var(--accent), #b02820);
  border-top: 2px solid var(--lantern-gold);
  flex-shrink: 0;
}

/* ===== 结算界面 ===== */
#result-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 245, 232, 0.96);
  z-index: 100;
}

.result-content {
  text-align: center;
  padding: 2rem;
  background: linear-gradient(135deg, #fff5e8, #ffe8d0);
  border-radius: 16px;
  border: 3px solid var(--lantern-gold);
  max-width: 340px;
  width: 85%;
  box-shadow:
    0 8px 32px rgba(150, 100, 50, 0.3),
    0 0 0 1px rgba(212, 55, 44, 0.2);
}

.result-content h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.result-content .pass {
  color: var(--lantern-red);
  text-shadow: 0 0 12px rgba(212, 55, 44, 0.3);
}

.result-content .fail {
  color: var(--text-dim);
}

#result-details {
  text-align: left;
  font-size: 0.85rem;
  line-height: 1.8;
  color: var(--text-dim);
  margin-bottom: 1.5rem;
  white-space: pre-line;
}

#result-details .total-line {
  color: var(--text);
  font-weight: 700;
  font-size: 1rem;
  border-top: 2px solid var(--lantern-gold);
  padding-top: 0.5rem;
  margin-top: 0.5rem;
}

#result-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ===== 烟花粒子 ===== */
.firework-particle {
  position: fixed;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 200;
}

@keyframes particle-fly {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  60% { opacity: 0.8; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.1); }
}

/* ===== 火焰传播 ===== */
.cell.fire-trail {
  animation: fire-pulse 0.4s ease-out;
}

@keyframes fire-pulse {
  0% { background: rgba(255, 100, 0, 0.4); transform: scale(1.05); }
  100% { background: var(--cell-bg); transform: scale(1); }
}

/* ===== 装饰元素 ===== */
#game-screen::before {
  content: '🏮';
  position: absolute;
  top: 50px;
  left: 4px;
  font-size: 1.2rem;
  opacity: 0.3;
  animation: lantern-sway 4s ease-in-out infinite;
  z-index: 0;
  pointer-events: none;
}

#game-screen::after {
  content: '🏮';
  position: absolute;
  top: 50px;
  right: 4px;
  font-size: 1.2rem;
  opacity: 0.3;
  animation: lantern-sway 4s ease-in-out infinite 2s;
  z-index: 0;
  pointer-events: none;
}
