/* Pipes 3D tokens: dark mode only changes these values. */
:root {
  --g-pipes3d: #3b6fd1;
  --p3-cell: #ffffff;
  --p3-grid: rgb(196 196 190 / 0.6);
  --p3-edge: #d9d9d4;
  --p3-pipe: #8a96a3;
  --p3-water: #2f86de;
  --p3-source: #1b5fae;
  --p3-wire: #c9cbc6;
  --p3-select: #e08a1e;
  --p3-hint: var(--hint-target);
  --p3-context: var(--hint-context);
  --p3-axis-x: #d9534f;
  --p3-axis-y: #3fa65a;
  --p3-axis-z: #3d7fe0;
  --p3-locked: #eeeeea;
}
:root[data-theme='dark'] {
  --g-pipes3d: #6b97ea;
  --p3-cell: #1a1a1a;
  --p3-grid: rgb(86 86 86 / 0.6);
  --p3-edge: #3a3a3a;
  --p3-pipe: #6f7a86;
  --p3-water: #3d95ec;
  --p3-source: #8cc4ff;
  --p3-wire: #3a3d42;
  --p3-select: #f0a540;
  --p3-axis-x: #ef7672;
  --p3-axis-y: #5cc276;
  --p3-axis-z: #6fa2f0;
  --p3-locked: #2a2a2a;
}

.pipes3d-shell {
  --game-accent: var(--g-pipes3d);
}
.pipes3d-shell .shell-stage {
  gap: var(--space-2);
  padding: 0 var(--space-4);
}
.pipes3d-shell .shell-board-area {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}
.p3-board-wrap {
  width: min(520px, calc(100vw - 32px), calc(100dvh - 300px));
  max-width: 100%;
  margin: 0 auto;
}
/* Tutorial lesson above the board (pipes3d.js lessonView). */
.p3-lesson {
  display: flex;
  width: min(520px, 100%);
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-left: 4px solid var(--game-accent);
  border-radius: var(--radius-m);
  background: var(--surface);
}
.p3-lesson > div {
  min-width: 0;
  flex: 1;
}
.p3-lesson strong {
  font-size: 15px;
}
.p3-lesson p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}
.p3-lesson .p3-control {
  flex: none;
  min-height: 36px;
  font-size: 14px;
}
.p3-board-wrap.with-lesson {
  width: min(520px, calc(100vw - 32px), calc(100dvh - 430px));
}
.p3-board-wrap.voxel.with-lesson {
  width: min(520px, calc(100vw - 32px), calc(100dvh - 520px));
}
/* Voxel boards share the screen with the turn buttons below them. */
.p3-board-wrap.voxel {
  width: min(520px, calc(100vw - 32px), calc(100dvh - 400px));
}
.p3-host {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
}
.p3-status {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.p3-status b {
  color: var(--text);
}
.p3-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
}
.p3-control {
  min-height: 44px;
  padding: 0 var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font: 600 15px var(--font-app);
  cursor: pointer;
}
.p3-control:disabled {
  opacity: 0.45;
  cursor: default;
}
.p3-segments {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--line);
}
.p3-segment {
  min-height: 38px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font: 600 14px var(--font-app);
  cursor: pointer;
}
.p3-segment.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.12);
}
.p3-help {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}
/* Yaw, pitch and roll buttons below a voxel board. */
.p3-turns {
  display: grid;
  width: min(100%, 420px);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}
.p3-turn-group {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.p3-turn-label {
  color: var(--text-muted);
  font-size: 12px;
}
.p3-turn-buttons {
  display: flex;
  gap: 6px;
}
.p3-turn {
  display: grid;
  width: 48px;
  height: 44px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.p3-turn:disabled {
  opacity: 0.4;
  cursor: default;
}
.p3-turn:focus-visible {
  outline: 2px solid var(--game-accent);
  outline-offset: 2px;
}
.p3-turn svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.p3-turn svg .axis {
  stroke-dasharray: 2 2.5;
  opacity: 0.5;
}
.p3-turn svg .dot {
  fill: currentColor;
}
.p3-turn svg path:last-child {
  stroke: var(--game-accent);
  stroke-width: 2.4;
}

/* The board: drags rotate it, so the page must not scroll or zoom underneath. */
.p3-stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.p3-cube-stage {
  perspective: 1100px;
}
.p3-cube {
  --p3-cube: 200px;
  position: relative;
  width: var(--p3-cube);
  aspect-ratio: 1;
  transform-style: preserve-3d;
}
.p3-face {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  background-color: var(--p3-cell);
  background-image:
    linear-gradient(to right, var(--p3-grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--p3-grid) 1px, transparent 1px);
  background-size: calc(100% / var(--n)) calc(100% / var(--n));
  background-position: -0.5px -0.5px;
  outline: 1px solid var(--p3-edge);
  backface-visibility: hidden;
}
.p3-face::after {
  /* Shade from the light in pipes3d-view.js, so the cube reads as a solid. */
  content: '';
  position: absolute;
  inset: 0;
  background: #000;
  opacity: var(--shade, 0);
  pointer-events: none;
}
.p3-face::before {
  content: attr(data-face);
  position: absolute;
  top: 2px;
  left: 5px;
  z-index: 1;
  color: var(--text-muted);
  font-size: 11px;
  pointer-events: none;
}
.p3-face.is-away {
  pointer-events: none;
}
.p3-cell {
  position: relative;
  display: block;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.p3-cell:focus-visible {
  outline: 3px solid var(--game-accent);
  outline-offset: -3px;
}
.p3-cell svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.p3-pipe {
  transition: transform 160ms ease-out;
  stroke: var(--p3-pipe);
  stroke-width: 22;
  fill: var(--p3-pipe);
}
.p3-pipe.no-transition {
  transition: none;
}
.p3-cell.is-wet .p3-pipe {
  stroke: var(--p3-water);
  fill: var(--p3-water);
}
.p3-pipe .p3-terminal {
  stroke-width: 0;
}
.p3-pipe .p3-source {
  fill: var(--p3-source);
  stroke: var(--p3-cell);
  stroke-width: 6;
}
.p3-cell.is-locked {
  background: var(--p3-locked);
}
.p3-cube-stage.has-locks .p3-cell:not(.is-locked) {
  box-shadow: inset 0 0 0 3px var(--game-accent);
}
.p3-cell.hint-target {
  box-shadow: inset 0 0 0 4px var(--p3-hint);
}
.p3-cell.hint-context {
  box-shadow: inset 0 0 0 3px var(--p3-context);
}
.p3-cube-stage.is-solved .p3-face {
  outline-color: var(--success);
}
.p3-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.p3-voxel-stage.is-holding {
  cursor: move;
}
/* While a piece is selected, drags turn the piece instead of the view. */
.p3-voxel-stage.is-holding::after {
  content: '視角已鎖定 · 點空白處取消';
  position: absolute;
  top: 6px;
  left: 50%;
  padding: 4px 10px;
  border: 1px solid var(--p3-select);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  pointer-events: none;
  transform: translateX(-50%);
  white-space: nowrap;
}
.p3-voxel-stage.is-solved .p3-canvas {
  border-radius: 12px;
  box-shadow: inset 0 0 0 2px var(--success);
}

/* Picture rules: the real cube faces at a fixed view (a turn or a view change animates while its frame shows), and
   the voxel block as a projected SVG of the WebGL geometry. */
.pipes3d-shell .p3-demo {
  position: relative;
  width: 100%;
  height: 100%;
  container-type: size;
}
.p3-demo .p3-stage {
  cursor: default;
  touch-action: auto;
}
.p3-demo .p3-cube {
  --p3-cube: 58cqmin;
  transform: var(--home) rotateY(var(--yaw));
}
.p3-demo .p3-cell {
  cursor: default;
}
.shell-demo-frame.on .p3-demo-spin {
  animation: p3-demo-spin 900ms ease-in-out both;
}
@keyframes p3-demo-spin {
  from {
    transform: var(--home) rotateY(var(--yaw-from));
  }
}
.shell-demo-frame.on .p3-demo-spin .p3-face::after {
  animation: p3-demo-shade 900ms ease-in-out both;
}
@keyframes p3-demo-shade {
  from {
    opacity: var(--shade-from);
  }
}
.shell-demo-frame.on .p3-demo-turn {
  animation: p3-demo-turn 320ms ease-out both;
}
@keyframes p3-demo-turn {
  from {
    transform: rotate(-90deg);
  }
}
.p3v {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.p3v line {
  stroke-linecap: round;
}
.p3v-wire {
  stroke: var(--p3-wire);
}
.p3v-wire.selected {
  stroke: var(--p3-select);
}
.p3v-rod.dry {
  stroke: var(--p3-pipe);
}
.p3v-rod.wet {
  stroke: var(--p3-water);
}
.p3v-rod.source {
  stroke: var(--p3-source);
}
.p3v-ball.dry {
  fill: var(--p3-pipe);
}
.p3v-ball.wet {
  fill: var(--p3-water);
}
.p3v-ball.source {
  fill: var(--p3-source);
}

@media (prefers-reduced-motion: reduce) {
  .shell-demo-frame.on .p3-demo-spin,
  .shell-demo-frame.on .p3-demo-spin .p3-face::after,
  .shell-demo-frame.on .p3-demo-turn {
    animation: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .p3-pipe {
    transition: none;
  }
}
