:root {
  --bg-top: #f7f8ff;
  --bg-bottom: #efefff;
  --panel: rgba(245, 245, 255, 0.84);
  --panel-strong: rgba(255, 255, 255, 0.92);
  --panel-soft: rgba(255, 255, 255, 0.68);
  --line: rgba(126, 138, 196, 0.18);
  --line-strong: rgba(126, 138, 196, 0.3);
  --ink: #2d3457;
  --muted: #7781af;
  --accent: #7a82ff;
  --accent-strong: #9399ff;
  --accent-soft: rgba(122, 130, 255, 0.12);
  --ok: #3d8f66;
  --warn: #ba7f38;
  --danger: #c55b7b;
  --shadow-lg: 0 24px 70px rgba(124, 132, 214, 0.18);
  --shadow-md: 0 14px 36px rgba(124, 132, 214, 0.12);
  --shadow-sm: 0 8px 20px rgba(124, 132, 214, 0.08);
  --radius-xxl: 30px;
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --sans: "Avenir Next", "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 14%, rgba(255, 255, 255, 0.95), transparent 22%),
    radial-gradient(circle at 82% 18%, rgba(207, 214, 255, 0.65), transparent 26%),
    radial-gradient(circle at 70% 74%, rgba(193, 201, 255, 0.34), transparent 22%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}

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

button {
  cursor: pointer;
}

.page {
  width: min(1180px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 28px 0 32px;
}

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

.shell-card,
.history-drawer {
  position: relative;
  background: linear-gradient(180deg, rgba(246, 246, 255, 0.92), rgba(240, 241, 255, 0.78));
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-xxl);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}

.shell-card::before,
.history-drawer::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.8), transparent 34%),
    radial-gradient(circle at bottom right, rgba(181, 190, 255, 0.22), transparent 28%);
  pointer-events: none;
}

.config-card,
.result-card-shell {
  padding: 26px;
}

.card-header,
.field-row,
.history-meta,
.history-actions,
.editor-head,
.submit-row,
.result-tools,
.route-switch {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.card-header {
  justify-content: space-between;
  margin-bottom: 22px;
}

.card-header h1,
.card-header h2,
.history-drawer h2 {
  margin: 0;
  color: var(--ink);
}

.card-header h1 {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: var(--accent-strong);
}

.card-header h2 {
  font-size: 15px;
  font-weight: 800;
}

.card-kicker {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

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

.config-stack,
.result-shell,
.history-list,
.meta-grid,
.thumb-grid {
  display: grid;
  gap: 18px;
}

.surface-panel,
.empty-state,
.raw-panel,
.status-card,
.result-card,
.history-item,
.thumb-card,
.editor {
  position: relative;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}

.surface-panel,
.empty-state,
.raw-panel,
.status-card,
.history-item,
.editor {
  padding: 16px 18px;
}

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

.config-block {
  display: grid;
  gap: 18px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.field-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.field-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.field-note,
.inline-note,
.hint,
.raw-note,
.history-empty,
.meta-item span,
.status-body,
.drop-copy span,
.result-summary {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(156, 165, 224, 0.28);
  border-radius: var(--radius-lg);
  background: var(--panel-strong);
  color: var(--ink);
  padding: 14px 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(122, 130, 255, 0.5);
  box-shadow: 0 0 0 4px rgba(122, 130, 255, 0.12);
}

textarea {
  min-height: 158px;
  resize: vertical;
}

input[type="range"] {
  padding: 0;
  border: 0;
  box-shadow: none;
  background: transparent;
}

.switch-row {
  width: 100%;
  justify-content: space-between;
  color: var(--ink);
  font-weight: 700;
}

.switch-row input {
  width: 20px;
  height: 20px;
}

.route-panel {
  gap: 12px;
}

.route-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

.route-title-block {
  display: grid;
  gap: 4px;
}

.route-title {
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.route-subtitle {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.icon-toggle {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(156, 165, 224, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.88);
}

.icon-toggle span {
  font-size: 16px;
  line-height: 1;
  transition: transform 0.16s ease;
}

.collapsed .icon-toggle span {
  transform: rotate(-90deg);
}

.top-row {
  justify-content: space-between;
}

.route-panel-body {
  display: grid;
  gap: 12px;
}

.route-collapsed-note {
  padding-top: 2px;
}

.route-inline {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.route-inline .hint {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(156, 165, 224, 0.24);
}

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

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

.size-preset {
  display: grid;
  gap: 4px;
  justify-items: start;
  padding: 16px 18px;
  border-radius: 22px;
  border: 1px solid rgba(156, 165, 224, 0.26);
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  text-align: left;
  font-size: 16px;
  font-weight: 800;
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.size-preset span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.size-preset:hover {
  transform: translateY(-1px);
  border-color: rgba(122, 130, 255, 0.3);
}

.size-preset.active {
  border-color: rgba(122, 130, 255, 0.36);
  background: linear-gradient(180deg, rgba(225, 248, 252, 0.98), rgba(243, 252, 253, 0.96));
}

.drop-zone {
  border: 1.5px dashed rgba(122, 130, 255, 0.38);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.55);
  padding: 18px;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.drop-zone.dragging {
  border-color: rgba(122, 130, 255, 0.66);
  background: rgba(122, 130, 255, 0.08);
}

.drop-copy {
  display: grid;
  gap: 6px;
  text-align: center;
}

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

.submit-row {
  justify-content: flex-start;
}

.button,
.ghost-button,
.link-button {
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 11px 18px;
  font-weight: 700;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.button:hover,
.ghost-button:hover,
.link-button:hover,
.size-preset:hover {
  transform: translateY(-1px);
}

.button:disabled,
.ghost-button:disabled {
  opacity: 0.56;
  cursor: not-allowed;
  transform: none;
}

.button {
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 14px 30px rgba(122, 130, 255, 0.22);
}

.primary-button {
  min-width: 120px;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  border-color: rgba(156, 165, 224, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.88);
}

.link-button {
  background: transparent;
  color: var(--muted);
  border-color: rgba(156, 165, 224, 0.18);
}

.soft-chip,
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(156, 165, 224, 0.22);
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.pill {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.result-header {
  grid-template-columns: auto 1fr auto;
  display: grid;
  align-items: center;
  gap: 12px;
}

.result-header h2 {
  text-align: center;
}

.result-topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.result-summary {
  flex: 1 1 320px;
}

.result-tools {
  justify-content: flex-end;
}

.result-status[data-tone="ok"] {
  background: rgba(221, 246, 232, 0.72);
  border-color: rgba(61, 143, 102, 0.2);
}

.result-status[data-tone="warn"] {
  background: rgba(255, 238, 219, 0.74);
  border-color: rgba(186, 127, 56, 0.22);
}

.result-status[data-tone="error"] {
  background: rgba(255, 228, 236, 0.76);
  border-color: rgba(197, 91, 123, 0.22);
}

.status-title {
  font-weight: 800;
  margin-bottom: 4px;
}

.empty-state {
  min-height: 180px;
  display: grid;
  align-content: center;
  gap: 8px;
}

.empty-state h3 {
  margin: 0;
  font-size: 18px;
}

.result-grid {
  display: grid;
  gap: 16px;
}

.result-card {
  overflow: hidden;
}

.image-frame {
  position: relative;
  aspect-ratio: 1 / 1;
  background:
    linear-gradient(135deg, rgba(122, 130, 255, 0.09), rgba(206, 210, 255, 0.18)),
    #f7f8ff;
}

.image-frame img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background:
    linear-gradient(45deg, #eef1ff 25%, transparent 25%),
    linear-gradient(-45deg, #eef1ff 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef1ff 75%),
    linear-gradient(-45deg, transparent 75%, #eef1ff 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}

.image-body {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.image-title {
  margin: 0;
  font-size: 16px;
}

.image-body .result-meta,
.history-meta,
.history-actions,
.editor-head,
.field-row,
.card-header,
.submit-row,
.result-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

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

.meta-item {
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(156, 165, 224, 0.14);
}

.meta-item strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.raw-panel summary {
  cursor: pointer;
  font-weight: 700;
}

.raw-panel pre {
  margin: 12px 0 0;
  max-height: 280px;
  overflow: auto;
  padding: 14px;
  border-radius: 16px;
  background: #242840;
  color: #f6f7ff;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
}

.thumb-grid {
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
}

.thumb-card {
  overflow: hidden;
  position: relative;
  aspect-ratio: 1 / 1;
}

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

.thumb-badge,
.mask-badge {
  position: absolute;
  top: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.9);
}

.thumb-badge {
  left: 8px;
}

.mask-badge {
  right: 8px;
  background: rgba(197, 91, 123, 0.92);
  color: #fff;
}

.thumb-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  background: rgba(39, 44, 78, 0.38);
  opacity: 0;
  transition: opacity 0.16s ease;
}

.thumb-card:hover .thumb-overlay {
  opacity: 1;
}

.editor-frame {
  padding: 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.62);
}

.editor-stage {
  position: relative;
  width: fit-content;
  margin: 0 auto;
}

.editor-stage img {
  display: block;
  max-width: 100%;
  max-height: 360px;
  border-radius: 14px;
  user-select: none;
  pointer-events: none;
}

#mask-canvas {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  cursor: crosshair;
}

.tool-button.active {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  border-color: transparent;
}

.history-drawer {
  position: fixed;
  top: 18px;
  right: 18px;
  bottom: 18px;
  width: min(420px, calc(100vw - 30px));
  padding: 18px;
  display: none;
  z-index: 40;
}

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

.loading-spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(122, 130, 255, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
  flex-shrink: 0;
}

.status-title-row {
  display: flex;
  align-items: center;
  margin-bottom: 4px;
}

.status-elapsed {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

.history-drawer[data-open="true"] {
  display: grid;
  gap: 16px;
  align-content: start;
}

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

.history-list {
  max-height: calc(100vh - 168px);
  overflow: auto;
  padding-right: 4px;
}

.history-item h3 {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.5;
}

.history-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(46, 50, 85, 0.34);
  backdrop-filter: blur(6px);
  display: none;
  z-index: 30;
}

.history-backdrop[data-open="true"] {
  display: block;
}

.hidden {
  display: none !important;
}

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

@media (max-width: 720px) {
  .page {
    width: min(100vw - 20px, 1240px);
    padding: 12px 0 20px;
  }

  .config-card,
  .result-card-shell,
  .history-drawer {
    padding: 18px;
    border-radius: 24px;
  }

  .field-row,
  .card-header,
  .result-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .result-header {
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  .result-header h2 {
    text-align: left;
  }

  .header-actions,
  .result-tools {
    justify-content: flex-start;
  }

  .route-panel-head {
    align-items: stretch;
  }

  .options-grid,
  .size-preset-grid,
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .field-head-actions {
    width: 100%;
    justify-content: space-between;
  }
}
