/*
 * Advanced Git: "history surgery". Ink-blue graphite, electric violet, rails and nodes.
 * Same family as git-history (monospace, terminal journal), a different branch of it.
 */

[data-ob-theme="advanced-git"] {
  --adv-rail: #8f73ff;
  --adv-cool: #5fd4ee;
  --adv-good: #7ee787;
  --adv-bad: #ff8b86;
  --adv-warn: #e3b341;
  --adv-grid: rgb(143 115 255 / 0.07);
}

@media (prefers-color-scheme: light) {
  [data-ob-theme="advanced-git"] {
    --adv-rail: #7a63d6;
    --adv-cool: #0b6a85;
    --adv-good: #116329;
    --adv-bad: #b4232e;
    --adv-warn: #7d4e00;
    --adv-grid: rgb(86 54 216 / 0.07);
  }
}

[data-ob-theme="advanced-git"] body {
  background-image: linear-gradient(90deg, var(--adv-grid) 1px, transparent 1px);
  background-size: 56px 56px;
}

[data-ob-theme="advanced-git"] .ob-header {
  font-family: var(--ob-font-mono);
}

[data-ob-theme="advanced-git"] .ob-header-inner {
  margin-bottom: 1.5rem;
}

[data-ob-theme="advanced-git"] .ob-title {
  color: var(--ob-color-accent-soft);
  text-transform: none;
  text-wrap: balance;
}

[data-ob-theme="advanced-git"] .ob-section > .ob-cover {
  display: none;
}

[data-ob-theme="advanced-git"] .ob-eyebrow {
  color: var(--ob-color-subtle);
  font: 0.75rem / 1.8 var(--ob-font-mono);
}

[data-ob-theme="advanced-git"] .ob-prose :is(h2, h3) {
  font-family: var(--ob-font-mono);
  font-weight: 500;
  letter-spacing: -0.025em;
}

[data-ob-theme="advanced-git"] .ob-prose h2 {
  margin-top: 2em;
}

[data-ob-theme="advanced-git"] .ob-prose blockquote {
  border-left-color: var(--ob-color-accent-border);
  color: var(--ob-color-muted);
}

[data-ob-theme="advanced-git"] .ob-prose :not(pre) > code {
  background: var(--ob-color-surface-raised);
  color: var(--ob-color-text);
}

[data-ob-theme="advanced-git"] .ob-tags a {
  border-radius: 4px;
  font: 0.7rem / 1.8 var(--ob-font-mono);
}

[data-ob-theme="advanced-git"] .ob-post-header {
  padding-block: 1rem 1.5rem;
  border-bottom: 1px solid var(--ob-color-border);
}

/* ---------- Code: dark panels in both schemes ---------- */

[data-ob-theme="advanced-git"] .ob-prose pre {
  --ob-color-subtle: #a2a9c0;
  --ob-color-text: #eceef6;
  --ob-color-muted: #bfc4d6;
  --ob-color-border: #4a5270;
  --ob-color-surface: #0d1018;
  --ob-color-accent-soft: #b8a9ff;
  color: var(--ob-color-code-text);
  padding: 1rem 1.2rem;
  border-color: var(--ob-color-border);
  border-radius: var(--ob-radius-sm);
  font-size: 0.85rem;
  line-height: 1.8;
}

[data-ob-theme="advanced-git"] .ob-code-block {
  overflow: hidden;
  border: 1px solid #4a5270;
  border-radius: var(--ob-radius);
  background: var(--ob-color-code-bg);
}

[data-ob-theme="advanced-git"] .ob-code-block pre {
  margin: 0;
  border: 0;
  border-radius: 0;
}

[data-ob-theme="advanced-git"] .ob-code-title {
  padding: 0.6rem 1.2rem;
  border: 0;
  border-bottom: 1px solid #4a5270;
  border-radius: 0;
  background: #181c27;
  color: #bfc4d6;
  font-size: 0.7rem;
}

[data-ob-theme="advanced-git"] .ob-numbered .ob-line::before {
  opacity: 1;
}

/* ---------- Lesson list: two rails and commit nodes ---------- */

[data-ob-theme="advanced-git"] .ob-prose #commit-log {
  margin-top: 1rem;
  border: 0;
  font: 500 clamp(0.9rem, 2.5vw, 1.2rem) / 1.8 var(--ob-font-mono);
  letter-spacing: -0.02em;
}

[data-ob-theme="advanced-git"] .ob-series-parts-full {
  margin-top: 1.5rem;
  padding-left: 1.6rem;
  border-left: 2px solid var(--adv-rail);
  box-shadow: -7px 0 0 -5px var(--adv-cool);
}

[data-ob-theme="advanced-git"] .ob-series-parts-full > li {
  position: relative;
}

[data-ob-theme="advanced-git"] .ob-series-parts-full > li::before {
  content: "";
  position: absolute;
  top: 1.55rem;
  left: -2.15rem;
  width: 11px;
  height: 11px;
  border: 2px solid var(--adv-rail);
  border-radius: 50%;
  background: var(--ob-color-page);
}

[data-ob-theme="advanced-git"] .ob-series-parts-full > li:nth-child(odd)::before {
  background: var(--adv-rail);
}

[data-ob-theme="advanced-git"] .ob-part {
  padding: 1rem 0.75rem;
  border-top: 0;
  border-bottom: 1px solid var(--ob-color-border);
  border-radius: 0;
  background: transparent;
}

[data-ob-theme="advanced-git"] .ob-part:is(:hover, :focus-visible) {
  background: var(--ob-color-surface);
}

[data-ob-theme="advanced-git"] .ob-part-number {
  color: var(--ob-color-subtle);
  font: 0.75rem / 2 var(--ob-font-mono);
}

[data-ob-theme="advanced-git"] .ob-part-title {
  color: var(--ob-color-accent-soft);
  font: 500 1rem / 1.6 var(--ob-font-mono);
}

[data-ob-theme="advanced-git"] .ob-part-summary {
  max-width: 65ch;
  margin-top: 0.3rem;
  color: var(--ob-color-muted);
  font-size: 0.9rem;
}

/* ---------- Series navigation: restyled, never rebuilt ---------- */

[data-ob-theme="advanced-git"] .ob-series-box {
  border-color: var(--ob-color-border);
  border-left: 3px solid var(--adv-rail);
}

[data-ob-theme="advanced-git"] .ob-series-box > .ob-eyebrow {
  color: var(--ob-color-subtle);
}

[data-ob-theme="advanced-git"] .ob-series-path {
  gap: 0;
}

[data-ob-theme="advanced-git"] .ob-series-path li {
  position: relative;
  flex: 0 0 auto;
  width: 0.75rem;
  height: 0.75rem;
  max-width: none;
  margin-right: 0.85rem;
  border: 2px solid var(--adv-rail);
  border-radius: 50%;
}

[data-ob-theme="advanced-git"] .ob-series-path li::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 100%;
  width: 0.85rem;
  height: 2px;
  transform: translateY(-50%);
  background: var(--adv-rail);
}

[data-ob-theme="advanced-git"] .ob-series-path li:last-child {
  margin-right: 0;
}

[data-ob-theme="advanced-git"] .ob-series-path li:last-child::after {
  display: none;
}

[data-ob-theme="advanced-git"] .ob-series-path li[data-done] {
  background: var(--ob-color-accent-soft);
  border-color: var(--ob-color-accent-soft);
}

[data-ob-theme="advanced-git"] .ob-series-path li[data-current] {
  width: 0.95rem;
  height: 0.95rem;
  border: 3px double var(--ob-color-text);
  background: var(--adv-rail);
}

[data-ob-theme="advanced-git"] .ob-series-nav a {
  text-underline-offset: 0.25em;
}

[data-ob-theme="advanced-git"] .ob-footer::before {
  content: "HEAD detached at main~3";
  display: block;
  width: min(var(--ob-reading-width), 100% - 2 * var(--ob-gutter));
  margin: 0 auto 2rem;
  color: var(--ob-color-subtle);
  font: 0.8rem / 1.8 var(--ob-font-mono);
}

/* ---------- Labs ---------- */

.adv-lab {
  --adv-line: var(--ob-color-border);
  margin-block: 1.25rem 2rem;
  overflow: hidden;
  border: 1px solid var(--adv-line);
  border-top: 3px solid var(--adv-rail);
  border-radius: 10px;
  background: var(--ob-color-surface);
  color: var(--ob-color-muted);
}

.adv-lab > * {
  min-width: 0;
}

.adv-lab-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25rem 0.75rem;
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid var(--adv-line);
  color: var(--ob-color-subtle);
  font: 0.65rem / 1.8 var(--ob-font-mono);
}

.adv-lab-intro,
.adv-lab-static,
.adv-lab-controls:not([hidden]) {
  padding: 1.1rem 1.25rem;
}

.adv-lab-intro {
  padding-bottom: 0;
}

[data-ob-theme="advanced-git"] .ob-prose .adv-lab h3 {
  margin: 0 0 0.5rem;
  color: var(--ob-color-accent-soft);
  font-size: clamp(1.25rem, 3vw, 1.7rem);
  line-height: 1.25;
}

.adv-lab p {
  margin-block: 0 0.9rem;
  font-size: 0.85rem;
  line-height: 1.7;
}

.adv-lab-intro p {
  max-width: 62ch;
  color: var(--ob-color-text);
}

[data-ob-theme="advanced-git"] .ob-prose .adv-lab li + li {
  margin-top: 0;
}

.adv-lab-status:empty {
  display: none;
}

.adv-lab-static ol {
  padding-left: 1.4rem;
  font-size: 0.85rem;
}

[data-ob-theme="advanced-git"] .ob-prose .adv-lab pre {
  margin-block: 0.25rem 1rem;
  font-size: 0.78rem;
  overflow-x: auto;
}

.adv-lab-controls[hidden] {
  display: none;
}

.adv-lab-hint,
.adv-lab-note {
  color: var(--ob-color-muted);
}

.adv-lab-note {
  margin: 1rem 0 0;
  padding-top: 0.8rem;
  border-top: 1px dashed var(--adv-line);
  color: var(--ob-color-subtle);
  font-size: 0.75rem;
}

.adv-lab-status {
  min-height: 1.7em;
  padding: 0.5rem 0.75rem;
  border-left: 3px solid var(--adv-cool);
  background: var(--ob-color-surface-raised);
  color: var(--ob-color-text);
}

.adv-lab-subtitle {
  margin: 1.25rem 0 0.5rem;
  color: var(--ob-color-text);
  font: 600 0.8rem / 1.6 var(--ob-font-mono);
}

.adv-lab-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-block: 0.9rem;
}

.adv-lab :is(button, select, input) {
  font: 0.75rem / 1.4 var(--ob-font-mono);
}

.adv-button,
.adv-icon-button {
  min-height: 2.5rem;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--ob-color-accent-border);
  border-radius: 4px;
  background: var(--ob-color-surface-raised);
  color: var(--ob-color-text);
  cursor: pointer;
}

.adv-icon-button {
  min-width: 2.5rem;
  padding-inline: 0.5rem;
  font-size: 1rem;
}

.adv-button:hover,
.adv-icon-button:hover:not([aria-disabled="true"]) {
  border-color: var(--ob-color-accent-soft);
  color: var(--ob-color-accent-soft);
}

.adv-button[aria-pressed="true"] {
  border-color: var(--ob-color-accent-soft);
  background: var(--ob-color-accent);
  color: var(--ob-color-accent-contrast);
  font-weight: 700;
}

.adv-button[aria-pressed="true"]::before {
  content: "\2713\00a0";
}

.adv-icon-button[aria-disabled="true"] {
  border-style: dashed;
  color: var(--ob-color-subtle);
  cursor: default;
}

.adv-lab :is(button, select, input, summary, pre):focus-visible {
  outline: 2px solid var(--ob-color-accent-soft);
  outline-offset: 3px;
}

.adv-lab :is(select, input) {
  min-height: 2.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--ob-color-accent-border);
  border-radius: 4px;
  background: var(--ob-color-surface-raised);
  color: var(--ob-color-text);
}

/* Rebase Bench */

.rb-todo,
.rb-log {
  margin: 0;
  padding: 0;
  list-style: none;
}

.rb-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.35rem 0.75rem;
  margin-bottom: 0.5rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--adv-line);
  border-left: 4px solid var(--adv-rail);
  border-radius: 4px;
  background: var(--ob-color-page);
}

.rb-row[data-state="squashed"],
.rb-row[data-state="fixed-up"] {
  margin-left: 1.25rem;
  border-left-style: double;
  border-left-width: 6px;
}

.rb-row[data-state="dropped"] {
  border-style: dashed;
  border-left-width: 4px;
}

.rb-row[data-state="dropped"] .rb-subject {
  text-decoration: line-through;
}

.rb-row[data-state="error"] {
  border-color: var(--adv-bad);
  border-width: 2px;
  border-style: solid;
}

.rb-row[data-state="waiting"] {
  border-style: dotted;
}

.rb-hash {
  color: var(--ob-color-subtle);
  font: 0.75rem / 1.4 var(--ob-font-mono);
  background: none;
}

.rb-subject {
  min-width: 0;
  color: var(--ob-color-text);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.rb-move {
  display: inline-flex;
  gap: 0.35rem;
}

.rb-note {
  grid-column: 1 / -1;
  color: var(--ob-color-subtle);
  font-size: 0.7rem;
}

.rb-result {
  margin-top: 0.5rem;
}

.rb-log {
  position: relative;
  margin-top: 0.75rem;
  padding-left: 1.6rem;
}

.rb-log::before {
  content: "";
  position: absolute;
  top: 0.9rem;
  bottom: 0.9rem;
  left: 0.45rem;
  width: 2px;
  background: var(--adv-rail);
}

.rb-log-row {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.15rem 0.75rem;
  padding: 0.35rem 0;
  font-size: 0.85rem;
}

.rb-log-row::before {
  content: "";
  position: absolute;
  top: 0.85rem;
  left: -1.6rem;
  width: 0.7rem;
  height: 0.7rem;
  box-sizing: border-box;
  border: 2px solid var(--adv-rail);
  border-radius: 50%;
  background: var(--ob-color-surface);
}

.rb-log-row[data-changed="true"]::before {
  background: var(--adv-rail);
}

.rb-base::before {
  border-style: dashed;
}

.rb-tag {
  color: var(--ob-color-accent-soft);
  font-size: 0.75rem;
}

.rb-joined {
  flex-basis: 100%;
  padding-left: 0.5rem;
  border-left: 2px solid var(--adv-cool);
  color: var(--ob-color-muted);
  font-size: 0.75rem;
}

.rb-empty,
.rb-base .rb-subject {
  color: var(--ob-color-subtle);
}

.rb-error {
  margin: 0.75rem 0;
  padding: 0.75rem 1rem;
  border: 2px solid var(--adv-bad);
  border-radius: 4px;
  background: var(--ob-color-page);
}

.rb-error p {
  margin: 0 0 0.35rem;
}

.rb-error-line {
  color: var(--adv-bad);
  font-weight: 700;
}

.rb-details {
  margin-top: 1rem;
  font-size: 0.8rem;
}

.rb-details summary {
  min-height: 2.5rem;
  padding-block: 0.5rem;
  cursor: pointer;
}

.rb-file {
  margin: 0.5rem 0 0;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  border: 1px solid var(--adv-line);
  border-radius: 4px;
  background: var(--ob-color-code-bg);
  color: var(--ob-color-code-text);
  font: 0.75rem / 1.7 var(--ob-font-mono);
}

/* Bisect Hunt */

.bh-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.6rem 0.75rem;
  margin-bottom: 0.9rem;
}

.bh-seed-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.bh-seed-group label {
  color: var(--ob-color-text);
  font-size: 0.75rem;
}

.bh-seed {
  width: 6rem;
}

.bh-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
  margin: 0.75rem 0 1rem;
  padding: 0;
  list-style: none;
}

@media (min-width: 36rem) {
  .bh-row { grid-template-columns: repeat(8, minmax(0, 1fr)); }
}

@media (min-width: 68rem) {
  .bh-row { grid-template-columns: repeat(16, minmax(0, 1fr)); }
}

.bh-item {
  position: relative;
  min-width: 0;
}

/* The rail runs behind the nodes of each row. */
.bh-item::before {
  content: "";
  position: absolute;
  top: 1.15rem;
  left: -0.2rem;
  right: -0.2rem;
  height: 2px;
  background: var(--adv-rail);
}

.bh-commit {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  width: 100%;
  min-height: 4.2rem;
  padding: 0.4rem 0.15rem;
  border: 1px solid var(--ob-color-accent-border);
  border-radius: 4px;
  background: var(--ob-color-page);
  color: var(--ob-color-text);
  cursor: pointer;
}

.bh-commit:disabled {
  cursor: default;
}

/* Node: shape changes with the state, so color is never the only signal. */
.bh-commit::before {
  content: "";
  width: 0.8rem;
  height: 0.8rem;
  box-sizing: border-box;
  border: 2px solid var(--ob-color-accent-soft);
  border-radius: 50%;
  background: var(--ob-color-page);
}

.bh-num {
  font-weight: 700;
  font-size: 0.8rem;
}

.bh-state {
  color: var(--ob-color-muted);
  font-size: 0.6rem;
  line-height: 1.3;
  text-align: center;
  overflow-wrap: anywhere;
}

.bh-commit[data-state="candidate"] {
  border-width: 2px;
  border-color: var(--ob-color-accent-soft);
}

.bh-commit[data-state="ruled-out"] {
  border-style: dashed;
  border-color: var(--ob-color-border);
  background: transparent;
  color: var(--ob-color-subtle);
}

.bh-commit[data-state="ruled-out"]::before {
  width: 0.4rem;
  height: 0.4rem;
  margin: 0.2rem;
  border-color: var(--ob-color-subtle);
  background: var(--ob-color-subtle);
}

.bh-commit[data-state="ruled-out"] .bh-state {
  color: var(--ob-color-subtle);
}

.bh-commit[data-state="good"]::before {
  border-color: var(--adv-good);
  background: var(--adv-good);
}

.bh-commit[data-state="good"] .bh-state {
  color: var(--adv-good);
}

.bh-commit[data-state="bad"]::before,
.bh-commit[data-state="culprit"]::before {
  border-radius: 1px;
  border-color: var(--adv-bad);
  background: var(--adv-bad);
  transform: rotate(45deg);
}

.bh-commit[data-state="bad"] .bh-state,
.bh-commit[data-state="culprit"] .bh-state {
  color: var(--adv-bad);
  font-weight: 700;
}

.bh-commit[data-state="culprit"] {
  border: 3px double var(--adv-bad);
}

.bh-commit[data-current="true"] {
  outline: 2px dashed var(--ob-color-accent-soft);
  outline-offset: 2px;
}

.bh-range,
.bh-steps {
  margin-bottom: 0.3rem;
  color: var(--ob-color-text);
}

.adv-lab-status[data-done] {
  border: 2px solid var(--adv-good);
  border-radius: 4px;
  font-weight: 700;
}

.bh-guide {
  margin-bottom: 0.9rem;
  padding: 0.75rem 1rem;
  border: 1px dashed var(--ob-color-accent-soft);
  border-radius: 4px;
  background: var(--ob-color-page);
}

.bh-guide p {
  margin-bottom: 0.3rem;
  color: var(--ob-color-text);
}

.bh-guide code {
  background: none;
  color: var(--ob-color-accent-soft);
}

@media (max-width: 40rem) {
  .rb-row {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .rb-row .rb-action {
    grid-column: 1 / 2;
  }

  .rb-row .rb-move {
    grid-column: 2 / 3;
    justify-self: start;
  }

  .adv-lab-intro,
  .adv-lab-static,
  .adv-lab-controls:not([hidden]) {
    padding-inline: 1rem;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .adv-button,
  .adv-icon-button,
  .bh-commit {
    transition: border-color 0.15s ease, background-color 0.15s ease;
  }

  .bh-commit[data-current="true"]::before,
  [data-ob-theme="advanced-git"] .ob-series-path li[data-current] {
    animation: adv-head-pulse 3.5s ease-in-out infinite;
  }
}

@keyframes adv-head-pulse {
  50% { transform: scale(1.18); }
}

@media print {
  [data-ob-theme="advanced-git"] body {
    background-image: none;
  }
}
