:root {
  --bg: #0c0d10; --panel: #16181d; --panel2: #1c1f26; --line: #2a2e37;
  --ink: #e7e3d8; --muted: #8b8f99; --accent: #e8c06a; --accent2: #6ab0ff;
  --good: #57c98a; --bad: #e8695b; --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); }
button { font-family: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink); padding: .5rem .85rem; font-size: .85rem; }
button:hover { border-color: #3a3f4a; }
button.primary { background: var(--accent); color: #1a1400; border-color: var(--accent); font-weight: 600; }
button.build { background: #23331f; color: var(--good); border-color: #2e4a2a; font-weight: 600; }
button.ghost { background: transparent; }
button.danger, button.ghost.danger { color: var(--bad); }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: .85rem; }

/* login */
body.login { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 2rem; width: 320px; display: flex; flex-direction: column; gap: .8rem; }
.login-card .brand { font-family: var(--mono); letter-spacing: .3em; font-size: 1.3rem; color: var(--accent); }
.login-card .sub { color: var(--muted); font-size: .8rem; margin-top: -.5rem; }
.login-card input, .title-input, .notes, .json, textarea, .script-in {
  background: #0f1115; border: 1px solid var(--line); color: var(--ink); border-radius: 8px;
  padding: .6rem .7rem; font-size: .9rem; font-family: inherit; width: 100%; }
.err { color: var(--bad); font-size: .8rem; min-height: 1rem; }

/* topbar */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .7rem 1.2rem;
  border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.topbar .brand { font-family: var(--mono); letter-spacing: .25em; color: var(--accent); font-weight: 600; }
.crumbs { color: var(--muted); font-size: .85rem; }

/* views */
.view { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1.2rem 4rem; }
.lib-head h1 { margin: .2rem 0; font-size: 1.4rem; }
.tmpl-group { margin-top: 2rem; }
.tmpl-group h2 { font-size: 1rem; display: flex; align-items: center; gap: .6rem; }
.tmpl-group h2 .tag { font-family: var(--mono); font-size: .7rem; color: var(--accent2);
  border: 1px solid var(--line); border-radius: 6px; padding: .1rem .4rem; }
.tmpl-desc { color: var(--muted); font-size: .82rem; margin: .2rem 0 .8rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .8rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem; cursor: pointer; transition: border-color .1s; position: relative; }
.card:hover { border-color: var(--accent); }
.card.new { display: grid; place-items: center; color: var(--muted); border-style: dashed; min-height: 92px; }
.card h3 { margin: 0 0 .3rem; font-size: .95rem; }
.card .meta { color: var(--muted); font-size: .74rem; }
.card .row { display: flex; align-items: center; gap: .5rem; margin-top: .5rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--good); } .dot.warn { background: var(--accent); } .dot.err { background: var(--bad); }

/* editor */
.editor-head { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.title-input { flex: 0 1 320px; font-size: 1rem; font-weight: 600; }
.pill { font-size: .72rem; padding: .15rem .5rem; border-radius: 20px; border: 1px solid var(--line); }
.pill.ok { color: var(--good); border-color: #2e4a2a; }
.pill.warn { color: var(--accent); border-color: #4a3f1f; }

.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tab { border: none; background: transparent; border-bottom: 2px solid transparent; border-radius: 0;
  color: var(--muted); padding: .5rem .8rem; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }

.field-label { display: block; font-size: .78rem; color: var(--muted); margin: 1rem 0 .3rem;
  font-family: var(--mono); text-transform: uppercase; letter-spacing: .05em; }
.notes { resize: vertical; }
.json { min-height: 460px; font-family: var(--mono); font-size: .82rem; line-height: 1.5; resize: vertical; white-space: pre; overflow-wrap: normal; overflow-x: auto; }
.errors { color: var(--bad); font-family: var(--mono); font-size: .78rem; margin-top: .6rem; white-space: pre-wrap; }

.scene-block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem; margin-bottom: .8rem; }
.scene-block .sh { display: flex; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.scene-block .sh .id { font-family: var(--mono); color: var(--accent); font-size: .82rem; }
.scene-block .sh .kind { font-size: .72rem; color: var(--muted); border: 1px solid var(--line);
  border-radius: 6px; padding: .1rem .4rem; }
.script-in { resize: vertical; }
.grp-title { font-size: .82rem; color: var(--accent2); font-family: var(--mono); margin: 1.4rem 0 .5rem; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: .5rem; margin-bottom: .5rem; align-items: start; }
.kv label { font-size: .8rem; color: var(--muted); padding-top: .5rem; font-family: var(--mono); }

/* build tab */
.build-status { font-family: var(--mono); font-size: .85rem; margin-bottom: .8rem; }
.log { background: #0a0b0e; border: 1px solid var(--line); border-radius: 8px; padding: .8rem;
  font-family: var(--mono); font-size: .78rem; line-height: 1.45; max-height: 420px; overflow: auto; white-space: pre-wrap; }
video { width: 100%; max-width: 360px; border-radius: 8px; border: 1px solid var(--line); margin-bottom: 1rem; display: block; }

.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: .6rem 1rem;
  font-size: .85rem; z-index: 20; }

/* current user + user management */
.whoami { font-family: var(--mono); font-size: .78rem; color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px; padding: .2rem .5rem; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 30; }
.modal[hidden] { display: none; }   /* author display:grid otherwise overrides the [hidden] attribute */
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.4rem; width: min(560px, 92vw); max-height: 86vh; overflow: auto; }
.modal-head { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; }
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.users-table { width: 100%; border-collapse: collapse; }
.users-table td { padding: .55rem .3rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.users-table .u-name { font-family: var(--mono); font-size: .88rem; }
.users-table .tag { font-family: var(--mono); font-size: .68rem; color: var(--accent2);
  border: 1px solid var(--line); border-radius: 6px; padding: .05rem .35rem; margin-left: .5rem; }
.users-table .meta { color: var(--muted); font-size: .74rem; margin-left: .4rem; }
.u-actions { text-align: right; white-space: nowrap; }
.u-actions button { padding: .3rem .55rem; font-size: .76rem; margin-left: .3rem; }
.new-user { margin-top: 1.2rem; }
.new-user-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.new-user-row .script-in { flex: 1 1 140px; width: auto; }
.chk { display: flex; align-items: center; gap: .3rem; font-size: .82rem; color: var(--muted); white-space: nowrap; }
.chk input { width: auto; }
