:root {
  color-scheme: light;
  --bg: #f4f8f7;
  --panel: #ffffff;
  --panel-soft: #f8fbfa;
  --text: #12221d;
  --muted: #66756f;
  --line: #dfe9e5;
  --primary: #0f9f6e;
  --primary-dark: #087a55;
  --primary-soft: #e8f8f1;
  --warning: #9a6400;
  --warning-soft: #fff8e8;
  --danger: #b42318;
  --shadow: 0 18px 44px rgb(20 64 48 / 8%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: radial-gradient(circle at 70% -10%, #dff7ee 0, transparent 38%), var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.direct-auth {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr);
  gap: 28px;
  align-items: center;
  margin-bottom: 18px;
  padding: 24px;
  border: 1px solid #a9dfcc;
  border-radius: 18px;
  background: linear-gradient(120deg, #ecfbf5, #fff);
  box-shadow: 0 12px 28px rgba(15, 159, 110, .08);
}
.direct-auth-copy h1 { margin: 6px 0 10px; font-size: clamp(22px, 3vw, 34px); }
.direct-auth-copy p { margin: 8px 0; line-height: 1.65; color: var(--muted); }
.direct-auth-copy .security-note { font-size: 13px; }
.direct-login-form { display: grid; gap: 10px; }
.direct-login-form label { font-size: 13px; font-weight: 700; }
.direct-login-form input { width: 100%; padding: 11px 12px; }
.direct-turnstile { min-height: 65px; }
.direct-route-notice { margin-bottom: 18px; padding: 10px 14px; border-radius: 12px; background: rgb(15 159 110 / 9%); color: var(--muted); font-size: 13px; }

.studio-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 12px clamp(18px, 4vw, 52px);
  border-bottom: 1px solid rgb(223 233 229 / 85%);
  background: rgb(255 255 255 / 90%);
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand img { width: 40px; height: 40px; border-radius: 11px; object-fit: cover; }
.brand span { display: grid; gap: 2px; }
.brand strong { font-size: 16px; }
.brand small { color: var(--muted); font-size: 11px; }
.studio-header nav { display: flex; align-items: center; gap: 9px; }

.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0 16px;
  font-weight: 650;
  cursor: pointer;
  text-decoration: none;
  transition: 160ms ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .5; transform: none; }
.button.primary { color: white; background: linear-gradient(135deg, var(--primary), #18b987); box-shadow: 0 8px 18px rgb(15 159 110 / 20%); }
.button.primary:hover { background: linear-gradient(135deg, var(--primary-dark), var(--primary)); }
.button.secondary { color: #24433a; border-color: var(--line); background: #fff; }
.text-button { padding: 5px 0; border: 0; color: var(--primary-dark); background: transparent; cursor: pointer; }

.studio-shell { width: min(1680px, calc(100% - 32px)); margin: 26px auto 56px; }
.status-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.status-grid article { display: grid; gap: 6px; min-height: 76px; padding: 15px 17px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: 0 6px 20px rgb(20 64 48 / 4%); }
.status-grid span, .eyebrow { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.status-grid strong { overflow: hidden; font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }

.retention-notice { margin: 12px 0; padding: 11px 15px; border: 1px solid #f3dfb2; border-radius: 10px; color: var(--warning); background: var(--warning-soft); font-size: 13px; }
.onboarding { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 12px 0; padding: 20px; border: 1px solid #a9dfcc; border-radius: 16px; background: linear-gradient(120deg, #ecfbf5, #f9fffc); box-shadow: var(--shadow); }
.onboarding h2 { margin: 5px 0 6px; font-size: 20px; }
.onboarding p { max-width: 760px; margin: 0; color: var(--muted); line-height: 1.5; }
.onboarding-actions { display: flex; flex-shrink: 0; gap: 8px; }
.existing-key-form { width: min(520px, 100%); }
.existing-key-form label { display: block; margin-bottom: 7px; font-weight: 650; }
.existing-key-form div { display: flex; gap: 8px; }
.existing-key-form input { flex: 1; min-width: 0; }

.message { margin: 12px 0; padding: 12px 15px; border-radius: 10px; color: #175c46; background: #eaf8f2; }
.message.error { color: var(--danger); background: #fff0ee; }
.message.warning { color: var(--warning); background: var(--warning-soft); }

.workspace { display: grid; grid-template-columns: minmax(270px, 340px) minmax(420px, 1fr) minmax(220px, 280px); gap: 14px; align-items: stretch; }
.settings-panel, .preview-panel, .history-panel, .library-panel { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: var(--shadow); }
.settings-panel, .history-panel { padding: 17px; }
.preview-panel { display: flex; min-height: 720px; flex-direction: column; padding: 17px; }
.library-panel { margin-top: 14px; padding: 17px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 15px; }
.panel-heading h2 { margin: 4px 0 0; font-size: 17px; }

.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 16px; padding: 4px; border-radius: 10px; background: #edf2f0; }
.mode-switch button { min-height: 36px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; cursor: pointer; }
.mode-switch button.active { color: var(--text); background: #fff; box-shadow: 0 3px 9px rgb(20 64 48 / 10%); font-weight: 700; }

.field { position: relative; display: grid; gap: 7px; margin-bottom: 14px; }
.field > span:first-child { font-size: 13px; font-weight: 700; }
.field small { color: var(--muted); font-size: 11px; text-align: right; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 10px; outline: 0; color: var(--text); background: var(--panel-soft); }
input, select { min-height: 42px; padding: 0 11px; }
textarea { resize: vertical; min-height: 160px; padding: 11px; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: #61c8a4; box-shadow: 0 0 0 3px rgb(15 159 110 / 12%); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 10px; }

.size-picker { display: grid; grid-column: 1 / -1; gap: 11px; min-width: 0; margin: 0 0 14px; padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-soft); }
.size-picker legend { padding: 0 5px; font-size: 13px; font-weight: 700; }
.resolution-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 4px; border-radius: 10px; background: #edf2f0; }
.resolution-switch button { display: grid; min-height: 48px; place-items: center; gap: 2px; border: 1px solid transparent; border-radius: 8px; color: var(--muted); background: transparent; cursor: pointer; }
.resolution-switch button strong { color: inherit; font-size: 13px; }
.resolution-switch button small { font-size: 10px; }
.resolution-switch button.active { border-color: #9ddbc4; color: var(--primary-dark); background: #fff; box-shadow: 0 3px 9px rgb(20 64 48 / 10%); }
.size-picker-label { color: var(--muted); font-size: 11px; font-weight: 700; }
.ratio-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.ratio-grid button { display: grid; min-height: 58px; place-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: var(--panel); cursor: pointer; }
.ratio-grid button strong { font-size: 11px; }
.ratio-grid button.active { border-color: #56b9ff; color: #1672d4; background: #edf6ff; box-shadow: 0 0 0 2px rgb(86 185 255 / 10%); }
.ratio-grid button:disabled { cursor: not-allowed; opacity: .38; }
.ratio-icon { display: block; width: 18px; height: 18px; border: 1.5px solid currentColor; border-radius: 3px; }
.ratio-icon.landscape { width: 21px; height: 14px; }
.ratio-icon.portrait { width: 14px; height: 21px; }
.ratio-icon.wide { width: 23px; height: 12px; }
.ratio-icon.tall { width: 12px; height: 23px; }
.ratio-icon.ultrawide { width: 25px; height: 10px; }
.size-summary { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 3px 10px; padding: 10px 11px; border-radius: 9px; color: var(--muted); background: var(--panel); }
.size-summary > span { font-size: 11px; }
.size-summary strong { color: var(--text); font-size: 14px; }
.size-summary small { grid-column: 1 / -1; font-size: 10px; }

.reference-field input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-box { display: grid; min-height: 130px; place-items: center; gap: 4px; overflow: hidden; border: 1px dashed #9fc8b9; border-radius: 11px; color: var(--muted); background: #f4fbf8; cursor: pointer; text-align: center; }
.upload-box img { width: 100%; max-height: 220px; object-fit: contain; background: #ecf2ef; }
.upload-box small { text-align: center; }
.advanced { margin-bottom: 14px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-soft); }
.advanced summary { padding: 11px; cursor: pointer; font-size: 13px; font-weight: 700; }
.advanced > div { padding: 0 11px 3px; }
.generate-button { width: 100%; min-height: 48px; }

.canvas { position: relative; display: grid; flex: 1; min-height: 600px; overflow: hidden; place-items: center; border: 1px solid var(--line); border-radius: 13px; background-color: #eef4f1; background-image: linear-gradient(#dfe8e4 1px, transparent 1px), linear-gradient(90deg, #dfe8e4 1px, transparent 1px); background-size: 28px 28px; }
.canvas-empty { display: grid; max-width: 360px; place-items: center; gap: 8px; padding: 40px; color: var(--muted); text-align: center; }
.canvas-empty strong { color: var(--text); font-size: 18px; }
.image-icon { display: grid; width: 60px; height: 60px; place-items: center; border-radius: 18px; color: white; background: linear-gradient(135deg, #0f9f6e, #5ed4ad); font-size: 26px; box-shadow: 0 14px 28px rgb(15 159 110 / 23%); }
.result-grid { display: grid; width: 100%; padding: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.result-card { overflow: hidden; margin: 0; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.result-card img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; background: #edf3f0; }
.result-card figcaption { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px; }
.result-meta { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.queue-badge, .count-badge { display: inline-flex; min-width: 28px; min-height: 26px; align-items: center; justify-content: center; border-radius: 999px; padding: 0 9px; color: var(--primary-dark); background: var(--primary-soft); font-size: 12px; font-weight: 750; }
.batch-list { display: grid; gap: 8px; max-height: 650px; overflow: auto; margin: 0; padding: 0; list-style: none; }
.batch-list li:not(.empty-row) { display: grid; gap: 5px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-soft); }
.batch-list strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.batch-list span { color: var(--muted); font-size: 11px; }
.empty-row { display: grid; min-height: 100px; place-items: center; color: var(--muted); font-size: 13px; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }

.busy .canvas::after { content: "正在调用 Image 2…"; position: absolute; inset: 0; display: grid; place-items: center; color: white; background: rgb(12 40 31 / 62%); backdrop-filter: blur(3px); font-weight: 750; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 300px 1fr; }
  .history-panel { grid-column: 1 / -1; }
  .batch-list { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); max-height: none; }
}

@media (max-width: 780px) {
  .direct-auth { grid-template-columns: 1fr; padding: 18px; }
  .studio-header { align-items: flex-start; padding: 12px 16px; }
  .studio-header nav .secondary:first-child { display: none; }
  .studio-shell { width: min(100% - 20px, 1680px); margin-top: 14px; }
  .status-grid { grid-template-columns: 1fr 1fr; }
  .onboarding { align-items: stretch; flex-direction: column; }
  .onboarding-actions { flex-wrap: wrap; }
  .workspace { grid-template-columns: 1fr; }
  .preview-panel { min-height: 520px; }
  .canvas { min-height: 430px; }
  .history-panel { grid-column: auto; }
}

@media (max-width: 500px) {
  .brand small, #download-all { display: none; }
  .studio-header nav { gap: 5px; }
  .button { padding: 0 11px; }
  .status-grid { grid-template-columns: 1fr; }
  .field-grid { grid-template-columns: 1fr; }
}

@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; --bg: #101713; --panel: #17211c; --panel-soft: #1c2923; --text: #edf8f3; --muted: #a3b6ae; --line: #2b3c34; --primary-soft: #123a2d; --warning-soft: #332a14; --shadow: 0 18px 44px rgb(0 0 0 / 24%); }
  .studio-header { background: rgb(23 33 28 / 92%); }
  .button.secondary, .mode-switch button.active, .resolution-switch button.active, .result-card { color: var(--text); background: var(--panel); }
  .mode-switch { background: #0e1713; }
  .resolution-switch { background: #0e1713; }
  .canvas { background-color: #121c17; background-image: linear-gradient(#28372f 1px, transparent 1px), linear-gradient(90deg, #28372f 1px, transparent 1px); }
  .onboarding { background: linear-gradient(120deg, #15372b, #17211c); }
  .direct-auth { background: linear-gradient(120deg, #15372b, #17211c); }
}
