/* Kept pages — strip variants + stack sheet picker */

/* Stack: una riga sotto header, lista nel foglio */
.kept-bar {
  display: none;
  width: 100%;
  align-items: stretch;
  justify-content: space-between;
  gap: 12px;
  margin: 2px 0 8px;
  padding: 12px 12px 12px 14px;
  border-radius: 16px;
  border: 1px solid color-mix(in srgb, var(--card-ink, #eee6d4) 16%, transparent);
  background: var(--pane, #323028);
  color: var(--card-ink, #eee6d4);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 10px color-mix(in srgb, #000 14%, transparent);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}
.kept-bar.on { display: flex; }
.kept-bar:hover,
.kept-bar:focus-visible {
  border-color: color-mix(in srgb, var(--card-ink, #eee6d4) 26%, transparent);
  box-shadow: 0 4px 14px color-mix(in srgb, #000 20%, transparent);
}
.kept-bar:active { transform: scale(0.992); }
.kept-bar-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.kept-bar-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 6px;
  width: 100%;
  font-size: 12px;
  line-height: 1.35;
}
.kept-bar-matter {
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--gold, #d4b46a);
  text-transform: none;
}
.kept-bar-when { color: var(--muted, #8a7d62); font-weight: 500; }
.kept-bar-sep { color: var(--muted, #8a7d62); opacity: 0.55; }
.kept-bar-body b,
.kept-bar-body #keptBarTitle {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
}
.kept-bar-desc {
  font-size: 12px;
  line-height: 1.4;
  color: color-mix(in srgb, var(--card-ink, #eee6d4) 78%, transparent);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.kept-bar-hint {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted, #8a7d62);
  font-weight: 500;
}
.kept-bar-more {
  flex: 0 0 auto;
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: -6px -4px -6px 0;
  padding: 10px 6px 10px 10px;
  color: color-mix(in srgb, var(--card-ink, #eee6d4) 58%, transparent);
  background: none;
  border: none;
  transition: color 0.15s ease, opacity 0.15s ease;
}
.kept-bar-icon {
  display: block;
  width: 20px;
  height: 20px;
}
.kept-bar:hover .kept-bar-more,
.kept-bar:focus-visible .kept-bar-more {
  color: color-mix(in srgb, var(--card-ink, #eee6d4) 90%, transparent);
}

/* Foglio archivio: massimo 3/4 schermo, solo la lista scrolla */
#keptPop.bugpop.sheet.kept-sheet {
  overflow: hidden !important;
  overscroll-behavior: none;
  max-height: 75dvh !important;
}
.bugpop.sheet.kept-sheet.on {
  display: flex !important;
  flex-direction: column;
  height: 75dvh;
  max-height: 75dvh;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
#keptPop .kept-sheet-head {
  flex: 0 0 auto;
  flex-shrink: 0;
  margin: 0 0 8px;
  padding-bottom: 2px;
  background: var(--card, #2a2822);
  position: relative;
  z-index: 0;
}
#keptPop .kept-sheet-head .handle {
  margin-bottom: 10px;
}
#keptPop.kept-sheet .sheet-title {
  flex: 0 0 auto;
  margin: 0;
}
#keptPop .kept-pop-scroll {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  z-index: 0;
}

html[data-shell="stack"][data-kept-stack="1"].kept-logged-on #keptStrip.on { display: none !important; }
html[data-shell="stack"][data-kept-stack="1"].kept-logged-on h1 { display: none; }
html[data-shell="stack"][data-kept-stack="1"].kept-logged-on .lead { display: none; }
html[data-shell="stack"][data-kept-stack="1"].kept-logged-on #inLine { margin-top: 0; }
html[data-shell="stack"][data-kept-stack="0"] #keptBar { display: none !important; }
html[data-shell="stack"][data-kept-stack="0"].kept-logged-on #keptStrip.on { display: flex !important; }

/* Stack sheet: capsule rettangolari, lista scrollabile nel 75vh */
#keptPop .kept-pop-list.kept-archivio {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  gap: 10px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 2px 2px 14px;
  margin: 0;
  background: transparent;
  color: var(--card-ink, #eee6d4);
  border: none;
  border-radius: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scroll-padding-top: 4px;
  scroll-padding-bottom: 16px;
  scrollbar-gutter: stable;
}
#keptPop .kept-pop-list.kept-archivio.has-more {
  /* niente overlay sopra le card: solo padding in fondo */
  padding-bottom: 18px;
}
#keptPop .kept-archivio .keptcard {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  text-align: left;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--card-ink, #eee6d4) 14%, transparent);
  padding: 14px 15px 12px;
  margin: 0;
  background: var(--pane, #323028);
  box-shadow: 0 1px 0 color-mix(in srgb, #000 22%, transparent);
  cursor: pointer;
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
#keptPop .kept-archivio .keptcard-head {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px 12px;
  width: 100%;
}
#keptPop .kept-archivio .keptcard-matter {
  display: inline-flex;
  align-items: center;
  max-width: 58%;
  padding: 4px 9px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gold, #d4b46a);
  background: color-mix(in srgb, var(--gold, #d4b46a) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--gold, #d4b46a) 22%, transparent);
  line-height: 1.25;
}
#keptPop .kept-archivio .keptcard-when {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
  max-width: 42%;
  line-height: 1.25;
}
#keptPop .kept-archivio .keptcard-when-rel {
  font-size: 12px;
  font-weight: 600;
  color: var(--card-ink, #eee6d4);
  opacity: 0.92;
}
#keptPop .kept-archivio .keptcard-when-date {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted, #8a7d62);
  white-space: nowrap;
}
#keptPop .kept-archivio .keptcard-title {
  margin: 0;
  font-size: 19px;
  line-height: 1.2;
  font-family: "Source Serif 4", Georgia, serif;
  font-weight: 600;
  color: var(--card-ink, #eee6d4);
}
#keptPop .kept-archivio .keptcard-desc {
  font-size: 13px;
  line-height: 1.5;
  color: color-mix(in srgb, var(--card-ink, #eee6d4) 78%, transparent);
  width: 100%;
}
#keptPop .kept-archivio .keptcard-foot {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-top: 2px;
  padding-top: 8px;
  border-top: 1px solid color-mix(in srgb, var(--card-ink, #eee6d4) 10%, transparent);
}
#keptPop .kept-archivio .keptcard-mode {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 12px;
  border-radius: 9px;
  font-size: 11px;
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid color-mix(in srgb, var(--card-ink, #eee6d4) 20%, transparent);
  color: color-mix(in srgb, var(--card-ink, #eee6d4) 88%, transparent);
  background: color-mix(in srgb, var(--card, #2a2822) 40%, var(--pane, #323028));
}
#keptPop .kept-archivio .keptcard.on {
  border-color: color-mix(in srgb, var(--gold, #d4b46a) 55%, transparent);
  background: color-mix(in srgb, var(--gold, #d4b46a) 10%, var(--pane, #323028));
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--gold, #d4b46a) 35%, transparent),
    0 6px 18px color-mix(in srgb, #000 28%, transparent);
}
#keptPop .kept-archivio .keptcard.on .keptcard-mode {
  background: var(--btn, #d4c08a);
  color: #1a1610;
  border-color: var(--gold, #d4b46a);
}
#keptPop .kept-archivio .keptcard.on .keptcard-when-rel {
  color: var(--gold, #d4b46a);
}

html[data-light="day"] #keptPop .kept-archivio .keptcard {
  background: var(--pane, #f7f3ea);
  border-color: color-mix(in srgb, var(--card-ink, #1c1915) 12%, transparent);
}
html[data-light="day"] #keptPop .kept-archivio .keptcard.on {
  background: color-mix(in srgb, var(--gold, #b49656) 14%, var(--pane, #f7f3ea));
}
html[data-light="day"] #keptPop .kept-archivio .keptcard.on .keptcard-mode {
  color: #1a1610;
}

@media (max-width: 520px) {
  .bugpop.sheet.kept-sheet.on {
    height: 75dvh;
    max-height: 75dvh;
  }
  #keptPop .kept-archivio .keptcard-head {
    flex-wrap: wrap;
  }
  #keptPop .kept-archivio .keptcard-matter {
    max-width: 100%;
  }
  #keptPop .kept-archivio .keptcard-when {
    align-items: flex-start;
    text-align: left;
    max-width: 100%;
  }
  #keptPop .kept-archivio .keptcard-title {
    font-size: 17px;
  }
}

/* Kept pages strip — variants A (carte), B (pillole), C (archivio). ?keptUi=a|b|c */

.keptstrip-label {
  display: none;
  margin: 0 0 8px;
  padding: 0 4px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted, #8a7d62);
  flex: 0 0 100%;
  width: 100%;
}

/* —— A: Carte (scroll orizzontale, etichetta + fade) —— */
html[data-kept-ui="a"] .keptstrip-label,
.kept-demo[data-kept-ui="a"] .keptstrip-label {
  display: block;
}
html[data-kept-ui="a"] .keptstrip.on,
.kept-demo[data-kept-ui="a"] .keptstrip.on {
  flex-wrap: nowrap;
  padding: 2px 2px 10px;
  margin: 4px 0 8px;
  -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 28px), transparent);
}
html[data-kept-ui="a"] .keptcard,
.kept-demo[data-kept-ui="a"] .keptcard {
  flex: 0 0 158px;
  min-height: 64px;
  border-radius: 16px;
  padding: 11px 13px;
  background: var(--card, #2a2822);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
html[data-kept-ui="a"] .keptcard.on,
.kept-demo[data-kept-ui="a"] .keptcard.on {
  border-color: rgba(212, 180, 106, 0.55);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
}

/* —— B: Pillole (una riga compatta, meta · titolo) —— */
html[data-kept-ui="b"] .keptstrip-label,
.kept-demo[data-kept-ui="b"] .keptstrip-label {
  display: block;
}
html[data-kept-ui="b"] .keptstrip.on,
.kept-demo[data-kept-ui="b"] .keptstrip.on {
  flex-wrap: nowrap;
  gap: 8px;
  padding: 0 0 12px;
  margin: 6px 0 4px;
}
html[data-kept-ui="b"] .keptcard,
.kept-demo[data-kept-ui="b"] .keptcard {
  flex: 0 0 auto;
  max-width: min(240px, 72vw);
  border-radius: 999px;
  padding: 9px 16px;
  background: color-mix(in srgb, var(--pane, #323028) 88%, transparent);
  border: 1px solid rgba(180, 150, 86, 0.18);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
html[data-kept-ui="b"] .keptcard small,
.kept-demo[data-kept-ui="b"] .keptcard small {
  display: inline;
  font-size: 11px;
  opacity: 0.72;
  margin: 0;
}
html[data-kept-ui="b"] .keptcard small::after,
.kept-demo[data-kept-ui="b"] .keptcard small::after {
  content: " · ";
  opacity: 0.5;
}
html[data-kept-ui="b"] .keptcard b,
.kept-demo[data-kept-ui="b"] .keptcard b {
  display: inline;
  font-size: 14px;
  margin: 0;
  font-weight: 600;
}
html[data-kept-ui="b"] .keptcard.on,
.kept-demo[data-kept-ui="b"] .keptcard.on {
  background: rgba(212, 180, 106, 0.14);
  border-color: rgba(212, 180, 106, 0.45);
  box-shadow: none;
}

/* —— C: Archivio (lista verticale, pannello) —— */
html[data-kept-ui="c"] .keptstrip-label,
.kept-demo[data-kept-ui="c"] .keptstrip-label {
  display: block;
  margin-bottom: 10px;
}
html[data-kept-ui="c"] .keptstrip.on,
.kept-demo[data-kept-ui="c"] .keptstrip.on {
  flex-direction: column;
  flex-wrap: nowrap;
  overflow-x: hidden;
  overflow-y: auto;
  max-height: min(38vh, 260px);
  gap: 0;
  padding: 10px 12px;
  margin: 6px 0 12px;
  background: var(--card, #2a2822);
  border-radius: 18px;
  border: 1px solid rgba(180, 150, 86, 0.2);
  -webkit-mask-image: none;
  mask-image: none;
}
html[data-kept-ui="c"] .keptcard,
.kept-demo[data-kept-ui="c"] .keptcard {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  border-radius: 0;
  border: none;
  border-left: 3px solid rgba(180, 150, 86, 0.22);
  padding: 12px 8px 12px 12px;
  margin: 0;
  background: transparent;
  box-shadow: none;
}
html[data-kept-ui="c"] .keptcard + .keptcard,
.kept-demo[data-kept-ui="c"] .keptcard + .keptcard {
  border-top: 1px solid rgba(180, 150, 86, 0.1);
}
html[data-kept-ui="c"] .keptcard b,
.kept-demo[data-kept-ui="c"] .keptcard b {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
}
html[data-kept-ui="c"] .keptcard small,
.kept-demo[data-kept-ui="c"] .keptcard small {
  flex: 0 0 auto;
  margin: 0;
  font-size: 10px;
  opacity: 0.65;
  text-align: right;
  max-width: 42%;
  line-height: 1.3;
}
html[data-kept-ui="c"] .keptcard.on,
.kept-demo[data-kept-ui="c"] .keptcard.on {
  border-left-color: var(--gold, #d4b46a);
  background: rgba(212, 180, 106, 0.07);
  box-shadow: none;
}

/* C compact: full = lista alta (default desktop legacy) */
html[data-kept-ui="c"][data-kept-compact="full"] .keptstrip.on,
.kept-demo[data-kept-ui="c"][data-kept-compact="full"] .keptstrip.on {
  max-height: min(38vh, 260px);
}

/* C · fold — una riga (pagina attiva), tap sull’etichetta per espandere */
html[data-kept-ui="c"][data-kept-compact="fold"] .keptstrip-label,
.kept-demo[data-kept-ui="c"][data-kept-compact="fold"] .keptstrip-label {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
html[data-kept-ui="c"][data-kept-compact="fold"] .keptstrip-label::after,
.kept-demo[data-kept-ui="c"][data-kept-compact="fold"] .keptstrip-label::after {
  content: " ▾";
  opacity: 0.75;
}
html[data-kept-ui="c"][data-kept-compact="fold"] .keptstrip.is-expanded .keptstrip-label::after,
.kept-demo[data-kept-ui="c"][data-kept-compact="fold"] .keptstrip.is-expanded .keptstrip-label::after {
  content: " ▴";
}
html[data-kept-ui="c"][data-kept-compact="fold"] .keptstrip.on.is-collapsed,
.kept-demo[data-kept-ui="c"][data-kept-compact="fold"] .keptstrip.on.is-collapsed {
  max-height: none;
  overflow: hidden;
  padding: 6px 10px 8px;
  margin: 4px 0 6px;
}
html[data-kept-ui="c"][data-kept-compact="fold"] .keptstrip.on.is-collapsed .keptcard:not(.on),
.kept-demo[data-kept-ui="c"][data-kept-compact="fold"] .keptstrip.on.is-collapsed .keptcard:not(.on) {
  display: none;
}
html[data-kept-ui="c"][data-kept-compact="fold"] .keptstrip.on.is-collapsed .keptcard.on,
.kept-demo[data-kept-ui="c"][data-kept-compact="fold"] .keptstrip.on.is-collapsed .keptcard.on {
  padding: 8px 8px 8px 11px;
  min-height: 0;
}
html[data-kept-ui="c"][data-kept-compact="fold"] .keptstrip.on.is-expanded,
.kept-demo[data-kept-ui="c"][data-kept-compact="fold"] .keptstrip.on.is-expanded {
  max-height: min(34vh, 200px);
  overflow-y: auto;
}

/* C · peek — massimo ~2 righe, scroll leggero */
html[data-kept-ui="c"][data-kept-compact="peek"] .keptstrip.on,
.kept-demo[data-kept-ui="c"][data-kept-compact="peek"] .keptstrip.on {
  max-height: 112px;
  overflow-y: auto;
  padding: 8px 10px;
  margin: 4px 0 8px;
}

/* C · inline — striscia orizzontale, card strette (poco verticale) */
html[data-kept-ui="c"][data-kept-compact="inline"] .keptstrip.on,
.kept-demo[data-kept-ui="c"][data-kept-compact="inline"] .keptstrip.on {
  flex-direction: row;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: none;
  max-height: none;
  gap: 8px;
  padding: 8px 10px;
  margin: 4px 0 8px;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}
html[data-kept-ui="c"][data-kept-compact="inline"] .keptcard,
.kept-demo[data-kept-ui="c"][data-kept-compact="inline"] .keptcard {
  flex: 0 0 clamp(148px, 44vw, 188px);
  width: auto;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 10px 10px 11px;
  border-radius: 12px;
  border: 1px solid rgba(180, 150, 86, 0.16);
  border-left: 3px solid rgba(180, 150, 86, 0.28);
  scroll-snap-align: start;
}
html[data-kept-ui="c"][data-kept-compact="inline"] .keptcard + .keptcard,
.kept-demo[data-kept-ui="c"][data-kept-compact="inline"] .keptcard + .keptcard {
  border-top: none;
}
html[data-kept-ui="c"][data-kept-compact="inline"] .keptcard small,
.kept-demo[data-kept-ui="c"][data-kept-compact="inline"] .keptcard small {
  max-width: 100%;
  text-align: left;
  font-size: 10px;
}
html[data-kept-ui="c"][data-kept-compact="inline"] .keptcard b,
.kept-demo[data-kept-ui="c"][data-kept-compact="inline"] .keptcard b {
  font-size: 15px;
}

/* —— Mobile / narrow (stack shell, phone preview) —— */
@media (max-width: 520px) {
  .keptstrip-label {
    font-size: 10px;
    margin-bottom: 6px;
    padding: 0 2px;
  }

  /* A: card width scales with viewport, still one-hand scroll */
  html[data-kept-ui="a"] .keptstrip.on,
  .kept-demo[data-kept-ui="a"] .keptstrip.on {
    margin: 2px 0 6px;
    padding: 0 0 8px;
    gap: 8px;
    scroll-snap-type: x proximity;
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 18px), transparent);
    mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 18px), transparent);
  }
  html[data-kept-ui="a"] .keptcard,
  .kept-demo[data-kept-ui="a"] .keptcard {
    flex: 0 0 clamp(124px, 36vw, 152px);
    min-height: 56px;
    padding: 10px 11px;
    scroll-snap-align: start;
  }
  html[data-kept-ui="a"] .keptcard b,
  .kept-demo[data-kept-ui="a"] .keptcard b {
    font-size: 15px;
    line-height: 1.2;
  }
  html[data-kept-ui="a"] .keptcard small,
  .kept-demo[data-kept-ui="a"] .keptcard small {
    font-size: 10px;
  }

  /* C full/peek: stacked rows on narrow screens */
  html[data-kept-ui="c"]:not([data-kept-compact="inline"]) .keptcard,
  .kept-demo[data-kept-ui="c"]:not([data-kept-compact="inline"]) .keptcard {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 11px 8px 11px 11px;
    min-height: 48px;
  }
  html[data-kept-ui="c"]:not([data-kept-compact="inline"]) .keptcard b,
  .kept-demo[data-kept-ui="c"]:not([data-kept-compact="inline"]) .keptcard b {
    font-size: 16px;
    width: 100%;
  }
  html[data-kept-ui="c"]:not([data-kept-compact="inline"]) .keptcard small,
  .kept-demo[data-kept-ui="c"]:not([data-kept-compact="inline"]) .keptcard small {
    max-width: 100%;
    text-align: left;
    font-size: 11px;
    opacity: 0.72;
  }

  html[data-kept-ui="c"] .keptstrip.on,
  .kept-demo[data-kept-ui="c"] .keptstrip.on {
    border-radius: 16px;
    -webkit-overflow-scrolling: touch;
  }

  html[data-kept-ui="c"] .keptstrip.on ~ h1 {
    margin-top: 4px;
    font-size: 22px;
  }
  html[data-kept-ui="c"] .keptstrip.on ~ .lead {
    margin-bottom: 10px;
    font-size: 14px;
  }
}

@media (min-width: 521px) and (max-width: 900px) {
  html[data-kept-ui="a"] .keptcard,
  .kept-demo[data-kept-ui="a"] .keptcard {
    flex: 0 0 clamp(140px, 28vw, 168px);
  }
}
