:root {
  --bg: #0d0f0e;
  --surface: #151917;
  --surface-2: #1c211f;
  --line: #2a312e;
  --text: #e8ece9;
  --muted: #94a19b;
  --accent: #22c55e;
  --accent-ink: #04210f;
  --accent-soft: rgba(34, 197, 94, 0.12);
  --warn: #f5b041;
  --danger: #f87171;
  --radius: 12px;
  --focus: 0 0 0 3px rgba(34, 197, 94, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.2; margin: 0 0 12px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 4px; }
h3 { font-size: 1rem; margin: 0; }
p { margin: 0 0 10px; }
kbd { font: 11px ui-monospace, monospace; padding: 1px 5px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--focus); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.lead { font-size: 1.05rem; color: #c9d2cd; max-width: 62ch; }
.warn { color: var(--warn); }

/* Layout */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
  background: rgba(13, 15, 14, 0.92); backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 16px; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background:
  conic-gradient(var(--accent) 0 25%, #0b3d1f 0 50%, var(--accent) 0 75%, #0b3d1f 0) 0 0 / 11px 11px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 32px 24px 48px; }
.view.narrow { max-width: 680px; margin: 0 auto; }
.footer { border-top: 1px solid var(--line); padding: 20px 24px; color: var(--muted); font-size: 13px; text-align: center; }
.footer p { margin: 4px auto; max-width: 80ch; }
.row { display: flex; gap: 8px; align-items: stretch; }
.row > input { flex: 1; min-width: 0; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.actions.split { justify-content: space-between; }
.spacer { flex: 1; }

/* Controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: #3b4541; background: #222825; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #2fd56b; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #2b0606; }
.btn.small { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.danger-text { color: var(--danger) !important; }
input[type=password], input[type=text], input:not([type]), input[readonly] {
  min-height: 42px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; width: 100%;
}
input[type=range] { accent-color: var(--accent); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; }
label { font-weight: 600; font-size: 14px; }
.form-error { color: var(--danger); margin-top: 8px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 8px; }

.balance {
  font-size: 13px; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--text); text-decoration: none; white-space: nowrap;
}
.balance.low { border-color: var(--warn); color: var(--warn); }
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.4);
}
.menu-panel button { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; border-radius: 6px; background: none; color: var(--text); font: inherit; cursor: pointer; }
.menu-panel button:hover { background: var(--surface-2); }

/* Connect steps */
.steps { list-style: none; counter-reset: s; padding: 0; margin: 28px 0 16px; display: grid; gap: 12px; }
.steps > li { counter-increment: s; position: relative; padding: 16px 16px 14px 60px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.steps > li::before {
  content: counter(s); position: absolute; left: 16px; top: 15px; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 14px;
}
.steps p { margin: 0; color: #c9d2cd; }
.key-form { margin-top: 10px; }
.key-form label { display: block; margin-bottom: 6px; }

/* Setup + top-up */
.spinner { width: 40px; height: 40px; margin: 24px auto 20px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.center-actions { justify-content: center; }
.topup { padding: 20px; margin-bottom: 18px; border: 1px solid rgba(245, 176, 65, .45); border-radius: 16px; background: rgba(245, 176, 65, .07); }
.topup h2 { font-size: 1.15rem; margin-bottom: 6px; }
.topup .actions { justify-content: flex-start; margin: 12px 0; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin-right: 6px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Drop zone */
.drop {
  display: grid; place-items: center; text-align: center; gap: 4px; padding: 36px 20px;
  border: 2px dashed #34403b; border-radius: 16px; background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: #17201b; }
.drop-title { font-size: 1.15rem; font-weight: 700; margin: 0; }
.drop p { margin: 0; }
.list-head { display: flex; justify-content: space-between; align-items: center; margin: 28px 0 12px; }
.jobs { display: grid; gap: 14px; }

/* Job card */
.job { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.job-head { display: grid; grid-template-columns: 72px 1fr auto auto; gap: 14px; align-items: center; padding: 14px 14px 14px 16px; }
.thumb { width: 72px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.thumb.placeholder { background: repeating-conic-gradient(#222926 0 25%, #1a201d 0 50%) 0 0 / 12px 12px; }
.job-title { min-width: 0; }
.job-title .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-title .meta { margin: 0; font-size: 13px; }
.badge { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.busy { background: rgba(96, 165, 250, .12); color: #93c5fd; }
.badge.bad { background: rgba(248, 113, 113, .12); color: var(--danger); }
.job-body { padding: 0 16px 16px; display: grid; gap: 14px; }

.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .4s ease; }
.progress.indeterminate > i { width: 30%; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }
.progress-line { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.notice { font-size: 14px; color: var(--warn); margin: 0; }

.callout { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font-size: 14px; }
.callout.error { border-color: rgba(248, 113, 113, .4); background: rgba(248, 113, 113, .07); }
.callout.info { border-color: rgba(34, 197, 94, .35); background: var(--accent-soft); }
.callout p:last-child { margin-bottom: 0; }
.callout .actions { margin-top: 10px; justify-content: flex-start; }

/* Settings */
.settings { display: grid; gap: 16px; padding-top: 4px; }
.q > .q-title { font-weight: 700; font-size: 14px; margin: 0 0 8px; }
.targets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.choice { position: relative; display: block; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); cursor: pointer; font-weight: 400; }
.choice:hover { border-color: #3b4541; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice:has(input:checked) { border-color: var(--accent); background: #112016; }
.choice:has(input:focus-visible) { box-shadow: var(--focus); }
.choice b { display: block; font-size: 14px; }
.choice span { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); flex-wrap: wrap; }
.seg button, .seg label { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: 14px; padding: 7px 14px; border-radius: 8px; cursor: pointer; }
.seg label input { position: absolute; opacity: 0; pointer-events: none; }
.seg [aria-checked=true], .seg label:has(input:checked) { background: var(--surface-2); color: var(--text); }
.seg label:has(input:focus-visible) { box-shadow: var(--focus); }
details.more > summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 600; width: fit-content; }
details.more > summary:hover { color: var(--text); }
details.more[open] > summary { margin-bottom: 10px; }
.checks { display: grid; gap: 8px; }
.checks label { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; font-size: 14px; }
.checks label input { margin-top: 3px; }
.checks small { color: var(--muted); }
.slider { display: grid; grid-template-columns: 170px 1fr 44px; gap: 10px; align-items: center; font-size: 14px; }
.slider label { font-weight: 400; }
.slider output { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.mask-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.mask-thumb { width: 64px; height: 40px; object-fit: cover; border-radius: 6px; background: #000; border: 1px solid var(--line); }
.estimate { font-size: 14px; color: #c9d2cd; display: grid; gap: 2px; }
.estimate b { color: var(--text); }
.run-buttons { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Results */
.result { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.result video { width: 100%; border-radius: 10px; background: #000; display: block; }
.downloads { display: grid; gap: 8px; }
.file { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.file div { min-width: 0; }
.file b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file span { font-size: 12px; color: var(--muted); }

/* Dialogs */
dialog {
  width: min(560px, calc(100vw - 32px)); padding: 24px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); box-shadow: 0 24px 64px rgba(0,0,0,.6);
}
dialog::backdrop { background: rgba(0, 0, 0, .65); }
dialog ul { padding-left: 20px; color: #c9d2cd; }
dialog form label { display: block; margin-bottom: 6px; }
dialog.paint { width: min(1200px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 16px; display: none; }
dialog.paint[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px; }
.paint-head p { margin: 0; font-size: 14px; }
.paint-stage { display: grid; place-items: center; min-height: 0; overflow: hidden; background: #000; border-radius: 10px; }
.paint-stage canvas { max-width: 100%; max-height: calc(100vh - 230px); touch-action: none; cursor: crosshair; display: block; }
.paint-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.paint-tools .size { display: flex; gap: 8px; align-items: center; font-weight: 600; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  padding: 12px 18px; border-radius: 10px; background: #26302b; border: 1px solid var(--line); box-shadow: 0 12px 32px rgba(0,0,0,.45);
  max-width: calc(100vw - 32px);
}

@media (max-width: 720px) {
  main { padding: 20px 16px 40px; }
  .topbar { padding: 12px 16px; }
  .brand span:last-child { display: none; }
  #btn-link { padding: 8px 10px; }
  .job-head { grid-template-columns: 56px 1fr auto; }
  .job-head .badge { grid-column: 2; grid-row: 2; justify-self: start; }
  .job-head .remove { grid-column: 3; grid-row: 1; }
  .thumb { width: 56px; height: 36px; }
  .result { grid-template-columns: 1fr; }
  .targets { grid-template-columns: 1fr; }
  .slider { grid-template-columns: 1fr 44px; }
  .slider label { grid-column: 1 / -1; }
  .row { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
