:root {
  color-scheme: dark;
  --bg: #07111d;
  --panel: #171c24;
  --panel-soft: rgba(10, 18, 30, 0.94);
  --line: rgba(120, 154, 195, 0.2);
  --line-strong: rgba(142, 199, 255, 0.32);
  --text: #edf4ff;
  --muted: #8ca2c3;
  --accent: #12253f;
  --accent-strong: #173256;
  --accent-bright: #2d7fff;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 12% 18%, rgba(117, 226, 255, 0.12), transparent 28%),
    radial-gradient(circle at 86% 12%, rgba(255, 140, 108, 0.12), transparent 24%),
    linear-gradient(180deg, #07111d 0%, #040810 100%);
  color: var(--text);
}
body {
  font-family: "IBM Plex Sans", "Segoe UI", Arial, sans-serif;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: radial-gradient(circle at center, rgba(0,0,0,.44), transparent 78%);
  opacity: .18;
}
.templates-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  padding: 8px;
}
.top-stack {
  display: grid;
  gap: 8px;
}
.top {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 58px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  flex-wrap: wrap;
  overflow: hidden;
}
.top::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 35%),
    linear-gradient(90deg, rgba(117, 226, 255, 0.05), transparent 42%, rgba(255, 140, 108, 0.04));
}
.brand-stack {
  position: relative;
  display: grid;
  gap: 3px;
  flex: 1 1 340px;
  min-width: 0;
}
.title-main {
  font-family: "Chakra Petch", "IBM Plex Sans", "Segoe UI", sans-serif;
  letter-spacing: .06em;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  flex-wrap: nowrap;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}
.title-project {
  font-size: 11px;
  letter-spacing: .03em;
  color: var(--muted);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.title-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  line-height: 1.4;
  min-width: 0;
  min-height: 1.4em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.top .spacer {
  flex: 1;
}
.header-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}
.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 1px solid #35547c;
  border-radius: 0;
  background: #12253f;
  box-shadow: none;
}
.lang-switch button {
  min-width: 42px;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #d7e8ff;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background .16s ease, color .16s ease, transform .16s ease;
}
.lang-switch button.is-active {
  background: #1d3d67;
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(106, 167, 255, 0.18);
}
.shell-links {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: 0;
}
.shell-links a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 0;
  border: 1px solid #35547c;
  background: var(--accent);
  color: #d7e8ff;
  text-decoration: none;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .02em;
  line-height: 1;
  white-space: nowrap;
  transition: background .16s ease, border-color .16s ease;
}
.shell-links a:hover,
.shell-links a:focus-visible {
  border-color: var(--line-strong);
  background: var(--accent-strong);
}
.shell-links a[aria-current="page"] {
  border-color: #35547c;
  background: var(--accent);
  color: #d7e8ff;
  box-shadow: inset 0 0 0 1px rgba(106, 167, 255, 0.08);
}
.shell-links a[href="/editor/"] {
  border-color: rgba(152, 201, 255, 0.48);
  background: linear-gradient(135deg, #2d7fff 0%, #204cbb 100%);
  color: #f7fbff;
  font-weight: 700;
  box-shadow: 0 10px 22px rgba(45, 127, 255, 0.2);
}
.shell-links a[href="/editor/"]:hover,
.shell-links a[href="/editor/"]:focus-visible,
.shell-links a[href="/editor/"][aria-current="page"] {
  border-color: #9fd0ff;
  background: linear-gradient(135deg, #4691ff 0%, #2a5fd3 100%);
  color: #fff;
  box-shadow: 0 12px 26px rgba(45, 127, 255, 0.26);
}
.templates-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 14% 16%, rgba(117, 226, 255, 0.08), transparent 28%),
    linear-gradient(180deg, rgba(7, 12, 20, 0.98), rgba(4, 8, 15, 0.99));
}
.templates-frame {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  display: block;
  background: transparent;
  opacity: 1;
  transition: opacity .22s ease, transform .22s ease;
}
.templates-stage[data-frame-state="loading"] .templates-frame,
.templates-stage[data-frame-state="warning"] .templates-frame,
.templates-stage[data-frame-state="error"] .templates-frame {
  opacity: 0;
  transform: scale(1.004);
  pointer-events: none;
}
.template-detail-loader {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(4, 8, 15, 0.52), rgba(4, 8, 15, 0.78));
  transition: opacity .24s ease, visibility .24s ease;
}
.templates-stage[data-frame-state="ready"] .template-detail-loader {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.template-detail-loader-card {
  width: min(460px, 100%);
  display: grid;
  gap: 12px;
  padding: 22px;
  border: 1px solid rgba(142, 199, 255, 0.22);
  background:
    linear-gradient(180deg, rgba(12, 21, 34, 0.98), rgba(8, 14, 24, 0.94));
  box-shadow:
    0 22px 54px rgba(0, 0, 0, 0.34),
    inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}
.template-detail-loader-kicker {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  padding: 0 10px;
  border: 1px solid rgba(117, 226, 255, 0.22);
  background: rgba(9, 22, 38, 0.72);
  color: #7de4ff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.template-detail-loader-title {
  color: #f7fbff;
  font-size: clamp(28px, 4vw, 40px);
  line-height: .92;
  letter-spacing: -.05em;
}
.template-detail-loader-detail {
  max-width: 40ch;
  color: #abc2dd;
  font-size: 14px;
  line-height: 1.5;
}
.template-detail-loader-bar {
  position: relative;
  overflow: hidden;
  height: 10px;
  border: 1px solid rgba(95, 131, 176, 0.28);
  background: rgba(8, 14, 24, 0.84);
}
.template-detail-loader-bar span {
  position: absolute;
  inset: 1px auto 1px 1px;
  width: 34%;
  background: linear-gradient(90deg, rgba(73, 145, 255, 0.18), rgba(117, 226, 255, 0.92), rgba(255, 140, 108, 0.58));
  animation: template-detail-loader-sweep 1.15s ease-in-out infinite;
}
.templates-stage[data-frame-state="warning"] .template-detail-loader-kicker {
  border-color: rgba(255, 212, 132, 0.3);
  background: rgba(55, 36, 8, 0.46);
  color: #ffd484;
}
.templates-stage[data-frame-state="error"] .template-detail-loader-kicker {
  border-color: rgba(255, 158, 158, 0.28);
  background: rgba(55, 16, 18, 0.48);
  color: #ff9e9e;
}
.templates-stage[data-frame-state="warning"] .template-detail-loader-bar span,
.templates-stage[data-frame-state="error"] .template-detail-loader-bar span {
  width: calc(100% - 2px);
  animation: none;
  transform: none;
}
@keyframes template-detail-loader-sweep {
  0% {
    transform: translateX(-115%);
  }
  55% {
    transform: translateX(125%);
  }
  100% {
    transform: translateX(250%);
  }
}
.template-gallery {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: rgba(8, 13, 22, 0.985);
  overflow: auto;
}
.template-gallery-intro {
  display: grid;
  gap: 0;
  max-width: 24ch;
}
.template-gallery-kicker {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid rgba(117, 226, 255, 0.24);
  background: rgba(10, 26, 43, 0.6);
  color: #7de4ff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.template-gallery-intro h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 4rem);
  line-height: .95;
  letter-spacing: -.05em;
}
.template-gallery-intro p {
  margin: 0;
  color: #abc2dd;
  font-size: 18px;
  line-height: 1.5;
}
.template-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.template-gallery-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid rgba(83, 118, 158, 0.18);
  border-radius: 0;
  background: rgba(10, 16, 26, 0.82);
  text-decoration: none;
  color: inherit;
  transition: border-color .16s ease, background .16s ease, transform .16s ease;
}
.template-gallery-card:hover,
.template-gallery-card:focus-visible {
  border-color: rgba(126, 222, 255, 0.4);
  background: rgba(12, 20, 32, 0.92);
  transform: translateY(-1px);
}
.template-gallery-preview {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid rgba(116, 163, 214, 0.22);
  background:
    linear-gradient(135deg, rgba(6, 13, 22, 0.96), rgba(15, 25, 39, 0.9)),
    radial-gradient(circle at 24% 18%, color-mix(in srgb, var(--template-gallery-accent, #69e6ff) 32%, transparent), transparent 34%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    0 18px 36px rgba(0, 0, 0, 0.22);
}
.template-gallery-preview::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 42%;
  background: linear-gradient(180deg, transparent 0%, rgba(3, 8, 14, 0.82) 100%);
  pointer-events: none;
}
.template-gallery-preview img,
.template-gallery-preview-fallback {
  width: 100%;
  height: 100%;
}
.template-gallery-preview img {
  display: block;
  object-fit: cover;
  transform: scale(1.01);
}
.template-gallery-preview-fallback {
  display: grid;
  place-items: center;
  padding: 18px;
  text-align: center;
  color: #ecf5ff;
  font-family: "Chakra Petch", "IBM Plex Sans", "Segoe UI", sans-serif;
  font-size: 28px;
  line-height: 1;
  letter-spacing: .04em;
  background:
    radial-gradient(circle at 18% 16%, color-mix(in srgb, var(--template-gallery-accent, #69e6ff) 26%, transparent), transparent 30%),
    linear-gradient(135deg, rgba(8, 14, 23, 0.9), rgba(14, 22, 35, 0.96));
}
.template-gallery-card-head {
  display: grid;
  gap: 6px;
}
.template-gallery-card-head strong {
  font-size: 28px;
  line-height: .95;
  letter-spacing: -.05em;
  color: #f7fbff;
}
.template-gallery-card-head span {
  color: #9cb4cf;
  line-height: 1.5;
}
.template-gallery-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.template-gallery-badges span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(83, 118, 158, 0.26);
  border-radius: 0;
  background: rgba(11, 19, 31, 0.44);
  color: #cfe0f4;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.template-gallery-action {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid rgba(152, 201, 255, 0.48);
  border-radius: 0;
  background: linear-gradient(135deg, #2d7fff 0%, #204cbb 100%);
  color: #f7fbff;
  font-weight: 700;
  letter-spacing: .03em;
}
.template-gallery-action::after {
  content: "→";
  font-size: 18px;
}
.template-gallery-empty {
  display: grid;
  gap: 8px;
  padding: 22px;
  border: 1px dashed rgba(110, 149, 194, 0.28);
  background: rgba(9, 15, 24, 0.72);
  color: #d7e6fb;
}
.template-gallery-empty span {
  color: #9cb4cf;
  line-height: 1.5;
}
body.template-detail {
  overflow: hidden;
}
@media (max-width: 720px) {
  .top {
    align-items: stretch;
    flex-direction: column;
    min-height: 0;
  }
  .templates-shell {
    padding: 8px;
    gap: 8px;
  }
  .header-actions {
    width: 100%;
  }
  .shell-links {
    width: 100%;
  }
  .shell-links a {
    flex: 1 1 auto;
  }
  .template-gallery {
    padding: 14px;
  }
  .template-gallery-intro p {
    font-size: 16px;
  }
  .template-detail-loader {
    padding: 14px;
  }
  .template-detail-loader-card {
    padding: 16px;
  }
}
