.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.6rem 16px;
  background: var(--desk);
  border-bottom: 1px solid #000;
}

.toolbar__brand {
  font: 800 1.3rem var(--font-ui);
  letter-spacing: -0.02em;
  color: var(--brass);
  text-decoration: none;
}

.toolbar__title {
  flex: 1 1 8rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

/* What Enter and Tab will do where you're writing, centered in the bar between the title and
   the tabs. On narrow screens it takes a row of its own under them. */
.toolbar__hint {
  order: 1;
  flex: 1 0 100%;
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  min-width: 0;
  margin: 0;
  color: var(--chrome-muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.toolbar__hint > * { overflow: hidden; text-overflow: ellipsis; }
.toolbar__hint-text--settled { opacity: 0; transition: opacity 0.3s; }
.toolbar:hover .toolbar__hint-text--settled { opacity: 1; }

@media (min-width: 64rem) {
  .toolbar:has(.toolbar__hint) .toolbar__title { flex: 0 1 auto; max-width: min(28rem, 40%); }
  .toolbar__hint { order: 0; flex: 1 1 0; }
}

.toolbar__status:empty { display: none; }
.toolbar__status { flex-shrink: 0; color: var(--chrome); }

.toolbar__tabs, .toolbar__options, .toolbar__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

/* Menus that drop down from a button. The script's ☰ menu always does; on phones the views and
   the desk's menus do too. Elsewhere those show inline. */
.bar-menu[popover] { position: static; inset: auto; margin: 0; padding: 0; border: 0; overflow: visible; background: none; color: inherit; }

.bar-menu__button {
  display: none;
  align-items: center;
  gap: 0.3em;
  padding: 0.3em 0.5em;
  border: 0;
  border-radius: 6px;
  background: var(--desk-light);
  color: var(--chrome);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}

.toolbar .bar-menu__button--more { display: inline-flex; }
.bar-menu__button--more { font-size: 1.1rem; }
.toolbar__actions[popover]:not(:popover-open) { display: none; }

/* Only as tall as its rows, and it scrolls if they outgrow the screen. */
.bar-menu[popover]:popover-open {
  position: fixed;
  inset: auto;
  top: calc(var(--toolbar-height, 3rem) - 0.25rem);
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0.15rem;
  width: max-content;
  height: auto;
  max-height: calc(100dvh - var(--toolbar-height, 3rem) - 1rem);
  margin: 0;
  padding: 0.3rem;
  overflow-y: auto;
  border: 1px solid #000;
  border-radius: 8px;
  background: var(--desk-light);
  color: var(--chrome);
  box-shadow: var(--shadow-menu);
  font-size: 0.9rem;
}

.bar-menu:popover-open :is(a, .button, summary) {
  display: flex;
  justify-content: flex-start;
  width: 100%;
  padding: 0.45em 0.75em;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--chrome);
  font: inherit;
  text-align: left;
  text-decoration: none;
}

.bar-menu:popover-open :is(a, .button, summary):is(:hover, :active) { background: var(--desk); }
.bar-menu:popover-open form { display: block; }
.bar-menu:popover-open .menu__items { position: static; display: flex; flex-direction: column; min-width: 0; margin: 0 0 0 0.75rem; padding: 0; background: none; box-shadow: none; }
.bar-menu:popover-open .menu[open] summary { color: var(--chrome-muted); }
.toolbar__actions.bar-menu:popover-open { right: 16px; }
.toolbar__page-actions { display: flex; align-items: center; gap: 0.5rem; }
.toolbar__page-actions--menu { display: none; }
.toolbar__home { display: none; }
.toolbar__actions .toolbar__home { display: flex; }

@media (max-width: 40rem) {
  .bar-menu__button { display: inline-flex; }
  .bar-menu[popover]:not(:popover-open) { display: none; }

  .toolbar { gap: 0.4rem; padding-inline: 12px; }
  .toolbar__brand, .toolbar__title { display: none; }
  .toolbar__options { flex-wrap: nowrap; margin-right: auto; font-size: 0.8rem; }
  .toolbar__options .button { padding: 0.35em 0.55em; font-size: inherit; }
  .toolbar__page-actions { display: none; }
  .toolbar__page-actions--menu { display: flex; flex-direction: column; align-items: stretch; gap: 0.15rem; }

  .toolbar__tabs.bar-menu:popover-open { left: 12px; }
  .toolbar__tabs > .toolbar__tab--current { display: none; }
  .toolbar__actions.bar-menu:popover-open { right: 12px; }
}

.toolbar__tab {
  padding: 0.3em 0.7em;
  border-radius: 6px;
  color: var(--chrome-muted);
  text-decoration: none;
}

.toolbar__tab--current { background: var(--desk-light); color: var(--chrome); }

.switch {
  display: inline-flex;
  border: 2px solid var(--chrome-muted);
  border-radius: 6px;
  overflow: hidden;
}

.switch__option {
  padding: 0.3em 0.7em;
  border: 0;
  background: transparent;
  color: var(--chrome-muted);
  font: inherit;
  cursor: pointer;
}

.switch__option[aria-pressed="true"] { background: var(--chrome); color: var(--desk); }
.switch__option:disabled { opacity: 0.35; cursor: default; }
.toolbar__history { font-size: 1.05em; line-height: 1; }
.toolbar__history:disabled { opacity: 0.35; cursor: default; }

.paper-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

.switch--width { align-items: center; }
.switch--width .switch__option { padding-inline: 0.6em; font-weight: 700; }
.switch__label { color: var(--chrome-muted); font-size: 0.85em; }

/* A phone's screen is narrower than the standard page, so there's no wider to go. */
@media (max-width: 40rem) { .switch--width { display: none; } }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }

.menu__items {
  position: absolute;
  right: 0;
  top: calc(100% + 0.3rem);
  z-index: 11;
  display: grid;
  min-width: 13rem;
  padding: 0.3rem;
  border-radius: 6px;
  background: var(--chrome);
  box-shadow: var(--shadow-menu);
}

.menu__items a {
  padding: 0.5em 0.7em;
  border-radius: 4px;
  color: var(--desk);
  text-decoration: none;
}

.menu__items a:hover { background: var(--chrome-muted); }

/* Write or Produce. Writing is handwritten on the legal pad; Produce is typed, edged in the
   current revision's color once a production is sending out revisions. */
.modes {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid #000;
  border-radius: 999px;
  background: var(--desk-light);
}

.modes a {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  min-height: 2rem;
  padding: 0 0.9em;
  border-radius: 999px;
  color: var(--chrome-muted);
  text-decoration: none;
}

.modes a:hover { color: var(--chrome); }
.modes__write { font: 700 1.05rem var(--font-hand); }
.modes__produce { font: 700 0.8rem var(--font-typed); letter-spacing: 0.12em; text-transform: uppercase; }
.modes__write[aria-current] { background: var(--pad-yellow); color: var(--ink); }
.modes__produce[aria-current] { background: var(--typed-paper); color: var(--typed-ink); box-shadow: inset 0 -3px 0 var(--revision-color, transparent); }
.modes__revision { width: 0.6rem; height: 0.6rem; border: 1px solid rgb(0 0 0 / 0.45); border-radius: 50%; background: var(--revision-color); }

/* On wider screens the switch moves between the sides; on phones the other side is one of the views in the dropdown instead. */
@media (min-width: 40.01rem) {
  .toolbar__tab--other-side { display: none; }
}

@media (max-width: 40rem) {
  .modes { display: none; }
  .desk-header .modes { display: inline-flex; }
}

/* The View menu: how the paper looks. */
.view-menu .menu__items {
  left: 0;
  right: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.6rem;
  min-width: max-content;
  padding: 0.75rem;
  border: 1px solid #000;
  background: var(--desk-light);
}

/* The bar stays quiet so the page gets the attention: tools are plain words until hovered, and only
   the page's main action (New card) is filled in. A thin line separates where you are from what you can do. */
/* On the Writer side the bar is a mahogany rail with a brass inlay along its foot. */
.toolbar { padding-block: 0.45rem; background: linear-gradient(var(--mahogany), var(--mahogany-deep)); border-bottom: 2px solid #120a06; box-shadow: inset 0 -1px 0 var(--brass-line); }
.toolbar__brand { line-height: 1; }
.toolbar__title { font-size: 0.95rem; font-weight: 400; color: var(--chrome-muted); }
.toolbar__hint { font-size: 0.8rem; opacity: 0.85; }

.toolbar .button--quiet {
  padding: 0.35em 0.65em;
  border: 0;
  background: transparent;
  color: var(--chrome);
  font-size: 0.95rem;
  font-weight: 500;
}

.toolbar .button--quiet:hover:not(:disabled), .toolbar .menu[open] > summary.button--quiet { background: var(--desk-light); filter: none; }

.toolbar__tab { padding: 0.35em 0.15em; margin-inline: 0.45em; border-radius: 0; font-size: 0.95rem; font-weight: 500; }
.toolbar__tab:hover { color: var(--chrome); }
.toolbar__tab--current { background: none; box-shadow: inset 0 -2px 0 var(--brass); }

.toolbar__options, .toolbar__page-actions { gap: 0.15rem; }

@media (min-width: 40.01rem) {
  .toolbar__options { padding-left: 0.75rem; border-left: 1px solid var(--chrome-rule); }
}

.toolbar .toolbar__history { display: inline-flex; padding: 0.4em; }
.toolbar__history svg, .bar-menu__button--more svg { display: block; width: 1.05rem; height: 1.05rem; }
.toolbar__history:disabled { opacity: 0.3; }

.toolbar .bar-menu__button { background: transparent; }
.toolbar .bar-menu__button:hover, .toolbar .bar-menu__button:has(+ :popover-open) { background: var(--desk-light); }
.toolbar .bar-menu__button--more { padding: 0.4em; }

/* Menus read as grouped rows, with their keys lined up on the right. */
.toolbar__actions.bar-menu:popover-open { min-width: 17rem; padding: 0.4rem; font-size: 0.95rem; }
.bar-menu:popover-open :is(a, .button, summary) { font-weight: 400; }
.bar-menu__label { margin: 0.55rem 0.75rem 0.15rem; color: var(--chrome-muted); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.8; }
.bar-menu__rule { height: 1px; margin: 0.3rem 0.4rem 0; border: 0; background: var(--chrome-rule); }
.bar-menu:popover-open .toolbar__keys { justify-content: space-between; gap: 1.5rem; }
.bar-menu:popover-open .toolbar__keys kbd { margin: 0; }
.bar-menu:popover-open .menu > summary { justify-content: space-between; cursor: pointer; }
.bar-menu:popover-open .menu > summary::after { content: "▸"; color: var(--chrome-muted); font-size: 0.8em; }
.bar-menu:popover-open .menu[open] > summary::after { content: "▾"; }
.bar-menu:popover-open .menu__items { margin: 0 0 0.2rem 0.5rem; padding-left: 0.25rem; border-left: 1px solid var(--chrome-rule); border-radius: 0; }

/* The View menu is a small settings card: a label on the left, its control on the right. */
.view-menu .menu__items {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.35rem 1.25rem;
  width: 19rem;
  min-width: 0;
  padding: 0.6rem;
  border-radius: 8px;
  font-size: 0.95rem;
}

.view-menu__label { padding-left: 0.65em; color: var(--chrome-muted); }
.view-menu .menu__items > :is(.button, .view-menu__count) { grid-column: 1 / -1; }
.view-menu .view-menu__focus, .view-menu .view-menu__sprint, .view-menu .view-menu__checks { justify-content: space-between; width: 100%; padding-block: 0.5em; }
.view-menu__rule { grid-column: 1 / -1; width: 100%; height: 1px; margin: 0.15rem 0; border: 0; background: var(--chrome-rule); }
.view-menu .switch { border-width: 1px; border-color: color-mix(in srgb, var(--chrome) 25%, transparent); }
.view-menu .switch__option { padding-block: 0.25em; }
.view-menu__checks::after { color: var(--chrome-muted); }
.view-menu__hint { color: var(--chrome-muted); font-size: 0.85em; }
.view-menu__checks[aria-pressed="true"]::after { color: var(--accent); }
/* On Read it as a reader the writing tools stay in their places, greyed, with the way back above them. */
.view-menu__waiting-note { grid-column: 1 / -1; margin: 0; padding-left: 0.65em; color: var(--chrome-muted); font-size: 0.85em; }
.view-menu .view-menu__waiting:disabled { opacity: 0.4; cursor: default; }

@media (max-width: 40rem) { .view-menu__label--width { display: none; } }

/* Every menu that drops from the bar is the same dark card, however it's built. */
.toolbar .menu__items { padding: 0.4rem; border: 1px solid #000; border-radius: 8px; background: var(--desk-light); color: var(--chrome); box-shadow: var(--shadow-menu); font-size: 0.95rem; }
.toolbar .menu__items a, .toolbar :is(.yarn-menu__choice, .yarn-menu__empty, .structure-menu__choice) { color: var(--chrome); }
.toolbar .yarn-menu__tip { color: var(--chrome-muted); }
.toolbar .menu__items a:hover, .toolbar :is(.yarn-menu__choice, .structure-menu__choice):hover { background: var(--desk); }
.toolbar :is(.structure-menu__heading, .structure-menu__count, .structure-menu__author, .structure-menu__credit) { color: var(--chrome-muted); }
.toolbar .structure-menu__rule { border-top-color: var(--chrome-rule); }

/* Hung from the View button's right edge so it stays on the screen; a phone's button sits further left. */
@media (min-width: 40.01rem) { .view-menu .menu__items { left: auto; right: 0; } }
@media (max-width: 40rem) { .view-menu .menu__items { width: 17rem; } }
.view-menu .switch { justify-self: end; }
.toolbar .structure-menu__items { left: auto; right: 0; width: max-content; max-width: min(24rem, calc(100vw - 2rem)); }

/* The Producer bar has six: Top sheet, Script ▾, Schedule ▾, Reports, Crew and On set. A group hangs its
   views under its button; the one you're on is marked in it. */
.toolbar--produce .toolbar__title { flex-basis: 0; }
.toolbar__tab--group { display: inline-flex; align-items: center; gap: 0.3em; border: 0; background: none; font: inherit; cursor: pointer; }
.toolbar__tab--group span { font-size: 0.75em; }
.toolbar__tab--group:has(+ :popover-open) { background: var(--desk-light); color: var(--chrome); }
.toolbar__group-name { display: none; }
.toolbar__group[popover]:not(:popover-open) { display: none; }
.toolbar__group.bar-menu:popover-open { min-width: 13rem; overflow-x: hidden; }
.toolbar__group .toolbar__tab, .toolbar__tabs:popover-open .toolbar__tab { box-sizing: border-box; margin-inline: 0; }
.toolbar__group.bar-menu:popover-open .toolbar__tab--current { background: var(--desk); color: var(--chrome); font-weight: 700; }

/* Folded into the one dropdown (phones, and narrow tablets): each group is listed in place under its name. */
.toolbar__tabs:popover-open .toolbar__tab--group { display: none; }
.toolbar__tabs:popover-open .toolbar__group[popover] { position: static; display: flex; flex-direction: column; gap: 0.15rem; max-height: none; padding: 0; border: 0; background: none; box-shadow: none; }
.toolbar__tabs:popover-open .toolbar__group-name { display: block; margin: 0.4rem 0 0.1rem; padding: 0 0.75em; color: var(--chrome-muted); font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.toolbar__tabs:popover-open .toolbar__group .toolbar__tab { padding-left: 1.25em; }
.toolbar__tabs:popover-open .toolbar__group .toolbar__tab--current { display: flex; background: var(--desk); color: var(--chrome); font-weight: 700; }

/* Below a laptop the six don't fit beside the title, so they fold into the view dropdown the phone uses,
   while the Writer/Producer switch and the menu stay on the bar. */
@media (min-width: 40.01rem) and (max-width: 56rem) {
  .toolbar--produce .bar-menu__button:not(.bar-menu__button--more) { display: inline-flex; }
  .toolbar--produce .toolbar__tabs[popover]:not(:popover-open) { display: none; }
  .toolbar--produce .toolbar__tabs.bar-menu:popover-open { left: auto; right: 4rem; }
  .toolbar--produce .toolbar__tabs .toolbar__tab--other-side { display: none; }
  .toolbar--produce .toolbar__tabs .toolbar__tab { margin-inline: 0; }
  .toolbar--produce .toolbar__tabs > .toolbar__tab--current { display: none; }
  .toolbar--produce .toolbar__title { flex-basis: 8rem; }
}

/* Where you are, quietly: the page and scene take the hint's place once writing has started, and the hint comes
   back while the pointer is on the bar. */
.toolbar__position { display: none; font-variant-numeric: tabular-nums; }
.script--placed .toolbar__position:not(:empty) { display: inline; }
.script--placed .toolbar__hint-text { display: none; }
.script--placed .toolbar:hover .toolbar__hint-text { display: inline; }
.script--placed .toolbar:hover .toolbar__position { display: none; }
.toolbar__status:not(:empty)::before { content: "· "; }

/* Things that go together on the bar, like Flip all cards and Flip board. */
.toolbar__group { display: inline-flex; align-items: center; gap: 0.1rem; padding: 0 0.15rem; border-inline: 1px solid var(--chrome-rule); }
.toolbar__page-actions:not(.toolbar__page-actions--menu) .flip-board--menu { display: none; }
@media (max-width: 40rem) { .toolbar__group { border: 0; padding: 0; } .flip-board--bar { display: none; } }
