:root {
  --bg: #0b0f14; --card: #151b23; --card2: #1c2430; --line: #263040;
  --text: #e6edf3; --dim: #8b98a9; --green: #3fb950; --red: #f85149;
  --amber: #e3b341; --blue: #58a6ff; --violet: #a371f7;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 15px; margin: 0 0 12px; letter-spacing: .2px; }
.muted { color: var(--dim); }
.small { font-size: 13px; }
.err { color: var(--red); min-height: 1.4em; }

button { font: inherit; background: var(--blue); color: #04111f; border: 0; border-radius: 10px;
  padding: 8px 14px; font-weight: 600; cursor: pointer; }
button:hover { filter: brightness(1.1); }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 50%, transparent); }
button:disabled { opacity: .5; cursor: default; }
input, select { font: inherit; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; min-width: 0; }
input[type=color] { padding: 2px; height: 34px; width: 100%; }
input[type=range] { width: 100%; padding: 0; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); display: inline-block; }

.top { position: sticky; top: 0; z-index: 2; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; flex-wrap: wrap; }
nav { display: flex; gap: 4px; overflow-x: auto; }
nav button { background: transparent; color: var(--dim); padding: 6px 12px; }
nav button[aria-selected=true] { background: var(--card2); color: var(--text); }

main { max-width: 1040px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 { margin-bottom: 16px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.row-between h2 { margin: 0; }
.grow { flex: 1 1 200px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-word; }

.shot-wrap { width: 252px; height: 252px; border-radius: 28px; overflow: hidden; border: 6px solid #263040; background: #000; margin-bottom: 8px; }
.shot-wrap img { display: block; }
#bat-chart { width: 100%; height: auto; display: block; }

/* faces */
.slots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.slot { background: var(--card2); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.slot img, .lib-item img, .thumb-blank { width: 120px; height: 120px; border-radius: 16px; background: #000; object-fit: cover; }
.thumb-blank { display: grid; place-items: center; color: var(--dim); font-size: 12px; }
.slot select { width: 100%; }
.lib { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.lib-item { background: var(--card2); border: 1px solid transparent; border-radius: 12px; padding: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; color: var(--text); font-weight: 500; }
.lib-item:hover { border-color: var(--blue); }
.editor { display: grid; grid-template-columns: 300px 1fr; gap: 20px; }
.preview canvas { width: 300px; height: 300px; border-radius: 34px; border: 8px solid #263040; image-rendering: pixelated; background: #000; }
.controls { display: flex; flex-direction: column; gap: 12px; }
.controls label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--dim); }
.controls label.check, label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; margin: 0; }
legend { padding: 0 6px; color: var(--text); font-weight: 600; font-size: 13px; }
.item { background: var(--card2); border-radius: 10px; padding: 8px; display: grid;
  grid-template-columns: 1fr 1fr 1fr; gap: 6px; align-items: end; margin-bottom: 6px; }
.item .item-head { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: var(--text); font-size: 13px; }
.item .item-head button { padding: 2px 8px; }
.hide { display: none !important; }

/* todos */
.todos { list-style: none; padding: 0; margin: 0; }
.todo { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.todo:last-child { border-bottom: 0; }
.todo input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--green); }
.todo .t { flex: 1; cursor: text; }
.todo.done .t { text-decoration: line-through; color: var(--dim); }
.prio { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.prio.p2 { background: var(--red); } .prio.p1 { background: var(--amber); } .prio.p0 { background: var(--dim); }
.due { font-size: 12px; color: var(--dim); white-space: nowrap; }
.due.late { color: var(--red); }
.todo .acts { display: flex; gap: 4px; }
.todo .acts button { padding: 2px 8px; background: transparent; color: var(--dim); border: 1px solid var(--line); }

/* games */
.board ol { margin: 0; padding-left: 22px; font-variant-numeric: tabular-nums; }
.board li { padding: 2px 0; }
.board li span { color: var(--dim); font-size: 12px; margin-left: 8px; }

.fav { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; margin-bottom: 12px; }

.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--card2);
  border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; }

/* login */
body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 28px; width: min(380px, 100%); }
.login-card .brand { margin-bottom: 18px; }
.login-card form { display: flex; gap: 8px; margin-top: 16px; }
#code { flex: 1; font-size: 24px; letter-spacing: 6px; text-align: center; font-variant-numeric: tabular-nums; }

@media (max-width: 720px) {
  .editor { grid-template-columns: 1fr; }
  .preview { justify-self: center; }
  .slots { grid-template-columns: 1fr; }
  .top { padding: 10px; }
}
