/* 3D studio — light/dark theme via CSS variables */
:root {
  color-scheme: dark;
  --bg: #15161a;
  --surface: #1e2026;
  --surface-2: #272a31;
  --border: #33363f;
  --text: #e9eaee;
  --muted: #9a9ead;
  --accent: #6d8bff;
  --accent-text: #ffffff;
  --danger: #ef5b5b;
  --star: #f5b83d;
  --viewer-bg: #2a2c31;
  --grid-major: #6a6e78;
  --grid-minor: #464a53;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .25);
  --radius: 12px;
  --trellis: #4fb3a5;
  --hunyuan: #c88cff;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f5f7; --surface: #ffffff; --surface-2: #eef0f3; --border: #dde0e6;
    --text: #1b1d22; --muted: #646a78; --viewer-bg: #e4e6ea; --grid-major: #a3a8b3; --grid-minor: #ccd0d7;
    --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .06);
    --trellis: #19806f; --hunyuan: #8a3fd1;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #eef0f3; --border: #dde0e6;
  --text: #1b1d22; --muted: #646a78; --viewer-bg: #e4e6ea; --grid-major: #a3a8b3; --grid-minor: #ccd0d7;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .06);
  --trellis: #19806f; --hunyuan: #8a3fd1;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0; line-height: 1.25; }
svg { width: 1em; height: 1em; fill: currentColor; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 650; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand svg { width: 22px; height: 22px; color: var(--accent); }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; }
.topnav a.active, .topnav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--text); border-radius: 8px; width: 36px; height: 36px; cursor: pointer; display: grid; place-items: center; }
.icon-btn svg { width: 18px; height: 18px; }

main { padding: 16px max(16px, env(safe-area-inset-left)) 40px; max-width: 1600px; margin: 0 auto; }

/* controls */
input, select, button { font: inherit; color: inherit; }
input[type="search"], input:not([type]), select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 38px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.disabled { opacity: .45; pointer-events: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); cursor: pointer; user-select: none; min-height: 38px; }
.chip input { margin: 0; accent-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 12px; cursor: pointer; color: var(--muted); min-height: 36px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--accent); color: var(--accent-text); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.toolbar input[type="search"] { flex: 1 1 240px; }
.star { color: var(--muted); }
.star.on { color: var(--star); }
.chip .star { color: var(--star); }

/* gallery */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; grid-column: 1 / -1; }
.card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); transition: transform .12s ease, border-color .12s ease; }
.card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.thumb { aspect-ratio: 1; background: var(--viewer-bg); display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-pending { color: var(--muted); font-size: .9rem; }
.card-body { padding: 10px 12px 12px; }
.card-title { color: var(--text); font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 6px; color: var(--muted); font-size: .85rem; }
.card-params { color: var(--muted); font-size: .82rem; margin-top: 6px; font-variant-numeric: tabular-nums; }
.card-date { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.badge.gen-trellis2 { color: var(--trellis); border-color: color-mix(in srgb, var(--trellis) 45%, transparent); }
.badge.gen-hunyuan3d-2\.1 { color: var(--hunyuan); border-color: color-mix(in srgb, var(--hunyuan) 45%, transparent); }
.badge.game { color: var(--accent); }
.fav-btn { position: absolute; top: 8px; right: 8px; width: 36px; height: 36px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer; background: color-mix(in srgb, var(--surface) 80%, transparent); backdrop-filter: blur(6px); }
.fav-btn svg { width: 20px; height: 20px; }
.fav-btn.inline { position: static; flex: none; background: var(--surface-2); }
.cmp-check { position: absolute; top: 8px; left: 8px; display: flex; align-items: center; gap: 4px; padding: 6px 9px; border-radius: 999px; cursor: pointer; background: color-mix(in srgb, var(--surface) 80%, transparent); backdrop-filter: blur(6px); font-size: .85rem; }
.cmp-check input { margin: 0; accent-color: var(--accent); }
.compare-bar { display: none; position: sticky; top: 58px; z-index: 5; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; margin-bottom: 14px; background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); }
.compare-bar.show { display: flex; }
.compare-bar span { flex: 1; }

/* model page */
.model-page { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
.viewer-head { display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 10px; flex-wrap: wrap; }
.back { font-weight: 500; }
.viewer { position: relative; height: min(72vh, 760px); min-height: 320px; border-radius: var(--radius); overflow: hidden; background: var(--viewer-bg); border: 1px solid var(--border); touch-action: none; }
.viewer canvas { display: block; width: 100% !important; height: 100% !important; }
.viewer-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.viewer.loading::after { content: "Загрузка…"; position: absolute; top: 10px; left: 12px; color: var(--muted); font-size: .85rem; }
.view-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.hint { color: var(--muted); font-size: .82rem; margin-top: 8px; }
.side-col { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 74px; max-height: calc(100vh - 90px); overflow: auto; padding-right: 2px; }
.title-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.title-row h1 { cursor: text; word-break: break-word; }
.rename { font-size: 1.2rem; font-weight: 600; flex: 1; }
.gen-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--muted); font-size: .88rem; margin-top: -6px; }
.images { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.images figure { margin: 0; background: var(--viewer-bg); border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.images img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; }
.images figcaption { font-size: .78rem; color: var(--muted); padding: 5px 8px; }
.images .checker img { background: repeating-conic-gradient(#8884 0 25%, #0000 0 50%) 50% / 16px 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.compare-pick { display: grid; gap: 6px; min-width: 0; }
.compare-pick select { width: 100%; min-width: 0; }
.side-col > * { min-width: 0; }
.compare-pick label, .tags label { color: var(--muted); font-size: .85rem; }
table.meta { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.meta th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 10px 6px 0; width: 45%; vertical-align: top; }
table.meta td { padding: 6px 0; font-variant-numeric: tabular-nums; word-break: break-word; }
table.meta tr + tr { border-top: 1px solid var(--border); }
table.meta.small { font-size: .82rem; margin-top: 6px; }
details summary { cursor: pointer; color: var(--muted); }
.tags { display: grid; gap: 6px; }
.tag-row { display: flex; gap: 8px; }
.tag-row input { flex: 1; min-width: 0; }
.files { list-style: none; padding: 0; margin: 8px 0 0; font-size: .88rem; }
.files li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; }
.files span { color: var(--muted); }

/* compare page */
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.compare-cell header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.compare-cell .viewer { height: min(64vh, 680px); }
.compare-stats { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: .88rem; margin-top: 8px; font-variant-numeric: tabular-nums; }
.compare-stats a { margin-left: auto; }

/* login / settings */
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.login { max-width: 360px; margin: 12vh auto 0; text-align: center; display: grid; gap: 12px; }
.login form { display: grid; gap: 10px; }
.login input { min-height: 44px; font-size: 1rem; }
.login .btn { min-height: 44px; }
.login-error { color: var(--danger); min-height: 1.4em; }
.settings { max-width: 720px; display: grid; gap: 14px; }
.settings h2 { font-size: 1.05rem; margin: 0 0 10px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.panel p { margin: 8px 0 0; }
.url-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.url-row code { background: var(--surface-2); padding: 8px 10px; border-radius: 8px; word-break: break-all; flex: 1; min-width: 0; }
.pass-form { display: grid; gap: 10px; max-width: 420px; }
.ok { color: #3fb37f; }
.warn { color: var(--star); }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
h1.editable { cursor: text; }
.title-row h1 { cursor: default; }
.title-row h1.editable { cursor: text; }

/* studio: create */
.q-count { display: none; min-width: 18px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: .75rem; margin-left: 4px; }
.q-count.on { display: inline-block; }
.create-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.queue-hint { color: var(--muted); font-size: .88rem; }
.queue-hint.busy { color: var(--text); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.create-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.create-grid .panel { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; }
.field > label { color: var(--muted); font-size: .85rem; }
.field .seg { flex-wrap: wrap; }
textarea { font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; resize: vertical; width: 100%; }
.btn.big { min-height: 46px; font-size: 1rem; }
.btn:disabled { opacity: .5; cursor: default; }
.dropzone { display: grid; place-items: center; text-align: center; min-height: 260px; border: 2px dashed var(--border); border-radius: var(--radius); background: var(--surface-2); color: var(--muted); cursor: pointer; padding: 12px; overflow: hidden; }
.dropzone.small { min-height: 90px; }
.dropzone.over { border-color: var(--accent); }
.dropzone.loading { opacity: .6; }
.dropzone.has { padding: 0; background: var(--viewer-bg); }
.dropzone img { max-width: 100%; max-height: 360px; display: block; object-fit: contain; }
.nobg-box figure { margin: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.nobg-box img { width: 100%; max-height: 300px; object-fit: contain; display: block; background: repeating-conic-gradient(#8884 0 25%, #0000 0 50%) 50% / 16px 16px; }
.nobg-box figcaption { font-size: .78rem; color: var(--muted); padding: 5px 8px; }
.seed-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seed-row input[type="number"] { width: 160px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 38px; }
input[type="number"], input[type="password"] { font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 38px; }
.concepts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.concept { padding: 0; border: 2px solid transparent; border-radius: 10px; overflow: hidden; cursor: pointer; background: var(--viewer-bg); }
.concept:hover { border-color: var(--accent); }
.concept img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.concept-actions { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.bthumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.bthumb { position: relative; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; background: var(--viewer-bg); }
.bthumb img { width: 100%; height: 100%; object-fit: cover; }
.bthumb button { position: absolute; top: 2px; right: 2px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }

/* studio: queue + monitor */
.queue-page { display: grid; gap: 16px; }
.monitor { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.mon-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: grid; gap: 8px; align-content: start; }
.mon-title { color: var(--muted); font-size: .85rem; }
.mon-big { font-size: 1.4rem; font-weight: 650; }
.mon-big .muted { font-size: .85rem; font-weight: 400; }
.mon-row { display: flex; justify-content: space-between; color: var(--muted); font-size: .88rem; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s ease; }
.bar-fill.hot { background: var(--danger); }
.bar-label { color: var(--muted); font-size: .82rem; }
.jobs { display: grid; gap: 8px; }
.job { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.job.st-running { border-left-color: var(--accent); }
.job.st-done { border-left-color: #3fb37f; }
.job.st-error { border-left-color: var(--danger); }
.job.st-queued { border-left-color: var(--star); }
.job-main { flex: 1 1 360px; min-width: 0; display: grid; gap: 4px; }
.job-title { font-weight: 600; word-break: break-word; }
.job-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; color: var(--muted); font-size: .85rem; }
.job-meta .stage { color: var(--text); }
.job-error { color: var(--danger); font-size: .88rem; word-break: break-word; }
.job pre { white-space: pre-wrap; word-break: break-word; font-size: .75rem; background: var(--surface-2); padding: 8px; border-radius: 8px; max-height: 280px; overflow: auto; }
.job-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.game-panel { display: grid; gap: 10px; }
.game-panel[open] > summary { margin-bottom: 10px; }
.game-panel summary { cursor: pointer; }
.game-panel .field { margin-bottom: 10px; }

@media (max-width: 900px) {
  .create-grid { grid-template-columns: 1fr; }
  .dropzone { min-height: 200px; }
  .topnav { overflow-x: auto; }
  .topnav a { white-space: nowrap; padding: 6px 8px; }
  .brand span { display: none; }
}

/* toast */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); transition: all .2s ease; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

/* mobile */
@media (max-width: 900px) {
  .model-page { grid-template-columns: 1fr; }
  .side-col { position: static; max-height: none; }
  .viewer { height: 58vh; }
  .compare-grid { grid-template-columns: 1fr; }
  .compare-cell .viewer { height: 44vh; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 10px; }
  .card-body { padding: 8px 10px 10px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
