:root {
  --bg: #14161a; --panel: #1c1f25; --line: #2e333c; --text: #e6e8ec; --muted: #8b93a1;
  --accent: #e0563f; --accent-2: #f07a5f; --input: #12141a; --danger: #ff7b72;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f4f5f7; --panel: #fff; --line: #d9dde3; --text: #1c1f25; --muted: #6a7280; --input: #fff; --danger: #c62828; color-scheme: light; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, "Microsoft YaHei", sans-serif; }
h1 { font-size: 17px; margin: 0; white-space: nowrap; }
header button { white-space: nowrap; }
#modelStatus { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; font-size: 12px; }
h2 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
[hidden] { display: none !important; }

header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
main { display: grid; grid-template-columns: 380px 1fr; gap: 16px; padding: 16px; align-items: start; }
@media (max-width: 860px) { main { grid-template-columns: 1fr; } }
@media (max-width: 520px) { #modelStatus { order: 9; flex-basis: 100%; } header .spacer { display: none; } }

#panel, #results { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
#panel { display: flex; flex-direction: column; gap: 12px; }

.tabs { display: flex; background: var(--input); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.tabs button { flex: 1; border: 0; background: none; color: var(--muted); padding: 7px; border-radius: 6px; cursor: pointer; font: inherit; }
.tabs button.active { background: var(--accent); color: #fff; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input[type=number], input[type=password], input[type=text], select, textarea {
  width: 100%; background: var(--input); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; font: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, #drop:focus, .drop:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
.row button { white-space: nowrap; }
.checks { display: flex; flex-direction: column; gap: 5px; }
.checks label { display: flex; align-items: center; gap: 7px; cursor: pointer; }

button { font: inherit; border-radius: 7px; padding: 7px 14px; cursor: pointer; border: 1px solid var(--line); background: var(--input); color: var(--text); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-2); }
button.ghost:hover { border-color: var(--muted); }
button:disabled { opacity: .55; cursor: not-allowed; }
.run { display: flex; align-items: center; gap: 10px; }
.run .primary { min-width: 120px; padding: 9px 14px; }

#error { border: 1px solid var(--danger); color: var(--danger); border-radius: 7px; padding: 8px 10px; white-space: pre-wrap; word-break: break-word; }

#drop { border: 1px dashed var(--line); border-radius: 8px; min-height: 84px; display: grid; place-items: center; text-align: center; cursor: pointer; background: var(--input); padding: 8px; }
#drop.over, .drop.over { border-color: var(--accent); }
.drop { border: 1px dashed var(--line); border-radius: 8px; min-height: 56px; display: grid; place-items: center; text-align: center; cursor: pointer; background: var(--input); padding: 8px; font-size: 13px; color: var(--muted); }
#srcList, .src-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
#srcList:empty, .src-grid:empty { display: none; }
#upDlg { max-width: min(94vw, 560px); }
.src-grid .src-item:first-child { border-color: var(--line); }
#upMsg { font-size: 12px; white-space: pre-wrap; }
#upMsg:empty { display: none; }
.src-item { position: relative; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: var(--input); }
.src-item:first-child { border-color: var(--accent); }
.src-item img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: pointer; }
.src-item .tag { position: absolute; left: 4px; bottom: 4px; background: var(--accent); color: #fff; font-size: 11px; padding: 0 6px; border-radius: 4px; }
.src-item button { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; padding: 0; line-height: 1; border-radius: 50%; background: #000a; color: #fff; border: 0; }

.results-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
#resultTabs { flex: none; }
#resultTabs button { flex: none; padding: 5px 18px; }
.check { display: flex; align-items: center; gap: 7px; cursor: pointer; }
#square { display: flex; flex-direction: column; gap: 12px; }
#square p { margin: 0; text-align: center; }
#sqMore { align-self: center; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--input); display: flex; flex-direction: column; }
.card .thumb { position: relative; aspect-ratio: 1; display: grid; place-items: center; background: repeating-conic-gradient(#8882 0% 25%, transparent 0% 50%) 50% / 16px 16px; }
.card img { max-width: 100%; max-height: 100%; cursor: zoom-in; display: block; }
.card.pending .thumb { background: none; color: var(--muted); text-align: center; }
.card.pending .thumb span { display: block; }
.card.failed .thumb { background: none; color: var(--danger); place-items: start; padding: 10px; overflow: auto; font-size: 12px; white-space: pre-wrap; word-break: break-word; }
.card .meta { padding: 8px 10px; font-size: 12px; display: flex; flex-direction: column; gap: 4px; }
.card .p { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.card .acts button { padding: 3px 9px; font-size: 12px; }
.badge { color: var(--danger); }
.spin { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; margin: 0 auto 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 18px; max-width: min(92vw, 460px); width: 100%; }
dialog::backdrop { background: #000a; }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog p { margin: 0; }
.dlg-actions, .dlg-head { display: flex; gap: 8px; align-items: center; }
#modelsDlg { max-width: min(96vw, 1000px); }
.table-wrap { overflow: auto; max-height: 70vh; margin-top: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { position: sticky; top: 0; background: var(--panel); }
td code { font-size: 12px; }

#lightbox { padding: 0; border: 0; background: transparent; width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh; cursor: zoom-out; }
#lightbox[open] { display: grid; place-items: center; }
#lightbox::backdrop { background: #000e; }
#lightbox img { max-width: 96vw; max-height: 96vh; }

.note { border: 1px solid var(--accent); border-radius: 8px; padding: 10px 12px; font-size: 13px; display: flex; flex-direction: column; gap: 8px; }
a.btn { display: inline-block; text-decoration: none; border-radius: 7px; padding: 6px 14px; }
a.btn.primary { background: var(--accent); color: #fff; font-weight: 600; }
a.btn.primary:hover { background: var(--accent-2); }

/* 卡片角标 */
.card .count, .card .mine { position: absolute; left: 6px; top: 6px; font-size: 11px; padding: 1px 8px; border-radius: 999px; background: #000b; color: #fff; pointer-events: none; }
.card .mine { left: auto; right: 6px; background: var(--accent); }
.sq-mark { position: absolute; top: 6px; right: 6px; padding: 2px 9px; font-size: 11px; border-radius: 999px; background: #000b; color: #fff; border: 1px solid #fff5; }
.sq-mark:hover { background: var(--accent); border-color: var(--accent); }
.sq-mark.done, .sq-mark.done:hover { background: #2e7d32e0; border-color: transparent; cursor: default; }
.sq-mark.up { cursor: progress; }
.sq-mark.err { background: #c62828e0; border-color: transparent; }
button.danger { color: var(--danger); }

/* 广场设置 / 分享 */
details summary { cursor: pointer; font-size: 12px; }
details[open] summary { margin-bottom: 10px; }
details .field + .field { margin-top: 10px; }
#sqMsg { font-size: 12px; white-space: pre-wrap; }
#sqMsg:empty { display: none; }
#refClear { font-size: 12px; padding: 6px 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.chips button { padding: 4px 10px; font-size: 12px; }
.chips button.on { border-color: var(--accent); color: var(--accent-2); }
.row .unit { align-self: center; white-space: nowrap; font-size: 12px; }
#shareHours { max-width: 120px; }

/* 详情 */
#detail { padding: 0; width: 100%; max-width: min(96vw, 1320px); height: min(92vh, 920px); max-height: 92vh; overflow: hidden; }
#detail[open] { display: flex; flex-direction: column; }
.dt-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.dt-head b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.dt-head button { width: 34px; height: 34px; padding: 0; font-size: 18px; line-height: 1; flex: none; }
.dt-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 430px; gap: 16px; padding: 16px; }
.dt-left { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.dt-stage { position: relative; flex: 1; min-height: 240px; border-radius: 10px; overflow: hidden; background: repeating-conic-gradient(#8882 0% 25%, transparent 0% 50%) 50% / 16px 16px; }
.dt-stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; cursor: zoom-in; }
.dt-tag { position: absolute; left: 10px; top: 10px; z-index: 1; background: #000b; color: #fff; font-size: 12px; padding: 2px 9px; border-radius: 6px; pointer-events: none; }
.dt-under { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.dt-under a, .ref-tile a { color: var(--accent-2); text-decoration: none; white-space: nowrap; }
#dtThumbs { display: flex; gap: 8px; overflow-x: auto; flex: none; padding-bottom: 2px; }
#dtThumbs:empty { display: none; }
#dtThumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; border: 2px solid transparent; cursor: pointer; flex: none; background: var(--input); }
#dtThumbs img.on { border-color: var(--accent); }
.dt-right { display: flex; flex-direction: column; gap: 12px; min-width: 0; min-height: 0; overflow: auto; }
.dt-sec { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: var(--input); display: flex; flex-direction: column; gap: 10px; }
.dt-sec h3 { margin: 0; font-size: 11px; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
#dtEdited { font-weight: 400; letter-spacing: 0; }
#dtPrompt { white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow: auto; font-size: 13px; }
#dtPrompt textarea { width: 100%; }
.dt-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.dt-acts:empty { display: none; }
.dt-acts button { padding: 6px 12px; font-size: 13px; }
#dtRefs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
#dtRefs:empty { display: none; }
#dtRefsNote:empty { display: none; }
.ref-tile { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.ref-tile img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; cursor: zoom-in; background: var(--panel); display: block; }
.ref-tile div { display: flex; justify-content: space-between; gap: 6px; }
#dtInfo { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; margin: 0; font-size: 12px; }
#dtInfo dt { color: var(--muted); white-space: nowrap; }
#dtInfo dd { margin: 0; word-break: break-all; }
#dtMsg { color: var(--danger); font-size: 12px; white-space: pre-wrap; }
#dtMsg.ok { color: var(--muted); }
@media (max-width: 860px) {
  #detail { max-width: 100vw; max-height: 100vh; height: 100vh; border-radius: 0; }
  .dt-body { grid-template-columns: 1fr; grid-auto-rows: max-content; overflow: auto; }
  .dt-stage { flex: none; height: 55vh; }
  .dt-right { overflow: visible; }
}
