:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --ink: #151820;
  --muted: #687083;
  --line: #dfe5ef;
  --accent: #2457e6;
  --accent-dark: #183ba6;
  --soft: #edf2ff;
  --danger: #b42318;
  --success: #067647;
  --shadow: 0 20px 60px rgba(33, 45, 74, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 32px;
}

.workspace {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.header h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 56px);
  line-height: 1.05;
  letter-spacing: 0;
}

.header p {
  max-width: 560px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--accent-dark);
  background: var(--soft);
  font-size: 14px;
  font-weight: 700;
}

.tool-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
  align-items: stretch;
  min-width: 0;
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px;
}

.upload-box {
  display: grid;
  place-items: center;
  min-height: 178px;
  padding: 24px;
  border: 1.5px dashed #aeb9cc;
  border-radius: 8px;
  background: #fbfcff;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease;
}

.upload-box:hover {
  border-color: var(--accent);
  background: var(--soft);
}

.upload-box input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.upload-title {
  display: block;
  font-size: 20px;
  font-weight: 800;
}

.upload-copy {
  display: block;
  max-width: 260px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.section-block {
  display: grid;
  gap: 12px;
}

.section-block h2,
.section-block label,
.preview-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}

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

.style-option {
  position: relative;
  min-height: 48px;
}

.style-option input {
  position: absolute;
  opacity: 0;
}

.style-option span {
  display: grid;
  place-items: center;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #333a48;
  background: #fff;
  font-size: 14px;
  font-weight: 700;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.style-option input:checked + span {
  border-color: var(--accent);
  color: var(--accent-dark);
  background: var(--soft);
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 108px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--ink);
  outline: none;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 87, 230, 0.12);
}

.generate-button {
  height: 52px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

.generate-button:hover {
  background: var(--accent-dark);
}

.generate-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.message {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

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

.message.success {
  color: var(--success);
}

.preview-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.preview-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 12px;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
}

.preview-head span,
.download-link {
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.download-link {
  color: var(--accent-dark);
  font-weight: 800;
}

.image-stage {
  display: grid;
  place-items: center;
  min-height: 520px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #f1f4f9 25%, transparent 25%),
    linear-gradient(-45deg, #f1f4f9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f1f4f9 75%),
    linear-gradient(-45deg, transparent 75%, #f1f4f9 75%);
  background-color: #ffffff;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

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

.result-stage {
  position: relative;
}

.result-stage span {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.result-stage.loading::after {
  content: "";
  width: 36px;
  height: 36px;
  border: 3px solid #cfd8ea;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

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

@media (min-width: 1201px) {
  .tool-grid {
    grid-template-columns: 390px minmax(0, 1fr);
  }

  .preview-area {
    grid-template-columns: minmax(0, 0.86fr) minmax(0, 1.14fr);
  }
}

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

  .header {
    flex-direction: column;
  }

  .image-stage {
    min-height: 360px;
  }
}

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

  .controls,
  .preview-area {
    padding: 14px;
  }

  .header h1 {
    font-size: 30px;
  }

  .header p {
    font-size: 15px;
  }

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