:root {
  --bg: #1b1d22; --panel: #23262d; --panel2: #2b2f37; --line: #383d47; --text: #e6e8ec; --muted: #9aa1ad;
  --acc: #4f8cff; --acc2: #3a6fd6; --ok: #2fb67c; --warn: #e5a23b; --err: #e5534b; --r: 8px;
  font-family: 'Noto Sans Thai', 'Sarabun', system-ui, sans-serif; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--acc); text-decoration: none; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h2 { font-size: 20px; } h3 { font-size: 16px; }
button, .btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; font: inherit; display: inline-flex; gap: 6px; align-items: center; }
button:hover { border-color: #566070; } button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--acc); border-color: var(--acc); color: #fff; } button.primary:hover { background: var(--acc2); }
button.danger { color: var(--err); } button.ghost { background: none; border-color: transparent; }
input, select, textarea { background: #15171b; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; width: 100%; }
input[type=checkbox], input[type=color], input[type=range] { width: auto; padding: 0; }
input[type=color] { height: 28px; width: 40px; border: none; background: none; }
textarea { resize: vertical; min-height: 60px; }
label { display: block; color: var(--muted); font-size: 12px; margin: 8px 0 3px; }
label.inline { display: inline-flex; gap: 6px; align-items: center; color: var(--text); font-size: 13px; margin: 0; }
.muted { color: var(--muted); } .small { font-size: 12px; } .grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; } .row.end { justify-content: flex-end; margin-top: 14px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar .brand { font-weight: 700; color: var(--text); }
.topbar nav a { color: var(--muted); margin-right: 12px; } .topbar nav a.on { color: var(--text); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td input, td select { padding: 4px 6px; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); }
.tag.ok { color: var(--ok); border-color: var(--ok); } .tag.warn { color: var(--warn); border-color: var(--warn); } .tag.err { color: var(--err); border-color: var(--err); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); }
.tabs button.on { color: var(--text); border-color: var(--acc); }
.series-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.series-grid .card { cursor: pointer; } .series-grid .card:hover { border-color: var(--acc); }
.pages-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.thumb { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; cursor: pointer; position: relative; }
.thumb:hover { border-color: var(--acc); }
.thumb .img { height: 180px; background-size: cover; background-position: top center; background-color: #000; }
.thumb .cap { padding: 4px 6px; font-size: 11px; display: flex; justify-content: space-between; gap: 4px; }
.progress { height: 6px; background: var(--panel2); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: var(--acc); transition: width .3s; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 4px solid var(--acc); padding: 10px 14px; border-radius: 6px; max-width: 420px; box-shadow: 0 4px 20px #0008; }
.toast.error { border-left-color: var(--err); } .toast.ok { border-left-color: var(--ok); }
.modal-bg { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 900; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px; width: min(560px, 94vw); max-height: 90vh; overflow: auto; }
.login-box { max-width: 360px; margin: 12vh auto; }
.drop { border: 2px dashed var(--line); border-radius: var(--r); padding: 24px; text-align: center; color: var(--muted); cursor: pointer; }
.drop.over { border-color: var(--acc); color: var(--text); }
.jobbar { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
@media (max-width: 700px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------------- editor ---------------- */
body.editor { overflow: hidden; display: flex; flex-direction: column; }
.ed-top { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ed-main { flex: 1; display: flex; min-height: 0; }
.ed-tools { width: 46px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0; }
.ed-tools button { width: 36px; height: 36px; justify-content: center; padding: 0; font-size: 16px; }
.ed-tools button.on { background: var(--acc); border-color: var(--acc); }
.ed-stage { flex: 1; overflow: auto; background: #0f1012; position: relative; }
.ed-stage .canvas-wrap { margin: 20px auto; width: max-content; box-shadow: 0 0 0 1px #000, 0 8px 30px #000a; }
.ed-side { width: 320px; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.ed-side section { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.ed-side h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; display: flex; justify-content: space-between; align-items: center; }
.layers { max-height: 260px; overflow-y: auto; }
.layer { display: flex; gap: 6px; align-items: center; padding: 4px 6px; border-radius: 4px; cursor: pointer; font-size: 12px; }
.layer:hover { background: var(--panel2); } .layer.sel { background: #2c3d5c; }
.layer .name { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.layer button { padding: 0 4px; border: none; background: none; }
.bubbles { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.bubble-item { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px; font-size: 12px; }
.bubble-item.sel { border-color: var(--acc); }
.bubble-item .src { color: var(--muted); margin-bottom: 4px; }
.bubble-item textarea { min-height: 40px; font-size: 13px; }
.status-bar { padding: 3px 10px; background: var(--panel); border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); display: flex; gap: 16px; }
.menu { position: relative; }
.menu .items { display: none; position: absolute; top: 100%; left: 0; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; min-width: 220px; z-index: 50; padding: 4px; }
.menu.open .items { display: block; }
.menu .items button { width: 100%; border: none; background: none; justify-content: flex-start; }
.menu .items button:hover { background: var(--panel); }
.brush-cursor { position: fixed; pointer-events: none; border: 1px solid #fff; border-radius: 50%; mix-blend-mode: difference; z-index: 40; display: none; }
button.danger-fill { background: var(--err); border-color: var(--err); color: #fff; }
.thumb.dragging { opacity: .4; }
.thumb.drop-target { outline: 2px dashed var(--acc); outline-offset: 2px; }
.thumb .cap button { padding: 0 4px; }
/* usage report */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-top: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.tile-label { color: var(--muted); font-size: 12px; }
.tile-value { font-size: 26px; font-weight: 600; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: 11px; }
.utable td, .utable th { padding: 6px 8px; }
.utable .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.utable .cost { min-width: 64px; }
.utable .srow { cursor: pointer; background: var(--panel2); }
.utable .srow:hover { background: #333845; }
.utable .crow.top td { background: rgba(229, 162, 59, 0.08); }
.chev { display: inline-block; width: 12px; color: var(--muted); }
.ubar { flex: 1; height: 10px; background: transparent; min-width: 60px; }
.ubar-fill { height: 100%; background: var(--acc); border-radius: 0 4px 4px 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: none; border-radius: 0; background: none; color: var(--muted); }
.seg button.on { background: var(--acc); color: #fff; }
details > summary { cursor: pointer; }
