:root {
  color-scheme: light;
  --ink: #101828;
  --muted: #667085;
  --line: #d9e2ef;
  --panel: rgba(255, 255, 255, 0.88);
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --cyan: #06b6d4;
  --green: #10b981;
  --rose: #e11d48;
  --shadow: 0 24px 70px rgba(31, 41, 55, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 10%, rgba(37, 99, 235, 0.22), transparent 28%),
    radial-gradient(circle at 86% 8%, rgba(6, 182, 212, 0.18), transparent 24%),
    linear-gradient(180deg, #edf5ff 0%, #f8fbff 46%, #f3f6fb 100%);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

.site-shell {
  width: min(1450px, calc(100% - 44px));
  margin: 0 auto;
  padding: 30px 0 42px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 26px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  object-fit: cover;
  box-shadow: 0 18px 35px rgba(37, 99, 235, 0.28);
}

h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.05;
  font-weight: 950;
}

.brand p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.studio {
  display: grid;
  grid-template-columns: minmax(330px, 410px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.composer {
  border: 1px solid rgba(148, 163, 184, 0.36);
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  padding: 20px;
  position: sticky;
  top: 22px;
}

.canvas {
  border: 1px solid rgba(148, 163, 184, 0.36);
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  align-self: start;
  padding: 14px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.panel-title span {
  font-weight: 900;
  font-size: 18px;
}

.panel-title strong {
  font-size: 12px;
  color: #1d4ed8;
  background: #eaf2ff;
  border: 1px solid #c8dcff;
  border-radius: 999px;
  padding: 6px 10px;
}

label {
  display: block;
  margin-bottom: 8px;
  color: #253047;
  font-size: 13px;
  font-weight: 850;
}

textarea,
input,
select {
  width: 100%;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

textarea {
  min-height: 280px;
  resize: vertical;
  padding: 14px;
  line-height: 1.65;
}

input,
select {
  min-height: 46px;
  padding: 0 12px;
}

.char-row {
  color: var(--muted);
  font-size: 12px;
  margin: 8px 0 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 112px;
  gap: 13px;
}

.button-row {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

button,
.download {
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-weight: 900;
  text-decoration: none;
  transition: transform 120ms ease, background 120ms ease, opacity 120ms ease;
}

button:active,
.download:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
  transform: none;
}

.primary {
  flex: 1;
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.22);
}

.primary.loading .arrow {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.48);
  border-top-color: #fff;
  border-radius: 50%;
  color: transparent;
  animation: spin 850ms linear infinite;
}

.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--blue-dark), #0891b2);
}

.ghost {
  width: 46px;
  color: var(--blue);
  background: #eaf2ff;
  border: 1px solid #c8dcff;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 22px;
  padding: 14px 4px 0;
  color: var(--muted);
  font-size: 13px;
}

.site-footer nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.site-footer a {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  color: #1d4ed8;
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(148, 163, 184, 0.32);
  border-radius: 999px;
  font-weight: 850;
  text-decoration: none;
}

.site-footer a:hover {
  color: #0f172a;
  background: #fff;
}

.progress {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  margin-bottom: 14px;
}

.progress[hidden] {
  display: none;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--cyan), var(--green));
  transition: width 420ms ease;
}

.notice {
  display: none;
  margin-bottom: 14px;
  padding: 13px 14px;
  color: #9f1239;
  background: #fff1f3;
  border: 1px solid #fecdd3;
  border-radius: 13px;
  line-height: 1.5;
}

.notice.show {
  display: block;
}

.preview-stage {
  min-height: 0;
  display: grid;
  place-items: center;
  aspect-ratio: var(--preview-ratio, 16 / 9);
  border: 1px dashed rgba(100, 116, 139, 0.38);
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.05), rgba(6, 182, 212, 0.04)),
    rgba(255, 255, 255, 0.6);
}

.preview-stage.has-image {
  display: block;
  padding: 0;
  overflow: hidden;
  border-style: solid;
  background: #fff;
}

.inline-results {
  display: grid;
  gap: 12px;
  min-height: 100%;
  padding: 12px;
}

.inline-results.layout-1 {
  grid-template-columns: 1fr;
}

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

.inline-results.layout-3 {
  grid-template-columns: 1.15fr 0.85fr;
}

.inline-results.layout-3 .result-card:first-child {
  grid-row: span 2;
}

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

.empty-card {
  text-align: center;
}

.empty-kicker {
  display: inline-flex;
  margin-bottom: 12px;
  color: #1d4ed8;
  background: #eaf2ff;
  border: 1px solid #c8dcff;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 850;
}

.empty-card strong {
  display: block;
  font-size: 24px;
  line-height: 1.35;
}

.result-card {
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.image-frame {
  position: relative;
  min-height: 0;
  aspect-ratio: var(--preview-ratio, 16 / 9);
  background: linear-gradient(135deg, #eef4ff, #f8fafc);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.image-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.image-fallback {
  display: none;
  padding: 28px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

.result-card.failed img {
  display: none;
}

.result-card.failed .image-fallback {
  display: block;
}

.result-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  border: 0;
  background: transparent;
}

.countdown {
  position: absolute;
  left: 12px;
  bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(203, 213, 225, 0.8);
  border-radius: 999px;
  padding: 6px 10px;
  white-space: nowrap;
}

.countdown.expired {
  color: var(--rose);
  font-weight: 900;
}

.download {
  min-height: 34px;
  padding: 0 13px;
  color: white;
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  font-size: 12px;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.24);
  backdrop-filter: blur(14px);
}

.download:hover {
  background: rgba(16, 185, 129, 0.92);
  text-decoration: none;
}

.download.disabled {
  pointer-events: none;
  opacity: 0.58;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(15, 23, 42, 0.76);
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: 96vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.34);
}

.lightbox-close {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 44px;
  height: 44px;
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 50%;
  font-size: 28px;
}

.terms-mask {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(10px);
}

.terms-mask[hidden] {
  display: none;
}

.terms-card {
  width: min(680px, 100%);
  max-height: min(86vh, 720px);
  overflow: auto;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(203, 213, 225, 0.9);
  border-radius: 18px;
  box-shadow: 0 34px 90px rgba(15, 23, 42, 0.3);
  padding: 22px;
}

.terms-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.terms-head img {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  object-fit: cover;
}

.terms-head h2 {
  margin: 0;
  font-size: 22px;
}

.terms-head p,
.terms-body p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.terms-body {
  padding: 14px 0 18px;
  border-top: 1px solid var(--line);
}

.terms-body ul {
  margin: 12px 0;
  padding-left: 20px;
  color: #253047;
  line-height: 1.75;
}

.terms-body li + li {
  margin-top: 7px;
}

.terms-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.terms-confirm,
.terms-secondary {
  width: 100%;
}

.terms-confirm {
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.22);
}

.terms-secondary {
  color: #1d4ed8;
  background: #eaf2ff;
  border: 1px solid #c8dcff;
}

@media (max-width: 980px) {
  .site-shell {
    width: min(100% - 24px, 780px);
    padding: 18px 0 28px;
  }

  .studio {
    grid-template-columns: 1fr;
  }

  .composer {
    position: static;
  }

  .canvas,
  .preview-stage {
    min-height: 0;
  }
}

@media (min-width: 981px) and (max-height: 860px) {
  .site-shell {
    width: min(1360px, calc(100% - 44px));
    padding: 18px 0 18px;
  }

  .site-header {
    margin-bottom: 16px;
  }

  .brand-logo {
    width: 46px;
    height: 46px;
    border-radius: 14px;
  }

  h1 {
    font-size: 28px;
  }

  .brand p {
    margin-top: 4px;
    font-size: 13px;
  }

  .studio {
    grid-template-columns: minmax(320px, 370px) minmax(0, 1fr);
    gap: 18px;
  }

  .composer {
    padding: 16px;
    top: 14px;
  }

  .panel-title {
    margin-bottom: 14px;
  }

  textarea {
    min-height: 205px;
    line-height: 1.55;
  }

  input,
  select,
  button {
    min-height: 42px;
  }

  .char-row {
    margin: 7px 0 14px;
  }

  .form-grid {
    gap: 10px;
  }

  .button-row {
    margin-top: 14px;
  }

  .canvas {
    padding: 12px;
  }

  .preview-stage {
    max-height: calc(100vh - 210px);
    overflow: hidden;
  }

  .site-footer {
    margin-top: 12px;
    padding-top: 8px;
  }
}

@media (min-width: 981px) and (max-height: 760px) {
  .site-shell {
    padding: 12px 0;
  }

  .site-header {
    margin-bottom: 12px;
  }

  .brand-logo {
    width: 42px;
    height: 42px;
  }

  h1 {
    font-size: 26px;
  }

  .composer {
    padding: 14px;
  }

  textarea {
    min-height: 170px;
  }

  .preview-stage {
    max-height: calc(100vh - 176px);
  }

  .site-footer {
    margin-top: 8px;
    padding-top: 4px;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 26px;
  }

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

  .button-row,
  .result-actions {
    flex-wrap: wrap;
  }

  .inline-results,
  .inline-results.layout-2,
  .inline-results.layout-3,
  .inline-results.layout-4 {
    grid-template-columns: 1fr;
  }

  .inline-results.layout-3 .result-card:first-child {
    grid-row: auto;
  }

  .ghost {
    flex: 1 1 46px;
  }

  .site-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .terms-actions {
    grid-template-columns: 1fr;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
