/* «Шаблоны» — the template gallery (template-gallery.js).
   Spec: PROJECT_CONTEXT/TEMPLATE_GALLERY_2026-10-06.md
   Colours come from the Studio tokens (skin-studio.css: --bg, --bg-2, --panel,
   --panel-2, --line, --text, --muted, --accent, --danger, --shadow-lg), so the
   dark and light themes follow by themselves. Screenshots are <img>: the
   skin's background-image:none!important would erase CSS backgrounds.
   No transform on positioned overlays (WebKit animation trap). */

.pf-tg-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  height: var(--tb-h, 40px);
  padding: 0 14px;
  border-radius: 12px;
  border: 1.5px solid var(--accent, #b8f24e);
  background: transparent;
  color: var(--accent, #b8f24e);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.pf-tg-btn:hover { background: rgba(184, 242, 78, 0.1); }
.pf-tg-btn:focus-visible { outline: 2px solid var(--accent, #b8f24e); outline-offset: 2px; }
.pf-tg-btn-count {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(184, 242, 78, 0.16);
  font-size: 12px;
  line-height: 18px;
  text-align: center;
}
.pf-tg-dot {
  display: none;
  position: absolute;
  top: -4px;
  right: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent, #b8f24e);
  box-shadow: 0 0 0 2px var(--bg, #15181f);
}
.pf-tg-btn.is-hinting { animation: pfTgGlow 1.4s ease-in-out 3; }
.pf-tg-btn.is-hinting .pf-tg-dot { display: block; animation: pfTgPulse 1.4s ease-in-out infinite; }
@keyframes pfTgGlow { 50% { box-shadow: 0 0 0 6px rgba(184, 242, 78, 0.18); } }
@keyframes pfTgPulse { 50% { transform: scale(1.7); opacity: 0.35; } }
[data-theme="light"] .pf-tg-btn { border-color: #5f8f12; color: #4c7410; }
[data-theme="light"] .pf-tg-btn:hover { background: rgba(95, 143, 18, 0.08); }
[data-theme="light"] .pf-tg-btn-count { background: rgba(95, 143, 18, 0.12); }
[data-theme="light"] .pf-tg-dot { background: #5f8f12; }

.pf-tg-hint {
  position: fixed;
  z-index: 1300;
  width: 300px;
  max-width: calc(100vw - 24px);
  padding: 14px 14px 12px;
  border-radius: 14px;
  border: 1px solid var(--line, #313745);
  background: var(--panel, #1a1e27);
  color: var(--text, #eef1f6);
  box-shadow: var(--shadow-lg, 0 20px 40px -12px rgba(8, 10, 14, 0.6));
  font-size: 13px;
  line-height: 1.45;
}
.pf-tg-hint::before {
  content: "";
  position: absolute;
  top: -7px;
  left: var(--pf-tg-arrow-x, 24px);
  width: 12px;
  height: 12px;
  background: var(--panel, #1a1e27);
  border-left: 1px solid var(--line, #313745);
  border-top: 1px solid var(--line, #313745);
  transform: rotate(45deg);
}
/* placeHint() sets is-detached when the hint hangs below the last topbar row,
   away from the button: an arrow there would point at some other control. */
.pf-tg-hint.is-detached::before { display: none; }
.pf-tg-hint-title { display: block; margin-bottom: 4px; font-size: 14px; }
.pf-tg-hint-body { margin: 0 0 10px; color: var(--muted, #9aa3b4); }
.pf-tg-hint-actions { display: flex; gap: 8px; }

.pf-tg-primary,
.pf-tg-ghost {
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.pf-tg-primary { border: 0; background: var(--accent, #b8f24e); color: #15181f; }
.pf-tg-primary:hover { filter: brightness(1.06); }
.pf-tg-ghost { border: 1px solid var(--line, #313745); background: transparent; color: var(--text, #eef1f6); }
.pf-tg-ghost:hover { border-color: var(--muted, #9aa3b4); }

html.pf-tg-open { overflow: hidden; }
.pf-tg-overlay {
  position: fixed;
  inset: 0;
  z-index: 1450;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 10, 14, 0.62);
}
.pf-tg-overlay[hidden] { display: none; }
.pf-tg-sheet {
  display: flex;
  flex-direction: column;
  width: min(1240px, 100%);
  height: min(880px, 100%);
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid var(--line, #313745);
  background: var(--bg-2, #1a1e27);
  color: var(--text, #eef1f6);
  box-shadow: var(--shadow-lg, 0 20px 40px -12px rgba(8, 10, 14, 0.6));
}
/* The header is a grid so × can never leave the first row, however long the
   previous-project name in «↶ Вернуть «<имя>»» is: that link takes whatever room
   the title column (200 px at least) leaves and shortens itself with an
   ellipsis. On a phone it drops to its own row (see the max-width: 720px block). */
.pf-tg-head {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) auto auto;
  align-items: start;
  gap: 14px;
  padding: 20px 22px 10px;
}
.pf-tg-heading { grid-column: 1; grid-row: 1; min-width: 0; }
.pf-tg-title { margin: 0; font-size: 22px; line-height: 1.2; color: var(--text, #eef1f6); }
.pf-tg-subtitle { margin: 6px 0 0; font-size: 13px; color: var(--muted, #9aa3b4); }
.pf-tg-undo-link {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  max-width: 100%;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  border: 0;
  background: none;
  color: var(--accent, #b8f24e);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.pf-tg-close {
  grid-column: 3;
  grid-row: 1;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line, #313745);
  background: transparent;
  color: var(--text, #eef1f6);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.pf-tg-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 6px 22px 14px;
  border-bottom: 1px solid var(--line, #313745);
}
.pf-tg-search,
.pf-tg-input {
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line, #313745);
  background: var(--panel, #1a1e27);
  color: var(--text, #eef1f6);
  font-size: 14px;
}
.pf-tg-search { flex: 0 1 300px; min-width: 200px; }
.pf-tg-search:focus,
.pf-tg-input:focus { outline: none; border-color: var(--accent, #b8f24e); }
.pf-tg-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pf-tg-chip {
  height: 32px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--line, #313745);
  background: transparent;
  color: var(--muted, #9aa3b4);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.pf-tg-chip:hover { color: var(--text, #eef1f6); }
.pf-tg-chip.is-active { border-color: var(--accent, #b8f24e); background: var(--accent, #b8f24e); color: #15181f; }
.pf-tg-body { flex: 1 1 auto; overflow-y: auto; padding: 16px 22px 26px; }
/* skin-studio.css puts letter-spacing:-0.02em !important on every h1-h3, which
   squeezed this uppercase label: only !important wins here. */
.pf-tg-section-title {
  margin: 6px 0 12px;
  font-size: 12px;
  letter-spacing: 0.06em !important;
  text-transform: uppercase;
  color: var(--muted, #9aa3b4);
}
.pf-tg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 18px 16px;
  margin-bottom: 22px;
}
.pf-tg-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text, #eef1f6);
  text-align: left;
  cursor: pointer;
}
.pf-tg-card:focus-visible { outline: none; }
.pf-tg-art {
  position: relative;
  display: block;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--line, #313745);
  background: var(--panel-2, #20242e);
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.pf-tg-card:hover .pf-tg-art,
.pf-tg-card:focus-visible .pf-tg-art { transform: translateY(-3px); border-color: var(--accent, #b8f24e); }
.pf-tg-art img { display: block; width: 100%; height: 100%; object-fit: cover; }
.pf-tg-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text, #eef1f6);
  background: var(--panel-2, #20242e);
}
.pf-tg-badges { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.pf-tg-badge { padding: 3px 7px; border-radius: 6px; font-size: 11px; font-weight: 800; background: var(--accent, #b8f24e); color: #15181f; }
.pf-tg-badge.is-current { background: #eef1f6; color: #15181f; }
.pf-tg-name { font-size: 13.5px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.pf-tg-kind { font-size: 12px; color: var(--muted, #9aa3b4); overflow-wrap: anywhere; }
.pf-tg-card.is-loading { cursor: progress; }
.pf-tg-card.is-loading .pf-tg-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 14, 0.55);
}
.pf-tg-card.is-loading .pf-tg-art::before {
  content: "";
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--accent, #b8f24e);
  animation: pfTgSpin 0.8s linear infinite;
}
@keyframes pfTgSpin { to { transform: rotate(360deg); } }
.pf-tg-card-wrap { position: relative; min-width: 0; }
.pf-tg-card-wrap .pf-tg-card { width: 100%; }
.pf-tg-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 0;
  background: rgba(8, 10, 14, 0.7);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.pf-tg-remove:hover { background: var(--danger, #fb6e6e); }
.pf-tg-plate {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 22px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px dashed var(--line, #313745);
  color: var(--text, #eef1f6);
  font-size: 14px;
}
.pf-tg-plate.is-large { flex-direction: column; align-items: flex-start; padding: 24px; font-size: 15px; }
.pf-tg-save { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.pf-tg-save .pf-tg-input { flex: 1 1 260px; }
.pf-tg-note,
.pf-tg-empty { margin: 8px 0 18px; color: var(--muted, #9aa3b4); font-size: 14px; }

.pf-tg-toast {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 28px;
  z-index: 1460;
  display: flex;
  align-items: center;
  gap: 14px;
  width: max-content;
  max-width: calc(100vw - 32px);
  margin: 0 auto;
  padding: 12px 14px 12px 18px;
  border-radius: 12px;
  border: 1px solid var(--line, #313745);
  background: var(--panel, #1a1e27);
  color: var(--text, #eef1f6);
  box-shadow: var(--shadow-lg, 0 20px 40px -12px rgba(8, 10, 14, 0.6));
  font-size: 14px;
  animation: pfTgToastIn 0.2s ease-out;
}
.pf-tg-toast[hidden] { display: none; }
.pf-tg-toast-undo {
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--accent, #b8f24e);
  background: transparent;
  color: var(--accent, #b8f24e);
  font-weight: 700;
  cursor: pointer;
}
@keyframes pfTgToastIn { from { opacity: 0; } to { opacity: 1; } }
[data-theme="light"] .pf-tg-toast-undo,
[data-theme="light"] .pf-tg-undo-link { border-color: #5f8f12; color: #4c7410; }

/* app.js wizard, step 0: «Игра: … · Сменить игру» (renderBasicTemplatePickerRow) */
.basic-template-picker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line, #313745);
  background: var(--panel-2, #20242e);
}
.basic-template-picker-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  color: var(--text, #eef1f6);
}
.basic-template-picker-btn { flex: 0 0 auto; }

@media (max-width: 720px) {
  .pf-tg-overlay { padding: 8px; }
  .pf-tg-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Title and × stay on the first row; the undo link takes the full row below. */
  .pf-tg-head { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; }
  .pf-tg-close { grid-column: 2; }
  .pf-tg-undo-link { grid-column: 1 / -1; grid-row: 2; margin-top: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .pf-tg-btn.is-hinting,
  .pf-tg-btn.is-hinting .pf-tg-dot,
  .pf-tg-toast { animation: none; }
  .pf-tg-art { transition: none; }
}
