:root {
  color-scheme: light;
  --bg: #edf4f2;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-strong: #ffffff;
  --surface-soft: #f5faf8;
  --text: #17201f;
  --muted: #687877;
  --line: rgba(23, 32, 31, 0.12);
  --accent: #0e8f7e;
  --accent-strong: #075f56;
  --accent-soft: rgba(14, 143, 126, 0.12);
  --ink: #213a5c;
  --warm: #c87f45;
  --danger: #c24141;
  --shadow: 0 24px 70px rgba(23, 32, 31, 0.12);
  --radius: 8px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101817;
  --surface: rgba(24, 33, 32, 0.8);
  --surface-strong: #1d2928;
  --surface-soft: #162221;
  --text: #edf7f4;
  --muted: #9fb0ad;
  --line: rgba(237, 247, 244, 0.14);
  --accent: #65d6c5;
  --accent-strong: #a7f2e7;
  --accent-soft: rgba(101, 214, 197, 0.14);
  --ink: #9dbdf2;
  --warm: #f0ad72;
  --danger: #ff7f7f;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    linear-gradient(120deg, rgba(14, 143, 126, 0.13), transparent 32%),
    linear-gradient(220deg, rgba(33, 58, 92, 0.12), transparent 28%),
    var(--bg);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(rgba(23, 32, 31, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 32, 31, 0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, #000, transparent 78%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 8px 0 16px;
  backdrop-filter: blur(18px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: 0 16px 46px rgba(23, 32, 31, 0.07);
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: var(--radius);
  color: #fff;
  font-weight: 900;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.2), transparent),
    linear-gradient(135deg, var(--accent), var(--ink));
}

.brand strong,
.brand small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-link,
.search-box,
.icon-button,
.text-button,
.primary-button,
.secondary-button,
.category-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface-strong);
  transition:
    transform 170ms ease,
    border-color 170ms ease,
    background 170ms ease,
    box-shadow 170ms ease;
}

.admin-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 13px;
  text-decoration: none;
  white-space: nowrap;
}

.admin-link:hover,
.icon-button:hover,
.text-button:hover,
.secondary-button:hover,
.category-button:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  box-shadow: 0 12px 30px rgba(23, 32, 31, 0.08);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(360px, 42vw);
  min-height: 42px;
  padding: 0 12px;
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}

.search-icon {
  color: var(--muted);
  font-size: 20px;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  font-size: 18px;
}

.text-button {
  padding: 7px 10px;
  color: var(--muted);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(280px, 0.82fr);
  align-items: end;
  gap: 24px;
  min-height: 340px;
  padding: 54px 6px 38px;
}

.hero-copy {
  max-width: 880px;
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero h1 {
  max-width: 940px;
  margin: 0;
  font-size: clamp(42px, 7vw, 88px);
  line-height: 0.98;
  letter-spacing: 0;
}

.hero p:not(.eyebrow) {
  max-width: 760px;
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.85;
}

.hero-panel {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 0.8fr;
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
  box-shadow: var(--shadow);
}

.hero-panel div {
  min-height: 128px;
  padding: 20px;
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--surface-strong) 92%, var(--accent-soft)), var(--surface-strong));
}

.hero-panel-feature {
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--accent) 15%, var(--surface-strong)), var(--surface-strong)) !important;
}

.hero-panel strong,
.hero-panel span {
  display: block;
}

.hero-panel strong {
  margin-top: 8px;
  font-size: 34px;
  line-height: 1.05;
}

.hero-panel span {
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) minmax(360px, 430px);
  gap: 16px;
  align-items: start;
}

.sidebar,
.template-area,
.editor-panel,
.admin-list-panel,
.admin-editor-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  box-shadow: 0 16px 45px rgba(23, 32, 31, 0.06);
  backdrop-filter: blur(18px);
}

.sidebar,
.editor-panel,
.admin-list-panel {
  position: sticky;
  top: 96px;
}

.sidebar,
.editor-panel,
.template-area,
.admin-list-panel,
.admin-editor-panel {
  padding: 16px;
}

.section-title,
.toolbar,
.editor-header,
.preview-topline,
.editor-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-title {
  margin-bottom: 12px;
  font-weight: 850;
}

.category-list {
  display: grid;
  gap: 9px;
}

.category-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 0 11px;
  text-align: left;
}

.category-button span:first-child {
  overflow-wrap: anywhere;
}

.category-button .count {
  min-width: 28px;
  padding: 3px 7px;
  border-radius: 999px;
  color: var(--accent-strong);
  text-align: center;
  background: var(--accent-soft);
}

.category-button.active {
  border-color: transparent;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent),
    linear-gradient(135deg, var(--accent), var(--ink));
}

.category-button.active .count {
  color: #fff;
  background: rgba(255, 255, 255, 0.2);
}

.template-area {
  min-height: 680px;
}

.toolbar {
  margin-bottom: 16px;
}

.toolbar h2,
.editor-header h2 {
  margin: 0;
  font-size: 22px;
}

.sort-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.sort-wrap select,
.field select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface-strong);
  outline: 0;
}

.sort-wrap select {
  padding: 0 10px;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.template-card {
  display: grid;
  gap: 14px;
  min-height: 214px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
  text-align: left;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface-strong) 96%, var(--accent-soft)), var(--surface-strong));
}

.template-card:hover,
.template-card.active {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--accent) 62%, var(--line));
  box-shadow: 0 18px 42px rgba(23, 32, 31, 0.1);
}

.template-card.active {
  box-shadow:
    inset 0 0 0 1px var(--accent),
    0 18px 42px rgba(23, 32, 31, 0.1);
}

.card-topline,
.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 850;
  background: var(--accent-soft);
}

.favorite {
  color: var(--warm);
}

.template-card h3 {
  margin: 0;
  font-size: 20px;
  line-height: 1.35;
}

.template-card p,
.editor-desc {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.card-meta {
  color: var(--muted);
  font-size: 13px;
}

.editor-desc {
  margin: 12px 0 18px;
}

.variables-form {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label,
.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface-strong);
  outline: 0;
}

.field input,
.field select {
  min-height: 42px;
  padding: 0 11px;
}

.field textarea {
  min-height: 94px;
  padding: 10px 11px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
.search-box:focus-within,
.sort-wrap select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.example-gallery {
  margin: 0 0 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.example-gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
}

.example-card {
  display: block;
  min-width: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  line-height: 0;
  cursor: zoom-in;
}

.example-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--accent) 60%, var(--line));
  box-shadow: 0 14px 32px rgba(23, 32, 31, 0.12);
}

.example-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: linear-gradient(135deg, var(--surface-soft), var(--accent-soft));
}

.example-empty strong {
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.35;
}

.example-empty span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.example-empty {
  display: grid;
  grid-column: 1 / -1;
  gap: 5px;
  min-height: 100px;
  align-content: center;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface-soft) 80%, var(--accent-soft));
}

.preview-card {
  margin-top: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.preview-topline {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

pre {
  max-height: 320px;
  margin: 0;
  padding: 14px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.75;
}

.editor-actions {
  margin-top: 14px;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 14px;
  font-weight: 850;
}

.primary-button {
  flex: 1;
  border-color: transparent;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent),
    linear-gradient(135deg, var(--accent), var(--ink));
}

.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 34px rgba(14, 143, 126, 0.22);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary-button {
  color: var(--text);
  background: var(--surface-strong);
}

.empty-state {
  display: grid;
  min-height: 220px;
  place-items: center;
  align-content: center;
  gap: 8px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
  font-size: 20px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.lightbox-open {
  overflow: hidden;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
}

.image-lightbox[hidden] {
  display: none;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(7, 16, 15, 0.78);
  backdrop-filter: blur(14px);
}

.lightbox-panel {
  position: relative;
  z-index: 1;
  display: grid;
  max-width: min(1120px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  background: #07100f;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.42);
}

.lightbox-panel img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 48px);
  object-fit: contain;
  border-radius: var(--radius);
}

.lightbox-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  color: #fff;
  background: rgba(7, 16, 15, 0.72);
  border-color: rgba(255, 255, 255, 0.2);
}

.admin-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: end;
  padding: 42px 6px 28px;
}

.admin-hero h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 64px);
  line-height: 1.04;
}

.admin-hero p:not(.eyebrow) {
  max-width: 700px;
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.75;
}

.admin-actions,
.mini-actions,
.admin-bottom-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-workspace {
  display: grid;
  grid-template-columns: minmax(270px, 350px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.admin-search {
  width: 100%;
  margin-bottom: 12px;
}

.admin-template-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 250px);
  overflow: auto;
  padding-right: 2px;
}

.admin-template-category {
  display: grid;
  gap: 7px;
}

.admin-category-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
  background: var(--surface-strong);
  font-weight: 760;
}

.admin-category-header span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-category-header .category-indicator {
  color: var(--muted);
}

.admin-category-list {
  display: grid;
  gap: 8px;
}

.admin-category-list[hidden] {
  display: none;
}

.admin-template-item {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
  background: var(--surface-strong);
}

.admin-template-item strong,
.admin-template-item span {
  overflow-wrap: anywhere;
}

.template-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 0.5rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 11px;
  font-weight: 800;
}

.admin-template-item span {
  color: var(--muted);
  font-size: 13px;
}

.admin-template-item.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.admin-form {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.prompt-textarea {
  min-height: 280px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  line-height: 1.7;
}

.examples-manager,
.variables-manager {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.example-rows,
.variable-rows {
  display: grid;
  gap: 8px;
}

.example-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 42px;
  gap: 8px;
}

.variable-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(160px, 1fr) 42px;
  gap: 8px;
}

.example-row input,
.variable-row input {
  min-width: 0;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface-soft);
  outline: 0;
}

.example-row input:focus,
.variable-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.danger {
  color: var(--danger);
}

.admin-bottom-actions {
  justify-content: space-between;
  margin-top: 16px;
  color: var(--muted);
  line-height: 1.6;
}

.admin-empty {
  display: grid;
  gap: 6px;
  padding: 24px 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.admin-empty strong {
  color: var(--text);
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 180px minmax(0, 1fr);
  }

  .editor-panel {
    position: static;
    grid-column: 1 / -1;
  }

  .template-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-workspace {
    grid-template-columns: 260px minmax(0, 1fr);
  }
}

@media (max-width: 860px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .top-actions,
  .hero,
  .workspace,
  .toolbar,
  .editor-actions,
  .admin-hero,
  .admin-workspace,
  .admin-bottom-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .topbar {
    gap: 12px;
  }

  .top-actions {
    grid-template-columns: auto minmax(0, 1fr) 42px;
  }

  .search-box {
    width: 100%;
  }

  .hero {
    min-height: 0;
    padding: 32px 2px 24px;
  }

  .hero h1 {
    font-size: clamp(38px, 12vw, 60px);
  }

  .hero p:not(.eyebrow) {
    font-size: 16px;
  }

  .hero-panel {
    grid-template-columns: 1fr;
  }

  .hero-panel div {
    min-height: 88px;
  }

  .sidebar,
  .admin-list-panel {
    position: static;
  }

  .category-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .category-button {
    flex: 0 0 auto;
    width: auto;
    min-width: 112px;
  }

  .template-area {
    min-height: 0;
  }

  .template-grid,
  .example-gallery-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .admin-actions,
  .admin-bottom-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .admin-template-list {
    max-height: 360px;
  }

  .example-row {
    grid-template-columns: 1fr 42px;
  }

  .variable-row {
    grid-template-columns: 1fr 1fr 42px;
  }

  .sort-wrap {
    justify-content: space-between;
  }

  .editor-actions {
    gap: 10px;
  }
}

@media (max-width: 500px) {
  .top-actions {
    grid-template-columns: 1fr 42px;
  }

  .top-actions .admin-link {
    grid-column: 1 / -1;
  }

  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .hero h1 {
    font-size: 36px;
    line-height: 1.05;
  }

  .editor-header,
  .admin-editor-panel .editor-header {
    align-items: flex-start;
  }

  .mini-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .variable-row {
    grid-template-columns: 1fr 42px;
  }

  .variable-value {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .variable-remove {
    grid-column: 2;
    grid-row: 1;
  }
}
