/* Chunk picker: the three steps, one page at a time in one fixed text size, the two flags, and the check screen (see chunk-picker.js).
   Flat colours only, all from the theme tokens; the highlight and the two flags do not rely on colour alone (blue circle = start, red square = end).
   The picker fits the window: the page takes the room that is left and is never scrolled; a page that does not fit is split into sub-pages. */
.add-screen.cp-open { overflow: hidden; padding-top: 8px; padding-bottom: 12px; }
.add-screen.cp-open > * { max-width: 1400px; }
/* Above the page: the steps and, in the middle, what to do now. Below it: page buttons, Find, Undo, Back and Check. The add screen's own Back button and title are not shown here. */
.add-screen.cp-open .add-head { display: block; padding: 0 0 4px; }
.add-screen.cp-open .coll-back, .add-screen.cp-open .coll-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cp-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; min-width: 0; }
.add-body.cp-body { flex: 1 1 0; min-height: 0; }

.cp-wrap { display: flex; flex-direction: column; gap: 8px; flex: 1 1 0; min-height: 0; min-width: 0; overflow-y: auto; }
.cp-wrap button { min-height: 44px; }
.cp-work { display: flex; flex-direction: column; gap: 8px; flex: 1 1 auto; min-height: 260px; min-width: 0; }
.cp-work[hidden], .cp-confirm[hidden], .cp-results[hidden], .cp-find-panel[hidden] { display: none; }
.cp-note { margin: 0; }

/* The three steps: small buttons side by side, not stretched. The open one is filled in; a chosen one says "change" and can be pressed. */
.cp-steps { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 0; padding: 0; flex: 0 0 auto; }
.cp-step-btn { display: inline-flex; align-items: center; gap: 8px; padding: 4px 14px 4px 6px; text-align: left; border: 1px solid var(--border); border-radius: 999px; background: var(--card); color: var(--text); cursor: pointer; }
.cp-step-btn:hover:not(:disabled) { border-color: var(--muted); background: var(--control); }
.cp-step-btn:disabled { opacity: 0.5; cursor: default; }
.cp-step-n { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; background: var(--control); color: var(--text); font-weight: 700; }
.cp-step-t { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.cp-step-t strong { font-size: 0.95rem; }
.cp-step-note { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.cp-step.cp-now .cp-step-btn { border-width: 2px; padding: 3px 13px 3px 5px; background: var(--control); cursor: default; }
.cp-step-start.cp-now .cp-step-btn { border-color: var(--accent-2); }
.cp-step-start.cp-now .cp-step-n { background: var(--accent-2); color: var(--on-accent, #fff); }
.cp-step-end.cp-now .cp-step-btn { border-color: var(--accent); }
.cp-step-end.cp-now .cp-step-n { background: var(--accent); color: var(--on-accent, #fff); }
.cp-step-confirm.cp-now .cp-step-btn { border-color: var(--text); }
.cp-step-confirm.cp-now .cp-step-n { background: var(--text); color: var(--bg); }

/* What to do now, in the same row as the page buttons. */
.cp-banner { flex: 1 1 14rem; min-width: 0; text-align: center; }
.cp-banner-title { margin: 0; font-size: 1.1rem; line-height: 1.3; }
.cp-banner-title::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px; background: var(--accent-2); border-radius: 50%; }
.cp-top[data-mode="end"] .cp-banner-title::before { background: var(--accent); border-radius: 3px; }
.cp-top[data-mode="confirm"] .cp-banner-title::before { display: none; }
.cp-banner-title.cp-bad::before { display: none; }

.cp-nav { display: flex; align-items: center; gap: 8px; }
.cp-nav button { min-width: 44px; font-size: 1.3rem; line-height: 1; padding: 0 12px; }
.cp-pageno { min-width: 7.5rem; text-align: center; font-weight: 600; white-space: nowrap; }
.cp-tools { display: flex; align-items: center; gap: 8px; }
.cp-tools button:disabled { opacity: 0.45; }
.cp-tools [hidden] { display: none; }

.cp-find-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 0 0 auto; }
.cp-find-panel input { min-height: 44px; box-sizing: border-box; }
.cp-find-panel input[type="number"] { width: 9rem; }
.cp-find-panel input[type="search"] { flex: 1 1 10rem; min-width: 0; max-width: 20rem; }
.cp-results { display: flex; flex-direction: column; gap: 6px; max-height: 32%; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); flex: 0 1 auto; }
.cp-results-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.cp-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 6px; }
.cp-item { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cp-item-name { flex: 1 1 140px; text-align: left; overflow-wrap: anywhere; font-size: 0.88rem; line-height: 1.4; }
.cp-item-btn { flex: 0 0 auto; }

/* The page: it fills the room and never scrolls. One text size for every page (18 px, 15 px on a phone). */
.cp-stage { flex: 1 1 0; min-height: 160px; min-width: 0; display: flex; position: relative; }
/* The resume note floats over the bottom edge of the page: it takes no room and can be ignored. */
.cp-notice { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 4px; max-width: calc(100% - 24px); padding: 0 2px 0 12px; border: 1px solid var(--border); border-radius: 999px; background: color-mix(in srgb, var(--control) 92%, transparent); color: var(--muted); font-size: 0.8rem; line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; z-index: 2; }
.cp-notice button { min-height: 28px !important; min-width: 28px; padding: 0; border: 0; background: transparent; color: inherit; font-size: 1rem; }
.cp-stage:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.cp-sheet { flex: 1 1 auto; min-width: 0; display: flex; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
.cp-wrap[data-mode="end"] .cp-sheet { border-color: var(--accent); }
.cp-wrap[data-mode="start"] .cp-sheet { border-color: var(--accent-2); }
.cp-sheet-body { flex: 1 1 auto; min-width: 0; padding: 18px 28px 36px; overflow: hidden; box-sizing: border-box; font-family: var(--font-serif); font-size: 18px; line-height: 1.75; color: var(--text); overflow-wrap: anywhere; user-select: none; -webkit-user-select: none; touch-action: pan-y; }
.cp-para { margin: 0 0 0.8em; white-space: pre-wrap; }
.cp-para.cp-cont { margin-top: -0.8em; }
.cp-heading { margin: 0.4em 0 0.5em; font-size: 1.15em; line-height: 1.4; font-family: var(--font-sans); white-space: pre-wrap; }

.cp-w { position: relative; cursor: pointer; }
.cp-sel { background: color-mix(in srgb, var(--accent-2) 32%, var(--card)); }
@media (forced-colors: active) { .cp-sel { background: Highlight; color: HighlightText; } }

/* The two flags: a bar at the edge of the word and a knob below it. Start is a blue circle at the left edge; end is a red square at the right edge. */
.cp-flag { position: absolute; top: 0; width: 44px; height: calc(100% + 32px); touch-action: none; z-index: 1; cursor: grab; }
.cp-flag::before { content: ''; position: absolute; top: 0; bottom: 32px; left: 50%; width: 3px; margin-left: -1px; }
.cp-flag::after { content: ''; position: absolute; bottom: 4px; left: 50%; width: 24px; height: 24px; margin-left: -12px; }
.cp-flag-start { left: -22px; }
.cp-flag-start::before, .cp-flag-start::after { background: var(--accent-2); }
.cp-flag-start::after { border-radius: 50%; }
.cp-flag-end { right: -22px; }
.cp-flag-end::before, .cp-flag-end::after { background: var(--accent); }
.cp-flag-end::after { border-radius: 4px; }
.cp-flag:focus-visible { outline: 2px solid var(--text); outline-offset: -4px; }
.cp-dragging { user-select: none; cursor: grabbing; }
.cp-dragging .cp-flag { pointer-events: none; }

/* Under the page: the page buttons and Find on the left, Cancel or Back and Check on the right. */
.cp-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; flex: 0 0 auto; }
.cp-foot-left, .cp-foot-right { display: flex; align-items: center; gap: 8px; }
.cp-bad { color: var(--accent); }

/* Step 3: the start and the end of the text take the screen, side by side (one above the other on a phone). */
.cp-confirm { display: flex; flex-direction: column; gap: 10px; flex: 1 1 auto; min-height: 0; }
.cp-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; flex: 1 1 0; min-height: 240px; }
.cp-card { display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; padding: 14px 18px; border: 1px solid var(--border); border-top-width: 6px; border-radius: var(--radius); background: var(--card); }
.cp-card-start { border-top-color: var(--accent-2); }
.cp-card-end { border-top-color: var(--accent); }
.cp-card-head { display: flex; align-items: center; justify-content: center; gap: 10px; flex: 0 0 auto; }
.cp-card-mark { flex: 0 0 auto; width: 16px; height: 16px; background: var(--accent-2); border-radius: 50%; }
.cp-card-end .cp-card-mark { background: var(--accent); border-radius: 4px; }
.cp-card-page { font-size: 1.1rem; font-weight: 600; }
.cp-cut { margin: 0; flex: 1 1 0; min-height: 0; overflow: hidden; font-family: var(--font-serif); font-size: 18px; line-height: 1.7; overflow-wrap: anywhere; color: var(--text); }
.cp-ctx { color: var(--muted); }
.cp-first { background: color-mix(in srgb, var(--accent-2) 32%, var(--card)); border-left: 3px solid var(--accent-2); }
.cp-last { background: color-mix(in srgb, var(--accent-2) 32%, var(--card)); border-right: 3px solid var(--accent); }
.cp-card-actions { display: flex; flex-wrap: wrap; gap: 8px; flex: 0 0 auto; }
.cp-sum { margin: 0; text-align: center; color: var(--muted); flex: 0 0 auto; }
.cp-problem:empty { display: none; }
.cp-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; flex: 0 0 auto; }

@media (max-width: 760px) {
  .add-screen.cp-open { padding-left: 10px; padding-right: 10px; }
  .cp-wrap { gap: 6px; }
  .cp-wrap button { min-height: 40px; }
  .cp-steps { gap: 6px; }
  .cp-step-btn { gap: 6px; padding: 3px 10px 3px 4px; }
  .cp-step-n { width: 24px; height: 24px; font-size: 0.85rem; }
  .cp-step-t strong { font-size: 0.9rem; }
  .cp-step-note { display: none; }
  .cp-top { gap: 4px 10px; }
  .cp-steps { flex: 1 1 100%; min-width: 0; flex-wrap: nowrap; gap: 4px; }
  .cp-step { min-width: 0; }
  .cp-step-btn { padding: 2px 8px 2px 3px; gap: 4px; }
  .cp-step-t strong { font-size: 0.85rem; }
  .cp-banner { flex-basis: 100%; }
  .cp-banner-title { font-size: 1rem; }
  .cp-foot-left { flex: 1 1 100%; justify-content: space-between; }
  .cp-foot-right { flex: 1 1 100%; }
  .cp-foot-right button { flex: 1 1 auto; }
  .cp-pageno { min-width: 0; font-size: 0.9rem; }
  .cp-sheet-body { padding: 10px 14px 40px; font-size: 15px; line-height: 1.7; }

  .cp-cards { grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: 10px; min-height: 340px; }
  .cp-card { padding: 8px 12px; gap: 6px; }
  .cp-cut { min-height: 3.2em; }
  .cp-cut { font-size: 15px; line-height: 1.6; }
}

/* On a touch screen the flags are bigger to grab. */
@media (pointer: coarse), (max-width: 760px) {
  .cp-flag { width: 60px; height: calc(100% + 40px); }
  .cp-flag-start { left: -30px; }
  .cp-flag-end { right: -30px; }
  .cp-flag::before { width: 4px; margin-left: -2px; bottom: 38px; }
  .cp-flag::after { width: 34px; height: 34px; margin-left: -17px; bottom: 0; }
  .cp-sheet-body { line-height: 2; }
}

/* On a wide window the instruction sits in the true middle of the row, with the steps on the left. */
@media (min-width: 1280px) {
  .cp-top { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
  .cp-banner { flex: none; }
}

/* Step 3: Back and Add at the bottom right (where Back and Check your text were); Add opens a small choice above it. */
.cp-confirm-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex: 0 0 auto; }
.cp-add-wrap { position: relative; }
.cp-add-menu { position: absolute; z-index: 8; bottom: calc(100% + 6px); right: 0; display: flex; flex-direction: column; gap: 6px; min-width: 14rem; padding: 8px; border: 1px solid var(--border); border-radius: 12px; background: var(--card); }
.cp-add-menu[hidden] { display: none; }
@media (max-width: 760px) {
  .cp-confirm-foot { width: 100%; }
  .cp-confirm-foot .cp-add-wrap { flex: 1 1 auto; }
  .cp-confirm-foot .cp-add-wrap > button { width: 100%; }
  .cp-confirm-foot { position: relative; }
  .cp-confirm-foot .cp-add-wrap { position: static; }
  .cp-add-menu { left: 0; right: 0; min-width: 0; }
  .cp-add-menu .cp-fields { grid-template-columns: minmax(0, 1fr); gap: 6px; }
}
