/* rp bro — cards seat styles (library, character editor, lorebooks).
   Uses ONLY tokens/primitives from /tokens.css; every class is prefixed cl-. */

/* ---------- library ---------- */
.cl-library { position: relative; }
.cl-toolbar { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.cl-search { flex: 1; min-width: 0; border-radius: var(--r-pill); padding-left: var(--sp-4); }
.cl-count { font-size: var(--fs-sm); white-space: nowrap; }
.cl-import-hint { margin: 0 0 var(--sp-4); }

.cl-grid {
  display: grid; gap: var(--sp-4);
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
.cl-card { display: flex; flex-direction: column; padding: 0; overflow: hidden; min-width: 0; }
.cl-card[data-cast="mizuko"] { border-top: 3px solid var(--mizuko); }
.cl-card[data-cast="hinoko"] { border-top: 3px solid var(--hinoko); }
.cl-card[data-cast="denko"] { border-top: 3px solid var(--denko); }
.cl-card-media {
  position: relative; display: block; width: 100%; padding: 0; border: 0; cursor: pointer;
  background: linear-gradient(160deg, var(--accent-soft), var(--accent-2-soft));
  aspect-ratio: 4 / 5; overflow: hidden;
}
.cl-card-img { width: 100%; height: 100%; object-fit: cover; object-position: center top; display: block;
  transition: transform var(--dur) var(--ease); }
.cl-card-media:hover .cl-card-img { transform: scale(1.03); }
.cl-card-noimg { display: flex; align-items: center; justify-content: center; font-size: 48px; color: var(--accent); }
.cl-badge { position: absolute; left: var(--sp-2); top: var(--sp-2); background: var(--surface); box-shadow: var(--shadow-1); }
.cl-card-body { padding: var(--sp-3) var(--sp-3) 0; display: flex; flex-direction: column; gap: var(--sp-1); flex: 1; min-width: 0; }
.cl-card-name { font-size: var(--fs-lg); overflow-wrap: anywhere; }
.cl-tags { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.cl-tagline {
  margin: 0; font-size: var(--fs-sm);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.cl-card-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); padding: var(--sp-3); align-items: flex-start; }
.cl-card-actions .btn-sm { min-height: var(--tap); }
.cl-more { position: relative; }
.cl-more > summary { list-style: none; min-height: var(--tap); }
.cl-more > summary::-webkit-details-marker { display: none; }
.cl-more > summary::after { content: " ▾"; }
.cl-more[open] > summary::after { content: " ▴"; }
.cl-more-menu {
  position: absolute; right: 0; z-index: 5; margin-top: var(--sp-1);
  display: flex; flex-direction: column; gap: var(--sp-1); min-width: 150px;
  padding: var(--sp-2); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--shadow-2);
}
.cl-more-menu .btn { justify-content: flex-start; min-height: var(--tap); }
.cl-empty { grid-column: 1 / -1; }

.cl-drop-hint {
  display: none; position: absolute; inset: 0; z-index: 20; pointer-events: none;
  align-items: center; justify-content: center; text-align: center; padding: var(--sp-5);
  border: 3px dashed var(--accent); border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--accent-soft) 85%, transparent);
  color: var(--accent-strong); font-size: var(--fs-lg); font-weight: 600;
}
.cl-dropping .cl-drop-hint { display: flex; }

/* ---------- editor ---------- */
.cl-section { margin-bottom: var(--sp-4); }
.cl-section-title { margin-bottom: var(--sp-3); color: var(--accent-strong); }
.cl-section-title::before { content: "✦ "; color: var(--accent); }
.cl-identity { display: flex; gap: var(--sp-4); align-items: flex-start; }
.cl-avatar-col { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); width: 160px; flex: none; text-align: center; }
.cl-avatar-img {
  width: 150px; height: 188px; border-radius: var(--r-lg); object-fit: cover; object-position: center top;
  background: linear-gradient(160deg, var(--accent-soft), var(--accent-2-soft)); box-shadow: var(--shadow-1);
}
.cl-avatar-actions { justify-content: center; }
.cl-avatar-actions .btn-sm { min-height: var(--tap); }
.cl-macro-hint { margin: 0; padding: var(--sp-2) var(--sp-3); background: var(--accent-2-soft); border-radius: var(--r-md); color: var(--ink-2); }
.cl-greeting { display: flex; flex-direction: column; gap: var(--sp-1); }
.cl-greeting .btn-sm, .cl-greetings > div > .btn-sm { min-height: var(--tap); }
.cl-two { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }

.cl-chipbox { display: flex; flex-direction: column; gap: var(--sp-2); }
.cl-chips { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.cl-chips:empty { display: none; }
.cl-chip { padding-right: 2px; font-size: var(--fs-sm); }
.cl-chip-x {
  min-width: 32px; min-height: 32px; border: 0; background: transparent; cursor: pointer;
  border-radius: var(--r-pill); color: var(--ink-2); font-size: var(--fs-md); line-height: 1;
}
.cl-chip-x:hover { background: var(--surface); color: var(--danger); }
.cl-chip-row { display: flex; gap: var(--sp-2); }
.cl-chip-row .input { flex: 1; min-width: 0; }
.cl-chip-row .btn { min-height: var(--tap); }

.cl-savebar {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap;
  margin: var(--sp-4) calc(-1 * var(--sp-4)) 0; padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent); border-top: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.cl-dirty { box-shadow: 0 0 0 3px var(--accent-soft); }
.cl-dirty::after { content: " •"; }

/* ---------- lorebooks ---------- */
.cl-group-title { color: var(--ink-2); font-size: var(--fs-md); margin-top: var(--sp-2); }
.cl-book { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-3); }
.cl-book-main { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.cl-book-info { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; min-height: var(--tap); }
.cl-book-name { overflow-wrap: anywhere; }
.cl-book-meta { font-size: var(--fs-sm); }
.cl-chip-char { background: var(--accent-2-soft); }
.cl-book .cl-card-actions { padding: 0; }

/* toggle switch built on a real checkbox (keyboard + screen-reader friendly) */
.cl-switch { position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap); flex: none; cursor: pointer; }
.cl-switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.cl-switch-ui { width: 40px; height: 24px; border-radius: var(--r-pill); background: var(--line); position: relative;
  transition: background var(--dur) var(--ease); }
.cl-switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow-1); transition: transform var(--dur) var(--ease); }
.cl-switch input:checked + .cl-switch-ui { background: var(--ok); }
.cl-switch input:checked + .cl-switch-ui::after { transform: translateX(16px); }
.cl-switch input:focus-visible + .cl-switch-ui { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.cl-checks { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-4); margin-bottom: var(--sp-3); }
.cl-check { display: inline-flex; align-items: center; gap: var(--sp-2); min-height: var(--tap); cursor: pointer; }
.cl-check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.cl-num { max-width: 100%; }

.cl-entries-head { margin: var(--sp-2) 0 var(--sp-3); }
.cl-entries-head .btn-sm { min-height: var(--tap); }
.cl-entry { padding: 0; overflow: hidden; }
.cl-entry-off { opacity: .65; }
.cl-entry-head {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%; min-height: 52px;
  padding: var(--sp-2) var(--sp-4); border: 0; background: transparent; cursor: pointer; text-align: left;
}
.cl-entry-head:hover { background: var(--surface-2); }
.cl-entry-caret { color: var(--accent); width: 16px; flex: none; }
.cl-entry-headtext { display: flex; flex-direction: column; min-width: 0; }
.cl-entry-title { font-weight: 600; overflow-wrap: anywhere; }
.cl-entry-keys { font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cl-entry-body { padding: var(--sp-3) var(--sp-4) var(--sp-4); border-top: 1px solid var(--line); }
.cl-entry-body .btn-sm { min-height: var(--tap); }

/* ---------- phone ---------- */
@media (max-width: 720px) {
  .cl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
  .cl-card-body { padding: var(--sp-2) var(--sp-2) 0; }
  .cl-card-name { font-size: var(--fs-md); }
  .cl-card-actions { padding: var(--sp-2); gap: var(--sp-1); }
  .cl-card-actions .btn { flex: 1 1 auto; padding: 0 var(--sp-2); }
  .cl-more { flex: 1 1 100%; }
  .cl-more > summary { width: 100%; }
  .cl-more-menu { left: 0; right: 0; min-width: 0; }
  .cl-identity { flex-direction: column; align-items: stretch; }
  .cl-avatar-col { width: 100%; }
  .cl-savebar { bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: var(--sp-3);
    /* QA: .page has 12px side padding on phone; a -16px bleed overflowed by 4px -> horizontal scroll */
    margin-left: calc(-1 * var(--sp-3)); margin-right: calc(-1 * var(--sp-3)); padding-left: var(--sp-3); padding-right: var(--sp-3); }
}
/* QA: 44px tap targets on touch screens for the remaining small controls of the cards module */
@media (pointer: coarse), (max-width: 720px) {
  .cl-editor .btn-sm, .cl-book-editor .btn-sm, .cl-lorebooks .btn-sm, .cl-library .btn-sm { min-height: var(--tap); }
  .cl-chip-x { min-width: var(--tap); min-height: var(--tap); }
}
@media (max-width: 400px) {
  .cl-two { grid-template-columns: 1fr; }
  .cl-tagline { -webkit-line-clamp: 2; }
}

/* ---------- v2: library filter chips, AI draft, minor notice ---------- */
.cl-filters { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.cl-filter {
  min-height: 36px; padding: 0 var(--sp-4); border-radius: var(--r-pill); cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font: inherit; font-size: var(--fs-sm);
}
.cl-filter.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); font-weight: 600; }
@media (max-width: 720px), (pointer: coarse) { .cl-filter { min-height: var(--tap); } }
.cl-draft-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-3); }
.cl-draft-btn { min-height: var(--tap); background: linear-gradient(135deg, var(--accent-soft), var(--accent-2-soft)); border-color: transparent; font-weight: 600; }
.cl-minor-notice {
  margin-bottom: var(--sp-3); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md);
  background: color-mix(in srgb, var(--warn) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  font-size: var(--fs-sm); font-weight: 600;
}
