:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #656d76;
  --line: #d8dde3;
  --accent: #1f5fae;
  --accent-text: #ffffff;
  --accent-soft: #e7f0fb;
  --danger: #b42318;
  --good: #1a7f37;
  --field: #ffffff;
  --mark: #fff3b0;
  --radius: 8px;
  --sidebar: 300px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c;
    --panel: #1d2126;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --line: #333a42;
    --accent: #5b9be6;
    --accent-text: #0d1117;
    --accent-soft: #1e2b3b;
    --danger: #ff7b72;
    --good: #56d364;
    --field: #15181c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 18px; margin: 0; white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.char-picker { display: flex; align-items: center; gap: 6px; }
.char-picker select { max-width: 220px; }

/* ---------- controls ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
input[type="text"], input[type="url"], input[type="search"], input[type="date"], select, textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.danger-quiet { color: var(--danger); }
.mini {
  padding: 3px 8px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  cursor: pointer;
}
.mini:disabled { opacity: .4; cursor: default; }
.icon-btn { border: 0; background: none; font-size: 20px; cursor: pointer; padding: 2px 6px; }
.file-btn { position: relative; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- layout ---------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr) minmax(0, 1.15fr);
}
.sidebar, .editor, .output { overflow-y: auto; min-height: 0; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 12px;
}
.sidebar details { margin-top: 12px; }
.sidebar summary { font-weight: 600; cursor: pointer; padding: 4px 0; }
.sidebar ul { list-style: none; margin: 0 0 4px; padding: 0; }
.sidebar li a {
  display: block;
  padding: 5px 8px 5px 14px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}
.sidebar li a:hover { background: var(--accent-soft); }
.sidebar li a.active { background: var(--accent); color: var(--accent-text); }
.section-label { margin: 8px 0 2px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.sidebar-foot { margin-top: 20px; font-size: 12px; }

.editor { padding: 16px 20px 40px; }
.empty { max-width: 560px; margin: 40px auto; }
.empty h2 { margin-top: 0; }

.form-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.form-head h2 { margin: 0; font-size: 22px; }
.crumb { margin: 0 0 2px; font-size: 13px; }
.form-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

#fields { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide, .block, .cond { grid-column: 1 / -1; }
.field > label { font-weight: 600; font-size: 13.5px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.field.check { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: normal; font-size: 14px; }
.field.check input { margin-top: 3px; flex: none; }
.help { margin: 0; font-size: 12.5px; color: var(--muted); }
.inline { display: flex; gap: 6px; }
.inline .mini { flex: none; }
.tag {
  font-size: 11px; font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
}

.block, .cond {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px 12px;
  margin: 0;
  background: var(--panel);
}
.block legend { font-weight: 700; padding: 0 6px; }
.item { border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 8px; }
.item:first-of-type { border-top: 0; margin-top: 0; }
.item-head { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.item-num { font-weight: 600; font-size: 13px; color: var(--muted); }
.spacer { flex: 1; }
.item-body, .cond-body { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 12px; }
.item-body .block, .item-body .field.wide { grid-column: 1 / -1; }
.btn.add { margin-top: 10px; }
.cond-toggle { margin-bottom: 8px; }
.cond-body { margin-top: 8px; }
.cond-body[hidden] { display: none; }

/* ---------- output ---------- */
.output {
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 12px 16px 40px;
}
.output-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: none; cursor: pointer;
  padding: 6px 10px; border-radius: 6px; color: var(--muted); font-weight: 600;
}
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.toggle { font-size: 13px; display: flex; gap: 6px; align-items: center; }
.copy-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.status { font-size: 13px; }
.status.good { color: var(--good); }
.status.bad { color: var(--danger); }
.note { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
#bbcode { min-height: 60vh; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }

/* The preview mimics a light forum post whatever the site theme, because
   that is where the text ends up. */
.post {
  background: #ffffff;
  color: #353c41;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: auto;
  color-scheme: light;
}
.post img { max-width: 100%; height: auto; }
.post p { margin: 0 0 4px; }
.post table { max-width: 100%; }
.post hr { border: 0; border-top: 1px solid rgba(0, 0, 0, .25); margin: 12px 0; }
.post mark.unfilled { background: var(--mark); color: inherit; border-radius: 2px; box-shadow: 0 0 0 1px #e6c200 inset; }
.post .ipsSpoiler { border-left: 4px solid #c9d1d9; background: #f6f8fa; margin: 8px 0; padding: 0; }
.post .ipsSpoiler_header { padding: 6px 10px; font-weight: 600; font-size: 13px; color: #57606a; }
.post .ipsSpoiler_contents { padding: 4px 12px 10px; }

.copy-buffer { position: fixed; left: -9999px; top: 0; }

/* ---------- characters dialog ---------- */
dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  padding: 16px 20px 20px;
  width: min(860px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { margin: 0; }
.char-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; margin-top: 8px; }
.char-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.char-list li { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
.char-list li.current { border-color: var(--accent); }
.char-name { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.char-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.char-form { display: flex; flex-direction: column; gap: 8px; }
.char-form h3 { margin: 0; }
#char-fields { display: flex; flex-direction: column; gap: 8px; }
.error { color: var(--danger); margin: 0; min-height: 1em; font-size: 13px; }

.only-narrow { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); grid-template-rows: auto auto; overflow-y: auto; }
  .sidebar { grid-row: 1 / span 2; }
  .editor, .output { overflow: visible; }
  .output { border-left: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 760px) {
  .only-narrow { display: inline-block; }
  .brand { font-size: 16px; }
  .topbar { flex-wrap: wrap; }
  .char-picker .muted { display: none; }
  .layout { display: block; overflow-y: auto; }
  .sidebar {
    display: none;
    position: fixed; inset: 56px 0 0 0; z-index: 10;
    border-right: 0;
  }
  body.nav-open .sidebar { display: block; }
  .editor, .output { padding: 12px 16px 28px; }
  .section-body, .item-body, .cond-body { grid-template-columns: minmax(0, 1fr); }
  .char-layout { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- dockets ---------- */
.docket-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 10px; margin-bottom: 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--accent-soft);
}
.docket-bar[hidden] { display: none; }
.docket-bar label { font-weight: 600; font-size: 13.5px; }
.docket-bar select { width: auto; flex: 1 1 240px; min-width: 0; }
.docket-tools { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 12px; }
.docket-tools input { flex: 1 1 220px; width: auto; }
.docket-tools select { width: auto; }
.docket-list li { display: flex; flex-direction: column; gap: 2px; }
.docket-list li.closed { opacity: .65; }
#docket-fields { display: flex; flex-direction: column; gap: 8px; }

/* ---------- sections and checklists ---------- */
.section {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.section > summary {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::before {
  content: "▸";
  flex: none;
  width: 12px;
  color: var(--muted);
}
.section[open] > summary::before { transform: rotate(90deg); }
.section > summary:hover { background: var(--accent-soft); border-radius: var(--radius); }
.section-title { font-weight: 700; font-size: 15px; }
.section-meta { margin-left: auto; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.section.done .section-meta { color: var(--good); }
.section-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px 14px;
  align-items: start;
  padding: 4px 14px 14px;
}
.section-body > .field.wide, .section-body > .block, .section-body > .cond { grid-column: 1 / -1; }
.checklist {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 6px 12px;
  flex-wrap: wrap;
  padding: 7px 10px;
  border-top: 1px solid var(--line);
}
.check-row:first-child { border-top: 0; }
.check-row:hover { background: var(--accent-soft); }
.check-row.on { background: var(--accent-soft); }
.check-row.sub { padding-left: 34px; }
.check-row label { display: flex; align-items: flex-start; gap: 9px; flex: 1 1 260px; cursor: pointer; font-size: 14px; }
.check-row input[type="checkbox"] { margin-top: 3px; flex: none; }
.check-detail { display: flex; gap: 6px; flex: 0 1 260px; }
.check-detail input, .check-detail select { padding: 4px 8px; }

.disclaimer {
  font-size: 12px;
  color: var(--muted);
  border-left: 3px solid var(--line);
  padding: 2px 0 2px 8px;
  margin: 12px 0 0;
}
.form-foot { margin-top: 20px; }
