:root {
  color-scheme: dark;
  --bg: #12141a;
  --surface: #1b1e27;
  --line: #3a4254;
  --text: #e8eaed;
  --muted: #b8c0cc;
  --focus: #8ab4ff;
  --ok: #7dcea0;
  --danger: #f0a8a8;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0; font-weight: 650; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
  background: #12151c;
  border: 1px solid var(--line);
  border-radius: 4px;
  min-height: 32px;
  padding: 4px 8px;
}

button { cursor: pointer; background: #242a36; }
button:hover { border-color: var(--focus); }
button.primary { background: #2c3d5c; }
button.danger { color: var(--danger); }

textarea { resize: vertical; min-height: 32px; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: -64px;
  background: var(--surface);
  padding: 8px 12px;
  border: 1px solid var(--line);
  z-index: 40;
}
.skip-link:focus { top: 8px; }

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

#meta { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.toolbar { display: flex; gap: 8px; flex-shrink: 0; }

.banner {
  margin: 0;
  padding: 8px 16px;
  background: #3a2e18;
  color: #f3e2b3;
}
.banner.is-error { background: #3d2424; color: var(--danger); }
.banner.is-ok { background: #1d3328; color: var(--ok); }

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  flex: 1;
  min-height: 0;
}

.rail {
  border-right: 1px solid var(--line);
  overflow: auto;
  padding: 12px;
  background: #161922;
}

.rail-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sources { display: flex; flex-direction: column; gap: 4px; }

.sources button {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  width: 100%;
}

.sources button.is-on { border-color: var(--focus); background: #243044; }

.sources .count {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

main {
  overflow: auto;
  padding: 16px;
  min-width: 0;
}

.source-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}

.source-bar input[type="search"] { flex: 1; min-width: 180px; }

.hint { color: var(--muted); margin: 0; }
.note-help { color: var(--muted); font-size: 13px; margin: 0 0 12px; max-width: 80ch; }

.table-block {
  margin: 0 0 22px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.table-head {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.table-head h3 { margin: 0; font-size: 15px; font-weight: 650; flex: 1; }
.table-head .count { color: var(--muted); font-family: var(--mono); font-size: 12px; }

.grid-wrap { overflow-x: auto; }

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 1280px;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 6px;
  vertical-align: top;
  text-align: left;
}

th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: #222733;
  z-index: 1;
}

td input, td select, td textarea { width: 100%; }

.item-cell { min-width: 260px; }
.item-pick { display: flex; gap: 8px; align-items: center; }
.item-pick input { flex: 1; min-width: 0; }

.pick-icon, .monogram {
  display: grid;
  place-items: center;
  width: 36px;
  height: 32px;
  flex: 0 0 36px;
  background: #12100c;
  border: 1px solid var(--line);
}

.pick-icon img, .item-results img {
  width: 36px;
  height: 32px;
  image-rendering: pixelated;
}

.monogram { font-size: 10px; color: #c4a574; }

.num { width: 88px; }
.short { width: 72px; }
.chance-control { display: flex; gap: 4px; align-items: center; min-width: 180px; }
.chance-control select { width: auto; min-width: 88px; }
.chance-control input { width: 72px; }
.chance-prefix { color: var(--muted); font-family: var(--mono); }
.chance-control.is-bad input, .chance-control.is-bad select { border-color: var(--danger); }
.notes { min-width: 240px; }
.derived { color: var(--muted); font-family: var(--mono); font-size: 13px; line-height: 32px; }
input.is-bad { border-color: var(--danger); }
td.pick-col select { min-width: 148px; max-width: 240px; }

.item-results {
  position: fixed;
  z-index: 30;
  list-style: none;
  margin: 0;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  max-height: 280px;
  overflow: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.item-results button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: 0;
  text-align: left;
  padding: 6px 8px;
  min-height: 40px;
}

.item-results button.is-on, .item-results button:hover { background: #2a3142; }
.item-results .meta { margin-left: auto; color: var(--muted); font-family: var(--mono); font-size: 12px; }

.add-table { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.add-table input { width: 280px; }
