/* Blood on the Clocktower stats — dark theme, mobile first.
   Role colours are the dataviz reference palette's dark steps, slots blue /
   aqua / violet / red. Validated on the #1a1a19 surface, adjacent pairlist:
   worst CVD dE 17.3, worst normal-vision dE 20.9. Role identity is never
   carried by colour alone — every chip and bar is labelled. */
:root {
  --surface-0: #111110;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --surface-3: #2e2e2b;
  --border:    #3a3a36;
  --ink:       #ffffff;
  --ink-2:     #c3c2b7;
  --ink-3:     #8d8c83;
  --accent:    #c98500;

  --townsfolk: #3987e5;
  --outsider:  #199e70;
  --minion:    #9085e9;
  --demon:     #e66767;

  --good:      #3987e5;
  --evil:      #e66767;
  --win:       #199e70;
  --loss:      #8d8c83;

  --radius: 12px;
  --gap: 16px;

  --on-accent: #1a1205;
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: var(--font);
  --head-transform: none;
  --head-spacing: .2px;
  --chip-radius: 999px;
  --page-bg: var(--surface-0);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  /* Fixed attachment anchors the themed gradients to the viewport rather than
     the content box, so short pages don't show a seam where the gradient ends. */
  background: var(--page-bg);
  background-attachment: fixed;
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

.wrap { max-width: 880px; margin: 0 auto; padding: 0 16px 96px; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 880px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 8px;
}
.brand { font-weight: 700; margin-right: auto; font-size: 15px; white-space: nowrap;
         font-family: var(--font-head); text-transform: var(--head-transform);
         letter-spacing: var(--head-spacing); }
.brand span { color: var(--accent); }
.whoami {
  background: var(--surface-3); border: 1px solid var(--border); color: var(--ink-2);
  border-radius: var(--chip-radius); padding: 5px 12px; font-size: 13px;
  text-decoration: none; white-space: nowrap;
}
nav.tabs {
  display: flex; gap: 4px; max-width: 880px; margin: 0 auto;
  padding: 0 12px 8px; overflow-x: auto;
}
nav.tabs a {
  flex: 1; text-align: center; white-space: nowrap;
  padding: 9px 14px; border-radius: 999px; text-decoration: none;
  color: var(--ink-2); font-size: 14px; font-weight: 600;
}
nav.tabs a[aria-current="page"] { background: var(--surface-3); color: var(--ink); }

/* ---------- flashes ---------- */
.flashes { margin: 16px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.flash {
  padding: 11px 14px; border-radius: var(--radius); font-size: 14px;
  border: 1px solid var(--border); background: var(--surface-2);
}
.flash.success { border-color: #1f6b50; background: #12241d; color: #9fe3c6; }
.flash.error   { border-color: #7a3438; background: #2a1618; color: #f3b1b1; }

/* ---------- cards & forms ---------- */
h1 { font-size: 22px; margin: 22px 0 4px;
     font-family: var(--font-head); text-transform: var(--head-transform);
     letter-spacing: var(--head-spacing); }
h2 { font-size: 16px; margin: 0 0 12px;
     font-family: var(--font-head); text-transform: var(--head-transform);
     letter-spacing: var(--head-spacing); }
.sub { color: var(--ink-3); font-size: 14px; margin: 0 0 18px; }

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: var(--gap);
}

.field { margin-bottom: 18px; }
.field > label, .field-label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--ink-2); margin-bottom: 7px;
}
.hint { font-weight: 400; color: var(--ink-3); }

input[type=text], input[type=date], input[type=number], input[type=password],
input[type=search], select, textarea {
  width: 100%; padding: 12px; font-size: 16px; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; font-family: inherit;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
                    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 18px) 21px, calc(100% - 13px) 21px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}

/* segmented choices */
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg input {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.seg label {
  flex: 1 1 auto; min-width: 88px; text-align: center; cursor: pointer;
  padding: 11px 12px; border-radius: 10px; font-size: 14px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-2);
}
.seg input:checked + label {
  background: var(--surface-3); border-color: var(--accent); color: var(--ink);
}
.seg input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 1px; }

.seg.result label { padding: 14px; font-size: 15px; }
.seg.result input:checked + label.win  { background: #12241d; border-color: var(--win);  color: #9fe3c6; }
.seg.result input:checked + label.loss { background: #241617; border-color: var(--demon); color: #f0b3b3; }

/* role chips */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px; border-radius: var(--chip-radius);
  font-size: 12px; font-weight: 700; letter-spacing: .2px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink-2);
  white-space: nowrap;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); flex: none; }
.chip.townsfolk .dot { background: var(--townsfolk); }
.chip.outsider  .dot { background: var(--outsider); }
.chip.minion    .dot { background: var(--minion); }
.chip.demon     .dot { background: var(--demon); }
/* Alignment is a second channel so good/evil never rests on hue alone. */
.chip.minion, .chip.demon { border-style: dashed; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: var(--chip-radius);
  font-size: 12px; font-weight: 700;
}
.badge.won  { background: #12241d; color: #9fe3c6; border: 1px solid #1f6b50; }
.badge.lost { background: var(--surface-2); color: var(--ink-3); border: 1px solid var(--border); }

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  display: inline-block; text-align: center;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-3); color: var(--ink); padding: 12px 16px;
}
.btn-primary {
  width: 100%; padding: 15px; font-size: 16px;
  background: var(--accent); border-color: var(--accent); color: var(--on-accent);
}
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-danger { background: transparent; border-color: #7a3438; color: #f3b1b1; }
.btn-sm { padding: 7px 11px; font-size: 13px; }

details.more { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 4px; }
details.more > summary {
  cursor: pointer; font-size: 14px; font-weight: 600; color: var(--accent);
  list-style: none; padding: 4px 0 12px;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "＋ "; }
details.more[open] > summary::before { content: "－ "; }

/* toggle switch */
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.switch .track {
  width: 46px; height: 27px; border-radius: 999px; flex: none;
  background: var(--surface-3); border: 1px solid var(--border);
  position: relative; transition: background .15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 21px; height: 21px; border-radius: 50%; background: var(--ink-3);
  transition: transform .15s, background .15s;
}
.switch input:checked + .track { background: #4a3a10; border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(19px); background: var(--accent); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch .switch-label { font-size: 15px; font-weight: 600; }

/* combobox */
.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 260px; overflow-y: auto; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 4px;
  box-shadow: 0 12px 28px rgba(0,0,0,.5);
}
.combo-list[hidden] { display: none; }
.combo-list .opt {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 10px; border: 0; background: transparent; color: var(--ink);
  border-radius: 8px; text-align: left; font-size: 15px;
}
.combo-list .opt[aria-selected="true"], .combo-list .opt:hover { background: var(--surface-3); }
.combo-list .opt .rt { margin-left: auto; font-size: 11px; color: var(--ink-3); text-transform: uppercase; }
.combo-list .empty { padding: 10px; color: var(--ink-3); font-size: 14px; }

/* tag input */
.tags {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 8px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
}
.tags .tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 6px 4px 11px; font-size: 13px;
}
.tags .tag button {
  border: 0; background: transparent; color: var(--ink-3);
  padding: 0 4px; font-size: 15px; line-height: 1; cursor: pointer;
}
.tags input {
  flex: 1 1 120px; min-width: 120px; border: 0; background: transparent;
  padding: 7px 4px; color: var(--ink); font-size: 15px;
}
.tags input:focus { outline: none; }
.tags:focus-within { border-color: var(--accent); }

/* ---------- filters ---------- */
.filters { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.filters .field { margin: 0; }
.filters .full { grid-column: 1 / -1; }
@media (min-width: 620px) { .filters { grid-template-columns: repeat(4, 1fr); } }

/* ---------- game rows ---------- */
.game {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
}
.game-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.game-char { font-weight: 700; font-size: 17px; }
.game-meta {
  margin-top: 8px; color: var(--ink-3); font-size: 13px;
  display: flex; flex-wrap: wrap; gap: 4px 12px;
}
.game-notes {
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border);
  color: var(--ink-2); font-size: 14px; white-space: pre-wrap;
}
.game-with {
  margin-top: 8px; font-size: 13px; color: var(--ink-2);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px;
}
.game-actions { margin-top: 10px; display: flex; gap: 8px; }
.spacer { margin-left: auto; }

/* ---------- stats ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: var(--gap); }
@media (min-width: 620px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.tile .label { font-size: 12px; color: var(--ink-3); font-weight: 600; letter-spacing: .3px; }
.tile .value { font-size: 28px; font-weight: 700; margin-top: 4px; line-height: 1.1; }
.tile .value.dim { color: var(--ink-3); }
.tile .foot { font-size: 12px; color: var(--ink-3); margin-top: 3px; }

.viz { margin-bottom: var(--gap); }
.viz h2 { display: flex; align-items: baseline; gap: 8px; }
.viz h2 .note { font-size: 12px; font-weight: 400; color: var(--ink-3); }

/* horizontal bars, direct-labelled */
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 1fr; gap: 4px; }
.bar-head {
  display: flex; align-items: baseline; gap: 8px; font-size: 14px;
}
.bar-head .name { font-weight: 600; }
.bar-head .num { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; }
.bar-head .num.small { color: var(--ink-3); font-weight: 600; }
.bar-head .count { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.bar-track {
  height: 10px; border-radius: 5px; background: var(--surface-2);
  border: 1px solid var(--border); overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 5px; background: var(--ink-3); }
.bar-fill.townsfolk { background: var(--townsfolk); }
.bar-fill.outsider  { background: var(--outsider); }
.bar-fill.minion    { background: var(--minion); }
.bar-fill.demon     { background: var(--demon); }
.bar-fill.neutral   { background: var(--accent); }
.bar-row.small .bar-fill { opacity: .45; }

.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin: 0 0 14px; font-size: 13px; color: var(--ink-2); }
.legend .item { display: inline-flex; align-items: center; gap: 7px; }
.legend .swatch { width: 12px; height: 12px; border-radius: 3px; }

/* line chart */
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-svg .grid { stroke: var(--border); stroke-width: 1; }
.chart-svg .axis-label { fill: var(--ink-3); font-size: 11px; }
.chart-svg .series { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart-svg .pt { fill: var(--accent); stroke: var(--surface-1); stroke-width: 2; }
.chart-svg .hit { fill: transparent; cursor: pointer; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 40;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 13px; white-space: nowrap;
  box-shadow: 0 8px 20px rgba(0,0,0,.5); transform: translate(-50%, -115%);
}
.chart-tip[hidden] { display: none; }
.chart-wrap { position: relative; }

/* table */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.summary { width: 100%; border-collapse: collapse; font-size: 14px; }
table.summary th, table.summary td {
  padding: 10px 8px; text-align: right; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.summary th:first-child, table.summary td:first-child { text-align: left; }
table.summary thead th { color: var(--ink-3); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
table.summary td.dim { color: var(--ink-3); }
table.summary tbody tr:last-child td { border-bottom: 0; }

.empty-state {
  text-align: center; padding: 46px 20px; color: var(--ink-3);
  background: var(--surface-1); border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-state p { margin: 0 0 16px; }

/* toggles for which charts show */
.viz-toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.viz-toggles label {
  cursor: pointer; padding: 8px 12px; border-radius: 999px; font-size: 13px;
  font-weight: 600; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--ink-3);
}
.viz-toggles input {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.viz-toggles input:checked + label {
  background: var(--surface-3); border-color: var(--accent); color: var(--ink);
}
.viz-toggles input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 1px; }

/* login / who */
.centre { max-width: 380px; margin: 12vh auto 0; padding: 0 20px; text-align: center; }
.centre .logo { font-size: 30px; font-weight: 700; margin-bottom: 6px;
                font-family: var(--font-head); text-transform: var(--head-transform);
                letter-spacing: var(--head-spacing); }
.centre .logo span { color: var(--accent); }
.centre p { color: var(--ink-3); font-size: 14px; margin: 0 0 26px; }
.who-grid { display: grid; gap: 12px; }
.who-grid button { padding: 20px; font-size: 18px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
