:root {
  --bg: #f5f7fc;
  --panel: #ffffff;
  --line: #dce2ef;
  --text: #162033;
  --muted: #6a7488;
  --primary: #2f5bea;
  --primary-soft: #edf2ff;
  --success: #157347;
  --warn: #b06a11;
  --danger: #c0352b;
  --shadow: 0 18px 44px rgba(18, 31, 59, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(47, 91, 234, 0.08), transparent 24%),
    linear-gradient(180deg, #fbfcff 0%, var(--bg) 100%);
}

button,
input,
select {
  font: inherit;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 36px 18px;
}

.shell {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.header {
  margin-bottom: 22px;
  text-align: center;
}

.header h1 {
  margin: 0 0 8px;
  font-size: 2.3rem;
  letter-spacing: -0.03em;
}

.header p {
  margin: 0;
  color: var(--muted);
  max-width: 560px;
  margin-inline: auto;
  line-height: 1.6;
}

.intro-notes {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  justify-items: center;
}

.frame-toolbar {
  display: none;
}

.toolbar-status {
  justify-content: flex-end;
  flex-shrink: 0;
}

#uploadFile {
  display: none;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  font-size: 0.95rem;
}

input[type="number"]:focus,
select:focus {
  outline: 0;
  border-color: rgba(47, 91, 234, 0.55);
  box-shadow: 0 0 0 4px rgba(47, 91, 234, 0.12);
}

button {
  border: 0;
  border-radius: 14px;
  padding: 11px 16px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(47, 91, 234, 0.18);
}

.compact-btn {
  padding: 8px 12px;
  font-size: 0.92rem;
  white-space: nowrap;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.secondary {
  background: var(--primary-soft);
  color: #2347b8;
  box-shadow: none;
}

.secondary.is-downloaded {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 8px 20px rgba(47, 91, 234, 0.18);
}

.meta,
.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: #eef2f8;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.badge-idle {
  background: #eef2f8;
  color: var(--muted);
}

.badge-queued {
  background: #fff1db;
  color: var(--warn);
}

.badge-processing {
  background: #eaf1ff;
  color: #2953c7;
}

.badge-done {
  background: #e4f6eb;
  color: var(--success);
}

.badge-failed {
  background: #fde9e7;
  color: var(--danger);
}

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

.status-line {
  padding: 8px 14px;
  border-radius: 999px;
  background: #f3f6fd;
}

.error {
  color: var(--danger);
  margin-bottom: 0;
}

.hidden {
  display: none;
}

.frame-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.frame-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 20px;
  background: rgba(252, 253, 255, 0.96);
  display: flex;
  flex-direction: column;
}

.upload-form {
  display: grid;
  gap: 16px;
  margin-bottom: 18px;
}

.frame-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
  min-height: 42px;
}

.frame-head h2 {
  margin: 0;
  font-size: 1.06rem;
}

.frame-toolbar-query input {
  flex: 1;
  min-width: 170px;
}

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

.actions-with-status {
  justify-content: flex-end;
}

.image-frame {
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(90deg, rgba(47, 91, 234, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(47, 91, 234, 0.04) 1px, transparent 1px),
    #f8faff;
  background-size: 24px 24px, 24px 24px, auto;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 14px;
}

.frame-image {
  display: none;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 12px;
}

.result-full-frame {
  padding: 0;
}

.result-full-frame .frame-image {
  object-fit: cover;
  border-radius: 0;
}

.image-frame.has-image .frame-image {
  display: block;
}

.image-frame.has-image .placeholder {
  display: none;
}

.placeholder {
  width: 100%;
  height: 100%;
  padding: 28px;
  text-align: center;
  color: var(--muted);
  line-height: 1.6;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-placeholder {
  width: 100%;
  height: 100%;
  padding: 28px;
  text-align: center;
  transition: transform 0.18s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.upload-anim {
  position: relative;
  width: 88px;
  height: 88px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
}

.upload-anim-ring,
.upload-anim-core {
  position: absolute;
  inset: 0;
  border-radius: 20px;
}

.upload-anim-ring {
  border: 1px solid rgba(47, 91, 234, 0.18);
  background: rgba(47, 91, 234, 0.04);
  animation: uploadPulse 2.2s ease-in-out infinite;
}

.upload-anim-core {
  inset: 10px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(47, 91, 234, 0.2), rgba(47, 91, 234, 0.09));
  color: #2f5bea;
  animation: uploadFloat 2.2s ease-in-out infinite;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.upload-anim-core svg {
  width: 40px;
  height: 40px;
  stroke: currentColor;
  stroke-width: 1.65;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.upload-placeholder strong {
  display: block;
  color: var(--text);
  font-size: 1.1rem;
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}

.upload-placeholder span {
  display: block;
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.65;
}

.upload-frame {
  cursor: pointer;
  background:
    linear-gradient(180deg, rgba(237, 242, 255, 0.9), rgba(248, 250, 255, 0.96)),
    linear-gradient(90deg, rgba(47, 91, 234, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(47, 91, 234, 0.04) 1px, transparent 1px);
  background-size: auto, 24px 24px, 24px 24px;
}

.upload-frame:not(.has-image) {
  border-style: dashed;
}

.upload-frame:not(.has-image):hover .upload-placeholder {
  transform: translateY(-1px);
}

.upload-frame:not(.has-image):hover .upload-anim-ring {
  border-color: rgba(47, 91, 234, 0.28);
}

.upload-frame:not(.has-image):hover .upload-anim-core {
  background: linear-gradient(180deg, rgba(47, 91, 234, 0.22), rgba(47, 91, 234, 0.12));
}

@keyframes uploadFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-3px);
  }
}

@keyframes uploadPulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.9;
  }
  50% {
    transform: scale(1.06);
    opacity: 1;
  }
}

.upload-frame.has-image .upload-placeholder {
  display: none;
}

.sample-gallery {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.sample-gallery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.sample-gallery-head p {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
}

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

.sample-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  background: #fff;
  box-shadow: none;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  transition:
    transform 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease;
}

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

.sample-item:hover {
  transform: translateY(-1px);
  border-color: rgba(47, 91, 234, 0.35);
}

.sample-item.active {
  border-color: var(--primary);
  box-shadow: 0 10px 22px rgba(47, 91, 234, 0.2);
}

.settings-panel {
  border: 1px solid rgba(47, 91, 234, 0.12);
  border-radius: 18px;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(244, 247, 255, 0.92), rgba(255, 255, 255, 0.98)),
    radial-gradient(circle at top right, rgba(47, 91, 234, 0.08), transparent 32%);
  box-shadow: 0 14px 34px rgba(18, 31, 59, 0.06);
}

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

.settings-title {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.settings-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

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

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

.field-label {
  font-size: 0.9rem;
  color: var(--muted);
}

.field-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.95);
}

.field-input input,
.field-input select {
  border: 0;
  padding: 8px 10px;
  background: transparent;
  box-shadow: none;
}

.field-input input:focus,
.field-input select:focus {
  box-shadow: none;
}

.field-unit {
  padding: 6px 10px;
  border-radius: 12px;
  background: #f3f6fd;
  color: var(--muted);
  font-size: 0.82rem;
}

.field-input-select {
  grid-template-columns: minmax(0, 1fr);
}

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

.toggle-card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.88);
  cursor: pointer;
  transition:
    border-color 0.18s ease,
    transform 0.18s ease,
    box-shadow 0.18s ease;
}

.toggle-card:hover {
  transform: translateY(-1px);
  border-color: rgba(47, 91, 234, 0.2);
}

.toggle-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-indicator {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: #d7deed;
  position: relative;
  transition: background 0.18s ease;
}

.toggle-indicator::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 9px rgba(17, 30, 61, 0.18);
  transition: transform 0.18s ease;
}

.toggle-copy {
  display: grid;
  gap: 4px;
}

.toggle-copy strong {
  font-size: 0.95rem;
}

.toggle-copy span {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.toggle-card:has(input:checked) {
  border-color: rgba(47, 91, 234, 0.26);
  box-shadow: 0 12px 26px rgba(47, 91, 234, 0.08);
}

.toggle-card:has(input:checked) .toggle-indicator {
  background: var(--primary);
}

.toggle-card:has(input:checked) .toggle-indicator::after {
  transform: translateX(18px);
}

@media (max-width: 920px) {
  .frame-grid,
  .frame-toolbar {
    grid-template-columns: 1fr;
  }

  .toolbar-status {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-grid,
  .toggle-grid {
    grid-template-columns: 1fr;
  }

  .settings-head {
    flex-direction: column;
  }

  button {
    width: 100%;
  }

  .frame-toolbar-query input {
    min-width: 0;
  }

  .image-frame {
    aspect-ratio: 1 / 1;
  }

  .sample-gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
