/* 接水管 Pipe · 独立样式（选择器统一前缀 .g-pipe） */

.g-pipe {
  justify-content: flex-start;
}

/* ---------------- 顶部尺寸 ---------------- */

.g-pipe .pipe-head {
  align-items: center;
  min-height: 44px;
}

.g-pipe .pipe-head .grow { width: 100%; }
.g-pipe .pipe-head .seg { width: 100%; padding: 4px; }
.g-pipe .pipe-head .seg-item { min-height: 38px; font-size: 12px; }

/* ---------------- 数据 ---------------- */

.g-pipe .stats { gap: 8px; }
.g-pipe .stat { padding: 8px 6px; }
.g-pipe .stat-v { font-size: 16.5px; }

/* ---------------- 棋盘 ---------------- */

.g-pipe .pipe-boardwrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.g-pipe .pipe-board {
  position: relative;
  width: min(100%, clamp(224px, calc(100dvh - 372px), 460px));
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(var(--n, 6), minmax(0, 1fr));
  grid-template-rows: repeat(var(--n, 6), minmax(0, 1fr));
  border-radius: 18px;
  overflow: hidden;
  background:
    radial-gradient(120% 120% at 100% 0%, rgba(95, 224, 200, 0.09), transparent 58%),
    linear-gradient(160deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.018));
  border: 1px solid var(--line-2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 22px 54px -32px rgba(0, 0, 0, 0.95);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.g-pipe .pipe-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.g-pipe .pipe-cell::before {
  content: "";
  position: absolute;
  inset: 2px;
  z-index: 0;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.028);
  transition: background 0.16s ease, box-shadow 0.16s ease;
}

.g-pipe .pipe-cell:nth-child(even)::before {
  background: rgba(255, 255, 255, 0.045);
}

.g-pipe .pipe-cell:active::before { background: rgba(95, 224, 200, 0.14); }

.g-pipe .pipe-rot {
  position: absolute;
  inset: 0;
  z-index: 1;
  transition: transform 0.15s cubic-bezier(0.3, 0.9, 0.4, 1);
  will-change: transform;
}

.g-pipe .pipe-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.g-pipe .pipe-path {
  fill: none;
  stroke: #5a7089;
  stroke-width: 26;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 0.18s ease, filter 0.18s ease;
}

/* 通水 */
.g-pipe .pipe-cell.on .pipe-path {
  stroke: #5fe0c8;
  filter: drop-shadow(0 0 3px rgba(95, 224, 200, 0.85));
}

/* 漏水：只给格子描红边，管子保持灰蓝，避免整盘发红 */
.g-pipe .pipe-cell.leak::before {
  background: rgba(255, 92, 108, 0.06);
  box-shadow: inset 0 0 0 2px rgba(255, 92, 108, 0.6);
  animation: pipeLeak 1.2s ease-in-out infinite;
}

@keyframes pipeLeak {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(255, 92, 108, 0.6); }
  50% { box-shadow: inset 0 0 0 2.5px rgba(255, 92, 108, 0.95); }
}

/* 固定格（水源 / 出水口） */
.g-pipe .pipe-cell.fixed::before {
  background: rgba(95, 224, 200, 0.07);
  box-shadow: inset 0 0 0 1.5px rgba(95, 224, 200, 0.28);
}
.g-pipe .pipe-cell.is-outlet::before {
  background: rgba(255, 209, 102, 0.07);
  box-shadow: inset 0 0 0 1.5px rgba(255, 209, 102, 0.28);
}

/* 提示高亮 */
.g-pipe .pipe-cell.hint::after {
  content: "";
  position: absolute;
  inset: 1px;
  z-index: 3;
  border-radius: 8px;
  border: 2px solid var(--accent);
  box-shadow: 0 0 14px var(--accent);
  animation: pipeHint 0.6s ease;
  pointer-events: none;
}

@keyframes pipeHint {
  0% { opacity: 0; transform: scale(0.92); }
  60% { opacity: 1; transform: scale(1.03); }
  100% { opacity: 1; transform: scale(1); }
}

/* 固定格点按反馈（红闪，不打断旋转 transform） */
.g-pipe .pipe-cell.shake::before { animation: pipeNope 0.26s ease; }

@keyframes pipeNope {
  0%, 100% { background: rgba(255, 255, 255, 0.028); }
  45% { background: rgba(255, 92, 108, 0.32); }
}

/* ---------------- 水源 / 出水口徽标 ---------------- */

.g-pipe .pipe-badge {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.g-pipe .pipe-arrow-poly {
  fill: var(--accent);
  opacity: 0.92;
}

.g-pipe .pipe-cell.is-outlet .pipe-arrow-poly { fill: #ffd166; }

.g-pipe .pipe-badge-bg {
  fill: rgba(7, 11, 17, 0.86);
  stroke: var(--accent);
  stroke-width: 2.5;
}

.g-pipe .pipe-cell.is-outlet .pipe-badge-bg { stroke: #ffd166; }

.g-pipe .pipe-badge-ico { fill: var(--accent); }

.g-pipe .pipe-badge-ico-ring {
  fill: none;
  stroke: #ffd166;
  stroke-width: 4.5;
  stroke-linecap: round;
}

.g-pipe .pipe-badge-ico-dot { fill: #ffd166; }

.g-pipe .pipe-cell.on .pipe-badge-bg {
  stroke: #83ffe9;
  filter: drop-shadow(0 0 6px rgba(95, 224, 200, 0.8));
}

/* ---------------- 操作行 ---------------- */

.g-pipe .pipe-toolbar .btn { min-height: 44px; }

/* ---------------- 底部信息 ---------------- */

.g-pipe .pipe-meta { padding: 10px 12px 11px; }
.g-pipe .pipe-meta-head { align-items: baseline; gap: 8px; }
.g-pipe .pipe-meta-head .hint:first-child {
  color: var(--dim);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.g-pipe .pipe-meta-head .hint:first-child.ok { color: var(--accent); }
.g-pipe .pipe-meta-head .hint:last-child { flex: none; font-variant-numeric: tabular-nums; }
.g-pipe .pipe-meta-head .pipe-leak.bad { color: #ff8b96; }
.g-pipe .pipe-meta .progress { height: 5px; margin-top: 6px; }
.g-pipe .pipe-tip {
  margin-top: 7px;
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--faint);
}

/* ---------------- 结算覆盖层 ---------------- */

.g-pipe .pipe-over {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 11, 18, 0.85);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s;
}

.g-pipe .pipe-over.show { opacity: 1; visibility: visible; }

.g-pipe .pipe-over-card {
  width: 100%;
  max-width: 254px;
  text-align: center;
}

.g-pipe .pipe-over-title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: 0.01em;
}

.g-pipe .pipe-over-sub {
  margin-top: 5px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--dim);
}

.g-pipe .pipe-over-stats {
  display: flex;
  gap: 8px;
  margin: 13px 0;
}

.g-pipe .pipe-ostat {
  flex: 1;
  min-width: 0;
  padding: 7px 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
}

.g-pipe .pipe-ostat span {
  display: block;
  font-size: 10px;
  color: var(--faint);
  margin-bottom: 2px;
}

.g-pipe .pipe-ostat b {
  display: block;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.g-pipe .pipe-over .btn { min-height: 44px; }
.g-pipe .pipe-over-row2 { margin-top: 8px; }
.g-pipe .pipe-over-row2 .btn { min-height: 38px; font-size: 12.5px; }

/* ---------------- 窄屏 / 动效偏好 ---------------- */

@media (max-width: 359px) {
  .g-pipe .pipe-head .seg-item { font-size: 11px; }
  .g-pipe .stat-v { font-size: 15.5px; }
  .g-pipe .pipe-tip { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .g-pipe .pipe-rot { transition: none; }
  .g-pipe .pipe-cell.leak::before { animation: none; }
  .g-pipe .pipe-cell.hint::after { animation: none; }
  .g-pipe .pipe-cell.shake::before { animation: none; background: rgba(255, 92, 108, 0.25); }
}
