/* Focus mode: the words and nothing else. The bar and scrollbar leave the screen, which becomes all
   page, scaled up so every line still breaks where it does on the standard page. The bar comes back
   while the pointer is at the top edge, a key is pressed in it, or a finger pulls the page down. The
   words stay black but for the top and bottom three lines of the screen, which go grey as they scroll
   under the bands, and there's room under the last line for it to ride up to the typing line. */
.focus-edge, .focus-band { display: none; }

html.focus-mode { scrollbar-width: none; }
html.focus-mode::-webkit-scrollbar { display: none; }

.focus-mode .focus-edge {
  display: block;
  position: fixed;
  inset: 0 0 auto;
  z-index: 11;
  height: 0.75rem;
}

.focus-mode .toolbar {
  position: fixed;
  inset: 0 0 auto;
  transform: translateY(-100%);
  transition: transform 0.2s ease-out;
}

.focus-mode .toolbar:is(.toolbar--peek, :focus-within, :has(:popover-open, details[open])) { transform: none; }

.focus-mode .toolbar__hint { display: none; }

.focus-mode .desk { padding: 0; }

.focus-mode .paper {
  --paper-scale: 99 !important;
  padding-bottom: 60vh;
  box-shadow: none;
}

/* Just the words: no comments, plotline tabs, cast lists, card notes or margin checks. */
.focus-mode :is(.comment-layer, .check-layer, .scene .plotlines, .scene__cast, .scene__notes) { display: none !important; }

/* The page is the whole screen, so a margin note (today's pages) sits at its right edge rather than off it. */
.focus-mode .margin-note { left: auto; right: 1.5rem; width: auto; max-width: 13rem; }

/* Grey bands over the top and bottom of the screen, blended so they only reach the ink: "lighten"
   lifts dark type to the band's grey and leaves the paper and its rules, which are lighter, alone.
   They're fixed and the words scroll under them, so whatever nears an edge goes grey, whichever scene
   it's in. The whole screen is paper here, so there's no desk for them to tint. Each is
   three lines tall, two grey and one fading: the page is as wide as the screen, so
   these work out a line's height from the screen's width, matching .paper--typed and .paper--pad. */
.focus-mode .focus-band {
  display: block;
  position: fixed;
  inset-inline: 0;
  z-index: 8;
  height: calc(var(--focus-line) * 3);
  background: #9a9a90;
  mix-blend-mode: lighten;
  pointer-events: none;
}

.focus-mode:has(.paper--typed) .focus-band { --focus-line: calc(100vw / 51); }
.focus-mode:has(.paper--pad) .focus-band { --focus-line: max(2rem, 100vw / 26); }

/* Night's typed page is dark with light ink, so the bands work the other way: "darken" brings the ink
   down to a dim warm grey and leaves the darker page and its rules alone. The legal pad stays yellow
   at night, so it keeps the day's bands. */
html[data-theme="night"].focus-mode:has(.paper--typed) .focus-band {
  background: #6e675c;
  mix-blend-mode: darken;
}

.focus-band--top { top: 0; mask-image: linear-gradient(to bottom, #000 67%, transparent); }
.focus-band--bottom { bottom: 0; mask-image: linear-gradient(to top, #000 67%, transparent); }

/* The way out, on the bar only while focusing. */
.toolbar__leave-focus { display: none; }
.focus-mode .toolbar__leave-focus { display: inline-block; }
.toolbar__leave-focus-short { display: none; }

/* A phone's bar is one line, so the way out says less there, and the ☰ menu waits till you're back. */
@media (max-width: 40rem) {
  .focus-mode .toolbar .bar-menu__button--more { display: none; }
  .toolbar__leave-focus-long { display: none; }
  .toolbar__leave-focus-short { display: inline; }
}

@media (prefers-reduced-motion: reduce) {
  .focus-mode .toolbar { transition: none; }
}

/* The count in the View menu: the scene and page, the words, and today's against a goal. */
.view-menu__count {
  display: grid;
  gap: 0.15rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgb(255 255 255 / 0.12);
  color: var(--chrome-muted);
  font: 0.8rem/1.4 var(--font-ui);
}

.view-menu__count[hidden] { display: none; }
.view-menu__count p { margin: 0; }

.view-menu__today {
  justify-self: start;
  padding: 0.2rem 0;
  border: 0;
  background-color: transparent;
  background-image: linear-gradient(var(--accent), var(--accent));
  background-size: calc(var(--progress, 0) * 100%) 2px;
  background-position: left bottom;
  background-repeat: no-repeat;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.view-menu__today--met { color: var(--accent); font-weight: 700; }

.view-menu__goal { display: flex; align-items: center; gap: 0.5rem; }
.view-menu__goal[hidden] { display: none; }
.view-menu__goal input { width: 6rem; margin-left: 0.4rem; font: inherit; }

.toolbar__leave-focus kbd, .view-menu__focus kbd {
  margin-left: 0.4em;
  font: inherit;
  font-size: 0.85em;
  opacity: 0.7;
}

/* A finger has no Escape key. */
@media (hover: none) {
  .toolbar__leave-focus kbd { display: none; }
}

@media print {
  .focus-edge, .focus-band { display: none !important; }
}
