/* Template cards (/templates/, its kinds, the homepage's "Top templates"; built by scripts/templates-pages.mjs, played and
   filtered by assets/js/templates.js) and the template form (assets/js/template-modal.js). */

/* The library runs nearly edge to edge, with a thin gutter, so more templates fit on one screen. */
.tp-home, .tpl-head, .tpl-list { --lib-gutter: clamp(12px, 1.5vw, 24px); padding-inline: var(--lib-gutter); }

/* ---------- the page: a big search right under the nav, the filters in one row, then the grid ---------- */
.page-head.tpl-head { grid-template-columns: minmax(0, 1fr); gap: 14px; padding-top: calc(var(--nav-h) + clamp(14px, 1.8vw, 26px)); padding-bottom: clamp(16px, 1.8vw, 24px); }
.page-head.tpl-head > * { max-width: none; }
.tsearch { display: block; }
.tsearch-i { position: absolute; left: clamp(18px, 1.6vw, 26px); top: 50%; width: 26px; height: 26px; margin-top: -13px; fill: var(--ink-3); pointer-events: none; transition: fill var(--d-hover) ease; }
.tsearch .input { min-height: clamp(58px, 4.8vw, 72px); padding: 10px 20px 10px calc(clamp(18px, 1.6vw, 26px) + 42px); background: rgb(11 12 15 / .88); font: 500 clamp(1.0625rem, .95rem + .45vw, 1.375rem)/1.2 var(--f-text); }
.tsearch .input::placeholder { color: #7f8792; }
.tsearch:focus-within .tsearch-i { fill: var(--green); }
.tbar-row { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
.tbar-row .chip { --chip-c: var(--green); }
.tshapes { padding-left: 14px; border-left: 2px solid var(--edge-hi); }
a.chip { display: inline-flex; align-items: center; text-decoration: none; }
a.chip[aria-current="page"] { color: var(--ink-dark); background: var(--chip-c, var(--green)); box-shadow: inset -3px -3px 0 0 rgb(0 0 0 / .3), inset 3px 3px 0 0 rgb(255 255 255 / .45); }
.tcount { margin: 0 0 0 auto; color: var(--ink-3); font: 400 var(--t-label)/1 var(--f-pixel); letter-spacing: .04em; text-transform: uppercase; }
.tempty { margin-top: 12px; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.tpl-list { padding-bottom: clamp(56px, 7vw, 112px); }
@media (max-width: 640px) {
  /* the kinds scroll sideways in one line */
  .tbar-row nav.chips { flex-wrap: nowrap; overflow-x: auto; width: calc(100% + 2 * var(--lib-gutter)); margin-inline: calc(var(--lib-gutter) * -1); padding: 3px var(--lib-gutter); scrollbar-width: none; }
  .tbar-row nav.chips::-webkit-scrollbar { display: none; }
  .tbar-row nav.chips .chip { flex: none; }
  .tshapes { padding-left: 0; border-left: 0; }
}

/* ---------- the homepage section: right under the prompt band, heading and chips in one row ---------- */
.tp-home { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 18px 28px; padding-top: clamp(28px, 3.4vw, 52px); }
.tp-home .s-head { gap: 8px; max-width: 760px; margin: 0; }
.tp-home .s-head h2 { font-size: clamp(1.875rem, 1.1rem + 2.2vw, 3rem); }
.tp-home .s-head .lead { font-size: 1.0625rem; max-width: 62ch; }
.tp-home .tp-chips { justify-content: flex-end; }
.tp-home .tp-chips .chip { --chip-c: var(--green); }
.tp-home .tgrid, .tp-home .tp-more { grid-column: 1 / -1; }
.tp-more { display: flex; justify-content: center; margin: 14px 0 0; }
@media (max-width: 960px) { .tp-home { grid-template-columns: minmax(0, 1fr); } .tp-home .tp-chips { justify-content: flex-start; } }

/* ---------- cards: the video with its info on it. Big: 4 a row at 1440, 6 at 1920, 2 on a phone ---------- */
.tgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: clamp(10px, 1vw, 16px); margin: 0; padding: 0; list-style: none; }
.tc { min-width: 0; }
.tc[hidden] { display: none; }
.tc-link {
  --fc: var(--edge-hi);
  position: relative; display: block; aspect-ratio: 4 / 5; overflow: hidden; background: var(--well); color: var(--ink); text-decoration: none; -webkit-tap-highlight-color: transparent;
  box-shadow: 0 0 0 2px var(--fc);
  transition: box-shadow var(--d-hover) ease, transform var(--d-ui) var(--ease-out);
}
.tc-media, .tc-media img, .tc-media video { position: absolute; inset: 0; width: 100%; height: 100%; }
.tc-media img, .tc-media video { object-fit: cover; }
/* a wide-only template sits whole in the card, a little above the middle (the info is under it) */
.tc-media[data-shape="wide"] img, .tc-media[data-shape="wide"] video { object-fit: contain; object-position: 50% 38%; }
.tc-media video { opacity: 0; transition: opacity 240ms ease; }
.tc.playing .tc-media video { opacity: 1; }
/* the info: kind and length, name, shapes and price. "Use template" waits under the bottom edge (translateY = its
   height + the bottom padding) and slides up on hover or keyboard focus. */
.tc-info {
  position: absolute; left: 0; right: 0; bottom: 0; display: grid; gap: 3px; padding: 44px 14px 12px;
  /* nearly solid under the words (the previews have their own captions down there), a short fade above them */
  background: linear-gradient(to top, rgb(7 8 10 / .985), rgb(7 8 10 / .97) calc(100% - 44px), rgb(7 8 10 / 0));
  transform: translateY(42px); transition: transform 260ms var(--ease-out);
}
.tc-kind { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 .8125rem/1.3 var(--f-text); color: #bcc5ce; }
.tc-name { margin: 0; font: 600 1.3125rem/1.15 var(--f-display); letter-spacing: -0.015em; color: #fff; text-wrap: balance; }
.tc-row { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 8px; margin-top: 5px; }
.tc-shapes { display: inline-flex; gap: 6px; font: 500 .6875rem/1 var(--f-mono); color: #aeb7c0; }
.tc-shapes b { font-weight: 500; }
.tc-price { font: 600 .8125rem/1 var(--f-text); color: var(--green); white-space: nowrap; }
.tc-use {
  display: flex; align-items: center; justify-content: center; gap: 9px; height: 30px; margin-top: 9px;
  background: var(--green); color: var(--green-ink); font: 700 .875rem/1 var(--f-text);
  box-shadow: inset -3px -3px 0 0 rgb(0 0 0 / .3), inset 3px 3px 0 0 rgb(255 255 255 / .45);
}
.tc-use::after { content: ""; width: 7px; height: 7px; border: solid currentColor; border-width: 2.5px 2.5px 0 0; transform: rotate(45deg); }
@media (hover: hover) and (pointer: fine) {
  .tc-link:hover { --fc: var(--green); transform: translateY(-3px); }
  .tc-link:hover .tc-info { transform: none; }
}
.tc-link:focus-visible { --fc: var(--green); outline: 3px solid var(--green-hi); outline-offset: 4px; }
.tc-link:focus-visible .tc-info { transform: none; }
@media (max-width: 680px) { .tgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) {
  .tgrid { gap: 8px; }
  .tc-info { padding: 40px 10px 12px; }
  .tc-name { font-size: 1.0625rem; }
  .tc-price { font-size: .75rem; }
  .tc-kind { font-size: .6875rem; }
  .tc-shapes { display: none; }
}
@media (prefers-reduced-motion: reduce) { .tc-link, .tc-info, .tc-media video { transition: none; } .tc-link:hover { transform: none; } }

/* ---------- the template form (a <dialog>) ---------- */
.tm {
  --fw: 4px; --fc: var(--edge-hi);
  width: min(1180px, 100% - 32px); max-width: none; height: min(860px, 100dvh - 32px); max-height: none; margin: auto; padding: 0; border: 0;
  background: var(--bg-2); color: var(--ink); overflow: hidden;
  box-shadow: 0 calc(var(--fw) * -1) 0 0 var(--fc), 0 var(--fw) 0 0 var(--fc), calc(var(--fw) * -1) 0 0 0 var(--fc), var(--fw) 0 0 0 var(--fc), 14px 14px 0 0 rgb(0 0 0 / .55);
}
.tm[open] { display: grid; grid-template-rows: auto 1fr auto; }
.tm::backdrop { background: rgb(4 6 8 / .8); }
.tm-bar { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 0 8px 0 20px; background: var(--panel-2); border-bottom: 3px solid #0b0c0f; }
.tm-bar h2 { margin: 0; font-size: 1.375rem; letter-spacing: -0.02em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tm-bar .px-label { flex: none; }
.tm-x { margin-left: auto; flex: none; width: 44px; height: 44px; border: 0; background: var(--panel-3); color: var(--ink); cursor: pointer; display: grid; place-items: center; box-shadow: inset -3px -3px 0 0 #0d0f12, inset 3px 3px 0 0 rgb(255 255 255 / .1); }
.tm-x::before, .tm-x::after { content: ""; grid-area: 1 / 1; width: 18px; height: 3px; background: currentColor; transform: rotate(45deg); }
.tm-x::after { transform: rotate(-45deg); }
.tm-x:active { transform: translateY(2px); }
.tm-body { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(340px, .95fr); min-height: 0; }
.tm-view { position: relative; display: grid; align-content: center; justify-items: center; gap: 12px; padding: 24px; background: var(--well); min-height: 0; overflow: hidden; }
.tm-screen { position: relative; overflow: hidden; background: #000; box-shadow: 0 0 0 3px var(--edge-hi); }
.tm-screen > video, .tm-screen > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* the engine's stage (it names itself .gs-stage): design pixels, scaled to the screen by template-modal.js */
.tm-screen > .gs-stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.tm-live { position: absolute; left: 8px; top: 8px; z-index: 2; }
.tm-live .badge { height: 22px; }
.tm-note { margin: 0; max-width: 46ch; text-align: center; font-size: .875rem; line-height: 1.45; color: var(--ink-3); }
.tm-form { display: grid; align-content: start; gap: 22px; padding: 22px 24px 28px; overflow: auto; overscroll-behavior: contain; min-height: 0; }
.tm-form .field { gap: 8px; }
.tm-form .field > label, .tm-form .lbl { font-size: var(--t-small); font-weight: 600; }
.tm-form .req { color: var(--green); margin-left: 3px; }
.tm-form .field input:not([type="color"]):not([type="radio"]):not([type="file"]), .tm-form .field select, .tm-form .field textarea { min-height: 46px; padding: 10px 12px; }
.tm-form .field textarea { min-height: 84px; }
.tm-form .hint { font-size: .8125rem; color: var(--ink-3); }
.tm-form .count { justify-self: end; margin-top: -4px; font: 400 .6875rem/1 var(--f-mono); color: var(--ink-3); }
.tm-form .count.over { color: var(--err); }
.tm-form .field.bad input, .tm-form .field.bad textarea { border-color: var(--err); }
.tm-form .err { margin: 0; font-size: .8125rem; color: var(--err); }
.tm-group { display: grid; gap: 22px; padding-top: 20px; border-top: 2px solid var(--edge); }
.tm-group > h3 { margin: 0; font: 400 var(--t-label)/1 var(--f-pixel); letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); }
/* Write my text */
.tm-write { display: grid; gap: 10px; padding: 14px; background: var(--field); box-shadow: 0 0 0 3px var(--field-3); }
.tm-write label { font-size: var(--t-small); font-weight: 600; }
.tm-write-row { display: flex; gap: 8px; align-items: stretch; }
.tm-write-row .input { flex: 1; min-height: 44px; padding: 8px 12px; }
.tm-write-row .btn { margin-block: 3px; }
.tm-write .hint { font-size: .8125rem; color: #a9c9b8; }
/* segmented choices (shape, length, a choice slot): real radio buttons */
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.seg legend { padding: 0; margin-bottom: 8px; font-size: var(--t-small); font-weight: 600; float: left; width: 100%; }
.seg label { position: relative; display: inline-flex; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px; background: var(--panel-3); color: var(--ink-2); font: 600 .875rem/1 var(--f-text); cursor: pointer; box-shadow: inset -3px -3px 0 0 #0d0f12, inset 3px 3px 0 0 rgb(255 255 255 / .08); transition: background-color var(--d-hover) ease, color var(--d-hover) ease; }
.seg input:checked + span { background: var(--green); color: var(--green-ink); box-shadow: inset -3px -3px 0 0 rgb(0 0 0 / .3), inset 3px 3px 0 0 rgb(255 255 255 / .45); }
.seg input:focus-visible + span { outline: 3px solid var(--green-hi); outline-offset: 2px; }
.seg input:disabled + span { opacity: .45; cursor: not-allowed; }
@media (hover: hover) and (pointer: fine) { .seg input:not(:checked):not(:disabled) + span:hover { background: #30353e; color: var(--ink); } }
.seg .shape { display: inline-block; border: 2px solid currentColor; }
/* lists */
.tm-list { display: grid; gap: 8px; }
.tm-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.tm-row-f { display: grid; gap: 6px; }
.tm-row-f.two { grid-template-columns: 1fr 1fr; }
/* three or four inputs a row: two columns (an odd first one takes the full width), and more air between rows */
.tm-row-f.many { grid-template-columns: 1fr 1fr; }
.tm-row-f.many > :first-child:nth-last-child(odd) { grid-column: 1 / -1; }
.tm-row:has(.tm-row-f.many) + .tm-row { margin-top: 10px; }
.tm-del { width: 40px; height: 46px; border: 0; background: var(--panel-3); color: var(--ink-2); cursor: pointer; font: 700 1.125rem/1 var(--f-display); }
.tm-del:disabled { opacity: .35; cursor: default; }
@media (hover: hover) and (pointer: fine) { .tm-del:not(:disabled):hover { color: var(--ink); background: #30353e; } }
.tm-add { justify-self: start; }
/* colours */
.tm-colors { display: flex; flex-wrap: wrap; gap: 10px 16px; }
.tm-color { display: inline-flex; align-items: center; gap: 8px; font-size: .875rem; color: var(--ink-2); cursor: pointer; }
.tm-color input { width: 44px; height: 36px; padding: 0; border: 3px solid var(--edge-hi); background: var(--well); cursor: pointer; }
.tm-color input:focus-visible { outline: 3px solid var(--green-hi); outline-offset: 2px; }
/* files */
.tm-file { position: relative; display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; min-height: 64px; padding: 10px 12px; background: var(--well); border: 3px dashed var(--edge-hi); cursor: pointer; transition: border-color var(--d-hover) ease, background-color var(--d-hover) ease; }
.tm-file.drag, .tm-file:focus-within { border-color: var(--green); }
.tm-file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.tm-file .thumb { width: 44px; height: 44px; background: var(--panel-3) center / contain no-repeat; display: grid; place-items: center; color: var(--ink-3); font: 400 var(--t-label)/1 var(--f-pixel); }
.tm-file .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9375rem; }
.tm-file .name small { display: block; color: var(--ink-3); font-size: .8125rem; }
.tm-file .tm-del { position: relative; z-index: 1; height: 40px; }
/* the footer: price + Generate */
.tm-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; padding: 12px 16px 12px 24px; background: var(--panel); border-top: 3px solid #0b0c0f; }
.tm-price { display: grid; gap: 4px; }
.tm-price b { font: 700 1.375rem/1 var(--f-display); letter-spacing: -0.02em; }
.tm-price small { color: var(--ink-3); font-size: .8125rem; }
.tm-msg { flex: 1 1 220px; margin: 0; font-size: .9375rem; color: var(--ink-2); min-height: 1.4em; }
.tm-msg.bad { color: var(--err); }
.tm-msg.ok { color: var(--green-hi); }
.tm-msg a { color: inherit; }
.tm-foot .btn { margin-left: auto; }
.tm-foot .btn[aria-busy="true"] { opacity: .7; cursor: progress; }
@media (max-width: 860px) {
  .tm { width: 100%; height: 100dvh; max-height: 100dvh; box-shadow: none; }
  .tm-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; overflow: auto; }
  .tm-view { padding: 14px; }
  .tm-form { overflow: visible; padding: 18px 16px 24px; }
  .tm-foot { padding: 10px 12px 10px 16px; }
  .tm-bar { padding-left: 14px; }
  .tm-bar h2 { font-size: 1.125rem; }
}
@media (max-width: 420px) { .tm-row-f.two, .tm-row-f.many { grid-template-columns: 1fr; } .tm-write-row { flex-direction: column; } }
.tm-desc { margin: 0; color: var(--ink-2); font-size: .9375rem; line-height: 1.5; }
.tm-shot { position: relative; }
.tm-ctl { display: flex; gap: 8px; justify-content: center; }
.tm-ctl .btn { margin: 3px; min-height: 34px; }
