/* ==========================================================================
   Notebook — the Jupyter-style landing panel, its cells, the autocomplete
   dropdown, the README tab and the contact wizard.
   ========================================================================== */

/* The landing section owns no top border and reveals its bottom rule only
   once the notebook has finished booting (see scripts/reveal.js). */
.nb-section {
  border-top: none;
  padding-top: 60px;
  border-bottom-color: transparent;
  transition: border-bottom-color 0.6s ease;
}

/* --------------------------------------------------------------------------
   Frame
   -------------------------------------------------------------------------- */

.nb {
  border: 1px solid var(--rule);
  background: var(--nb-bg);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
}

.nb-head {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  border-bottom: 1px solid var(--rule);
  background: var(--nb-head-bg);
}

.nb-tabs {
  display: flex;
}

.nb-tab {
  padding: 12px 20px;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--muted);
  border-right: 1px solid var(--rule);
  transition: opacity 0.5s ease;
}

/* Tabs stay inert until the notebook intro has finished playing */
.nb-tab.nb-tab-locked {
  opacity: 0.3;
  pointer-events: none;
  cursor: default;
}

.nb-tab.active {
  background: var(--nb-bg);
  color: var(--ink);
  border-bottom: 2px solid var(--accent);
  margin-bottom: -1px;
}

.nb-meta {
  align-self: center;
  padding: 0 20px;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Cells
   -------------------------------------------------------------------------- */

.nb-cells {
  padding: 8px 0;
  position: relative;
}

.nb-cell {
  display: grid;
  grid-template-columns: 80px 1fr;
  align-items: start;
  padding: 8px 0;
  position: relative;
}

.nb-del {
  position: absolute;
  right: 8px;
  top: 10px;
  opacity: 0;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  background: none;
  border: none;
  padding: 0 4px;
  font-family: var(--font-mono);
  line-height: 1;
  transition: opacity 0.15s, color 0.15s;
}

.nb-cell:hover .nb-del {
  opacity: 1;
}

.nb-del:hover {
  color: var(--accent);
}

.nb-gutter {
  font-size: 11px;
  color: var(--muted);
  padding: 8px 12px 0 24px;
  text-align: right;
  letter-spacing: 0.05em;
}

.nb-gutter.in {
  color: var(--syn-key);
}

.nb-gutter.out {
  color: var(--accent);
}

.nb-body {
  padding: 6px 24px 6px 12px;
  white-space: pre-wrap;
}

.nb-cell.code .nb-body {
  background: var(--nb-code-bg);
  border-left: 3px solid var(--syn-key);
  padding: 10px 16px;
  color: var(--ink);
}

.nb-cell.markdown .nb-body {
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.5;
  padding-top: 8px;
  padding-bottom: 8px;
}

.nb-cell.markdown h3 {
  font-family: var(--font-sans);
  font-style: normal;
  font-weight: 600;
  font-size: 22px;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

/* The `# type a command…` prompt above the interactive cell */
.nb-hint .nb-body {
  color: var(--muted);
  font-size: 11px;
  padding-top: 6px;
  padding-bottom: 6px;
}

/* --------------------------------------------------------------------------
   Output syntax colours
   -------------------------------------------------------------------------- */

.nb-out {
  color: var(--ink);
}

.nb-out .key {
  color: var(--syn-key);
}

.nb-out .str {
  color: var(--accent);
}

.nb-out.is-error {
  color: var(--accent);
}

.nb-cell.code .nb-body .nb-kw,
.nb-cell.code .nb-body .nb-obj {
  color: var(--syn-key);
}

.nb-cell.code .nb-body .nb-fn {
  color: var(--accent);
}

.nb-cell.code .nb-body .nb-punc {
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Typing cursor
   -------------------------------------------------------------------------- */

.nb-cursor::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 0.85em;
  background: var(--accent);
  animation: nb-blink 1s steps(1) infinite;
  margin-left: 2px;
  vertical-align: -0.05em;
}

@keyframes nb-blink {
  50% {
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   Interactive prompt + autocomplete
   -------------------------------------------------------------------------- */

.nb-input-wrap {
  position: relative;
}

.nb-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink);
  caret-color: var(--accent);
  padding: 0;
}

.nb-input::placeholder {
  color: var(--muted);
}

.nb-autocomplete {
  position: absolute;
  bottom: 100%;
  left: 0;
  background: var(--nb-bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 4px 0;
  min-width: 300px;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.12);
  z-index: 10;
}

.nb-ac-item {
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.nb-ac-item.selected {
  background: var(--syn-key);
  color: var(--paper);
}

.nb-ac-desc {
  opacity: 0.6;
  font-size: 11px;
}

.nb-ac-item.selected .nb-ac-desc {
  opacity: 0.8;
}

/* --------------------------------------------------------------------------
   Contact wizard
   -------------------------------------------------------------------------- */

.nb-cw-body {
  white-space: pre;
  font-size: 13px;
  line-height: 1.7;
}

.nb-cw-step .nb-body {
  position: relative;
  white-space: normal;
}

.nb-cw-comment {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.nb-cw-line {
  display: flex;
  align-items: baseline;
  font-family: var(--font-mono);
  font-size: 13px;
}

.nb-cw-pre {
  white-space: pre;
  line-height: 1.7;
}

.nb-cw-key {
  color: var(--syn-key);
}

.nb-cw-str {
  color: var(--syn-str);
}

.nb-cw-inp {
  background: transparent;
  border: none;
  border-bottom: 1.5px solid var(--accent);
  outline: none;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--syn-str);
  padding: 0 3px 1px;
  min-width: 160px;
  flex: 1;
  caret-color: var(--accent);
  line-height: 1.7;
}

.nb-cw-inp::placeholder {
  color: var(--muted);
}

/* The template-index field is a narrow numeric slot, not a free-text one */
.nb-cw-inp.nb-cw-idx {
  min-width: 20px;
  width: 52px;
  flex: 0 0 auto;
}

/* --------------------------------------------------------------------------
   The TEMPLATES listing — a Python list literal whose entries are buttons
   -------------------------------------------------------------------------- */

.nb-cw-templates {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
}

.nb-cw-tpl {
  display: block;
  width: 100%;
  /* Reproduces the two-space indent the listing used to fake with `pre` */
  padding: 4px 8px 4px 16px;
  background: none;
  border: 0;
  border-radius: 3px;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}

/* `# 1` is one token — never let the wrap fall between the hash and the digit */
.nb-cw-tpl .nb-cw-comment {
  margin-left: 10px;
  white-space: nowrap;
}

/* `:active` matters most on touch, where there is no hover to preview a press */
.nb-cw-tpl:hover,
.nb-cw-tpl:active,
.nb-cw-tpl:focus-visible {
  background: var(--accent-soft);
  outline: none;
}

.nb-cw-tpl:focus-visible {
  box-shadow: inset 0 0 0 1px var(--accent);
}

.nb-cw-tpl:hover .nb-cw-comment,
.nb-cw-tpl:active .nb-cw-comment,
.nb-cw-tpl:focus-visible .nb-cw-comment {
  color: var(--accent);
}

.nb-cw-err {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--syn-err);
  margin-top: 4px;
}

.nb-cw-obj {
  white-space: pre;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
}

.nb-cw-status {
  display: block;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}

.nb-cw-success {
  color: var(--success);
  font-weight: 500;
}

.nb-cw-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.nb-cw-link:hover {
  opacity: 0.8;
}

.nb-cw-or {
  margin: 10px 0 8px;
}

.nb-cw-message-line {
  margin-top: 10px;
}

/* --------------------------------------------------------------------------
   README tab
   -------------------------------------------------------------------------- */

.nb-readme-body {
  white-space: normal;
  padding: 28px 24px 28px 12px;
}

.nb-readme {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.7;
  max-width: 660px;
}

.nb-readme h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 6px;
  letter-spacing: -0.02em;
}

.nb-readme h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 10px;
}

.nb-readme p {
  margin: 0 0 6px;
}

.nb-readme .lede,
.nb-readme .note {
  color: var(--muted);
}

.nb-readme .lede {
  margin: 0 0 28px;
  font-size: 14px;
}

.nb-readme .note {
  margin: 0 0 24px;
  font-size: 13px;
}

.nb-readme code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--nb-code-bg);
  padding: 1px 6px;
}

.nb-readme table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 24px;
}

.nb-readme thead tr,
.nb-readme tbody tr {
  border-bottom: 1px solid var(--rule);
}

.nb-readme tbody tr:last-child {
  border-bottom: none;
}

.nb-readme th {
  text-align: left;
  padding: 6px 24px 6px 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.06em;
}

.nb-readme td {
  padding: 7px 24px 7px 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
}

.nb-readme td + td {
  padding-right: 0;
  color: var(--muted);
}

.nb-readme .colophon {
  border-top: 1px solid var(--rule);
  padding-top: 14px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 800px) {
  .nb {
    overflow: hidden;
  }

  /* Both tabs stay reachable — the README is where the `cam` API is listed */
  .nb-tab {
    padding: 12px 12px;
  }

  .nb-meta {
    display: none;
  }

  /* Wide enough for `Out[12]:` on one line — anything narrower and the label
     wraps or runs into the cell body. */
  .nb-cell {
    grid-template-columns: 60px 1fr;
  }

  .nb-gutter {
    padding-left: 4px;
    padding-right: 6px;
    font-size: 10px;
    white-space: nowrap;
  }

  /* A grid item defaults to min-width:auto, so a long unbreakable line would
     widen the whole cell and get clipped by the frame. Let it shrink instead. */
  .nb-cell > .nb-body {
    min-width: 0;
  }

  .nb-body {
    padding-right: 14px;
    padding-left: 8px;
  }

  /* The dropdown is anchored inside the cell body, so it cannot ask for more
     width than the body has — the notebook clips its overflow. */
  .nb-autocomplete {
    min-width: 0;
    width: 100%;
  }

  .nb-ac-item {
    gap: 10px;
  }

  .nb-ac-desc {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Anything laid out with `white-space: pre` has to be allowed to wrap here,
     or it overflows the notebook and takes the gutter column with it. */
  .nb-cw-body,
  .nb-cw-obj,
  .nb-cw-pre {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  /* Each wizard field drops onto its own line rather than being squeezed */
  .nb-cw-line {
    flex-wrap: wrap;
  }

  /* Tapping a row is the primary way to pick a template on a phone, so it
     gets a thumb-sized target. */
  .nb-cw-tpl {
    padding: 9px 8px 9px 16px;
  }

  .nb-cw-inp {
    min-width: 120px;
  }

  /* 16px keeps iOS Safari from zooming the page in when a field takes focus */
  .nb-input,
  .nb-cw-inp {
    font-size: 16px;
  }

  .nb-cw-inp.nb-cw-idx {
    width: 60px;
  }
}

/* The `×` is revealed on hover, which touch devices never do — leaving an
   invisible but tappable delete target over every cell. */
@media (hover: none) {
  .nb-del {
    display: none;
  }
}
