/* Web-app surfaces — home (paste box) + view (translation reader). */

html,
body {
  background: var(--canvas);
  color: var(--ink);
  min-height: 100vh;
  /* Long German compounds (e.g. "Korrespondentendinner") would otherwise
     force horizontal scroll on phones, which makes sticky elements stop
     short of the right edge and bleed the canvas colour through. */
  overflow-x: clip;
}

body {
  line-height: 1.7;
  font-size: 17px;
}

a {
  color: var(--blue);
}

/* =================================================
   MASTHEAD — shared by home + view
   ================================================= */
.masthead {
  background: var(--masthead-bg);
  border-bottom: 3px solid var(--blue);
  padding: 14px 28px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.masthead-inner {
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--masthead-fg);
}
.masthead-mark,
.brand-mark {
  width: 32px;
  height: 32px;
  font-size: 15px;
  background: var(--blue);
  color: var(--paper);
}
.masthead-mark .dot,
.brand-mark .dot {
  color: var(--paper);
}
.masthead-wordmark,
.brand-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--masthead-fg);
  letter-spacing: -0.01em;
}
.masthead-divider {
  width: 1px;
  height: 18px;
  background: var(--masthead-border);
}
.masthead-meta,
.brand-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--masthead-fg-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 500;
}
.brand-meta {
  margin-left: auto;
}
.masthead-link {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--masthead-fg-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  font-weight: 600;
  padding: 6px 10px;
  border: 1px solid var(--masthead-border);
  transition: all 0.15s;
  margin-left: auto;
}
.masthead-link:hover {
  color: var(--masthead-fg);
  border-color: var(--masthead-fg);
}
.brand-meta + .masthead-link {
  margin-left: 8px;
}
.masthead-actions {
  margin-left: auto;
  display: flex;
  /* ≥14px keeps the 44px hit areas below from overlapping. */
  gap: 14px;
  align-items: center;
}
.iconbtn {
  position: relative;
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--masthead-fg-dim);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: all 0.15s;
}
/* Expand the touch target to the 44px minimum (Leitfaden 4.3) without enlarging
   the glyph or the masthead — an invisible hit area centred on the 30px button. */
.iconbtn::after {
  content: "";
  position: absolute;
  inset: -7px;
}
.iconbtn:hover {
  color: var(--masthead-fg);
  /* subtle light wash on the permanently-dark bar — valid in both themes */
  background: rgba(255, 255, 255, 0.1);
}
/* Theme toggle: show the glyph for the CURRENT appearance — sun = light,
   moon = dark. Defaults to sun before JS reflects state. Clicking flips it. */
.iconbtn[data-theme-cycle] svg {
  display: none;
}
.iconbtn[data-theme-cycle] .ic-theme-light {
  display: inline;
}
.iconbtn[data-theme-cycle][data-theme-state="dark"] .ic-theme-light {
  display: none;
}
.iconbtn[data-theme-cycle][data-theme-state="dark"] .ic-theme-dark {
  display: inline;
}

/* =================================================
   SUBBAR — view only
   ================================================= */
.subbar {
  background: var(--off);
  border-bottom: 1px solid var(--ink);
  padding: 10px 28px;
}
.subbar-inner {
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.pill {
  background: var(--blue);
  color: var(--paper);
  padding: 4px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.source-label {
  color: var(--ink-3);
  font-weight: 400;
  white-space: nowrap;
}
.source-link {
  color: var(--ink);
  font-weight: 500;
  text-decoration: none;
  border-bottom: 1px solid var(--ink-3);
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: none;
  letter-spacing: 0;
}
.source-link:hover {
  color: var(--blue);
  border-bottom-color: var(--blue);
}
@media (max-width: 640px) {
  .subbar-inner {
    gap: 8px;
    flex-wrap: wrap;
  }
  .source-label {
    display: none;
  }
}

/* =================================================
   HOME — paste box
   ================================================= */
.home {
  padding: 64px 28px 48px;
  background: var(--paper);
}
.home-inner {
  max-width: 640px;
  margin: 0 auto;
}
.home-eyebrow {
  display: inline-block;
  background: var(--blue);
  color: var(--paper);
  padding: 3px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 18px;
}
.home-title {
  font-size: 38px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin-bottom: 18px;
  text-wrap: balance;
  color: var(--ink);
}
.home-lede {
  font-size: 21px;
  font-weight: 500;
  line-height: 1.6;
  color: var(--ink-2);
  margin-bottom: 40px;
  max-width: 56ch;
}

.url-form {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px;
  background: var(--paper);
  border: 2px solid var(--ink);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.field-label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  font-weight: 600;
}
.url-input {
  font-family: var(--font-sans);
  font-size: 17px;
  padding: 12px 14px;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  outline: none;
}
.url-input:focus {
  outline: 2px solid var(--blue);
  outline-offset: 0;
}

/* Shared segmented toggle */
.toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--ink);
}
.toggle button {
  padding: 12px 14px;
  border: none;
  background: var(--paper);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-2);
  cursor: pointer;
  text-align: left;
}
.toggle button + button {
  border-left: 1px solid var(--ink);
}
.toggle button.on {
  background: var(--ink);
  color: var(--paper);
}
.toggle button .sub {
  display: block;
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 10px;
  color: var(--ink-3);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 4px;
}
.toggle button.on .sub {
  color: var(--on-ink-dim);
}
/* Three-way variant — the colour-scheme picker (auto / light / dark). */
.toggle.toggle-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.submit-btn {
  align-self: stretch;
  border: none;
  background: var(--blue);
  color: var(--paper);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 14px 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: background 0.15s;
}
.submit-btn:hover {
  background: var(--blue-deep);
}

.home-foot {
  margin-top: 32px;
  font-size: 14px;
  color: var(--ink-3);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}
.home-foot p + p {
  margin-top: 6px;
}

/* =================================================
   ACCELERATORS — bookmarklet, Android share, extension
   ================================================= */
.accel {
  margin-top: 56px;
  padding-top: 32px;
  border-top: 2px solid var(--ink);
}
.accel-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: 6px;
}
.accel-lede {
  font-size: 16px;
  color: var(--ink-2);
  margin-bottom: 22px;
  max-width: 56ch;
}
.accel-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 720px) {
  .accel-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}
.accel-card {
  padding: 18px;
  background: var(--paper);
  border: 1px solid var(--ink);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.accel-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--blue);
  font-weight: 700;
}
.accel-help {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-2);
  flex: 1;
}
/* Shared call-to-action across the three accelerator cards. Full-width and
   pinned to the bottom of each card so the buttons line up in a tidy row
   regardless of how much help text sits above them. */
.accel-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-height: 56px;
  margin-top: auto;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--paper);
  text-align: center;
  text-decoration: none;
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.3;
  letter-spacing: 0.02em;
  border: none;
  cursor: pointer;
}
.accel-cta:hover {
  background: var(--blue);
}
/* The bookmarklet is dragged into the bookmarks bar — the grab cursor hints
   that, and disabling selection makes the drag cleaner. */
.accel-cta--drag {
  cursor: grab;
  user-select: none;
}

/* =================================================
   SETTINGS — level, voice, theme
   ================================================= */
.settings {
  padding: 64px 28px 48px;
  background: var(--paper);
}
.settings-inner {
  max-width: 640px;
  margin: 0 auto;
}
.settings-card {
  margin-top: 32px;
  background: var(--paper);
  border: 2px solid var(--ink);
}
.group {
  padding: 22px 28px;
  border-bottom: 1px solid var(--ink);
}
.group:last-of-type {
  border-bottom-width: 2px;
}
.group-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.group-head h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.group-idx {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--blue);
  letter-spacing: 0.08em;
  font-weight: 700;
  text-transform: uppercase;
}
.help {
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.55;
  margin-bottom: 14px;
  max-width: 60ch;
}
.help a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 700;
  border-bottom: 1px solid var(--blue);
}
.select {
  position: relative;
}
.select select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding: 12px 14px;
  padding-right: 36px;
  background: var(--paper);
  border: 1px solid var(--ink);
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
}
.select select:focus {
  outline: 2px solid var(--blue);
  outline-offset: 0;
}
.select::after {
  content: "▾";
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-2);
  pointer-events: none;
  font-size: 12px;
}
.actions {
  background: var(--off);
  padding: 20px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.local-note {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.actions-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.save-status {
  font-size: 13px;
  color: var(--ok);
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}
.save {
  padding: 12px 28px;
  background: var(--blue);
  color: var(--paper);
  border: none;
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s;
}
.save:hover {
  background: var(--blue-deep);
}
.hidden {
  display: none !important;
}

/* =================================================
   READER — shared with view/error templates
   ================================================= */
.reader {
  background: var(--paper);
  padding: 48px 28px 64px;
  min-height: 60vh;
}
.reader-inner {
  max-width: 640px;
  margin: 0 auto;
}
.eyebrow {
  display: inline-block;
  background: var(--blue);
  color: var(--paper);
  padding: 3px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 16px;
}
.title {
  font-size: 38px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin-bottom: 18px;
  text-wrap: balance;
  color: var(--ink);
  overflow-wrap: anywhere;
  hyphens: auto;
  -webkit-hyphens: auto;
}
.meta-row {
  display: flex;
  align-items: center;
  gap: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding-bottom: 18px;
  margin-bottom: 28px;
  border-bottom: 2px solid var(--ink);
  flex-wrap: wrap;
}
.meta-row .sep {
  color: var(--blue);
  padding: 0 8px;
}
.meta-row a {
  color: var(--ink);
  border-bottom: 1px solid var(--ink-3);
  text-decoration: none;
}
.meta-row a:hover {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

/* =================================================
   BODY COPY — translated content
   ================================================= */
.body-copy {
  font-size: var(--body-size, 19px);
  line-height: var(--body-lh, 1.7);
  color: var(--ink);
  hyphens: auto;
  -webkit-hyphens: auto;
}
.body-copy h1,
.body-copy h2,
.body-copy h3,
.body-copy h4 {
  overflow-wrap: anywhere;
}
.body-copy p,
.body-copy li {
  overflow-wrap: break-word;
}
.body-copy p {
  margin-bottom: 18px;
  max-width: 60ch;
  text-wrap: pretty;
}
.body-copy > p:first-of-type,
.body-copy p.lead {
  font-size: calc(var(--body-size, 19px) * 1.1);
  font-weight: 500;
  color: var(--ink);
}
.body-copy h2 {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.3;
  margin-top: 36px;
  margin-bottom: 14px;
  letter-spacing: -0.01em;
  padding-left: 14px;
  border-left: 4px solid var(--blue);
}
.body-copy h3 {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
  margin-top: 32px;
  margin-bottom: 10px;
}
.body-copy strong {
  font-weight: 700;
}
.body-copy em {
  font-style: italic;
}
.body-copy ul,
.body-copy ol {
  list-style: none;
  padding: 0;
  margin: 16px 0 24px;
}
.body-copy li {
  position: relative;
  padding-left: 28px;
  margin-bottom: 8px;
  max-width: 60ch;
}
.body-copy ul li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: calc(var(--body-lh, 1.7) * 0.5em - 5px);
  width: 10px;
  height: 10px;
  background: var(--blue);
}
.body-copy ol {
  counter-reset: ls-counter;
}
.body-copy ol li {
  counter-increment: ls-counter;
}
.body-copy ol li::before {
  content: counter(ls-counter);
  position: absolute;
  left: 0;
  top: 0;
  color: var(--blue);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  line-height: inherit;
}
.body-copy hr {
  border: none;
  height: 1px;
  background: var(--ink);
  margin: 32px 0;
}

/* =================================================
   LOADING / ERROR
   ================================================= */
.loading {
  text-align: center;
  padding: 60px 0;
  color: var(--ink-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.loading-spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--rule);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 8px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.loading-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.draft-notice {
  background: var(--off);
  border-left: 3px solid var(--blue);
  padding: 16px 20px;
  margin-bottom: 28px;
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink-2);
}
.draft-notice p {
  margin: 0;
}
.draft-notice-label {
  margin-bottom: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.voice-hint {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--off);
  border-left: 3px solid var(--blue);
  padding: 14px 16px 14px 20px;
  margin-bottom: 28px;
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink-2);
  /* Ease in when it's un-hidden, instead of popping in abruptly. */
  animation: voice-hint-in 260ms ease both;
}
@keyframes voice-hint-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .voice-hint {
    animation: none;
  }
}
.voice-hint p {
  margin: 0;
  flex: 1;
}
.voice-hint a {
  color: var(--blue);
  border-bottom: 1px solid var(--blue);
  text-decoration: none;
}
.voice-hint-close {
  flex: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-3);
  font-size: 22px;
  line-height: 1;
  padding: 0 2px;
}
.voice-hint-close:hover {
  color: var(--ink);
}

.error-box {
  background: var(--ink);
  color: var(--paper);
  padding: 14px 20px;
  font-size: 15px;
  line-height: 1.5;
}
.error-box p {
  margin: 0;
}
.error-box a {
  color: var(--paper);
  border-bottom: 1px solid var(--paper);
  text-decoration: none;
}
.back-link {
  margin-top: 24px;
}

/* =================================================
   TOOLBAR — reader controls (Bedienleiste)
   Two labelled groups (read-aloud, and text size + spacing). On desktop
   it's a sticky bar under the masthead; on mobile it docks to the bottom
   as an app toolbar — two short rows, one per group, so every control
   keeps its label (Leitfaden 4.2/4.3 advise icon+label, not icon-only)
   and its ≥44px target (4.3) without sideways scrolling. The bar reserves
   space at the foot of the page, so it never covers content (10.2). The
   light/dark toggle lives in the masthead top-right, not here.
   ================================================= */
.page {
  position: relative;
}
.toolbar {
  /* One control surface, three responsive shapes — so there is a single,
     predictable location per viewport (no breakpoint flip on rotate):
       • wide (≥1080px): a floating vertical rail in the right margin, clear of
         the centred reading column, every control visible + labelled with state
       • medium (≤1079px): docked to the bottom as a full-width app toolbar
       • small (≤640px): bottom dock, each group collapsed into a labelled
         Vorlesen / Schrift popover so the bar stays calm */
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  pointer-events: none; /* the empty gutter stays click-through */
}
.toolbar-inner {
  pointer-events: auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 24px;
  background: var(--paper);
  border-top: 1px solid var(--ink);
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px));
}
.tool-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tool-pop {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
}
/* Selector carries .toolbar to out-specify the later `.toolbtn { display }`
   rule (the trigger has both classes). Shown only at ≤640px (popovers). */
.toolbar .tool-trigger {
  display: none;
}
.tool-trigger-glyph {
  font-weight: 700;
  font-size: 16px;
}
.tool-caret {
  margin-left: 2px;
  transition: transform 0.15s;
}
.tool-group.open .tool-caret {
  transform: rotate(180deg);
}
.tool-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
  white-space: nowrap;
}
/* Reserve room for the bottom dock so it never covers content. The medium
   (641–1079px) dock can flex-wrap onto two rows, so reserve for two; the ≤640
   dock is a single non-wrapping row of two triggers (overridden below), and the
   ≥1080 right-rail needs none (overridden in its block). */
body:has(.toolbar) {
  padding-bottom: 128px;
}
.toolbtn {
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink-2);
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: all 0.15s;
}
.toolbtn:hover {
  background: var(--off);
  color: var(--ink);
}
.toolbtn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}
.toolbtn.on {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.toolbtn svg {
  flex: none;
}
.toolbtn-text {
  font-size: 14px;
}
.toolbtn--mono {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  /* Pin a constant width so the rate readout doesn't grow from "1×" to "1.25×"
     and shove the −/+ buttons onto a new row when the tempo changes. Sized to
     fit the widest value ("1.25×" / "0.75×"). */
  min-width: 56px;
  white-space: nowrap;
}
.toolbtn[data-state="playing"] .ic-play {
  display: none;
}
.toolbtn[data-state="paused"] .ic-pause {
  display: none;
}

/* When a .tool-pop is laid out as a grid — the small-screen popover and the
   wide right-rail — the mono labels and the full-width actions (Vorlesen /
   Pause / Abstand, all `.toolbtn--wide`) span the full row; the −/1×/+ and
   A−/A/A+ triplets take one column each. Ignored in the flex bottom-dock layout
   (grid-column is inert there), so it's safe to declare once globally. */
.tool-pop .tool-label,
.tool-pop .toolbtn--wide {
  grid-column: 1 / -1;
}
.tool-pop .tool-label {
  padding-top: 2px;
}

/* Small screens (≤640px): keep the bottom dock but collapse each group into a
   labelled popover so the bar stays calm — two triggers (Vorlesen, Schrift),
   each opening its controls above the bar. Labels stay (Leitfaden 4.2/4.3) and
   every target keeps ≥44px without sideways scrolling. */
@media (max-width: 640px) {
  .toolbar-inner {
    position: relative;
    flex-wrap: nowrap;
    gap: 10px;
  }
  .tool-group {
    flex: 1 1 0;
    justify-content: center;
  }
  .toolbar .tool-trigger {
    display: inline-flex;
    width: 100%;
  }
  /* Popovers anchor to the bar (left/right inset) rather than the trigger, so a
     wide cluster can never overflow the screen edge. Only one opens at a time. */
  .tool-pop {
    display: none;
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: calc(100% + 10px);
    gap: 8px;
    background: var(--paper);
    border: 1px solid var(--ink);
    padding: 12px;
    z-index: 30;
  }
  /* A 3-column grid (same shape as the wide rail) keeps the cluster organised
     no matter which controls are visible: playback and Tempo / Schrift stack
     into tidy rows instead of ragged wrapping. The width is FIXED (not
     content-driven) so the rigid columns never shift when the rate readout
     swaps 1× ↔ 1.25×; the card centres over the bar. */
  .tool-group.open .tool-pop {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(232px, calc(100vw - 24px));
  }
  .tool-group.open .tool-trigger {
    background: var(--ink);
    color: var(--paper);
    border-color: var(--ink);
  }
  /* This dock is a single non-wrapping row of two triggers, so it only needs
     room for one row plus the home-indicator safe area. */
  body:has(.toolbar) {
    padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  }
}

/* Wide screens (≥1080px): float the controls as a vertical rail in the right
   margin, clear of the centred reading column (max 640px wide). Every control
   stays visible and labelled with its live state — no popovers. */
@media (min-width: 1080px) {
  /* Float in a band between the sticky masthead and the bottom, and centre the
     rail within it — so on a short window the rail can never ride up over the
     masthead's top-right actions (which sit at a lower z-index). */
  .toolbar {
    left: auto;
    right: 24px;
    top: 72px;
    bottom: 24px;
    transform: none;
    justify-content: flex-end;
    align-items: center;
  }
  .toolbar-inner {
    width: auto;
    max-width: 232px;
    max-height: 100%;
    overflow-y: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    border: 1px solid var(--ink);
    padding: 0;
  }
  /* Each group is a tidy 3-column grid. `display: contents` lifts the buttons
     out of .tool-pop so they become grid items directly: the mono labels and
     the icon+text actions (Vorlesen / Abstand / Pause) span the full width as
     section headers / rows, while the −/1×/+ and A−/A/A+ triplets line up one
     per column. No more orphaned "Tempo" / ragged wrapping. */
  .tool-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 14px;
  }
  .tool-group + .tool-group {
    border-top: 1px solid var(--ink);
  }
  .tool-pop {
    display: contents;
  }
  body:has(.toolbar) {
    padding-bottom: 0;
  }
}

/* Read-aloud word highlight via CSS Custom Highlight API */
::highlight(speech-word) {
  background-color: var(--blue);
  color: var(--paper);
}

/* =================================================
   READER CONTROLS
   ================================================= */
.page[data-size="s"] {
  --body-size: 17px;
}
.page[data-size="m"] {
  --body-size: 19px;
}
.page[data-size="l"] {
  --body-size: 22px;
}
.page[data-size="xl"] {
  --body-size: 25px;
}
.page[data-spacing="tight"] {
  --body-lh: 1.55;
}
.page[data-spacing="normal"] {
  --body-lh: 1.7;
}
.page[data-spacing="loose"] {
  --body-lh: 1.95;
}

/* =================================================
   PRINT / OFFLINE READING FASSUNG (Leitfaden 2.6)
   A clean print fallback: strip every piece of chrome (masthead, subbar,
   reader toolbar, footer) and all transient/interactive UI (loading state,
   voice hint, per-section speaker buttons), then lay the content out as plain
   black-on-white at a comfortable print size. The source URL is surfaced from
   the meta-row link so a printed copy still references where it came from.
   ================================================= */
@media print {
  /* Lay the whole document out as plain black-on-white. The frame colours
     (--canvas behind the reader, --paper card) only waste toner on paper. */
  html,
  body {
    background: #fff;
    color: #000;
    min-height: 0;
    overflow-x: visible;
  }

  /* Chrome + transient/interactive UI — none of it belongs on paper. */
  .masthead,
  .subbar,
  .toolbar,
  .credit,
  .voice-hint,
  .loading,
  .tts-play {
    display: none !important;
  }

  /* The reader reserves space at the foot of the page for the bottom-docked
     toolbar; with the toolbar gone, drop that reservation. */
  body:has(.toolbar) {
    padding-bottom: 0;
  }

  /* Let the content use the full printable width and shed the on-screen frame
     (card padding, centred column cap, minimum height). */
  .reader {
    padding: 0;
    min-height: 0;
    background: transparent;
  }
  .reader-inner {
    max-width: none;
    margin: 0;
  }

  /* Comfortable, ink-frugal type in physical (pt) units. */
  .body-copy {
    --body-size: 12pt;
    --body-lh: 1.5;
    color: #000;
  }
  .title {
    font-size: 22pt;
    color: #000;
  }

  /* Structural accents (h2 lead-rule, list bullets/numbers, separators) are
     blue on screen; print them in black so they survive a mono printer and
     don't depend on background-graphics being enabled. */
  .body-copy h2,
  .body-copy h3,
  .body-copy h4 {
    color: #000;
    break-after: avoid;
  }
  .body-copy h2 {
    border-left-color: #000;
  }
  .body-copy ul li::before {
    background: #000;
  }
  .body-copy ol li::before {
    color: #000;
  }
  .body-copy hr {
    background: #000;
  }
  .body-copy li,
  .body-copy p {
    break-inside: avoid;
  }

  /* Keep the AI-draft disclaimer (legally meaningful), but as a plain bordered
     note rather than a tinted callout. */
  .draft-notice {
    background: transparent;
    border-left-color: #000;
    color: #000;
  }

  /* Meta row: print in black and spell out the source URL after the host name
     so the paper copy is self-referential. */
  .meta-row,
  .meta-row a {
    color: #000;
  }
  .meta-row a::after {
    content: " (" attr(href) ")";
    font-family: var(--font-mono);
  }

  /* The active read-aloud tint must never bleed onto paper. */
  .tts-section.tts-active {
    background: transparent;
    box-shadow: none;
  }

  /* Inline links: black, no ornament — readable, no wasted ink. */
  .body-copy a {
    color: #000;
  }
}
