:root {
  --bg: #f6f6f4;
  --surface: #fff;
  --text: #1f2328;
  --muted: #6a737d;
  --border: #e2e2de;
  --primary: #2f6fde;
  --danger: #c23b30;
  --ok: #1f8a4c;
  --warn: #b26b00;
  --moderator: #fff7dd;
  --moderator-border: #e8c75a;
  --judge: #f1f5ff;
  --judge-border: #7d9be8;
  font-size: 15px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { overflow-x: clip; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
button, input, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
}
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.small { padding: 2px 8px; font-size: 13px; }
button:disabled { opacity: .5; }
input, textarea { border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; background: var(--surface); }

.login-page { justify-content: center; align-items: center; }
.login {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: min(340px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login h1 { font-size: 18px; margin: 0 0 6px; }
.error { color: var(--danger); margin: 0; font-size: 14px; }

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.top form { margin-left: auto; }
.brand { font-weight: 650; font-size: 15px; }
.link { color: var(--muted); }
.link.ok::before, .link.lost::before { content: "● "; }
.link.ok::before { color: var(--ok); }
.link.lost { color: var(--danger); }

.feed { flex: 1; width: 100%; max-width: 940px; margin: 0 auto; padding: 14px 14px 24px; }
.empty { color: var(--muted); text-align: center; padding: 60px 10px; }
.question { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; overflow-wrap: anywhere; }
.question .label, .question .meta { font-size: 13px; color: var(--muted); }
.round-title {
  font-size: 15px;
  font-weight: 650;
  color: var(--muted);
  margin: 24px 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.round-title::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent, #999);
  border-radius: 10px;
  padding: 10px 16px 12px;
  margin-bottom: 12px;
}
.card header { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 14px; }
.card .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent, #999); }
.card .name { font-weight: 650; }
.card .model, .card .state { color: var(--muted); font-size: 13px; }
.card .spacer { flex: 1; }
.card .stance { font-size: 12px; padding: 1px 8px; border-radius: 20px; }
.card .stance.agree { background: #e3f4e9; color: var(--ok); }
.card .stance.disagree { background: #fdecea; color: var(--danger); }
.card .body { margin-top: 6px; overflow-wrap: anywhere; }
.card .err { margin-top: 8px; background: #fdecea; color: #8a2a22; border-radius: 8px; padding: 8px 10px; font-size: 13px; white-space: pre-wrap; }
.card.failed { border-left-color: var(--danger); }
.card.moderator { background: var(--moderator); border-color: var(--moderator-border); }
.card.judge { background: var(--judge); border-color: var(--judge-border); }
.card.judge.brief { border-style: dashed; border-left-style: solid; }

.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown h1, .markdown h2, .markdown h3 { font-size: 16px; margin: 14px 0 6px; }
.markdown p, .markdown ul, .markdown ol { margin: 6px 0; }
.markdown ul, .markdown ol { padding-left: 22px; }
.markdown code { background: #f0f0ec; border-radius: 4px; padding: 1px 4px; font-size: 13px; font-family: Consolas, monospace; }
.markdown pre { background: #f6f8fa; border: 1px solid var(--border); border-radius: 8px; overflow-x: auto; padding: 10px 12px; }
.markdown pre code { background: none; padding: 0; }
.markdown table { border-collapse: collapse; display: block; overflow-x: auto; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 4px 8px; }

.composer {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 14px max(14px, env(safe-area-inset-bottom));
}
.composer > * { max-width: 1100px; margin: 0 auto; }
.status { font-size: 13px; color: var(--muted); min-height: 18px; margin-bottom: 4px; }
.status.paused { color: var(--warn); font-weight: 600; }
.new-box { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.new-box select { max-width: 100%; flex: 1 1 260px; border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px; background: var(--surface); color: var(--text); }
.new-box input[type="number"] { width: 56px; padding: 4px 6px; }
.new-box label { display: inline-flex; align-items: center; gap: 5px; }
.lineup { font-size: 12px; }
button.danger { color: var(--danger); border-color: #e6b8b4; }
.more-box { display: inline-flex; }
.more-box button { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.more-box input { width: 50px; border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: none; }
.row { display: flex; gap: 8px; align-items: flex-start; }
.row textarea { flex: 1; resize: none; min-height: 38px; max-height: 160px; }
.buttons { display: flex; gap: 6px; flex-wrap: wrap; }

/* ----- limits: a small window that folds into a button */
.limits-panel, .limits-fab {
  position: fixed;
  right: 12px;
  bottom: calc(var(--composer-h, 110px) + 10px);
  z-index: 6;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .14);
}
.limits-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; font-size: 13px; max-width: calc(100vw - 24px); }
.limits-head { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; border-bottom: 1px solid var(--border); font-weight: 600; }
.limits-head span { flex: 1; }
.limits-grid { display: grid; gap: 6px 12px; align-items: center; padding: 8px 12px 10px; }
.limits-grid .col-title { color: var(--muted); font-size: 12px; }
.limit-name { font-weight: 600; white-space: nowrap; }
.limit-cell { display: flex; flex-direction: column; gap: 1px; min-width: 88px; }
.limit-cell .line { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.limit-cell .bar { width: 50px; height: 6px; border-radius: 3px; background: #e7e7e2; overflow: hidden; }
.limit-cell .bar i { display: block; height: 100%; background: var(--ok); }
.limit-cell.mid .bar i { background: var(--warn); }
.limit-cell.low .bar i { background: var(--danger); }
.limit-cell.low .value { color: var(--danger); font-weight: 600; }
.limit-cell .reset, .limit-age { color: var(--muted); font-size: 11px; }
.limits-fab { border-radius: 20px; padding: 5px 12px; font-size: 13px; border: 2px solid var(--ok); }
.limits-fab.mid { border-color: var(--warn); }
.limits-fab.low { border-color: var(--danger); color: var(--danger); }

/* ----- navigation: a faint rail on the right, the table of contents on hover or tap */
.card, .question, .round-title { scroll-margin-top: 50px; }
.outline { position: fixed; right: 0; top: 50%; transform: translateY(-50%); z-index: 4; display: flex; align-items: center; }
.outline-rail { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; padding: 10px 6px; opacity: .35; cursor: pointer; max-height: 70vh; overflow: hidden; }
.outline-rail i { display: block; width: 10px; height: 3px; border-radius: 2px; background: var(--accent, #999); }
.outline-rail i.judge { width: 16px; background: var(--judge-border); }
.outline-rail i.moderator { background: var(--moderator-border); }
.outline-rail i.round { width: 4px; height: 4px; border-radius: 50%; background: var(--muted); margin-top: 3px; }
.outline-rail i.current { width: 20px; height: 4px; }
.outline-panel {
  display: none;
  width: 290px;
  max-height: 72vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 12px 0 0 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .14);
  font-size: 13px;
  padding: 6px 0;
}
.outline:hover .outline-panel, .outline.open .outline-panel { display: block; }
.outline:hover .outline-rail, .outline.open .outline-rail { display: none; }
.outline-head { display: flex; gap: 6px; padding: 2px 10px 6px; border-bottom: 1px solid var(--border); }
.outline-head button { flex: 1; padding: 3px 6px; font-size: 12px; }
.outline-panel ol { list-style: none; margin: 0; padding: 4px 0; }
.outline-rail .r-label {
  font-size: 10px;
  line-height: 14px;
  min-width: 14px;
  text-align: center;
  border-radius: 7px;
  background: #e2e2de;
  color: var(--muted);
  margin-top: 4px;
}
.outline-rail .r-label.current { background: var(--primary); color: #fff; }
.o-group { border-bottom: 1px solid #f0f0ec; }
.o-head { display: flex; align-items: center; gap: 4px; padding: 5px 10px 5px 4px; cursor: pointer; font-weight: 600; }
.o-head:hover { background: #f4f4f1; }
.o-group.current .o-title { color: var(--primary); }
.o-toggle { border: none; background: none; padding: 0 4px; color: var(--muted); font-size: 12px; }
.o-title { flex: 1; }
.o-meta { color: var(--muted); font-weight: 400; font-size: 12px; white-space: nowrap; }
.o-group:not(.open) .o-items { display: none; }
.o-items { list-style: none; margin: 0; padding: 0 0 4px; }
.o-item { display: flex; align-items: baseline; gap: 6px; padding: 3px 12px 3px 24px; cursor: pointer; border-left: 3px solid transparent; }
.o-item:hover { background: #f4f4f1; }
.o-item.current { border-left-color: var(--primary); background: #f0f4ff; }
.o-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent, #999); flex: none; }
.o-item .who { font-weight: 600; white-space: nowrap; }
.o-item .gist { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 640px) {
  .limits-panel { left: 8px; right: 8px; }
  :root { font-size: 14px; }
  .row { flex-direction: column; align-items: stretch; }
  .buttons button { flex: 1 1 40%; }
  .feed { padding: 10px 8px 20px; }
}
