/* Tab text.
 *
 * A guitar tab is fixed-width ASCII art whose meaning is entirely positional:
 * `white-space: pre` and a monospace family are what keep a note over the beat
 * it belongs to. Wrapping is never acceptable, so long lines scroll sideways
 * inside their own box rather than reflowing or pushing the page wide. */
.tab-block,
.tab,
.tab-input {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "DejaVu Sans Mono", monospace;
  white-space: pre;
  tab-size: 4;
}

.tab-block {
  overflow-x: auto;
  margin: 0;
  padding: 0.75rem;
  background: var(--bs-tertiary-bg);
  border-radius: 0.375rem;
  line-height: 1.35;
}

.tab-input {
  overflow-x: auto;
}

/* Tab pages -- the same content as .tab-block, recorded as a photograph or a
 * scan instead of as characters.
 *
 * The reasoning above still applies and is if anything simpler here: an image
 * of a tab must never be squeezed to fit a column, because unlike text it
 * cannot reflow, it can only distort. So it scales to the available width and
 * keeps its aspect ratio, and that is the whole rule. */
.tab-page {
  margin: 0 0 0.75rem;
}

.tab-page img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 0.375rem;
  background: var(--bs-tertiary-bg);
}

.tab-page figcaption {
  padding-top: 0.25rem;
  font-size: 0.875rem;
  color: var(--bs-secondary-color);
}

/* One page in the editing form: thumbnail, reorder arrows, delete checkbox. */
.tab-page-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border: 1px solid var(--bs-border-color);
  border-radius: 0.375rem;
  margin-bottom: 0.5rem;
}

.tab-page-thumb {
  width: 5rem;
  height: 5rem;
  /* `contain`, not `cover`: a thumbnail of a tab that has been cropped to a
   * square is a thumbnail of six horizontal lines, identical to every other
   * one. Letterboxing is what makes two pages tellable apart at this size. */
  object-fit: contain;
  background: var(--bs-tertiary-bg);
  border-radius: 0.25rem;
}

.tab-page-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* The camera button, and the photos taken but not yet saved.
 *
 * Hidden unless the pointer is coarse, which is the closest thing to "this is a
 * device you can point at a sheet of paper". A desktop browser ignores
 * `capture` entirely, so the button there would open the very same file dialog
 * as the picker two centimetres above it, under a label saying it takes a
 * photo. `display: none` rather than a visibility trick because that also takes
 * the input out of the tab order, and an invisible control a keyboard can still
 * reach is worse than no control at all. */
.tab-camera {
  display: none;
}

@media (pointer: coarse) {
  .tab-camera {
    display: block;
  }
}

/* Both file inputs are visually hidden and their labels are what is seen, so
 * the focus ring has to be moved across by hand or a keyboard lands on
 * nothing. */
.tab-camera input:focus-visible + label,
.tab-picker input:focus-visible + label {
  box-shadow: 0 0 0 0.25rem var(--bs-focus-ring-color, rgba(13, 110, 253, 0.25));
}

/* A row of the section formset that is checked for deletion. Kept in the DOM
 * and still submitted -- the checkbox is how the deletion is recorded -- but
 * visibly out of the way. Page rows behave the same way one level down. */
.section-form.is-deleted,
.tab-page-row.is-deleted {
  opacity: 0.45;
}

/* --- Reading mode -------------------------------------------------------
 *
 * A separate layout, not a variation on the app's: this page is read from a
 * music stand at arm's length. The whole viewport is the tab except for one
 * compact bar. `dvh` rather than `vh` because mobile browsers shrink the
 * visual viewport when their own chrome appears, and `100vh` would leave the
 * last line under it. */
body.reading {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  color: #111;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.reading-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0.75rem;
  padding-left: max(0.75rem, env(safe-area-inset-left));
  padding-right: max(0.75rem, env(safe-area-inset-right));
  border-bottom: 1px solid #ddd;
  font-size: 0.85rem;
}

.reading-back {
  text-decoration: none;
  font-size: 1.25rem;
  line-height: 1;
  color: inherit;
}

.reading-heading {
  min-width: 0;
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}

.reading-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reading-subtitle,
.reading-indicator {
  color: #666;
  white-space: nowrap;
}

.reading-indicator {
  margin-left: auto;
}

.reading-controls {
  display: flex;
  gap: 0.25rem;
}

.reading-controls button {
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 0.25rem;
  padding: 0.15rem 0.5rem;
  font: inherit;
  cursor: pointer;
  /* Comfortably hittable with a finger you have just taken off the strings. */
  min-width: 2.5rem;
  min-height: 2rem;
}

#reading-sections {
  flex: 1 1 auto;
  overflow-y: auto;
  /* One section per screenful. `proximity` rather than `mandatory`: mandatory
   * fights you when a section is taller than the viewport and you are trying
   * to scroll to the middle of it. */
  scroll-snap-type: y proximity;
}

.reading-section {
  scroll-snap-align: start;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0 1.5rem;
  border-bottom: 1px solid #eee;
}

.reading-section-head {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  padding: 0 0.75rem 0.35rem;
  font-size: 0.8rem;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.reading-warning {
  color: #8a5300;
  text-transform: none;
  letter-spacing: 0;
}

.reading .tab {
  flex: 1 1 auto;
  margin: 0;
  padding: 0 0.75rem;
  overflow-x: auto;
  overflow-y: hidden;
  line-height: 1.4;
  /* Set by static/js/reading.js, which measures the longest line and picks the
   * largest size that fits. The value here is only what shows before the
   * script runs. */
  font-size: 16px;
}

/* One scanned page, filling the screenful the way a typed tab does.
 *
 * `min-height: 0` is load-bearing rather than decorative: a flex item defaults
 * to `min-height: auto` and so refuses to shrink below its content, which for
 * an image zoomed past the viewport means the box grows instead of scrolling
 * and the reading bar is pushed off the top of the screen.
 *
 * The width is set by static/js/reading.js from the same multiplier the text
 * size uses. The rule here is only what applies before the script runs. */
.reading-page {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0 0.75rem;
}

/* Plain block layout with `margin: 0 auto`, deliberately not flex centring.
 * An auto margin resolves to zero when there is no free space, so a page
 * zoomed wider than its box lands hard against the left edge and every pixel
 * of it can be scrolled to. Flexbox centring (and `text-align: center`) put
 * the overflow on *both* sides instead, and the half that goes off the left is
 * unreachable -- you can scroll right, never left of the start.
 *
 * No `max-width: 100%` for the same reason: the whole point of the + button on
 * a scan is to grow it past the viewport. */
.reading-image {
  display: block;
  margin: 0 auto;
  height: auto;
}

@media print {
  .reading-bar,
  .reading-controls {
    display: none;
  }
  body.reading {
    height: auto;
    overflow: visible;
  }
}
