:root {
  color-scheme: light;
  --page-bg: #f5f8fb;
  --panel-bg: rgba(255, 255, 255, 0.92);
  --panel-soft: #f7fafc;
  --text: #102033;
  --muted: #61758a;
  --line: #d8e3ec;
  --accent: #7fd4cc;
  --accent-strong: #4eb8af;
  --accent-deep: #238c88;
  --danger: #c24f5d;
  --shadow: 0 18px 50px rgba(74, 101, 128, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(127, 212, 204, 0.28), transparent 28%),
    radial-gradient(circle at top right, rgba(153, 218, 238, 0.22), transparent 24%),
    linear-gradient(180deg, #ffffff 0%, #f4f7fb 100%);
}

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

button {
  border: 0;
}

.page-shell {
  width: min(1540px, calc(100vw - 36px));
  margin: 0 auto;
  padding: 18px 0 32px;
}

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

.page-header h1 {
  margin: 0 0 6px;
  font-size: 38px;
  line-height: 1.1;
}

.page-header p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.header-badge {
  align-self: center;
  padding: 12px 16px;
  border: 1px solid rgba(127, 212, 204, 0.5);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  color: var(--accent-deep);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

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

.results-column {
  display: grid;
  gap: 24px;
}

.panel {
  border: 1px solid rgba(216, 227, 236, 0.9);
  border-radius: var(--radius-xl);
  background: var(--panel-bg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.form-panel {
  padding: 22px 20px;
}

.latest-panel,
.tips-panel,
.history-panel {
  padding: 18px 18px 20px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.section-head h2 {
  margin: 0 0 6px;
  font-size: 22px;
  line-height: 1.2;
}

.section-head p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.status-chip {
  min-width: 74px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #f0f6f9;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.status-chip.ok {
  background: rgba(127, 212, 204, 0.18);
  color: #1f877c;
}

.status-chip.error {
  background: rgba(194, 79, 93, 0.12);
  color: var(--danger);
}

.field-grid {
  display: grid;
  gap: 14px;
}

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

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

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.field span,
.field-label-row {
  color: #33475b;
  font-size: 14px;
  font-weight: 700;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--text);
  outline: none;
  padding: 12px 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

textarea {
  min-height: 142px;
  resize: vertical;
  line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(78, 184, 175, 0.9);
  box-shadow: 0 0 0 4px rgba(127, 212, 204, 0.2);
}

.size-trigger {
  width: 100%;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.size-trigger:hover,
.size-trigger:focus-visible {
  border-color: rgba(78, 184, 175, 0.9);
  box-shadow: 0 0 0 4px rgba(127, 212, 204, 0.2);
  outline: none;
}

.size-trigger-chevron {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-right: 2px solid #5c6f82;
  border-bottom: 2px solid #5c6f82;
  transform: rotate(45deg) translateY(-2px);
}

.size-modal-open {
  overflow: hidden;
}

.size-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 18px;
}

.size-modal[hidden] {
  display: none;
}

.size-modal-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: rgba(16, 32, 51, 0.42);
  cursor: default;
}

.size-dialog {
  position: relative;
  width: min(480px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 24px;
  border: 1px solid rgba(216, 227, 236, 0.95);
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 28px 80px rgba(16, 32, 51, 0.24);
  animation: size-dialog-in 0.18s ease-out;
}

@keyframes size-dialog-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

.size-dialog-header h2 {
  margin: 0 0 6px;
  font-size: 21px;
  line-height: 1.25;
}

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

.size-dialog-close {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: transparent;
  color: #8696a6;
  cursor: pointer;
  font-size: 26px;
  line-height: 1;
}

.size-dialog-close:hover,
.size-dialog-close:focus-visible {
  background: #f1f5f8;
  color: var(--text);
  outline: none;
}

.size-control-group {
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
}

.size-control-label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.resolution-options,
.ratio-options {
  display: grid;
  gap: 8px;
}

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

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

.resolution-options button,
.ratio-options button {
  border: 1px solid var(--line);
  background: #fff;
  color: #405264;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.resolution-options button {
  min-height: 44px;
  border-radius: 12px;
  font-weight: 600;
}

.ratio-options button {
  min-width: 0;
  min-height: 72px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 7px;
  border-radius: 12px;
  font-size: 13px;
}

.resolution-options button:hover,
.resolution-options button:focus-visible,
.ratio-options button:hover,
.ratio-options button:focus-visible {
  border-color: var(--accent-strong);
  outline: none;
}

.resolution-options button.selected,
.ratio-options button.selected {
  border-color: #16b8aa;
  background: #effbf9;
  color: #137f78;
  box-shadow: inset 0 0 0 1px rgba(22, 184, 170, 0.08);
}

.ratio-shape {
  display: block;
  border: 1.5px solid currentColor;
  border-radius: 4px;
}

.ratio-square {
  width: 20px;
  height: 20px;
}

.ratio-landscape-3-2 {
  width: 23px;
  height: 15px;
}

.ratio-portrait-2-3 {
  width: 15px;
  height: 23px;
}

.ratio-landscape-16-9 {
  width: 26px;
  height: 15px;
}

.ratio-portrait-9-16 {
  width: 15px;
  height: 26px;
}

.ratio-landscape-4-3 {
  width: 24px;
  height: 18px;
}

.ratio-portrait-3-4 {
  width: 18px;
  height: 24px;
}

.ratio-landscape-21-9 {
  width: 28px;
  height: 12px;
}

.size-pixel-preview {
  display: grid;
  gap: 6px;
  margin-top: 2px;
  padding: 18px 0 20px;
  border-top: 1px solid #edf1f5;
}

.size-pixel-preview span {
  color: #8594a3;
  font-size: 14px;
}

.size-pixel-preview strong {
  font-size: 21px;
  line-height: 1.2;
}

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

.size-dialog-actions button {
  min-height: 44px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
}

.size-cancel-button {
  border: 1px solid var(--line);
  background: #fff;
  color: #405264;
}

.size-confirm-button {
  background: #16aa9e;
  color: #fff;
  box-shadow: 0 8px 20px rgba(22, 170, 158, 0.22);
}

.size-cancel-button:hover,
.size-cancel-button:focus-visible,
.size-confirm-button:hover,
.size-confirm-button:focus-visible {
  filter: brightness(0.98);
  outline: none;
}

.saved-key {
  margin: -4px 0 14px;
  padding: 10px 14px;
  border-radius: 999px;
  background: #f6f8fb;
  color: var(--muted);
  font-size: 13px;
}

.upload-zone {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 16px 18px;
  border: 1px dashed #cfdbe5;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #fbfdff 0%, #f7fafd 100%);
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.upload-zone.dragover,
.upload-zone:hover {
  border-color: var(--accent-strong);
  box-shadow: 0 10px 30px rgba(127, 212, 204, 0.18);
  transform: translateY(-1px);
}

.upload-icon {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(127, 212, 204, 0.18), rgba(78, 184, 175, 0.08)),
    radial-gradient(circle at center, #4eb8af 0 3px, transparent 4px);
  position: relative;
}

.upload-icon::before {
  content: "";
  position: absolute;
  inset: 12px 22px 12px 22px;
  border-radius: 999px;
  background: var(--accent-deep);
}

.upload-icon::after {
  content: "";
  position: absolute;
  left: 17px;
  right: 17px;
  top: 14px;
  height: 16px;
  clip-path: polygon(50% 0, 100% 65%, 70% 65%, 70% 100%, 30% 100%, 30% 65%, 0 65%);
  background: var(--accent-deep);
}

.upload-copy strong {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
}

.upload-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.upload-button,
.ghost-button,
.primary-button,
.link-button {
  transition: transform 0.2s ease, opacity 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.upload-button,
.ghost-button {
  padding: 10px 14px;
  border: 1px solid #dde6ee;
  border-radius: 14px;
  background: #fff;
  color: #526579;
  font-weight: 700;
}

.link-button {
  padding: 0;
  background: transparent;
  color: var(--accent-deep);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.reference-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.reference-item {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid #e3ebf2;
  border-radius: 16px;
  background: #fbfdff;
}

.reference-item img {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: cover;
  background: #eef4f8;
}

.reference-meta strong,
.reference-meta span {
  display: block;
}

.reference-meta strong {
  font-size: 14px;
}

.reference-meta span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.remove-reference {
  padding: 8px 10px;
  border-radius: 12px;
  background: #fff2f4;
  color: var(--danger);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.advanced-card {
  margin: 6px 0 18px;
  border: 1px solid #e3ebf2;
  border-radius: 18px;
  background: #f9fbfd;
}

.advanced-card summary {
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

.advanced-card summary::-webkit-details-marker {
  display: none;
}

.advanced-grid {
  padding: 0 16px 16px;
}

.primary-button {
  width: 100%;
  min-height: 52px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 18px 36px rgba(78, 184, 175, 0.28);
}

.primary-button:hover,
.ghost-button:hover,
.upload-button:hover,
.remove-reference:hover {
  transform: translateY(-1px);
}

.primary-button:disabled {
  opacity: 0.7;
  cursor: wait;
}

.result-state,
.history-list {
  min-height: 118px;
  border-radius: 18px;
  background: var(--panel-soft);
  padding: 16px;
}

.empty-state {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.latest-card {
  display: grid;
  gap: 14px;
}

.latest-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.image-tile {
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid #e1eaf1;
  background: #fff;
}

.image-tile img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: #ecf3f8;
}

.image-actions {
  display: flex;
  gap: 10px;
  padding: 12px;
}

.image-actions a,
.history-actions button {
  flex: 1;
  min-height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #f0f7f8;
  color: var(--accent-deep);
  text-decoration: none;
  font-weight: 700;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.meta-pill {
  padding: 8px 12px;
  border-radius: 999px;
  background: #edf4f7;
  color: #40596f;
  font-size: 13px;
}

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

.tip-card {
  min-height: 78px;
  padding: 16px;
  border-radius: 18px;
  background: #f8fafc;
  color: #405264;
  line-height: 1.7;
}

.history-list {
  display: grid;
  gap: 14px;
}

.history-item {
  display: grid;
  grid-template-columns: 124px minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 12px;
  border: 1px solid #e4ecf3;
  border-radius: 18px;
  background: #fff;
}

.history-item img {
  width: 124px;
  height: 124px;
  border-radius: 16px;
  object-fit: cover;
  background: #edf3f8;
}

.history-copy {
  display: grid;
  gap: 8px;
}

.history-copy strong {
  font-size: 16px;
}

.history-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.history-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-actions {
  display: grid;
  gap: 10px;
  min-width: 112px;
}

.history-actions button {
  border: 0;
  cursor: pointer;
}

@media (max-width: 1160px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .form-panel {
    order: 1;
  }
}

@media (max-width: 860px) {
  .page-shell {
    width: min(100vw - 20px, 720px);
    padding-top: 14px;
  }

  .page-header,
  .section-head,
  .upload-zone,
  .history-item {
    grid-template-columns: 1fr;
    display: grid;
  }

  .page-header {
    gap: 14px;
  }

  .two-columns,
  .triple-columns,
  .tip-grid {
    grid-template-columns: 1fr;
  }

  .history-item {
    justify-items: start;
  }

  .history-item img {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
  }

  .history-actions {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 520px) {
  .size-modal {
    padding: 10px;
  }

  .size-dialog {
    max-height: calc(100vh - 20px);
    padding: 20px 16px 16px;
    border-radius: 20px;
  }

  .ratio-options {
    gap: 7px;
  }

  .ratio-options button {
    min-height: 68px;
  }
}
