:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #1f2633;
  --muted: #6b7280;
  --line: #e5e8ef;
  --brand: #1f6feb;
  --brand-dark: #1658bf;
  --ok: #13a35b;
  --warn: #c27803;
  --bad: #d12f2f;
  --soft: #eef4ff;
  --shadow: 0 12px 30px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}
button, input { font: inherit; }
button {
  border: 0;
  background: var(--brand);
  color: white;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
}
button:hover { background: var(--brand-dark); }
button.secondary {
  background: #eef2f7;
  color: #243042;
}
button.secondary:hover { background: #dfe6f0; }
button.danger {
  background: #fff0f0;
  color: var(--bad);
}
button.danger:hover { background: #ffe0e0; }
button.ghost {
  background: transparent;
  color: var(--brand);
  padding: 6px 8px;
}
button.primary-lg {
  min-width: 132px;
  padding: 13px 18px;
  font-weight: 700;
}
button:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}
input[type="text"], input[type="password"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  width: 100%;
  background: white;
}
input[type="file"] {
  max-width: 100%;
}
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-card h1 {
  margin: 0 0 8px;
  font-size: 24px;
}
.login-card p {
  margin: 0 0 24px;
  color: var(--muted);
}
.login-actions {
  display: grid;
  gap: 12px;
}
.app-shell {
  min-height: 100vh;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(255, 255, 255, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand h1 {
  margin: 0;
  font-size: 19px;
}
.brand span {
  color: var(--muted);
  font-size: 13px;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}
.tabs {
  display: flex;
  gap: 8px;
  padding: 18px 24px 0;
}
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.tab.active {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}
.main {
  padding: 18px 24px 40px;
  max-width: 1280px;
  margin: 0 auto;
}
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.stat b {
  display: block;
  font-size: 24px;
}
.stat span {
  color: var(--muted);
  font-size: 13px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-head h2 {
  margin: 0;
  font-size: 18px;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.action-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.action-panel h2 {
  margin: 0 0 5px;
}
.action-panel p {
  margin: 0;
}
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.image-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}
.image-card.selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(31, 111, 235, .15);
}
.thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #e9edf5;
  overflow: hidden;
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.image-meta {
  padding: 9px;
  display: grid;
  gap: 6px;
}
.image-name {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.image-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.image-actions button {
  padding: 6px 8px;
  font-size: 12px;
}
.group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}
.group-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 14px;
}
.group-title {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 8px;
}
.group-title h3 {
  margin: 0 0 4px;
  font-size: 17px;
}
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  background: #eef2f7;
  color: #334155;
}
.badge.ok { background: #e7f7ee; color: var(--ok); }
.badge.warn { background: #fff7e0; color: var(--warn); }
.badge.bad { background: #fff0f0; color: var(--bad); }
.mini-thumbs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 12px 0;
}
.mini-thumbs img, .mini-empty {
  aspect-ratio: 1 / 1;
  width: 100%;
  border-radius: 6px;
  object-fit: cover;
  background: #eef2f7;
}
.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.round {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 12px;
}
.round-summary {
  color: var(--muted);
  font-size: 13px;
  margin-top: 10px;
  line-height: 1.5;
}
.round-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}
.result-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}
.result-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}
.result-card .caption {
  padding: 8px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}
.result-card .caption span {
  display: inline-block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result-placeholder {
  aspect-ratio: 1 / 1;
  background: #eef2f7;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 7px;
  text-align: center;
  padding: 10px;
}
.result-placeholder b {
  font-size: 15px;
}
.result-placeholder small {
  color: var(--muted);
  line-height: 1.35;
}
.result-placeholder.failed {
  background: #fff0f0;
  color: var(--bad);
}
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #dbeafe;
  border-top-color: var(--brand);
  border-radius: 999px;
  animation: spin .8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.form-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}
.empty {
  border: 1px dashed #cbd5e1;
  color: var(--muted);
  border-radius: 8px;
  padding: 28px;
  text-align: center;
}
.empty.compact {
  padding: 16px;
}
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #111827;
  color: white;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: none;
  z-index: 20;
  max-width: min(420px, calc(100vw - 36px));
}
.toast.show { display: block; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(15, 23, 42, .56);
  padding: 24px;
  overflow: auto;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--panel);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.modal-head h2 {
  margin: 0;
  font-size: 20px;
}
.small-modal {
  max-width: 620px;
}
.preview-img {
  display: block;
  max-width: 100%;
  max-height: 78vh;
  margin: 0 auto;
  border-radius: 8px;
}
.preview-card {
  max-width: 1180px;
}
.preview-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: min(72vh, 720px);
  background: #0b1220;
  border-radius: 8px;
  padding: 12px;
  overflow: hidden;
}
.preview-stage .preview-img {
  max-height: 74vh;
  object-fit: contain;
  user-select: auto;
  -webkit-user-select: auto;
  -webkit-touch-callout: default;
}
.preview-nav {
  position: absolute;
  top: 50%;
  width: 42px;
  height: 56px;
  transform: translateY(-50%);
  border-radius: 999px;
  padding: 0;
  background: rgba(255, 255, 255, .9);
  color: #111827;
  font-size: 34px;
  line-height: 1;
  z-index: 2;
}
.preview-nav:hover {
  background: white;
}
.preview-nav.prev { left: 14px; }
.preview-nav.next { right: 14px; }
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.create-card {
  max-width: 1180px;
}
.create-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
  background: white;
}
.create-section h3 {
  margin: 0 0 4px;
  font-size: 17px;
}
.create-section p {
  margin: 0;
}
.create-title {
  display: grid;
  grid-template-columns: 1fr minmax(220px, 360px);
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}
.upload-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}
.upload-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 124px;
  border-radius: 8px;
  padding: 12px 16px;
  background: var(--brand);
  color: white;
  cursor: pointer;
  font-weight: 700;
  overflow: hidden;
}
.upload-button:hover {
  background: var(--brand-dark);
}
.upload-button.disabled {
  background: #cbd5e1;
  cursor: wait;
}
.upload-button input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 80px;
}
.upload-button input:disabled {
  cursor: wait;
}
.upload-status {
  flex: 1 1 280px;
  min-width: 240px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #f8fafc;
}
.upload-status.hidden {
  display: none;
}
.upload-status.success {
  border-color: rgba(19, 163, 91, .35);
  background: #effaf4;
}
.upload-status.error {
  border-color: rgba(209, 47, 47, .35);
  background: #fff3f3;
}
.upload-status-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 13px;
}
.upload-status p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.upload-progress {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #e5e8ef;
}
.upload-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width .2s ease;
}
.upload-progress.indeterminate span {
  animation: uploadMove 1.1s infinite ease-in-out;
}
@keyframes uploadMove {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(260%); }
}
.selected-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
}
.selected-chip {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #f8fafc;
}
.selected-chip img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}
.selected-chip span {
  display: block;
  padding: 7px;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-remove {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  padding: 0;
  background: rgba(15, 23, 42, .76);
  color: white;
  line-height: 1;
  z-index: 1;
}
.chip-remove:hover {
  background: rgba(15, 23, 42, .92);
}
.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
  gap: 12px;
}
.result-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.picker-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}
.picker-card.selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(31, 111, 235, .14);
}
.picker-thumb {
  display: block;
  width: 100%;
  padding: 0;
  border-radius: 7px;
  overflow: hidden;
  background: #e9edf5;
}
.picker-thumb:hover {
  background: #e9edf5;
}
.picker-thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}
.picker-check {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  font-size: 13px;
  cursor: pointer;
}
.picker-check input {
  width: 18px;
  height: 18px;
}
.modal-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 10px;
  background: linear-gradient(to top, white 70%, rgba(255,255,255,0));
}
.library-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.count-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}
.count-option {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
  display: grid;
  gap: 8px;
  cursor: pointer;
}
.count-option:has(input:checked) {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(31, 111, 235, .14);
}
.count-option input[type="radio"] {
  width: 18px;
  height: 18px;
}
.count-option span {
  font-weight: 700;
}
.custom-count input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}
.live-note {
  border: 1px solid #fde68a;
  background: #fffbeb;
  color: #92400e;
  border-radius: 8px;
  padding: 11px 12px;
  margin-bottom: 14px;
  font-size: 14px;
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    padding: 12px 14px;
  }
  .toolbar { flex-wrap: wrap; justify-content: flex-end; }
  .tabs { padding: 14px 14px 0; overflow-x: auto; }
  .main { padding: 14px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .group-grid { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
  .action-panel,
  .upload-section {
    align-items: stretch;
    flex-direction: column;
  }
  .quick-actions,
  .library-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }
  button.primary-lg,
  .upload-button {
    width: 100%;
  }
  .upload-status {
    width: 100%;
    min-width: 0;
  }
  .create-title {
    grid-template-columns: 1fr;
  }
  .picker-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .result-library-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .count-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .selected-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .form-row { grid-template-columns: 1fr; }
  .modal { padding: 10px; }
  .modal-card { padding: 14px; }
  .preview-stage {
    min-height: 64vh;
    padding: 8px;
  }
  .preview-nav {
    width: 36px;
    height: 48px;
    font-size: 28px;
  }
}
