/* Example gallery */
.demo-gallery { display: grid; grid-template-columns: minmax(0, 2.1fr) minmax(0, 1fr); gap: 20px; align-items: stretch; }
.gallery-figure { display: flex; flex-direction: column; min-width: 0; margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.image-frame { position: relative; display: block; overflow: hidden; text-decoration: none; }
.schematic-figure .image-frame { background: #f5f4ef; }
.pcb-figure .image-frame { flex: 1 1 auto; min-height: 240px; background: #000; }
.pcb-figure .image-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.style-figure { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); margin-top: 24px; }
.style-figure .image-frame { background: #f5f4ef; align-self: center; }
.style-figure .image-frame img { display: block; width: 100%; height: auto; }
.style-figure figcaption { align-content: center; align-items: flex-start; padding: 28px; border-top: 0; border-left: 1px solid var(--line); }
.style-figure .fig-title { flex-basis: 100%; margin-top: 12px; font-size: 21px; line-height: 1.4; }
.style-figure .fig-desc { margin-top: 8px; font-size: 16px; }
.style-figure .text-link { order: 4; margin: 16px 0 0; }

/* Crop the schematic preview to the drawn area (source px: x 88, y 68, w 920, h 450 of 1800×1100). */
.crop-frame { display: block; position: relative; aspect-ratio: 920 / 450; overflow: hidden; background: #f5f4ef; }
.crop-frame img { position: absolute; max-width: none; width: 195.652%; height: auto; left: -9.565%; top: -15.111%; }

.zoomable { cursor: zoom-in; }
.zoomable:focus-visible { outline-offset: -4px; }
.hero .preview-schematic:focus-visible { outline-color: var(--teal); }
.hero .preview-schematic:focus-visible::after,
.schematic-figure .zoomable:focus-visible::after,
.pcb-figure .zoomable:focus-visible::after {
  content: ""; position: absolute; inset: 1px; z-index: 1;
  border: 3px solid var(--teal); pointer-events: none;
}
.pcb-figure .zoomable:focus-visible::after { border-color: var(--lime); }
.zoom-chip {
  position: absolute; right: 12px; bottom: 12px;
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  background: rgba(16, 33, 35, .88); color: #fff; border-radius: 999px;
  font-size: 14px; font-weight: 650; line-height: 1.2;
  transition: background .15s;
}
.zoomable:hover .zoom-chip, .zoomable:focus-visible .zoom-chip { background: var(--teal); }
.zoom-hint {
  position: absolute; right: 8px; bottom: 8px; width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(16, 33, 35, .82); color: #fff; border-radius: 6px; font-size: 16px;
}

.gallery-figure figcaption { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; padding: 14px 18px 16px; border-top: 1px solid var(--line); }
.fig-title { font-size: 15px; font-weight: 750; color: var(--ink); }
.fig-desc { flex: 1 1 100%; order: 3; font-size: 16px; line-height: 1.6; color: var(--soft); }
.text-link {
  margin-left: auto; display: inline-flex; align-items: center; gap: 4px; min-height: 44px; margin-block: -12px -8px;
  font-size: 14px; font-weight: 700; color: var(--teal-2); text-decoration: underline; text-underline-offset: 3px;
}
.text-link:hover { color: var(--teal); }

@media (max-width: 860px) {
  .demo-gallery { grid-template-columns: minmax(0, 1fr); }
  .style-figure { grid-template-columns: minmax(0, 1fr); }
  .style-figure figcaption { border-left: 0; border-top: 1px solid var(--line); }
  .pcb-figure .image-frame { flex: none; min-height: 0; aspect-ratio: 1202 / 1002; }
}
@media (max-width: 480px) {
  .gallery-figure figcaption { padding: 12px 14px 14px; }
  .text-link { margin-left: 0; order: 4; }
  .zoom-chip { right: 8px; bottom: 8px; padding: 5px 10px; font-size: 13px; }
}

/* Image viewer */
.viewer {
  width: 100vw; height: 100vh; max-width: none; max-height: none;
  width: 100dvw; height: 100dvh;
  margin: 0; padding: 0; border: 0;
  background: #0b1718; color: var(--on-dark);
  display: none;
}
.viewer[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.viewer::backdrop { background: rgba(5, 12, 13, .85); }
.viewer-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: max(10px, env(safe-area-inset-top)) max(2vw, 12px, env(safe-area-inset-right)) 10px max(2vw, 12px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--dark-line); background: var(--dark);
}
.viewer-title { margin: 0 auto 0 0; font-size: 16px; font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.viewer-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.vbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-width: 44px; min-height: 44px; padding: 0 10px;
  border: 1px solid #55716f; border-radius: 6px; background: var(--dark-2); color: var(--on-dark);
  font-size: 20px; font-weight: 700; line-height: 1; text-decoration: none;
}
.vbtn-text { font-size: 14px; padding: 0 14px; }
.vbtn:hover:not(:disabled) { background: #24423f; }
.vbtn:disabled { cursor: not-allowed; color: var(--on-dark-muted); background: var(--dark); border-color: var(--dark-line); }
.vbtn-close { font-size: 15px; padding: 0 14px; background: var(--lime); color: #142025; border-color: #b9d24c; }
.vbtn-close:hover { background: var(--lime-2); }
.viewer-zoom { min-width: 56px; text-align: center; font-size: 14px; font-variant-numeric: tabular-nums; color: var(--on-dark-muted); }
.viewer-stage { position: relative; min-height: 0; overflow: hidden; touch-action: none; cursor: grab; background: #1b2b2c; }
.viewer-stage.is-dragging { cursor: grabbing; }
.viewer[data-state="loading"] .viewer-stage, .viewer[data-state="error"] .viewer-stage { cursor: default; touch-action: auto; }
.viewer-stage:focus-visible { outline: 3px solid var(--lime); outline-offset: -3px; border-radius: 0; }
.viewer-img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; user-select: none; -webkit-user-drag: none; will-change: transform; }
.viewer[data-state="loading"] .viewer-img, .viewer[data-state="error"] .viewer-img { visibility: hidden; }
.viewer-feedback {
  position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; justify-content: safe center; gap: 16px;
  padding: 24px max(20px, env(safe-area-inset-right)) 24px max(20px, env(safe-area-inset-left));
  overflow-y: auto; text-align: center;
}
#viewer-status { max-width: 40ch; margin: 0; color: var(--on-dark); font-size: 16px; line-height: 1.6; }
#viewer-retry { flex: none; }
.viewer[data-state="loading"] #viewer-status::before {
  content: ""; display: block; width: 24px; height: 24px; margin: 0 auto 16px;
  border: 3px solid var(--dark-line); border-top-color: var(--lime); border-radius: 50%;
  animation: viewer-loading 1s linear infinite;
}
@keyframes viewer-loading { to { transform: rotate(360deg); } }
.viewer-help {
  margin: 0;
  padding: 8px max(2vw, 12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(2vw, 12px, env(safe-area-inset-left));
  font-size: 13px; color: #b3c5bf; border-top: 1px solid var(--dark-line); background: var(--dark);
}
body.viewer-open { overflow: hidden; }
/* Show touch instructions on touch-only devices, keyboard/mouse instructions elsewhere */
.help-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .help-pointer { display: none; }
  .help-touch { display: inline; }
}

@media (max-width: 900px), (max-height: 500px) {
  .viewer-bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  .viewer-title { grid-column: 1; grid-row: 1; font-size: 15px; }
  .viewer-tools { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; gap: 4px; min-width: 0; }
  .vbtn-close { grid-column: 2; grid-row: 1; }
}
@media (max-width: 480px) {
  .vbtn-text { padding: 0 10px; }
  .viewer-help { font-size: 13px; }
}
@media (max-height: 500px) {
  .viewer-help { max-height: 22dvh; overflow-y: auto; }
  .viewer-feedback { padding-top: 12px; padding-bottom: 12px; gap: 8px; }
  .viewer[data-state="loading"] #viewer-status::before { width: 20px; height: 20px; margin-bottom: 8px; }
}
@media (hover: none) {
  .viewer-help { font-size: 13px; }
}
