/*
 * Code on the page, and what it makes. Code is typed like everything else,
 * set off by a rule in the margin, with a two-colour ribbon: black for the
 * words, red for Ruby's own. Charts and tables take the page's face, so
 * they're typescript in a draft and print on the shelf.
 * Also inlined into PDFs (layouts/print), which define the same colours.
 */

/* Code, typed in the editor (code) and on the page (pre) */

/* Specific enough to beat Lexxy's own code styles, which scroll long lines:
 * on a page they wrap, so the layout never moves under the marks. */
.page__body pre,
.page__body .lexxy-editor__content code[data-language] {
  display: block;
  margin: 0 0 1.6em;
  padding: 0.1em 0 0.1em 2ch;
  border: 0;
  border-left: 2px solid var(--rule);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.86em;
  line-height: 1.55;
  tab-size: 2;
  white-space: pre-wrap;
  text-wrap: wrap;
  overflow: visible;
  overflow-wrap: anywhere;
}

/* No language to pick: code on the page is Ruby, and says so, quietly,
 * just above the block, in the space before it. */
.page lexxy-code-language-picker {
  display: none;
}

.page__body pre,
.page__body .lexxy-editor__content code[data-language] {
  position: relative;
}

.page__body pre::before,
.page__body .lexxy-editor__content code[data-language]::before {
  content: "Ruby";
  position: absolute;
  bottom: 100%;
  left: 2ch;
  color: var(--ink-faint);
  font-size: 0.78em;
  line-height: 1.7;
  letter-spacing: 0.04em;
  opacity: 0.8;
  pointer-events: none;
  user-select: none;
}

.page__body code[data-language] {
  .code-token__attr,
  .code-token__function {
    color: var(--red);
  }

  .code-token__property,
  .code-token__selector,
  .code-token__variable {
    color: var(--ink);
  }

  .code-token__comment {
    color: var(--ink-faint);
    font-style: italic;
  }

  .code-token__operator,
  .code-token__punctuation {
    color: var(--ink-soft);
  }
}

/* What a block made */

.notebook {
  margin: -0.6em 0 1.6em;

  > :last-child {
    margin-bottom: 0;
  }
}

.notebook__printed {
  margin: 0 0 0.8em;
  padding: 0 0 0 2ch;
  border-left: 2px dotted var(--rule);
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 0.86em;
  white-space: pre-wrap;
}

.notebook__value {
  margin: 0;
  color: var(--ink-faint);
  font-size: 0.86em;
}

.notebook__error {
  margin: 0;
  padding-left: 2ch;
  border-left: 2px solid var(--red);
  color: var(--red);
  font-size: 0.86em;
  white-space: pre-wrap;
}

/* Figures: charts and tables */

.figure {
  margin: 0 0 1.6em;
  padding: 0;
  break-inside: avoid;
}

.figure + .figure {
  margin-top: 1.2em;
}

.figure__header {
  margin-bottom: 0.4em;
}

.figure__title {
  margin: 0;
  font-weight: 700;
}

.figure__subtitle {
  margin: 0;
  color: var(--ink-soft);
}

.figure__chart {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  font-family: inherit;
}

.figure__caption {
  margin-top: 0.5em;
  color: var(--ink-soft);
  font-size: 0.9em;
  line-height: 1.5;
}

.figure__number {
  color: var(--ink);
  font-weight: 700;
}

.figure__source {
  margin: 0.2em 0 0;
  color: var(--ink-faint);
  font-size: 0.82em;
}

.figure__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;

  th,
  td {
    padding: 0.25em 0.8em 0.25em 0;
    text-align: left;
    vertical-align: baseline;
  }

  th {
    border-bottom: 1.5px solid var(--ink);
    font-weight: 700;
  }

  tbody tr:last-child td {
    border-bottom: 1.5px solid var(--ink);
  }

  .figure__numeric {
    padding-right: 0;
    padding-left: 0.8em;
    text-align: right;
  }
}

/* While typing: what each code block makes floats under it, in a layer the
 * editor doesn't own. Room is made for it below the block (see
 * notebook_controller.js). */

.typewriter .page__body {
  position: relative;
}

.notebook-layer {
  position: absolute;
  inset: 0 0 auto;
  pointer-events: none;
}

.notebook-layer__block {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: auto;
  transition: opacity 300ms var(--ease, ease);

  &[data-stale] {
    opacity: 0.45;
  }
}

.notebook-layer__offline {
  margin: 0;
  color: var(--ink-faint);
  font-size: 0.86em;
}

/* A file dragged over the page, to be read as data. */
.typewriter--dropping .page {
  outline: 2px dashed var(--ink-faint);
  outline-offset: -1.5cqi;
}

/* Data */

.data-files__hint {
  margin: -1.5rem 0 2rem;
  color: var(--ink-soft);
  font-family: var(--book);
}

.data-files__code {
  font-family: var(--typescript);
  font-size: 0.9rem;
}

/* The chart guide: a panel beside the page while typing, or a page of its own. */

.guide-panel {
  position: fixed;
  z-index: 4;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: min(420px, 100vw);
  background: var(--paper);
  box-shadow: -1px 0 0 var(--rule), -12px 0 32px -16px rgb(60 50 30 / 0.3);

  &[hidden] {
    display: none;
  }
}

.guide-panel__header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--rule);
}

.guide-panel__title {
  flex: 1;
  margin: 0;
  font-family: var(--typescript);
  font-weight: 700;
}

.guide-panel__link {
  color: var(--ink-faint);
  font-size: 0.85rem;
}

.guide-panel__close {
  padding: 0 0.25rem;
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;

  &:hover {
    color: var(--ink);
  }
}

.guide-panel__body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.5rem 1.25rem 3rem;
}

/* On a wide screen the page moves over, so both can be seen at once. */
@media (min-width: 1250px) {
  .guide-open .main {
    padding-right: calc(420px + 1.5rem);
  }

  .guide-open .tray {
    display: none;
  }
}

.guide-page {
  max-width: 640px;
  margin: 3rem auto 0;
}

.guide {
  font-size: 0.92rem;
  line-height: 1.55;

  code,
  kbd {
    font-family: var(--typescript);
    font-size: 0.92em;
  }
}

.guide__section {
  padding: 1rem 0 0.5rem;

  & + & {
    border-top: 1px solid var(--rule);
  }
}

.guide__heading {
  margin: 0.5rem 0 0.75rem;
  font-family: var(--typescript);
  font-size: 1rem;
}

.guide__subheading {
  margin: 1.25rem 0 0.4rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.guide__text {
  margin: 0 0 0.75rem;
  color: var(--ink-soft);
}

.guide__example {
  margin: 0 0 1.5rem;
}

.guide__example-title {
  margin: 0 0 0.15rem;
  font-weight: 600;
}

.guide__code {
  margin: 0 0 0.5rem;
  padding: 0.6rem 0 0.6rem 1.5ch;
  border-left: 2px solid var(--rule);
  font-family: var(--typescript);
  font-size: 0.82rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.guide__insert {
  padding: 0.2em 0.8em;
  border: 1px solid color-mix(in srgb, var(--ink) 20%, transparent);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;

  &:hover {
    color: var(--ink);
    background: color-mix(in srgb, var(--ink) 6%, transparent);
  }
}

.guide__settings {
  margin: 0;
}

.guide__setting {
  display: grid;
  grid-template-columns: 9.5rem 1fr;
  gap: 0.75rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--rule) 60%, transparent);

  dt {
    color: var(--red);
  }

  dd {
    margin: 0;
    color: var(--ink-soft);
  }
}

.guide__inline-example {
  display: block;
  margin-top: 0.15rem;
  color: var(--ink);
}

.guide__colors {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: 0.4rem 1rem;
  margin: 0 0 0.75rem;
  padding: 0;
  list-style: none;

  li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }
}

.guide__swatch {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
}
