/* «Keep a line» (UX run-08): the post page's well, the toolbar over a selection, the «Pick a
   line» and «Make a card» sheets, the marks in the text, and the slips the notebook page shares.
   A v2 sheet on css/toys.css tokens, light and dark. The marker yellow is the lemon object colour
   (DESIGN.md § 3): ink on lemon is 12.76:1 in both themes. Loaded by blog/template.html (every
   post page) and notebook/index.html. */

body.v2 {
  --k-key-depth: inset 0 0 0 1.5px var(--t-line), inset 0 -4px 0 rgba(0, 0, 0, 0.1);
  --k-key-depth-pressed: inset 0 0 0 1.5px var(--t-line), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
  --k-card-depth: inset 0 0 0 1.5px var(--t-line), inset 0 -6px 0 rgba(0, 0, 0, 0.07), 0 16px 30px -24px rgba(0, 0, 0, 0.45);
  --k-marker: #ffd23f;
  --k-marker-ink: #141414;
  --k-crowd: rgba(47, 85, 255, 0.16);
}
@media (prefers-color-scheme: dark) {
  body.v2 .keep-pill { box-shadow: 0 18px 36px -16px rgba(0, 0, 0, 0.7), inset 0 0 0 1.5px rgba(255, 255, 255, 0.22); }
  body.v2 { --k-crowd: rgba(141, 162, 255, 0.24); --k-key-depth: inset 0 0 0 1.5px var(--t-line), inset 0 -4px 0 rgba(0, 0, 0, 0.35); }
}

/* Marks in the note: the reader's kept lines and the lines other readers kept. */
::highlight(vk-kept) { background-color: var(--k-marker); color: var(--k-marker-ink); }
::highlight(vk-crowd) { background-color: var(--k-crowd); }
/* While words are selected: the whole sentences that «Keep» would keep, under the selection. */
::highlight(vk-pending) { background-color: rgba(255, 210, 63, 0.38); }

/* The hint under a post's title: the first-screen way in. The title keeps the hint's room from
   the first paint (a post with sentences only), and blog/keep.js lays the hint into it absolutely,
   so nothing below moves when it arrives. */
.blog-page > .bk-post-page:has(> .bk-post-body :is(p, li)) > .bk-post-title { margin-bottom: 72px; }
@media (scripting: none) { .blog-page > .bk-post-page > .bk-post-title { margin-bottom: 28px; } }
.bk-post-page > .keep-hint {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  height: 44px;
  margin: 0;
}
body.v2 .keep-hint-key {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  min-height: 44px;
  padding: 0 2px;
  border: 0;
  background: none;
  color: var(--t-ink-2);
  font: 500 0.9375rem/1.2 var(--t-display);
  cursor: pointer;
}
.keep-hint-key span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 0.22em; text-decoration-color: var(--t-line); }
body.v2 .keep-hint-key:hover { color: var(--t-ink); }
body.v2 .keep-hint-key:hover span { text-decoration-color: currentColor; }
.keep-hint-mark { flex: none; width: 18px; height: 8px; border-radius: 3px; background: var(--k-marker); transform: rotate(-6deg); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08); }
@media (scripting: none) { .keep-hint { display: none !important; } }

html.keep-locked { overflow: hidden; }

/* ---------- keys ---------- */

.keep-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--t-r-btn, 10px);
  background: var(--t-card);
  color: var(--t-ink) !important;
  box-shadow: var(--k-key-depth);
  text-decoration: none;
  cursor: pointer;
  transition: transform var(--t-base) var(--t-spring);
}
.keep-key:hover, .keep-key:focus-visible { background: var(--t-cobalt); color: #fff !important; box-shadow: none; }
.keep-key:active { transform: translateY(2px) scale(0.98); box-shadow: var(--k-key-depth-pressed); transition-duration: var(--t-fast); }
.keep-key-primary { background: var(--t-ink); color: var(--t-surface) !important; box-shadow: inset 0 -4px 0 rgba(255, 255, 255, 0.14); }
.keep-key [data-keep-count] { color: inherit; font-weight: 500; opacity: 0.85; }

/* ---------- key type ----------
   css/toys.css resets every button with `body.v2 button { font: inherit }`, which outranks a
   single class: a <button class="keep-key"> rendered 400 at 17px beside its 600 at 15px <a>
   twin. Prefixing body.v2 (post pages and /notebook/ alike) lifts the keys' own type above the
   reset without !important, for every <button> this feature draws (DESIGN.md § 9, key type). */
body.v2 .keep-key { font: 600 0.9375rem/1.1 var(--t-display); letter-spacing: normal; }
body.v2 .keep-pill-key { font: 600 0.9375rem/1 var(--t-display); letter-spacing: normal; }
body.v2 .keep-line-toggle { font: 400 1.0625rem/1.45 var(--t-display); letter-spacing: normal; }
body.v2 .keep-line-card { font: 600 0.75rem/1 var(--t-display); letter-spacing: normal; }

/* ---------- the well on a post page ---------- */

.blog-page:has(> .bk-post-page) { display: flex; flex-direction: column; }
.blog-page > .bk-post-page { position: relative; }
.blog-page > .keep-well { display: none; }
.blog-page:has(> .bk-post-page) > .keep-well { display: block; order: 1; }
.blog-page:has(> .bk-post-page) > .bk-post-nav { order: 2; }
/* The «Keep reading, day by day» row (UX run-03) stays last, after the post's neighbours. */
.blog-page:has(> .bk-post-page) > .stories { order: 3; }
.blog-page > .keep-well[hidden] { display: none; }
@media (scripting: none) { .blog-page > .keep-well { display: none !important; } }

.keep-well {
  width: 100%;
  max-width: 720px;
  margin: 44px auto 0;
  padding: 22px 20px 20px;
  border-radius: var(--t-r-l);
  background: var(--t-card);
  color: var(--t-ink);
  box-shadow: var(--k-card-depth);
}
.keep-well-main { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.keep-kicker { margin: 0 0 8px; color: var(--t-ink-2); font: 500 0.75rem/1.4 var(--t-mono); letter-spacing: 0.08em; text-transform: uppercase; }
.keep-title { margin: 0; font-size: 1.625rem; font-weight: 800; line-height: 1.05; letter-spacing: -0.02em; text-wrap: balance; }
.keep-lede { margin: 10px 0 0; max-width: 52ch; color: var(--t-ink-2); font-size: 1rem; line-height: 1.5; text-wrap: pretty; }
.keep-keys { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.keep-status, .keep-crowd { margin: 14px 0 0; min-height: 1.45em; color: var(--t-ink-2); font-size: 0.9375rem; line-height: 1.45; }
.keep-crowd { margin-top: 2px; }
.keep-status:empty { min-height: 0; margin: 0; }

/* The marker: a little page with three lines run over in yellow. Decoration only. */
.keep-marker {
  position: relative;
  display: grid;
  align-content: center;
  gap: 9px;
  width: 92px;
  height: 92px;
  padding: 0 16px;
  border-radius: 20px;
  background: var(--t-surface);
  box-shadow: inset 0 0 0 1.5px var(--t-line), inset 0 -5px 0 rgba(0, 0, 0, 0.08);
  transform: rotate(-3deg);
}
.keep-marker i { display: block; height: 9px; border-radius: 3px; background: var(--t-surface-2); }
.keep-marker i:nth-child(2) { width: 100%; background: var(--k-marker); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06); transform-origin: left; animation: k-stroke 0.9s var(--t-out) 0.4s both; }
.keep-marker i:nth-child(3) { width: 64%; }
.keep-marker i:first-child { width: 82%; }
@keyframes k-stroke { from { transform: scaleX(0); } }

/* «From your notebook»: one of the reader's own lines, back for a moment. */
.keep-recall { margin: 12px 0 0; padding: 16px 16px 14px; border-radius: var(--t-r-m); background: var(--t-surface); box-shadow: inset 0 0 0 1.5px var(--t-line); }
.keep-recall[hidden] { display: none; }
.keep-recall-when { color: var(--t-ink-2); font: 500 0.75rem/1.4 var(--t-mono); letter-spacing: 0.06em; text-transform: uppercase; }
.keep-recall-text { margin: 8px 0 6px; }
.keep-recall-text p { display: inline; margin: 0; overflow-wrap: anywhere; padding: 0.06em 0.18em; background: var(--k-marker); color: var(--k-marker-ink); font-size: 1.0625rem; font-weight: 600; line-height: 1.6; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
body.v2 .keep-recall-link { display: inline-flex; align-items: center; min-height: 44px; color: var(--toy-text, var(--t-ink)); font-weight: 600; text-decoration: underline; text-decoration-thickness: 1.5px; }

@media (min-width: 600px) {
  .keep-well { padding: 28px 28px 24px; }
  .keep-well-main { grid-template-columns: auto minmax(0, 1fr); gap: 22px; align-items: start; }
  .keep-title { font-size: 1.875rem; }
}

/* ---------- the toolbar over a selection ---------- */

.keep-pill {
  position: absolute;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border-radius: 16px;
  background: #141414;
  color: #f7f6f2;
  box-shadow: 0 18px 36px -16px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  white-space: nowrap;
}
.keep-pill[hidden] { display: none; }
.keep-pill.is-in { animation: k-pop 0.32s var(--t-spring); }
@keyframes k-pop { from { opacity: 0; transform: translateY(6px) scale(0.94); } }
.keep-pill-key {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.keep-pill-key:hover { background: rgba(255, 255, 255, 0.12); }
.keep-pill-keep { background: var(--k-marker); color: #141414; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16); }
.keep-pill-keep:hover { background: #ffdc66; }
.keep-pill-keep.is-kept { background: rgba(255, 255, 255, 0.14); color: #f7f6f2; box-shadow: none; }
.keep-pill-dot { width: 10px; height: 10px; border-radius: 3px; background: #141414; transform: rotate(-8deg); }
.keep-pill-keep.is-kept .keep-pill-dot { background: var(--k-marker); }
body.v2 .keep-pill :focus-visible { outline: 3px solid var(--k-marker); outline-offset: 2px; }
.keep-pill-note { padding: 0 10px; font-size: 0.875rem; line-height: 44px; }

/* ---------- sheets: pick a line, make a card ---------- */

.keep-sheet {
  position: fixed;
  inset: auto 0 0;
  width: 100%;
  max-width: none;
  max-height: 92svh;
  margin: 0;
  padding: 0 0 20px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 0;
  border-radius: 28px 28px 0 0;
  background: var(--t-card);
  color: var(--t-ink);
  box-shadow: 0 -30px 60px -20px rgba(0, 0, 0, 0.45);
}
.keep-sheet[open] { animation: k-sheet 0.5s var(--t-spring); }
@keyframes k-sheet { from { transform: translateY(40px); } }
.keep-sheet::backdrop { background: rgba(10, 10, 10, 0.42); }
.keep-sheet-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px 20px;
  background: var(--t-card);
  box-shadow: inset 0 -1.5px 0 var(--t-line);
}
.keep-sheet-title { margin: 0; font-size: 1.375rem; font-weight: 800; line-height: 1.1; letter-spacing: -0.015em; }
.keep-close {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--t-r-btn, 10px);
  background: var(--t-surface);
  color: var(--t-ink);
  box-shadow: var(--k-key-depth);
  cursor: pointer;
}
.keep-close:hover { background: var(--t-surface-2); }
.keep-fine { margin: 14px 20px 0; color: var(--t-ink-2); font-size: 0.9375rem; line-height: 1.45; }
.keep-sheet-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 20px 0; }

.keep-lines { list-style: none; margin: 14px 0 0; padding: 0 16px; display: grid; gap: 8px; }
.keep-line { display: flex; gap: 8px; align-items: stretch; }
.keep-line-toggle {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 12px 14px;
  border: 0;
  border-radius: 14px;
  background: var(--t-surface);
  color: var(--t-ink);
  box-shadow: var(--k-key-depth);
  text-align: left;
  cursor: pointer;
  transition: transform var(--t-base) var(--t-spring);
}
.keep-line-toggle:hover { background: var(--t-surface-2); }
.keep-line-toggle:active { transform: scale(0.99); }
.keep-line-toggle[aria-pressed="true"] { background: var(--k-marker); color: var(--k-marker-ink); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.14); }
.keep-line-text { display: block; overflow-wrap: anywhere; }
.keep-line-meta { display: block; margin-top: 6px; font: 500 0.75rem/1.3 var(--t-mono); letter-spacing: 0.04em; color: var(--t-ink-2); }
.keep-line-toggle[aria-pressed="true"] .keep-line-meta { color: #3d3a33; }
.keep-line-card {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  flex: none;
  width: 56px;
  min-height: 44px;
  border: 0;
  border-radius: 14px;
  background: var(--t-surface);
  color: var(--t-ink);
  box-shadow: var(--k-key-depth);
  cursor: pointer;
}
.keep-line-card:hover { background: var(--t-cobalt); color: #fff; box-shadow: none; }

.keep-card-body { display: grid; gap: 16px; padding: 14px 16px 0; }
.keep-card-stage { display: grid; place-items: center; padding: 12px; border-radius: 22px; background: var(--t-surface-2); }
.keep-card-canvas { display: block; width: auto; height: auto; max-width: 100%; max-height: 36svh; border-radius: 12px; box-shadow: 0 18px 34px -18px rgba(0, 0, 0, 0.5); }
.keep-card-side { display: grid; gap: 14px; align-content: start; }
.keep-choice { margin: 0; padding: 0; border: 0; min-width: 0; }
.keep-choice-label { padding: 0; margin: 0 0 8px; color: var(--t-ink-2); font: 500 0.75rem/1.4 var(--t-mono); letter-spacing: 0.08em; text-transform: uppercase; }
.keep-choice-row { display: flex; flex-wrap: wrap; gap: 6px; }
.keep-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 12px 0 9px;
  border-radius: var(--t-r-btn, 10px);
  background: var(--t-surface);
  box-shadow: var(--k-key-depth);
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
}
.keep-choice-shape .keep-chip { padding-left: 14px; }
.keep-chip input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.keep-chip:has(input:checked) { background: var(--t-ink); color: var(--t-surface); box-shadow: none; }
.keep-chip:has(input:focus-visible) { outline: 4px solid var(--t-ink); outline-offset: 3px; }
.keep-swatch { width: 18px; height: 18px; border-radius: 6px; box-shadow: inset 0 0 0 1.5px rgba(128, 128, 128, 0.55); }
.keep-chip:has(input:checked) .keep-swatch { box-shadow: 0 0 0 2px var(--t-surface); }
.keep-card-keys { display: flex; flex-wrap: wrap; gap: 8px; }
.keep-card-keys [hidden] { display: none; }
.keep-card-status { margin: 0; min-height: 1.4em; font-weight: 600; font-size: 0.9375rem; }
.keep-card-sheet .keep-fine { margin: 0; }

@media (min-width: 760px) {
  .keep-sheet {
    inset: 50% auto auto 50%;
    width: min(640px, calc(100% - 48px));
    max-height: min(86svh, 860px);
    padding-bottom: 24px;
    border-radius: 28px;
    transform: translate(-50%, -50%);
  }
  .keep-sheet[open] { animation-name: k-sheet-c; }
  @keyframes k-sheet-c { from { transform: translate(-50%, calc(-50% + 30px)); } }
  .keep-card-sheet { width: min(940px, calc(100% - 48px)); }
  .keep-card-body { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; padding-top: 20px; }
  .keep-card-body { padding: 20px 20px 0; }
  .keep-card-canvas { max-height: min(62svh, 600px); }
}

/* ---------- toast ---------- */

.keep-toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 60;
  margin: 0;
  padding: 12px 18px;
  border-radius: var(--t-r-btn, 10px);
  background: var(--t-ink);
  color: var(--t-surface);
  font: 600 0.9375rem/1.3 var(--t-display);
  box-shadow: 0 16px 30px -18px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity var(--t-base), transform var(--t-slow) var(--t-spring);
}
.keep-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .keep-pill.is-in, .keep-sheet[open], .keep-marker i:nth-child(2) { animation: none; }
  .keep-toast, .keep-key, .keep-line-toggle { transition: none; }
  .keep-toast { transform: translate(-50%, 0); }
  .keep-key:active, .keep-line-toggle:active { transform: none; }
}
@media (min-width: 600px) { body.v2 .keep-hint-key { font-size: 1rem; } }
