:root {
  --bg: #080a09;
  --panel: #0d1110;
  --panel-raised: #121715;
  --panel-soft: #171d1a;
  --line: #26302b;
  --line-strong: #3a4740;
  --text: #f0f4f2;
  --muted: #8d9a94;
  --dim: #5d6963;
  --accent: #5be0ae;
  --accent-strong: #2fb984;
  --queued: #e4b85e;
  --working: #67b8e8;
  --failed: #f08078;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.topbar {
  height: 72px;
  padding: 0 clamp(20px, 4vw, 52px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--accent);
  border-radius: 6px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .08em;
}
.brand { color: var(--text); font-size: 15px; font-weight: 750; }
.brand-subtitle { margin-top: 3px; color: var(--dim); font-size: 9px; font-weight: 700; letter-spacing: .16em; }
.connection { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.connection strong { font-weight: 600; }
.connection > span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(91,224,174,.1); }
.connection.offline > span { background: var(--failed); box-shadow: 0 0 0 3px rgba(240,128,120,.1); }

.workspace { min-height: calc(100vh - 72px); display: grid; grid-template-columns: minmax(320px, 380px) minmax(0, 1fr); }
.controls { padding: 38px clamp(22px, 3vw, 34px); background: var(--panel); border-right: 1px solid var(--line); }
.controls form { position: sticky; top: 30px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 34px; }
.eyebrow { margin: 0 0 8px; color: var(--dim); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
.panel-heading h1 { margin: 0; color: var(--text); font-size: 25px; line-height: 1.1; letter-spacing: 0; }
.section-number { color: var(--accent); font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; font-weight: 700; }
.field { margin-bottom: 26px; }
label, legend { color: var(--text); font-size: 12px; font-weight: 700; }
.label-row, .fieldset-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.label-row span, .field-hint { color: var(--dim); font-size: 10px; font-weight: 700; letter-spacing: .08em; }
.key-input-wrap { position: relative; margin-top: 10px; }
input[type="password"], input[type="text"], textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; background: #090c0b; color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
}
input[type="password"], input[type="text"] { height: 44px; padding: 0 42px 0 13px; }
textarea { min-height: 174px; padding: 13px; resize: vertical; line-height: 1.6; }
textarea::placeholder, input::placeholder { color: #58645e; }
input:focus, textarea:focus { border-color: var(--accent-strong); background: #0b100e; box-shadow: 0 0 0 3px rgba(91,224,174,.1); }
.input-action {
  position: absolute; right: 8px; top: 7px; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 4px;
  color: var(--muted); background: transparent; font-size: 17px; line-height: 1;
}
.input-action:hover, .input-action:focus-visible { color: var(--accent); background: var(--panel-soft); }
.balance-row { min-height: 24px; display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--dim); font-size: 11px; }
.balance-row strong { color: var(--accent); font-family: "Cascadia Code", Consolas, monospace; font-size: 13px; }
.refresh-balance { width: 24px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); background: transparent; line-height: 1; }
.refresh-balance:hover:not(:disabled), .refresh-balance:focus-visible { border-color: var(--accent-strong); color: var(--accent); }
.refresh-balance:disabled { cursor: wait; opacity: .5; }
fieldset { border: 0; padding: 0; margin: 0 0 28px; }
legend { margin: 0; }
.ratio-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ratio-grid label input { position: absolute; opacity: 0; pointer-events: none; }
.ratio-grid span {
  min-height: 78px; padding: 9px 5px; border: 1px solid var(--line); border-radius: 6px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px; color: var(--muted); background: #0a0d0c; cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.ratio-grid span:hover { border-color: var(--line-strong); background: var(--panel-soft); }
.ratio-grid input:checked + span { border-color: var(--accent-strong); background: #10241d; color: var(--accent); box-shadow: inset 0 0 0 1px rgba(91,224,174,.35); }
.ratio-grid b { font-size: 12px; }
.ratio-grid small { color: var(--dim); font-size: 9px; white-space: nowrap; transform: scale(.92); }
.ratio-grid input:checked + span small { color: #75b89d; }
.shape { display: block; border: 1.5px solid currentColor; }
.square { width: 17px; height: 17px; } .landscape { width: 22px; height: 16px; }
.portrait { width: 15px; height: 20px; } .wide { width: 25px; height: 14px; } .tall { width: 13px; height: 23px; }
.ultrawide { width: 27px; height: 12px; }
.form-footer { display: grid; gap: 11px; }
.capacity-note { display: flex; align-items: center; gap: 7px; color: var(--dim); font-size: 11px; }
.capacity-note i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.submit {
  width: 100%; height: 46px; padding: 0 15px; display: flex; align-items: center; justify-content: space-between;
  border: 1px solid var(--accent-strong); border-radius: 6px; color: #07100c; background: var(--accent);
  font-weight: 800; cursor: pointer; transition: background .15s, border-color .15s, transform .15s;
}
.submit b { font-size: 18px; font-weight: 500; }
.submit:hover { border-color: #82f1c6; background: #82f1c6; transform: translateY(-1px); }
.submit:disabled { opacity: .5; cursor: wait; transform: none; }
.form-error, .task-error { color: var(--failed); font-size: 12px; min-height: 20px; line-height: 1.45; }

.tasks-panel { min-width: 0; padding: 38px clamp(22px, 4vw, 54px) 54px; background: var(--bg); }
.tasks-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.tasks-heading h2 { margin: 0; color: var(--text); font-size: 28px; line-height: 1.05; letter-spacing: 0; }
.title-line { display: flex; align-items: center; gap: 12px; }
.live-indicator { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-size: 9px; font-weight: 800; letter-spacing: .14em; }
.live-indicator i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.tasks-heading > div > p:last-child { margin: 9px 0 0; color: var(--muted); font-size: 12px; }
.quiet-button { display: inline-flex; align-items: center; gap: 6px; padding: 6px 0; border: 0; background: transparent; color: var(--muted); font-size: 12px; }
.quiet-button span { color: var(--dim); font-size: 18px; line-height: 11px; }
.quiet-button:hover { color: var(--accent); }
.queue-rule { height: 1px; margin: 23px 0 20px; background: var(--line); }
.task-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.task-card { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-raised); transition: border-color .15s, transform .15s; }
.task-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.task-head, .task-meta, .task-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.task-meta { justify-content: flex-start; }
.task-head time, .task-ratio, .task-foot code, .task-resolution { color: var(--dim); font-size: 10px; }
.status-pill { padding: 4px 8px; border-radius: 999px; background: #2a2414; color: var(--queued); font-size: 11px; font-weight: 750; }
.status-processing { color: var(--working); background: #132532; }
.status-completed { color: var(--accent); background: #10271f; }
.status-failed { color: var(--failed); background: #2a1818; }
.task-prompt { min-height: 42px; margin: 14px 0; overflow: hidden; color: #dbe2de; line-height: 1.5; font-size: 13px; word-break: break-word; }
.preview { position: relative; width: 100%; aspect-ratio: var(--ratio, 1 / 1); max-height: 480px; overflow: hidden; border: 1px solid var(--line); border-radius: 5px; background: #090c0b; }
.preview img { width: 100%; height: 100%; object-fit: contain; display: none; }
.preview.ready img { display: block; }
.preview.ready { cursor: zoom-in; }
.preview-state { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); font-size: 11px; }
.preview.ready .preview-state { display: none; }
.task-error { min-height: 0; margin: 10px 0 0; }
.task-foot { margin-top: 12px; }
.task-identifiers, .task-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.task-foot code { overflow: hidden; text-overflow: ellipsis; }
.task-resolution { font-family: "Cascadia Code", Consolas, monospace; white-space: nowrap; }
.download, .copy-image { display: none; color: var(--accent); font-size: 12px; font-weight: 700; text-decoration: none; white-space: nowrap; }
.copy-image { border: 0; padding: 0; background: transparent; }
.download:hover { color: #9af5d1; }
.copy-image:hover, .copy-image:focus-visible { color: #9af5d1; }
.download.visible, .copy-image.visible { display: inline; }
.task-duration { min-height: 16px; margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.empty { min-height: 440px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); }
.empty-mark { width: 44px; height: 44px; margin-bottom: 15px; display: grid; grid-template-columns: repeat(3, 4px); align-content: center; justify-content: center; gap: 4px; border: 1px solid var(--line-strong); border-radius: 50%; }
.empty-mark span { width: 4px; height: 4px; background: var(--dim); }
.empty-mark span:nth-child(2) { background: var(--accent); }
.empty strong { color: var(--text); font-size: 14px; }
.empty p { margin: 8px 0 0; color: var(--dim); font-size: 12px; }
.empty.hidden { display: none; }

.image-viewer { width: min(96vw, 1400px); height: min(94vh, 1000px); max-width: none; max-height: none; padding: 0; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--text); background: #080a09; box-shadow: 0 24px 80px rgba(0,0,0,.7); }
.image-viewer::backdrop { background: rgba(0,0,0,.78); }
.viewer-toolbar { height: 46px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 12px 0 16px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.viewer-close { width: 30px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 4px; color: var(--text); background: var(--panel-soft); font-size: 21px; line-height: 1; }
.viewer-close:hover, .viewer-close:focus-visible { border-color: var(--accent-strong); color: var(--accent); }
.viewer-stage { position: relative; width: 100%; height: calc(100% - 46px); overflow: hidden; touch-action: none; cursor: grab; background: #050706; }
.viewer-stage.dragging { cursor: grabbing; }
.viewer-stage img { position: absolute; left: 50%; top: 50%; max-width: none; max-height: none; transform-origin: center; user-select: none; pointer-events: none; }

@media (max-width: 860px) {
  .workspace { grid-template-columns: minmax(290px, 330px) minmax(0, 1fr); }
  .ratio-grid { grid-template-columns: repeat(2, 1fr); }
  .ratio-grid label:last-child { grid-column: span 2; }
}

@media (max-width: 700px) {
  .topbar { height: 64px; padding: 0 18px; }
  .brand-subtitle { display: none; }
  .workspace { grid-template-columns: 1fr; min-height: calc(100vh - 64px); }
  .controls { padding: 26px 18px 30px; border-right: 0; border-bottom: 1px solid var(--line); }
  .controls form { position: static; }
  .panel-heading { margin-bottom: 26px; }
  textarea { min-height: 128px; }
  .ratio-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .ratio-grid label:last-child { grid-column: auto; }
  .ratio-grid span { min-height: 70px; padding: 7px 2px; }
  .ratio-grid small { font-size: 8px; transform: scale(.86); }
  .tasks-panel { padding: 28px 18px 42px; }
  .tasks-heading h2 { font-size: 24px; }
  .task-list { grid-template-columns: 1fr; }
  .empty { min-height: 300px; }
  .image-viewer { width: 100vw; height: 100vh; border: 0; border-radius: 0; }
}

@media (max-width: 390px) {
  .connection strong { display: none; }
  .ratio-grid { grid-template-columns: repeat(2, 1fr); }
  .ratio-grid label:last-child { grid-column: auto; }
}
