:root {
  --bg: #0b0d12;
  --bg-2: #11141b;
  --card: #141821;
  --line: #232a37;
  --fg: #e9ecf3;
  --muted: #8f98aa;
  --accent: #8b7cff;
  --accent-2: #22d3ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6fa; --bg-2: #eceef4; --card: #ffffff; --line: #dfe3ec;
    --fg: #141821; --muted: #5d667a; --accent: #6a5af9; --accent-2: #0891b2;
    --ok: #059669; --warn: #b45309; --err: #dc2626; --shadow: 0 10px 30px rgba(20, 24, 33, .08);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent-2); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.brand-mark { width: 14px; height: 26px; border-radius: 4px; background: linear-gradient(160deg, var(--accent), var(--accent-2)); }
.top-link { color: var(--muted); text-decoration: none; font-size: .925rem; }
.top-link:hover { color: var(--fg); }

.wrap { max-width: 960px; margin: 0 auto; padding: 8px 16px 48px; }
.hero { padding: 28px 0 8px; }
.hero h1 { font-size: clamp(1.7rem, 4.6vw, 2.6rem); line-height: 1.15; margin: 0 0 10px; letter-spacing: -.02em; }
.hero p { margin: 0; color: var(--muted); max-width: 640px; }
.grad { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-top: 18px; box-shadow: var(--shadow);
}
.card h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-size: 1.15rem; }
.step {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  font-size: .85rem; font-weight: 700; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.conn-row {
  display: flex; align-items: center; gap: 14px; padding: 12px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg-2); margin-bottom: 10px; flex-wrap: wrap;
}
.conn-row.done { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.conn-icon {
  flex: none; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  font-weight: 800; color: #fff; background: linear-gradient(135deg, #4285f4, #34a853);
}
.conn-icon.polli { background: linear-gradient(135deg, #f472b6, #8b5cf6); }
.conn-info { flex: 1 1 220px; min-width: 0; }
.conn-title { font-weight: 650; }
.conn-sub { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.conn-sub .ok { color: var(--ok); font-weight: 700; }
.conn-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.manual { margin-top: 4px; }
.manual summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.manual-body { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.manual-body input { flex: 1 1 240px; }

.field { margin-bottom: 16px; min-width: 0; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.field-tools { display: flex; gap: 14px; }
.label { display: block; font-weight: 600; margin-bottom: 8px; }
.field-head .label { margin: 0; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 16px; }
@media (max-width: 640px) { .row { grid-template-columns: 1fr; } }

input, textarea, select {
  width: 100%; font: inherit; color: var(--fg); background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; outline: none;
}
textarea { resize: vertical; min-height: 76px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.chip {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px; cursor: pointer;
  font: inherit; font-size: .95rem; text-align: left; color: var(--fg); background: var(--bg-2); border: 1px solid var(--line);
  transition: border-color .15s, background .15s, transform .05s;
}
.chip:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.chip:active { transform: scale(.98); }
.chip[aria-pressed="true"] {
  border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--bg-2));
}
.chip[aria-pressed="true"]::after { content: "✓"; margin-left: auto; color: var(--accent); font-weight: 800; }
.chip-emoji { font-size: 1.15rem; }

.count { display: flex; gap: 8px; }
.count input { width: 110px; flex: none; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick button, .link {
  font: inherit; cursor: pointer; border-radius: 10px;
}
.quick button { padding: 0 14px; color: var(--fg); background: var(--bg-2); border: 1px solid var(--line); }
.quick button:hover { border-color: var(--accent); }
.link { padding: 0; border: 0; background: none; color: var(--accent-2); font-size: .9rem; }

.order-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 6px; }
.estimate { color: var(--muted); font-size: .95rem; }
.hint { color: var(--muted); font-size: .875rem; margin: 10px 0 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; border-radius: 10px;
  color: var(--fg); background: color-mix(in srgb, var(--fg) 8%, var(--bg-2)); border: 1px solid var(--line);
  transition: filter .15s, background .15s, opacity .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled, .chip:disabled, .quick button:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; }
.btn.primary { color: #fff; border: 0; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.btn.big { min-height: 50px; padding: 0 26px; font-size: 1.05rem; border-radius: 12px; }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 50%, var(--line)); background: transparent; }
.icon-btn { font: inherit; width: 36px; height: 36px; border-radius: 10px; cursor: pointer; color: var(--fg); background: var(--bg-2); border: 1px solid var(--line); }

.phase { margin: 0 0 10px; font-weight: 600; }
.progress { height: 10px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); overflow: hidden; }
.bar { height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s ease; }
.stats { color: var(--muted); font-size: .9rem; margin: 8px 0 12px; font-variant-numeric: tabular-nums; }
.run-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.tile {
  position: relative; aspect-ratio: 1870 / 4063; padding: 0; border-radius: 10px; overflow: hidden; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--line); font: inherit; color: var(--fg);
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .3s; }
.tile img[src] { opacity: 1; }
.tile-n {
  position: absolute; top: 6px; left: 6px; font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 6px;
  background: rgba(0, 0, 0, .55); color: #fff;
}
.tile-status {
  position: absolute; inset: auto 0 0 0; padding: 4px 6px; font-size: .7rem; text-align: center; color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, .7));
}
.tile-status:empty { display: none; }
.tile[data-state="gen"], .tile[data-state="proc"], .tile[data-state="up"] {
  border-color: color-mix(in srgb, var(--accent) 60%, var(--line));
  background: linear-gradient(110deg, var(--bg-2) 30%, color-mix(in srgb, var(--accent) 18%, var(--bg-2)) 50%, var(--bg-2) 70%);
  background-size: 250% 100%; animation: shimmer 1.4s linear infinite;
}
.tile[data-state="done"] { border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.tile[data-state="fail"] { border-color: var(--err); }
.tile[data-state="fail"] .tile-status { background: color-mix(in srgb, var(--err) 85%, black); }
.tile[data-state="stopped"] { opacity: .55; }
@keyframes shimmer { to { background-position: -150% 0; } }
@media (prefers-reduced-motion: reduce) { .tile { animation: none !important; } .bar { transition: none; } }

.log { margin-top: 16px; }
.log summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.log ol { margin: 8px 0 0; padding-left: 20px; max-height: 260px; overflow: auto; font-size: .85rem; color: var(--muted); }
.log li.warn { color: var(--warn); }
.log li.error { color: var(--err); }
.log time { font-variant-numeric: tabular-nums; opacity: .7; }

.how-list { margin: 0 0 12px; padding-left: 20px; }
.how-list li { margin-bottom: 8px; }

.foot { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; padding: 24px 16px 40px; color: var(--muted); font-size: .875rem; }
.foot a { color: var(--muted); }

dialog#lightbox {
  width: min(920px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card); color: var(--fg); box-shadow: var(--shadow);
}
dialog#lightbox::backdrop { background: rgba(0, 0, 0, .65); }
.lb { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: 18px; padding: 18px; }
.lb-media { background: var(--bg-2); border-radius: 12px; overflow: hidden; aspect-ratio: 1870 / 4063; }
.lb-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lb-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.lb-head h3 { margin: 0; font-size: 1.1rem; }
.lb-label { margin: 14px 0 4px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.lb-prompt { margin: 0 0 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.lb-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
@media (max-width: 640px) {
  .lb { grid-template-columns: 1fr; }
  .lb-media { max-width: 220px; margin: 0 auto; }
}

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 140%); max-width: min(560px, calc(100vw - 32px));
  padding: 12px 16px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
  transition: transform .25s ease, opacity .25s ease, visibility .25s; z-index: 50; opacity: 0; visibility: hidden;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
.toast[data-kind="error"] { border-color: var(--err); }
