:root {
  --threadline-sage: #1f6254;
  --threadline-coral: #d96845;
}

body.threadline-open { overflow: hidden; }

.threadline-launch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0 0 22px;
  padding: 16px 18px;
  border: 1px solid #cbdcd1;
  border-radius: 15px;
  background: linear-gradient(135deg, #f3f8f4, #fffaf4);
  box-shadow: 0 8px 22px rgba(32, 50, 40, .06);
}
.threadline-launch div { display: grid; gap: 3px; }
.threadline-launch strong { color: #244b40; font-size: 1rem; }
.threadline-launch span { color: var(--muted); font-size: .86rem; line-height: 1.4; }
.threadline-launch button {
  flex: 0 0 auto;
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  padding: 10px 15px;
  background: var(--threadline-sage);
  color: #fff;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
}
.threadline-launch button:hover, .threadline-launch button:focus-visible { filter: brightness(1.08); outline: 3px solid rgba(31, 98, 84, .2); }
.threadline-launch button span { margin-left: 8px; color: inherit; font-size: 1rem; }

.threadline-overlay { position: fixed; inset: 0; z-index: 1000; }
.threadline-reader {
  --threadline-size: 34px;
  --tl-bg: #f6f0e6;
  --tl-card: #fffdf8;
  --tl-ink: #17382f;
  --tl-muted: #687d76;
  --tl-line: #d6d7ca;
  --tl-accent: #d96845;
  --tl-action: #1f6254;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--tl-bg);
  color: var(--tl-ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.threadline-theme-blue { --tl-bg: #e9f1f2; --tl-card: #f8fbfa; --tl-line: #c7d7d5; }
.threadline-theme-dark { --tl-bg: #12211e; --tl-card: #1b302b; --tl-ink: #f1f5ec; --tl-muted: #a7bcb5; --tl-line: #36534b; --tl-accent: #f08a63; --tl-action: #8bd0bd; }
.threadline-topbar { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between; min-height: 76px; padding: 12px max(20px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--tl-bg), transparent 5%); border-bottom: 1px solid color-mix(in srgb, var(--tl-line), transparent 35%); backdrop-filter: blur(16px); }
.threadline-brand { display: flex; align-items: center; gap: 11px; }
.threadline-brand > span:last-child { display: grid; }
.threadline-brand strong { font: 600 1.25rem/1.05 Georgia, "Times New Roman", serif; }
.threadline-brand small { margin-top: 3px; color: var(--tl-muted); font-size: .62rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.threadline-mark { width: 29px; display: grid; gap: 4px; }
.threadline-mark i { display: block; height: 2px; border-radius: 2px; background: var(--tl-accent); }
.threadline-mark i:nth-child(1) { width: 19px; transform: rotate(-7deg); }
.threadline-mark i:nth-child(2) { width: 28px; background: var(--tl-action); }
.threadline-mark i:nth-child(3) { width: 22px; transform: rotate(7deg); }
.threadline-close { width: 46px; height: 46px; border: 1px solid var(--tl-line); border-radius: 50%; background: var(--tl-card); color: var(--tl-ink); font-size: 1.8rem; line-height: 1; cursor: pointer; }
.threadline-close:focus-visible { outline: 3px solid color-mix(in srgb, var(--tl-action), transparent 68%); }

.threadline-shell { width: min(820px, calc(100% - 36px)); margin: 0 auto; padding: 32px 0 max(44px, env(safe-area-inset-bottom)); }
.threadline-document-meta { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.threadline-document-meta span { display: block; margin-bottom: 6px; color: var(--tl-accent); font-size: .68rem; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
.threadline-document-meta h1 { max-width: 680px; margin: 0; overflow: hidden; color: var(--tl-ink); font: 500 1.55rem/1.2 Georgia, "Times New Roman", serif; text-overflow: ellipsis; white-space: nowrap; }
.threadline-percent { color: var(--tl-action); font-size: 1rem; }
.threadline-progress { height: 4px; margin-top: 17px; overflow: hidden; border-radius: 5px; background: var(--tl-line); }
.threadline-progress i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--tl-accent), var(--tl-action)); transition: width .2s ease; }

.threadline-settings { margin-top: 18px; border: 1px solid var(--tl-line); border-radius: 14px; background: var(--tl-card); }
.threadline-settings > summary { display: flex; align-items: center; justify-content: space-between; min-height: 48px; padding: 10px 14px; color: var(--tl-action); font-weight: 850; cursor: pointer; list-style: none; }
.threadline-settings > summary::-webkit-details-marker { display: none; }
.threadline-settings > summary span { display: grid; place-items: center; width: 33px; height: 28px; border-radius: 8px; background: color-mix(in srgb, var(--tl-action), transparent 88%); font-family: Georgia, serif; }
.threadline-settings-panel { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; padding: 0 14px 15px; border-top: 1px solid var(--tl-line); }
.threadline-settings fieldset { min-width: 0; margin: 14px 0 0; padding: 0; border: 0; }
.threadline-settings legend { margin-bottom: 8px; font-size: .76rem; font-weight: 850; }
.threadline-settings fieldset > small { display: block; margin-top: 6px; color: var(--tl-muted); font-size: .67rem; line-height: 1.35; }
.threadline-choice-row { display: flex; gap: 5px; }
.threadline-choice-row button, .threadline-size-controls button { min-height: 38px; border: 1px solid var(--tl-line); border-radius: 9px; padding: 7px 9px; background: transparent; color: var(--tl-muted); font: inherit; font-size: .74rem; font-weight: 800; cursor: pointer; }
.threadline-choice-row button[aria-pressed="true"] { border-color: var(--tl-action); background: color-mix(in srgb, var(--tl-action), transparent 88%); color: var(--tl-ink); }
.threadline-setting-line { display: grid; gap: 7px; }
.threadline-size-controls { display: flex; gap: 5px; }
.threadline-size-controls button { flex: 1; color: var(--tl-action); }
.threadline-themes button { display: grid; justify-items: center; gap: 3px; flex: 1; padding: 5px; }
.threadline-themes i { display: block; width: 25px; height: 15px; border: 1px solid #aeb9b3; border-radius: 4px; }
.threadline-themes .cream { background: #f6f0e6; }
.threadline-themes .blue { background: #e9f1f2; }
.threadline-themes .dark { background: #12211e; }
.threadline-spacing-toggle { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 0; padding-top: 14px; border-top: 1px solid var(--tl-line); cursor: pointer; }
.threadline-spacing-toggle span { display: grid; }
.threadline-spacing-toggle small { margin-top: 2px; color: var(--tl-muted); font-size: .7rem; }
.threadline-spacing-toggle input { width: 22px; height: 22px; accent-color: var(--tl-action); }

.threadline-stage { min-height: 475px; display: grid; grid-template-rows: minmax(72px, auto) auto minmax(72px, auto); align-content: center; gap: 22px; padding: 28px 0 18px; }
.threadline-context { width: min(660px, 92%); max-height: 58px; margin: 0 auto; overflow: hidden; color: var(--tl-muted); font-size: .9rem; line-height: 1.55; opacity: .35; }
.threadline-before { align-self: end; }
.threadline-after { align-self: start; }
.threadline-active { position: relative; min-height: 230px; display: flex; align-items: center; overflow: hidden; border: 1px solid var(--tl-line); border-radius: 25px; padding: clamp(28px, 6vw, 52px); background: var(--tl-card); box-shadow: 0 22px 58px rgba(25, 55, 47, .12); }
.threadline-active > i { position: absolute; left: 0; top: 25%; width: 5px; height: 50%; border-radius: 0 5px 5px 0; background: var(--tl-accent); }
.threadline-active p { margin: 0; color: var(--tl-ink); font-size: var(--threadline-size); font-weight: 580; line-height: 1.55; letter-spacing: 0; text-align: left; }
.threadline-font-serif .threadline-active p, .threadline-font-serif .threadline-context { font-family: Georgia, "Times New Roman", serif; }
.threadline-font-sans .threadline-active p, .threadline-font-sans .threadline-context { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.threadline-spacing-roomy .threadline-active p { line-height: 1.72; letter-spacing: .035em; word-spacing: .08em; }
.threadline-active[data-kind="heading"] p { color: var(--tl-action); font-size: calc(var(--threadline-size) * .78); font-weight: 850; }
.threadline-recovery { width: min(700px, 96%); margin: -9px auto; padding: 13px 16px; border-left: 4px solid var(--tl-accent); border-radius: 4px 12px 12px 4px; background: color-mix(in srgb, var(--tl-accent), transparent 90%); }
.threadline-recovery[hidden] { display: none; }
.threadline-recovery span { color: var(--tl-accent); font-size: .62rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.threadline-recovery p { margin: 5px 0 0; color: var(--tl-ink); font-size: .95rem; line-height: 1.55; }
.threadline-recovery-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--tl-muted); font-size: .76rem; }
.threadline-recovery-row button { border: 1px solid transparent; border-radius: 10px; padding: 9px 10px; background: transparent; color: var(--tl-action); font: inherit; font-weight: 850; cursor: pointer; }
.threadline-recovery-row button[aria-pressed="true"] { border-color: var(--tl-line); background: var(--tl-card); }
.threadline-recovery-row button:disabled { opacity: .3; cursor: default; }
.threadline-controls { display: grid; grid-template-columns: 130px 1fr; gap: 13px; margin-top: 16px; }
.threadline-controls button { min-height: 62px; display: flex; align-items: center; justify-content: center; gap: 10px; border-radius: 16px; font: inherit; font-weight: 850; cursor: pointer; }
.threadline-controls button:disabled { opacity: .35; cursor: default; }
.threadline-controls [data-threadline-back] { border: 1px solid var(--tl-line); background: var(--tl-card); color: var(--tl-ink); }
.threadline-controls [data-threadline-next] { border: 0; background: var(--tl-action); color: var(--tl-bg); font-size: 1rem; box-shadow: 0 10px 25px color-mix(in srgb, var(--tl-action), transparent 74%); }
.threadline-theme-dark .threadline-controls [data-threadline-next] { color: #10221d; }
.threadline-privacy { margin: 14px 0 0; color: var(--tl-muted); font-size: .7rem; line-height: 1.4; text-align: center; }

@media (max-width: 760px) {
  .threadline-launch { display: grid; margin-bottom: 16px; padding: 13px; }
  .threadline-launch button { width: 100%; }
  .threadline-topbar { min-height: 68px; padding-top: max(9px, env(safe-area-inset-top)); padding-right: max(14px, env(safe-area-inset-right)); padding-left: max(14px, env(safe-area-inset-left)); }
  .threadline-brand small { display: none; }
  .threadline-shell { width: calc(100% - 24px); padding-top: 18px; padding-bottom: max(28px, env(safe-area-inset-bottom)); }
  .threadline-document-meta h1 { max-width: calc(100vw - 105px); font-size: 1.25rem; }
  .threadline-settings-panel { grid-template-columns: 1fr; gap: 0; }
  .threadline-stage { min-height: 455px; gap: 15px; padding: 18px 0 12px; }
  .threadline-context { width: 92%; font-size: .82rem; }
  .threadline-active { min-height: 245px; border-radius: 21px; padding: 28px 23px; }
  .threadline-active p { font-size: clamp(24px, var(--threadline-size), 42px); }
  .threadline-controls { position: sticky; bottom: max(9px, env(safe-area-inset-bottom)); z-index: 2; grid-template-columns: 104px 1fr; }
  .threadline-controls button { min-height: 60px; box-shadow: 0 8px 22px rgba(20, 45, 39, .16); }
}

@media (max-width: 390px) {
  .threadline-stage { min-height: 425px; }
  .threadline-active { min-height: 225px; }
}

@media (prefers-reduced-motion: reduce) {
  .threadline-reader *, .threadline-reader *::before, .threadline-reader *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

