/* The caption picker and the template editor (13.13, static/js/captemplates.js). Card-free like the rest of the app
   (flat.css): the tiles are pictures, so they keep rounded frames, and the one picked gets an outline ring; everything
   else is type, hairlines and the page's own tokens, so both themes follow. Phones first. */

/* ---------- the picker: two tabs, a grid of tiles that move ---------- */
.cpk { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.cpk-tabs { margin: 0; }
.cpk-n { color: var(--text-3); font-weight: 600; margin-left: 2px; }
.cpk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 18px 14px; }
.cpk.compact .cpk-grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 14px 12px; }
.cpk-grid.mine { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
.cpk-wait { padding: 18px 0; }
.cpk-tile { display: flex; flex-direction: column; gap: 4px; align-items: stretch; text-align: left; padding: 0; margin: 0;
  background: none; border: 0; color: var(--text); cursor: pointer; font: inherit; min-width: 0; }
.cpk-tile b { margin-top: 6px; font-weight: 650; font-size: var(--fs-sm); color: var(--text-hi); line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cpk-tile small { color: var(--text-3); font-size: var(--fs-xs); line-height: 1.35; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.cpk-tile.on b { color: var(--accent-text); }
.cpk-pic { position: relative; display: block; aspect-ratio: 9 / 5; border-radius: 10px; overflow: hidden; background: #26262e;
  transition: transform var(--t, .18s) var(--spring, ease); }
.cpk-pic.tall { aspect-ratio: 9 / 16; }
.cpk-pic img, .cpk-pic video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.cpk-tile:hover .cpk-pic { transform: translateY(-2px); }
.cpk-tile.on .cpk-pic { outline: 2px solid var(--brand-ink); outline-offset: 3px; }
.cpk-tile:focus-visible { outline: none; }
.cpk-tile:focus-visible .cpk-pic { outline: 2px solid var(--focus-ring, var(--brand-ink)); outline-offset: 3px; }
.cpk-none, .cpk-plus { display: grid; place-items: center; color: #e9edf5; }
.cpk-none .icon, .cpk-plus .icon { width: 30px; height: 30px; opacity: .9; }
.cpk-plus { background: var(--media-bg); color: var(--text-2); }
.cpk-mine { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cpk-acts { display: flex; flex-wrap: wrap; gap: 2px 12px; }
.cpk-acts .link { font-size: var(--fs-xs); font-weight: 600; display: inline-flex; gap: 4px; align-items: center; padding: 4px 0; }
.cpk-foot { margin: 0; line-height: 1.55; max-width: 70ch; }
.cpk-foot .link { display: inline; font-weight: 600; }
@media (prefers-reduced-motion: reduce) {
  .cpk-pic video { display: none; }
  .cpk-pic, .cpk-tile:hover .cpk-pic { transition: none; transform: none; }
}

/* ---------- the template editor: the live picture beside the form, above it on a phone ---------- */
.cte { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr); gap: 26px; align-items: start; margin-top: 6px; }
.cte-prev { position: sticky; top: 0; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.cte-frame { position: relative; width: 100%; aspect-ratio: 9 / 16; border-radius: 12px; overflow: hidden; background: #26262e; }
.cte-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cte-frame img:not([src]) { visibility: hidden; }
.cte-spin { position: absolute; top: 10px; right: 10px; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .3); border-top-color: #fff; animation: cteSpin .9s linear infinite; }
.cte-spin[hidden] { display: none; }
@keyframes cteSpin { to { transform: rotate(360deg); } }
.cte-note { line-height: 1.45; min-height: 1.45em; }
.cte-form { display: flex; flex-direction: column; gap: 14px; min-width: 0; max-height: min(70vh, 760px); overflow-y: auto;
  padding-right: 4px; }
.cte-form .field { margin: 0; }
.cte-sec { padding-top: 14px; border-top: 1px solid var(--rule); display: flex; flex-direction: column; gap: 10px; }
.cte-h { margin: 0; font-size: var(--fs); font-weight: 650; color: var(--text-hi); }
.cte-row { display: grid; grid-template-columns: 104px minmax(0, 1fr) auto; gap: 8px 12px; align-items: center; }
.cte-row > .seg, .cte-row > .cte-sw { grid-column: 2 / span 2; }
.cte-k { color: var(--text-2); font-size: var(--fs-sm); font-weight: 550; }
.cte-row input[type="range"] { width: 100%; }
.cte-out { min-width: 3.2em; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; font-size: var(--fs-sm); }
.cte-fonts { display: flex; flex-wrap: wrap; gap: 4px 18px; max-height: 196px; overflow-y: auto; padding: 2px 0; }
.cte-fonts.mine { max-height: none; }
.cte-font { background: none; border: 0; border-bottom: 2px solid transparent; padding: 5px 0 4px; font-size: 18px; line-height: 1.2;
  color: var(--text); cursor: pointer; font-synthesis: none; white-space: nowrap; }
.cte-font:hover { color: var(--text-hi); border-bottom-color: var(--rule-3); }
.cte-font.on { color: var(--accent-text); border-bottom-color: var(--brand-ink); }
.cte-own { display: inline-flex; align-items: center; gap: 2px; }
.cte-x { width: 28px; height: 28px; color: var(--text-3); }
.cte-x:hover { color: var(--text-hi); }
.cte-up { gap: 8px 12px; align-items: center; }
.cte-up small { line-height: 1.45; }
.cte-sw { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cte-dot { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--rule-3); padding: 0; cursor: pointer;
  display: grid; place-items: center; color: var(--text-2); background: none; }
.cte-dot.on { outline: 2px solid var(--brand-ink); outline-offset: 2px; }
.cte-dot.none .icon { width: 14px; height: 14px; }
.cte-pick { width: 34px; height: 26px; padding: 0; border: 0; background: none; cursor: pointer; }
.cte-switch { gap: 14px; cursor: pointer; }
.cte-switch small { display: block; margin-top: 2px; line-height: 1.4; }
.cte-logos { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.cte-logo { width: 64px; height: 64px; border-radius: 10px; border: 0; padding: 6px; cursor: pointer; display: grid; place-items: center;
  background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface-3) 0 50%) 50% / 12px 12px; color: var(--text-2); }
.cte-logo img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.cte-logo.none { background: var(--surface-2); display: flex; flex-direction: column; gap: 2px; }
.cte-logo.none small { font-size: var(--fs-xs); color: var(--text-3); }
.cte-logo.on { outline: 2px solid var(--brand-ink); outline-offset: 3px; }
.cte-foot { margin-top: 20px; gap: 10px; padding-top: 14px; border-top: 1px solid var(--rule); }
.cte-del { color: var(--rose); }

@media (max-width: 767px) {
  .cte { grid-template-columns: 1fr; gap: 16px; }
  .cte-prev { position: static; flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
  .cte-frame { width: 140px; flex: none; }
  .cte-form { max-height: none; overflow: visible; padding-right: 0; }
  .cte-row { grid-template-columns: 92px minmax(0, 1fr) auto; }
  .cte-row .seg { display: flex; width: 100%; }
  .cte-row .seg button { flex: 1 1 auto; padding: 0 6px; }
  .cte-foot .btn { flex: 1 1 auto; }
  .cpk-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; }
  .cpk-grid.mine { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) { .cte-spin { animation: none; } }
