:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #16202b;
  --muted: #5c6b7c;
  --line: #dbe2ec;
  --accent: #d94f30;
  --accent-ink: #ffffff;
  --ok: #2b8a3e;
  --err: #c92a2a;
  --radius: 10px;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; gap: 22px;
  background: #16202b; color: #fff; padding: 12px clamp(16px, 4vw, 42px);
}
.topbar .logo { font-weight: 900; letter-spacing: 1px; font-size: 18px; color: #fff; }
.topbar .logo span { color: var(--accent); }
.topbar nav { display: flex; gap: 16px; flex-wrap: wrap; }
.topbar nav a { color: #cbd5e1; font-weight: 600; }
.topbar nav a.active, .topbar nav a:hover { color: #fff; text-decoration: none; }

main { padding: 24px clamp(16px, 4vw, 42px); max-width: 1500px; margin: 0 auto; }
h1 { font-size: 26px; margin: 4px 0 18px; }
h2 { font-size: 18px; margin: 26px 0 12px; }
p.lead { color: var(--muted); margin-top: -10px; }

.banner-warn {
  background: #fff3bf; border: 1px solid #f0c000; color: #5c4d00;
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 18px; font-size: 14px;
}

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: #eef2f7; font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
tr:last-child td { border-bottom: 0; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #e7ecf3; color: var(--muted); }
.badge.ok { background: #d3f9d8; color: var(--ok); }
.badge.err { background: #ffe3e3; color: var(--err); }
.badge.busy { background: #fff3bf; color: #8a6d00; }
.badge.tag { background: #edf2ff; color: #3b5bdb; margin: 1px 2px 1px 0; }

button, .btn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer;
  background: var(--ink); color: #fff; font-weight: 700; font-size: 14px;
  padding: 9px 16px; border-radius: 8px; text-decoration: none;
}
button:hover, .btn:hover { background: #2a3948; text-decoration: none; }
.btn.accent { background: var(--accent); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }

input[type=text], input[type=password], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; background: #fff; color: var(--ink);
}
textarea.code { font-family: Consolas, monospace; font-size: 13px; min-height: 260px; }
label { display: block; font-weight: 600; font-size: 13.5px; margin: 12px 0 4px; }
form.inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
form.inline > div { flex: 1 1 180px; }
code.key { font-family: Consolas, monospace; font-size: 13px; background: #eef2f7; padding: 3px 8px; border-radius: 6px; }

/* template gallery */
.gallery-tools { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.gallery-tools input { max-width: 320px; }
.gallery-tools select { max-width: 180px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(238px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.card .thumb-wrap { background: #eef2f7; border-radius: 6px; overflow: hidden; display: flex; justify-content: center; }
.card canvas { display: block; width: 100%; height: auto; opacity: 0; transition: opacity .25s; }
.card canvas.ready { opacity: 1; }
.card .card-title { font-weight: 700; font-size: 13.5px; margin: 8px 0 2px; }
.card .card-meta { font-size: 12px; color: var(--muted); }
.card label.pick { display: flex; align-items: center; gap: 7px; margin: 8px 0 0; font-size: 13px; cursor: pointer; }
.card input[type=checkbox] { width: auto; }

/* focal-point picker on library images */
.focus-pick { position: relative; cursor: crosshair; background: #dfe5ec; }
.focus-pick .focus-dot {
  position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(217,79,48,.85); box-shadow: 0 0 0 2px rgba(0,0,0,.4);
  pointer-events: none;
}
.focus-pick[data-inactive] .focus-dot { background: rgba(120,130,140,.7); }
.focus-hint { font-size: 11px; margin: 2px 0 4px; color: var(--muted); }
.focus-hint.ok { color: var(--ok); font-weight: 600; }
.focus-hint.err { color: var(--err); font-weight: 600; }

/* worker */
#worker-log { background: #0d1520; color: #d7e1ec; border-radius: var(--radius); padding: 14px; min-height: 380px; max-height: 70vh; overflow-y: auto; font-family: Consolas, monospace; font-size: 13px; }
.log-row { padding: 3px 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.log-row.ok { color: #8ce99a; }
.log-row.err { color: #ffa8a8; }
.log-time { color: #5c6b7c; }
.log-thumb { border-radius: 4px; border: 1px solid #2a3948; }
#worker-toggle.running { background: var(--err); }
#worker-status { color: var(--muted); font-weight: 600; }

/* jobs */
.job-outputs { display: flex; gap: 10px; flex-wrap: wrap; }
.job-thumb { position: relative; display: inline-block; line-height: 0; cursor: zoom-in; }
.job-thumb img { height: 96px; border-radius: 5px; border: 1px solid var(--line); background: #eef2f7; transition: transform .12s, box-shadow .12s; }
.job-thumb:hover img { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(22,32,43,.22); }
.job-thumb .thumb-cap {
  position: absolute; left: 4px; bottom: 4px; padding: 1px 6px; border-radius: 4px;
  background: rgba(13,21,32,.72); color: #fff; font-size: 10.5px; font-weight: 700;
  letter-spacing: .3px; text-transform: uppercase; line-height: 1.5;
}

/* lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center;
  background: rgba(9,14,20,.9); padding: 40px 72px;
}
.lightbox[hidden] { display: none; }
.lb-figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 14px; max-height: 100%; }
.lb-image {
  max-width: min(88vw, 900px); max-height: 78vh; border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5); background: #fff;
}
.lb-caption { text-align: center; color: #fff; max-width: 90vw; }
.lb-template { display: block; font-size: 18px; font-weight: 800; letter-spacing: .3px; }
.lb-meta { display: block; margin-top: 6px; font-size: 13px; color: #a9b6c4; }
.lb-nav, .lb-close {
  position: absolute; background: rgba(255,255,255,.1); color: #fff; border: 0; cursor: pointer;
  border-radius: 50%; display: flex; align-items: center; justify-content: center; padding: 0;
}
.lb-nav { top: 50%; transform: translateY(-50%); width: 52px; height: 52px; font-size: 30px; }
.lb-nav:hover, .lb-close:hover { background: rgba(255,255,255,.24); }
.lb-prev { left: 18px; }
.lb-next { right: 18px; }
.lb-close { top: 18px; right: 18px; width: 44px; height: 44px; font-size: 26px; }
.lb-counter { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); color: #a9b6c4; font-size: 13px; font-weight: 600; }
@media (max-width: 720px) {
  .lightbox { padding: 16px; }
  .lb-nav { width: 42px; height: 42px; font-size: 24px; }
  .lb-prev { left: 6px; } .lb-next { right: 6px; }
}

/* playground */
#playground { display: grid; grid-template-columns: minmax(320px, 480px) 1fr; gap: 18px; align-items: start; }
@media (max-width: 980px) { #playground { grid-template-columns: 1fr; } }
#pg-canvas { max-width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #eef2f7; }
#pg-error { color: var(--err); font-size: 13.5px; min-height: 20px; }

.footer-note { color: var(--muted); font-size: 13px; margin-top: 26px; }
