:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  --bg: #f4f7f8;
  --panel: #ffffff;
  --text: #162128;
  --muted: #5c6972;
  --line: #d8e1e5;
  --accent: #16756f;
  --accent-dark: #0f5551;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(24, 42, 52, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

body.no-scroll {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: minmax(360px, 440px) minmax(0, 1fr);
  gap: 20px;
  width: min(1440px, calc(100vw - 32px));
  margin: 16px auto;
  min-height: calc(100vh - 32px);
}

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

.controls {
  padding: 22px;
}

.titlebar h1,
.result-head h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.titlebar p,
.result-head p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
}

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

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

.field > span {
  font-size: 14px;
  font-weight: 700;
}

textarea,
input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fbfcfd;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 160px;
  padding: 12px;
  line-height: 1.55;
}

input[type="number"] {
  height: 42px;
  padding: 0 12px;
}

textarea:focus,
input[type="number"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 117, 111, 0.14);
}

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

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

.preset-grid button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfb;
  color: var(--text);
  cursor: pointer;
}

.preset-grid button.active,
.preset-grid button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.hint {
  margin: -8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

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

.upload {
  display: grid;
  gap: 6px;
  border: 1px dashed #9bb0b9;
  border-radius: 8px;
  padding: 16px;
  background: #f8fbfb;
  cursor: pointer;
}

.upload input {
  display: none;
}

.upload span {
  font-weight: 700;
}

.upload small {
  color: var(--muted);
  line-height: 1.45;
}

.preview-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.preview {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #eef4f5;
}

.preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  cursor: pointer;
}

.primary {
  height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.primary:disabled {
  cursor: progress;
  opacity: 0.65;
}

.error {
  margin: 0;
  color: var(--danger);
  background: #fff4f2;
  border: 1px solid #ffc9c2;
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.45;
}

.results {
  min-width: 0;
  padding: 22px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 16px;
}

.result-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.empty {
  min-height: 120px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f8fbfb;
}

.empty.hidden {
  display: none;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  align-content: start;
}

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

.image-preview-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: #eef4f5;
  cursor: zoom-in;
}

.image-preview-button img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  display: block;
  background: #eef4f5;
}

.image-preview-button:hover img {
  filter: brightness(0.96);
}

.result-card footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
}

.download {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--accent-dark);
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 54px 20px 24px;
  background: rgba(8, 18, 24, 0.86);
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: min(96vw, 1400px);
  max-height: calc(100vh - 104px);
  object-fit: contain;
  border-radius: 8px;
  background: #eef4f5;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.34);
}

.lightbox-close {
  position: fixed;
  top: 16px;
  right: 18px;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.lightbox-download {
  position: fixed;
  right: 72px;
  top: 17px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  padding: 0 14px;
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    width: min(100vw - 20px, 720px);
    margin: 10px auto;
  }

  .preview-list {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 520px) {
  .controls,
  .results {
    padding: 16px;
  }

  .split,
  .preset-grid {
    grid-template-columns: 1fr;
  }
}
