/* Tutti design system: the tokens and the components the site and the score viewer share. The one stylesheet
   both load first (site pages before styles.css; the viewer bundles it before its own styles), so a component looks the
   same wherever it appears. What each token and component is for, and when not to use it: DESIGN.md.
   Only class-scoped rules beyond the tokens, so it sits next to either app's own styles. */

:root {
  --myrtle-deep: #173a33;
  --myrtle: #2b5a4f;
  --myrtle-line: #3f7264;
  --leaf: #a3bfae;
  --paper: #f5f6ef;
  --vellum: #eceee3;
  --vellum-deep: #dfe3d4;
  --ink: #1a2521;
  --ink-soft: #4a5a53;
  --brass: #c9a34e;
  --brass-deep: #8a6a22;
  --rubric: #9e3b32;
  --sheet: #fffffb;
  --line: #d3d8c8;
  --line-soft: #e3e6da;
  --ink-faint: #7f8c85;
  --accent-soft: rgba(43, 90, 79, 0.1);

  --serif: "Alegreya", Georgia, "Times New Roman", serif;
  --sans: "Alegreya Sans", "Gill Sans", "Segoe UI", sans-serif;

  /* type scale, 18px body, roughly a fourth */
  --t-small: 0.875rem;
  --t-body: 1.125rem;
  --t-lead: 1.3125rem;
  --t-h3: 1.375rem;
  --t-h2: 2rem;
  --t-h1: clamp(2.75rem, 1.6rem + 2.8vw, 4rem);

  --gutter: clamp(20px, 4vw, 64px);
  --radius-s: 3px;
  --radius-m: 6px;
  --focus: 0 0 0 3px var(--vellum), 0 0 0 5px var(--brass-deep);
  --shadow-float: 0 12px 32px rgba(23, 58, 51, 0.18), 0 2px 6px rgba(23, 58, 51, 0.1);
}

/* The masthead sets its own type, so it reads the same inside a page with another body size. */
.masthead { font-family: var(--sans); font-size: var(--t-body); line-height: 1.5; }
.masthead svg { display: block; }
/* The Worker marks score pages before paint, including older viewer releases. */
body.in-score > .masthead { display: none; }

/* ---------- signed-in toggles ---------- */
/* Signed out unless <html> says otherwise: account-hint.js marks it before the first paint from the last known
   state, account-chrome.js from the page's own state. No hint: signed out, never an empty avatar. */
:root:not([data-signed-in="true"]) [data-when-signed-in],
:root[data-signed-in="true"] [data-when-signed-out] { display: none !important; }
/* Until the real render, the remembered initial and pages reading (account-hint.js); after it, never again,
   whatever the element holds (the render also drops the variables). */
.account-avatar:not([data-rendered]):empty::before { content: var(--hint-initial, ""); }
.nav-quota:not([data-rendered]) .quota-main:empty::before { content: var(--hint-quota-main, ""); }
.nav-quota:not([data-rendered]) .quota-extra:empty::before { content: var(--hint-quota-extra, ""); }
.nav-quota:not([data-rendered]) .quota-fill { width: var(--hint-quota-left, 0%); }
:root:not([data-quota-hint]) .nav-quota:not([data-rendered]),
:root[data-quota-hint="plain"] .nav-quota:not([data-rendered]) .quota-bar { display: none; }
:root[data-quota-hint="empty"] .nav-quota:not([data-rendered]) .quota-main::before { color: var(--brass); }

.link-button {
  background: none; border: 0; padding: 0; cursor: pointer;
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px;
}
.link-button--quiet { color: var(--ink-soft); font-size: 1rem; }
.link-button:hover { text-decoration-thickness: 2px; }

[hidden] { display: none !important; }
.svg-defs { position: absolute; }
.link-button:disabled { cursor: default; }
.account { position: relative; }
.account-menu {
  position: absolute; right: 0; top: calc(100% + 14px); z-index: 30;
  display: flex; flex-direction: column; gap: 14px; min-width: 205px; max-width: calc(100vw - 40px);
  padding: 20px; border-top: 3px solid var(--brass); border-radius: var(--radius-s);
  color: var(--ink); background: var(--vellum); box-shadow: 0 12px 32px rgba(0,0,0,.2);
}
.masthead-nav .account-menu .link-button { text-align: left; color: var(--ink); }
.masthead-nav .account-menu .link-button:hover { color: var(--myrtle-deep); }
.account-email { font-size: 1rem; overflow-wrap: anywhere; color: var(--ink-soft); }

/* ---------- masthead ---------- */
.masthead {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 22px;
  padding: 14px var(--gutter);
  background: var(--myrtle-deep); color: var(--vellum);
  border-bottom: 1px solid rgba(163, 191, 174, 0.18);
}

.brand {
  display: inline-flex; align-items: flex-end; text-decoration: none; color: var(--vellum);
  line-height: 1;
}
.brand-t { width: 30px; height: 33px; fill: var(--brass); margin-right: -1px; }
.brand-rest {
  font-family: var(--serif); font-weight: 500; font-size: 1.75rem; letter-spacing: 0.01em;
  transform: translateY(1px);
}

.masthead-beta {
  font-family: var(--serif); font-style: italic; font-size: 1.0625rem; color: var(--brass);
  padding-left: 22px; border-left: 1px solid rgba(163, 191, 174, 0.3);
}

.masthead-nav { margin-left: auto; display: flex; align-items: center; gap: 26px; font-size: 1.0625rem; }
.masthead-nav a { text-decoration: none; color: var(--leaf); }
.masthead-nav a:hover { color: var(--vellum); }
.masthead--reading { flex-wrap: wrap; }
.masthead--reading .masthead-nav { flex-wrap: wrap; }
.masthead-nav .link-button { text-decoration: none; color: var(--leaf); }
.masthead-nav .link-button:hover { color: var(--vellum); }
.masthead-nav .account-signin {
  color: var(--vellum); border: 1px solid rgba(236, 238, 227, 0.5); border-radius: 999px; padding: 5px 16px;
}
.masthead-nav .account-signin:hover { border-color: var(--vellum); }
.masthead :focus-visible { box-shadow: 0 0 0 2px var(--myrtle-deep), 0 0 0 4px var(--brass); }

.account { display: inline-flex; align-items: center; gap: 12px; }
.account-avatar {
  width: 34px; height: 34px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--brass); color: var(--myrtle-deep); font-family: var(--serif); font-weight: 700; font-size: 1.05rem;
}

/* ---------- pages left (account-chrome.js): this period's pages, a bar, a popover ---------- */
.account-area { display: inline-flex; align-items: center; gap: 18px; }
.nav-quota { position: relative; display: inline-flex; }
.quota-chip {
  display: inline-flex; flex-direction: column; gap: 4px; padding: 3px 2px; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: .9375rem; line-height: 1.1; text-align: left; color: var(--leaf);
}
.quota-reading { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.quota-main { color: var(--vellum); font-variant-numeric: tabular-nums; }
.quota-extra { color: var(--brass); font-size: .8125rem; }
.quota-bar { display: block; height: 3px; border-radius: 2px; background: rgba(236, 238, 227, 0.2); overflow: hidden; }
.quota-fill { display: block; height: 100%; background: var(--leaf); transition: width .3s ease; }
.nav-quota[data-empty="true"] .quota-main { color: var(--brass); }
.quota-chip:hover .quota-main { color: #fff; }
.quota-popover {
  position: absolute; right: 0; top: calc(100% + 12px); z-index: 30; width: 280px; max-width: calc(100vw - 32px);
  display: flex; flex-direction: column; gap: 8px; padding: 16px 18px;
  border-top: 3px solid var(--brass); border-radius: var(--radius-s);
  color: var(--ink); background: var(--vellum); box-shadow: 0 12px 32px rgba(0,0,0,.2); font-size: .9375rem; line-height: 1.4;
  white-space: normal; text-align: left;
}
/* Covers the gap above the panel, so a pointer moving from the button to the panel stays inside. */
.quota-popover::before { content: ''; position: absolute; left: 0; right: 0; top: -15px; height: 15px; }
.account-error { font-size: .9375rem; color: var(--rubric); }
.quota-lines { display: flex; flex-direction: column; gap: 6px; }
.quota-lines p { margin: 0; }
.masthead-nav .quota-popover .quota-link { display: inline-block; align-self: flex-start; color: var(--myrtle); text-decoration: underline; }
.masthead-nav .quota-popover .quota-link:hover { color: var(--myrtle-deep); }

@media (max-width: 860px) {
  .masthead { gap: 14px; }
  .masthead-nav > a { display: none; }
  .masthead-nav { gap: 16px; }
  .masthead--reading .masthead-nav > a { display: inline; }
}

@media (max-width: 560px) {
  .masthead { padding-top: 10px; padding-bottom: 10px; }
  .masthead--reading .masthead-nav { flex-basis: 100%; margin-left: 0; }
  .masthead-beta { font-size: 0.9375rem; padding-left: 12px; }
  .brand-rest { font-size: 1.5rem; }
  .brand-t { width: 26px; height: 29px; }
  .masthead-nav .account-signin { padding: 4px 12px; }
}

@media (max-width: 360px) {
  .account-area { gap: 10px; }
  .quota-extra { display: none; }
  .masthead { gap: 8px; }
  .masthead-beta { padding-left: 8px; font-size: .8125rem; }
  .masthead-nav { gap: 8px; }
  .masthead-nav .account-signin { padding-left: 8px; padding-right: 8px; white-space: nowrap; }
}

/* ---------- buttons ----------
   One pill. Size: the default 48px (pages), --compact 32px and --small 27px (tool bars and panels).
   Light ground: --ink (the step's one main action), --line (secondary), --soft (a tool), --ghost (a quiet tool).
   Dark ground: --brass (the main action), --on-dark (secondary), --ghost-dark (a quiet tool). --on: a toggle that
   is on. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 48px; padding: 0 26px;
  font-family: var(--sans); font-size: 1.0625rem; font-weight: 700; letter-spacing: 0.01em;
  border: 1.5px solid transparent; border-radius: 999px;
  cursor: pointer; text-decoration: none;
  transition: background-color .15s ease, border-color .15s ease;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn--ink { background: var(--myrtle-deep); color: var(--vellum); }
.btn--ink:hover { background: var(--myrtle); }
.btn--line { background: transparent; border-color: var(--ink); color: var(--ink); }
.btn--line:hover { background: var(--vellum-deep); }
.btn--wide { width: 100%; }
.btn--compact, .btn--small { gap: 6px; font-size: .9375rem; font-weight: 500; letter-spacing: 0; white-space: nowrap; }
.btn--compact { min-height: 32px; height: 32px; padding: 0 14px; }
.btn--small { min-height: 27px; height: 27px; padding: 0 10px; font-size: .875rem; }
.btn--compact svg, .btn--small svg { width: auto; height: auto; }
.btn--compact:disabled, .btn--small:disabled { opacity: .45; cursor: default; }
.btn--ink:disabled:hover { background: var(--myrtle-deep); }
.btn--soft { background: var(--sheet); border-color: var(--line); color: var(--ink); }
.btn--soft:hover { border-color: var(--myrtle-line); }
.btn--ghost { background: transparent; color: var(--ink); }
.btn--ghost:hover { background: rgba(23, 58, 51, 0.07); }
.btn--on, .btn--on:hover { background: var(--accent-soft); border-color: rgba(43, 90, 79, 0.45); color: var(--myrtle-deep); }
.btn--brass { background: var(--brass); border-color: var(--brass); color: var(--myrtle-deep); font-weight: 700; }
.btn--brass:hover { background: #d6b264; border-color: #d6b264; }
.btn--on-dark { background: transparent; border-color: rgba(236, 238, 227, 0.4); color: var(--vellum); }
.btn--on-dark:hover { border-color: var(--vellum); background: rgba(236, 238, 227, 0.06); }
.btn--on-dark.btn--on { background: transparent; border-color: var(--brass); color: var(--brass); }
.btn--ghost-dark { background: transparent; color: var(--vellum); }
.btn--ghost-dark:hover, .btn--ghost-dark.btn--on { background: rgba(236, 238, 227, 0.1); border-color: transparent; color: var(--vellum); }

/* ---------- icon buttons ----------
   A round button holding one icon. --compact 28px in tool bars; --off a part or layer turned off; --on-dark on the
   dark ground. */
.icon-button {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none;
  background: none; border: 0; border-radius: 50%; cursor: pointer; color: var(--ink-soft);
}
.icon-button svg { width: 20px; height: 20px; }
.icon-button:hover { background: var(--vellum-deep); color: var(--ink); }
.icon-button--compact { width: 28px; height: 28px; }
.icon-button--compact svg { width: auto; height: auto; }
.icon-button--compact:disabled { opacity: .35; cursor: default; background: none; }
.icon-button--off { color: var(--ink-faint); opacity: .6; }
.icon-button--on-dark { color: rgba(236, 238, 227, 0.8); }
.icon-button--on-dark:hover { background: rgba(236, 238, 227, 0.1); color: var(--vellum); }

/* ---------- modals ---------- */
.modal {
  font-family: var(--sans); font-size: var(--t-body); line-height: 1.5;
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 36px 32px 30px;
  border: 0; border-radius: 6px;
  background: var(--vellum); color: var(--ink);
  box-shadow: 0 40px 80px -30px rgba(10, 30, 25, 0.6);
  border-top: 5px solid var(--brass);
}
.modal::backdrop { background: rgba(16, 42, 36, 0.72); }
.modal[open] { animation: modal-in .22s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.modal-close-form { position: absolute; top: 12px; right: 12px; margin: 0; }
.modal-title { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 1.875rem; line-height: 1.15; padding-right: 32px; }
.modal-lede { margin: 10px 0 22px; color: var(--ink-soft); overflow-wrap: anywhere; }
.modal-lede strong { color: var(--ink); }

@media (max-width: 560px) {
  .modal { padding: 30px 22px 24px; }
}
