/* GitCommandLab — interactive command demo cards */

.git-command-lab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr));
  gap: 18px;
  margin: 1.5em 0;
}

.git-command-lab {
  border: none;
  padding: 0;
  background-color: transparent;
  color: inherit;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-wrap: anywhere;
  /* Isolate each card's layout so a click on one card's graph doesn't
     trigger repaint checks against the whole page. Pages with many labs
     (SEBook/tools/git.md has 28) feel dramatically smoother with this.
     We use `layout` only (not `layout paint`) — including `paint` clips
     the label-burst drop-shadow at the card's edges. */
  contain: layout;
}

.git-command-lab__header {
  margin-bottom: 6px;
  min-width: 0;
}

.git-command-lab__row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
}
.git-command-lab__caption {
  flex: 1 1 260px;
  min-width: 0;
  order: 1;
}
.git-command-lab__caption > .git-command-lab__desc:first-child { margin-top: 0; }
.git-command-lab__caption > .git-command-lab__rebase-file { margin-top: 10px; margin-bottom: 0; }

.git-command-lab__action {
  flex: 1 1 280px;
  min-width: 0;
  order: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.git-command-lab__action > .git-command-lab__btn { align-self: flex-end; }

.git-command-lab__graphs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-self: stretch;
}
.git-command-lab__graphs > .git-command-lab__graph { align-self: stretch; }
.git-command-lab__graph-after { display: none; }

/* ----- Print layout: show Before | After side by side ----- */
@media print {
  .git-command-lab { break-inside: avoid; page-break-inside: avoid; }
  /* Keep the button visible as a labelled pill showing the command, but strip
     its interactive affordances — printing doesn't click. */
  .git-command-lab__btn {
    cursor: default !important;
    box-shadow: none !important;
    align-self: flex-start !important;
    margin: 4px 0 10px !important;
  }
  .git-command-lab__btn .git-command-lab__icon { display: none !important; }
  .git-command-lab__row {
    display: block !important;
  }
  .git-command-lab__caption,
  .git-command-lab__action { display: block !important; }
  .git-command-lab__graphs {
    display: flex !important;
    flex-direction: row !important;
    gap: 14px !important;
    align-items: flex-start;
  }
  .git-command-lab__graphs > .git-command-lab__graph,
  .git-command-lab__graphs > .git-command-lab__graph-after {
    display: block !important;
    flex: 1 1 0 !important;
    min-width: 0 !important;
  }
  /* Before / After headers above each graph */
  .git-command-lab__graphs > .git-command-lab__graph::before,
  .git-command-lab__graphs > .git-command-lab__graph-after::before {
    content: attr(data-state-label);
    display: block;
    font-family: 'Fira Code', 'Cascadia Code', Menlo, monospace;
    font-size: 10pt;
    font-weight: 700;
    color: #1f2d3d;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  .git-command-lab__graph svg,
  .git-command-lab__graph-after svg { max-width: 100% !important; height: auto !important; }
}

.git-command-lab__btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  background-color: #2774AE;
  color: #ffffff;
  border: 1px solid #2774AE;
  border-radius: 999px;
  padding: 7px 16px 7px 12px;
  cursor: pointer;
  font-family: 'Fira Code', 'Cascadia Code', Menlo, monospace;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  overflow-wrap: anywhere;
  word-break: break-word;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 120ms ease, box-shadow 160ms ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.git-command-lab__btn .git-command-lab__cmd {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.git-command-lab__btn .git-command-lab__icon { flex: 0 0 auto; }

@media (max-width: 520px) {
  .git-command-lab { padding: 12px 12px 10px; }
  .git-command-lab__btn {
    font-size: 12.5px;
    padding: 6px 12px 6px 10px;
    border-radius: 14px;
  }
  .git-command-lab__rebase-file { font-size: 11.5px; }
  .git-command-lab__rebase-file code { padding: 8px 10px; }
}
.git-command-lab__btn:hover {
  background-color: #1e5f8d;
  border-color: #1e5f8d;
  box-shadow: 0 2px 6px rgba(39,116,174,0.25);
}
.git-command-lab__btn:active { transform: translateY(1px); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.git-command-lab__btn:focus-visible {
  outline: 2px solid #1e5f8d;
  outline-offset: 2px;
}

.git-command-lab__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-size: 10px;
  line-height: 1;
}

.git-command-lab__btn--undo {
  background-color: transparent;
  color: #b03a2e;
  border-color: #b03a2e;
  box-shadow: none;
}
.git-command-lab__btn--undo:hover {
  background-color: rgba(176,58,46,0.08);
  border-color: #b03a2e;
  box-shadow: 0 2px 6px rgba(176,58,46,0.14);
}
/* Icon BOX size (18×18) is now set on .git-command-lab__icon directly so
   both play- and undo/restart-variants take the same vertical space — the
   button's height no longer jumps by ~3px when toggling between the two
   states, which was shifting the graph below it at click time. Only the
   glyph font-size differs. */
.git-command-lab__btn--undo .git-command-lab__icon,
.git-command-lab__btn--restart .git-command-lab__icon {
  font-size: 17px;
}

.git-command-lab__btn .git-command-lab__cmd,
.git-command-lab__btn code.git-command-lab__cmd {
  background: transparent !important;
  background-color: transparent !important;
  color: inherit;
  padding: 0;
  margin: 0;
  border: none;
  font: inherit;
  box-shadow: none;
}

.git-command-lab__desc {
  margin: 0;
  color: #000;
  font-size: 1.05em;
  line-height: 1.5;
}
.git-command-lab__desc > p { margin: 0 0 1em; }
.git-command-lab__desc > p:last-child { margin-bottom: 0; }

.git-command-lab__rebase-file {
  margin: 0 0 20px;
  padding: 0;
  background-color: #f4f6f8;
  border: 1px solid #d8dde2;
  border-radius: 6px;
  overflow: hidden;
  font-family: 'Fira Code', 'Cascadia Code', Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.45;
}
.git-command-lab__rebase-file code {
  overflow-x: auto;
}
.git-command-lab__rebase-file-header {
  padding: 6px 10px;
  background-color: #e6eaee;
  color: #5a6573;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-bottom: 1px solid #d8dde2;
}
.git-command-lab__rebase-file code {
  display: block;
  padding: 10px 12px;
  background: transparent !important;
  color: #1f2d3d;
  white-space: pre;
  font: inherit;
}
html.dark-mode .git-command-lab__rebase-file {
  background-color: #0f1721;
  border-color: #2f3a4a;
}
html.dark-mode .git-command-lab__rebase-file-header {
  background-color: #1a2332;
  color: #9aa6b2;
  border-bottom-color: #2f3a4a;
}
html.dark-mode .git-command-lab__rebase-file code {
  color: #e6edf3;
}

/* Block layout with inline-block centering for the SVG. We deliberately
   avoid `display: flex; justify-content: center` here because the SVG's
   width/height are tweened per frame by js/git-graph.js (_animateDimensions).
   A flex parent would re-flex-center every frame as the intrinsic size
   (and, via `height: auto`, the displayed aspect ratio) shifts, which
   showed up as horizontal + vertical stutter throughout the 720ms glide.
   Block + text-align:center keeps the SVG centered without a per-frame
   re-flex, so the canvas size smoothly tracks the nodes/labels/edges. */
.git-command-lab__graph {
  display: block;
  text-align: center;
  overflow-x: auto;
}
.git-command-lab__graph .git-graph-svg {
  display: inline-block;
  max-width: 100%;
  height: auto;
}
/* Workbench is a block sibling above the SVG — full width, left-aligned
   content even though the parent's text-align centers the SVG. */
.git-command-lab__graph .git-workbench,
.git-command-lab__graph-after .git-workbench,
.git-command-lab__graph-static .git-workbench {
  width: 100%;
  min-width: 0;
  text-align: left;
}

/* ----- Multi-step button group (Back + Forward/Restart) ----- */
.git-command-lab__btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-self: flex-end;
  align-items: center;
  justify-content: flex-end;
  max-width: 100%;
}
.git-command-lab--multi .git-command-lab__action > .git-command-lab__btn-group {
  align-self: flex-end;
}

.git-command-lab__btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: transparent;
  color: #5a6573;
  border: 1px solid #c4cbd3;
  border-radius: 999px;
  padding: 6px 14px 6px 11px;
  cursor: pointer;
  font-family: 'Fira Code', 'Cascadia Code', Menlo, monospace;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.2;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, opacity 160ms ease;
}
.git-command-lab__btn-back:hover:not(:disabled) {
  background-color: #f1f3f5;
  border-color: #9aa6b2;
  color: #1f2d3d;
}
.git-command-lab__btn-back:focus-visible {
  outline: 2px solid #9aa6b2;
  outline-offset: 2px;
}
.git-command-lab__btn-back:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.git-command-lab__btn-back .git-command-lab__icon { font-size: 11px; }
.git-command-lab__btn-back-label { font: inherit; }

html.dark-mode .git-command-lab__btn-back {
  color: #9aa6b2;
  border-color: #3a4556;
}
html.dark-mode .git-command-lab__btn-back:hover:not(:disabled) {
  background-color: rgba(154,166,178,0.1);
  border-color: #5a6573;
  color: #e6edf3;
}

@media print {
  .git-command-lab__btn-back { display: none !important; }
}

/* ----- Restart button (multi-step final state) ----- */
.git-command-lab__btn--restart {
  background-color: transparent;
  color: #1a7d5a;
  border-color: #1a7d5a;
  box-shadow: none;
}
.git-command-lab__btn--restart:hover {
  background-color: rgba(26,125,90,0.08);
  border-color: #1a7d5a;
  box-shadow: 0 2px 6px rgba(26,125,90,0.14);
}
html.dark-mode .git-command-lab__btn--restart {
  color: #4ade80;
  border-color: #4ade80;
}
html.dark-mode .git-command-lab__btn--restart:hover {
  background-color: rgba(74,222,128,0.12);
}

/* ----- Step progress indicator (multi-step) ----- */
.git-command-lab__step-progress {
  margin-top: 10px;
  font-family: 'Fira Code', 'Cascadia Code', Menlo, monospace;
  font-size: 11.5px;
  color: #6b7280;
  font-variant-numeric: tabular-nums;
}
html.dark-mode .git-command-lab__step-progress { color: #9aa6b2; }

/* ----- Print steps grid (hidden on screen, shown in print) ----- */
.git-command-lab__print-steps { display: none; }

.git-command-lab__graph-static svg { max-width: 100%; height: auto; display: block; }

@media print {
  /* Multi-step: hide the interactive row, show the static steps grid */
  .git-command-lab--multi > .git-command-lab__row { display: none !important; }

  .git-command-lab__print-steps {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px 18px;
    margin-top: 8px;
  }

  .git-command-lab__print-step {
    display: flex;
    flex-direction: column;
    gap: 5px;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .git-command-lab__print-step-label {
    font-family: 'Fira Code', 'Cascadia Code', Menlo, monospace !important;
    font-size: 9pt !important;
    font-weight: 700 !important;
    line-height: 1.25 !important;
    color: #1f2d3d !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  .git-command-lab__print-step-label--initial {
    color: #5a6573 !important;
  }
  .git-command-lab__print-step-label code {
    background: transparent !important;
    padding: 0 !important;
    font-size: 9pt !important;
    line-height: 1.25 !important;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 700 !important;
    color: #1f2d3d !important;
    font-family: 'Fira Code', 'Cascadia Code', Menlo, monospace !important;
  }

  .git-command-lab__print-step-desc,
  .git-command-lab__print-step-desc p {
    font-size: 8pt !important;
    line-height: 1.35 !important;
    color: #374151 !important;
  }
  .git-command-lab__print-step-desc code {
    font-size: 8pt !important;
    padding: 0 2px !important;
    font-family: 'Fira Code', 'Cascadia Code', Menlo, monospace !important;
  }
  .git-command-lab__print-step-desc p { margin: 0 0 3px; }
  .git-command-lab__print-step-desc p:last-child { margin-bottom: 0; }

  .git-command-lab__graph-static svg { max-width: 100% !important; height: auto !important; }
  .git-command-lab__step-progress { display: none !important; }
}

/* ----- Dark mode ----- */
html.dark-mode .git-command-lab {
  border-color: #2f3a4a;
  color: #e6edf3;
}
html.dark-mode .git-command-lab__desc { color: #fff; }
html.dark-mode .git-command-lab__btn {
  background-color: transparent;
  color: #4a9fd9;
  border-color: #4a9fd9;
}
html.dark-mode .git-command-lab__btn:hover {
  background-color: rgba(74,159,217,0.12);
  border-color: #66b1e3;
  color: #66b1e3;
}
html.dark-mode .git-command-lab__btn--undo {
  background-color: transparent;
  color: #f1948a;
  border-color: #f1948a;
}
html.dark-mode .git-command-lab__btn--undo:hover {
  background-color: rgba(241,148,138,0.12);
  border-color: #f1948a;
}

/* ----- Modal (popup) presentation ----- */

.git-command-lab-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 35, 0.55);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: gcl-modal-fade 140ms ease-out;
}

.git-command-lab-modal {
  background-color: #ffffff;
  color: #1f2d3d;
  border-radius: 10px;
  padding: 28px 28px 20px;
  position: relative;
  max-width: min(720px, 96vw);
  max-height: 92vh;
  overflow: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
}
html.dark-mode .git-command-lab-modal { background-color: #1c2533; color: #e6edf3; }

.git-command-lab-modal .git-command-lab {
  border: none;
  padding: 0;
  background-color: transparent;
}

.git-command-lab-modal__close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  color: #5a6573;
  padding: 4px 8px;
  border-radius: 4px;
}
.git-command-lab-modal__close:hover { background-color: #f1f3f5; color: #1f2d3d; }
html.dark-mode .git-command-lab-modal__close { color: #9aa6b2; }
html.dark-mode .git-command-lab-modal__close:hover { background-color: #2a323e; color: #e6edf3; }

.git-command-lab__output {
  margin: 0 0 10px;
  padding: 10px 14px;
  background: #0d1117;
  color: #e6edf3;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  border-radius: 6px;
  border: 1px solid #30363d;
  white-space: pre-wrap;
  word-break: break-all;
}
html.dark-mode .git-command-lab__output {
  background: #010409;
  border-color: #21262d;
}

@keyframes gcl-modal-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Respect OS-level "reduce motion" — disable button/link transitions,
   modal fade-in, and lane-layout transitions inside git graphs. The
   JS-driven label-burst and commit-burst in js/git-graph.js should also
   check `window.matchMedia('(prefers-reduced-motion: reduce)').matches`
   before animating — that guard is added alongside this rule. */
@media (prefers-reduced-motion: reduce) {
  .git-command-lab__btn,
  .git-command-lab__btn-back { transition: none !important; }
  .git-command-lab-modal-overlay { animation: none !important; }
}
