/* Base layout + tokens. Deliberately small: HTMX means the server owns rendering,
   so there is no component framework to theme around. */

:root {
  --bg: #10131a;
  --surface: #171b24;
  --border: #262c3a;
  --text: #e6e9ef;
  --muted: #98a2b3;
  --accent: #b98a3a;
  --sidebar-w: 16rem;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f7f8fa; --surface: #fff; --border: #e3e6ec;
    --text: #1a1d24; --muted: #5c6472;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  display: flex;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  padding: 1rem .75rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .75rem;
  transition: width .15s ease, padding .15s ease;
}

/* Collapsed: the sidebar slides to width 0 (the flexbox content column simply
   grows to fill the space, nothing else has to react) and .sidebar-toggle-collapsed
   — normally hidden, since the one inside the sidebar covers this case — takes
   over as the way back in. */
html.sidebar-collapsed .sidebar {
  width: 0; flex: 0 0 0; padding: 0; border-right: 0; overflow: hidden;
}

.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.brand { font-size: 1.1rem; font-weight: 600; padding: .25rem .5rem; }

.sidebar-toggle {
  flex: 0 0 auto; width: 1.6rem; height: 1.6rem; padding: 0;
  display: grid; place-items: center; line-height: 1; font-size: .85rem;
  border: 1px solid var(--border); border-radius: 6px;
  background: none; color: var(--muted); cursor: pointer;
}
.sidebar-toggle:hover { color: var(--text); border-color: var(--accent); }

/* Lives outside <aside>, fixed, and stays hidden until the sidebar collapses out
   from under it — see the comment on the button itself in base.html. */
.sidebar-toggle-collapsed {
  display: none; position: fixed; top: .85rem; left: .85rem; z-index: 20;
  background: var(--surface);
}
html.sidebar-collapsed .sidebar-toggle-collapsed { display: grid; }

.campaign-switcher { display: flex; flex-direction: column; gap: .25rem; }
.campaign-switcher label { font-size: .75rem; color: var(--muted); text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-section {
  margin: .75rem 0 .25rem; padding: 0 .5rem;
  font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.nav-link {
  padding: .4rem .5rem; border-radius: 6px;
  color: var(--text); text-decoration: none;
}
.nav-link:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }

.sidebar-footer {
  margin-top: auto; display: flex; flex-direction: column; gap: .35rem;
  padding-top: .75rem; border-top: 1px solid var(--border);
  font-size: .8rem; color: var(--muted);
}

/* ── Content ─────────────────────────────────────────────── */
.content { flex: 1; padding: 1.5rem 2rem; min-width: 0; }
.muted { color: var(--muted); }

.signin, .gate {
  margin: auto; max-width: 26rem; text-align: center;
  display: flex; flex-direction: column; gap: 1rem; padding-top: 15vh;
}

/* ── Controls ────────────────────────────────────────────── */
select, input, textarea {
  padding: .4rem .5rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font: inherit; width: 100%;
}

.button, button {
  padding: .45rem .9rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
  cursor: pointer; text-decoration: none; display: inline-block;
}
.button.primary { background: var(--accent); border-color: var(--accent); color: #17130a; font-weight: 600; }

/* A point-buy score: −/+ either side of the number, so landing on an exact
   budget doesn't mean hunting for the number input's own tiny spinner. */
.stepper { display: flex; align-items: stretch; gap: 0; max-width: 8rem; }
.stepper input[type="number"] {
  text-align: center; border-radius: 0; border-left: 0; border-right: 0;
  -moz-appearance: textfield;
}
.stepper input[type="number"]::-webkit-inner-spin-button,
.stepper input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper-btn {
  flex: 0 0 auto; width: 2rem; padding: .45rem 0;
  border-radius: 0; font-weight: 600; line-height: 1;
}
.stepper-btn:first-child { border-radius: 6px 0 0 6px; }
.stepper-btn:last-child { border-radius: 0 6px 6px 0; }
.linklike {
  background: none; border: none; padding: 0; color: var(--muted);
  cursor: pointer; text-align: left; text-decoration: underline;
}
.linklike.danger { color: crimson; }

/* Wide content must scroll inside its own box, never the page. */
.scroll-x { overflow-x: auto; max-width: 100%; }

#toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; }

/* ── Character browser ───────────────────────────────────── */
.split { display: grid; grid-template-columns: minmax(14rem, 20rem) 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 60rem) { .split { grid-template-columns: 1fr; } }

/* Character selector — a strip of chips rather than a stacked card list. Three
   lines per character pushed the sheet below the fold on a phone: you scrolled
   past the roster to reach the thing you had just selected. One line each now,
   wrapping onto more lines as the viewport narrows — never a horizontal scrollbar. */
.roster {
  display: flex; flex-wrap: wrap; gap: .35rem; margin: 0 0 1rem; padding: 0;
}
.roster-chip {
  display: inline-flex; align-items: baseline; gap: .35rem; flex: 0 0 auto;
  padding: .35rem .7rem;
  border: 1px solid var(--border); border-radius: 999px;
  color: var(--text); text-decoration: none; background: var(--surface);
  white-space: nowrap; font-size: .9rem;
}
.roster-chip:hover { border-color: var(--accent); }
.roster-chip.is-selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
}
.roster-chip .chip-flag { font-size: .75rem; }

/* A row of inline form controls (label + input + button) — the assign-ownership
   row, an equip/gold form beside a carried item, a city's roll/pin/delete row.
   Wraps rather than overflowing when the row is narrower than its controls. */
.assign { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin: .4rem 0; }
.assign-owners { margin: 0 0 1rem; font-size: .9rem; }
.assign-owners summary { cursor: pointer; color: var(--muted); }
.assign-owners .assign span { min-width: 8rem; }

/* A vertical picker beside a detail panel (Equipment Manager, Shopping cities,
   NPCs, Diaries) — the panel already claims most of the width, so, unlike
   `.roster` above, this is a plain stacked list: one row per entry, each free to
   wrap onto multiple lines, never a horizontal strip. */
.side-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .3rem; }
.side-list-item {
  border: 1px solid var(--border); border-radius: 8px; padding: .5rem .6rem;
  background: var(--surface);
}
.side-list-item > a { display: block; color: var(--text); text-decoration: none; }
.side-list-item > a:hover strong { color: var(--accent); }
.side-list-item strong { display: block; }
.side-list-item.is-selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}
.side-list-item .assign { margin: .35rem 0 0; }

/* Sheet tabs. */
.tabs { display: flex; flex-wrap: wrap; gap: .25rem; margin: 1rem 0 .75rem; }
.tab {
  flex: 0 0 auto; padding: .4rem .8rem; font: inherit; font-size: .9rem; cursor: pointer;
  color: var(--muted); background: none; white-space: nowrap;
  border: 0; border-bottom: 2px solid transparent; border-radius: 0;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

.slots { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .75rem; }
.slots li { display: flex; flex-direction: column; align-items: center; min-width: 3.5rem; }
.spell-list, .actions, .summons, .inventory, .equipped {
  list-style: none; margin: 0 0 .5rem; padding: 0;
}
.spell-list li, .summons li, .inventory li, .equipped li { padding: .15rem 0; }
.actions li { padding: .2rem 0; border-bottom: 1px solid var(--border); }
.actions summary, .feature summary { cursor: pointer; display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.feature { padding: .2rem 0; }

.sheet { display: grid; gap: 1.25rem; }
.sheet-head h2 { margin: 0 0 .15rem; }

.tiles { display: flex; flex-wrap: wrap; gap: .4rem; }
.tile {
  display: grid; gap: .1rem; padding: .45rem .7rem; min-width: 5rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.tile-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.tile-value { font-size: 1.05rem; font-weight: 600; }

.chip {
  display: inline-block; padding: .15rem .5rem; margin-right: .3rem;
  border-radius: 999px; background: color-mix(in srgb, var(--accent) 18%, transparent);
  font-size: .8rem;
}

.sheet-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1.25rem; }
.skills-section { grid-column: span 2; }
@media (max-width: 60rem) { .skills-section { grid-column: auto; } }

.abilities, .saves, .skills { list-style: none; margin: 0; padding: 0; display: grid; gap: .15rem; }
.skills { grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); }
.abilities li, .saves li, .skills li {
  display: flex; justify-content: space-between; gap: .5rem;
  padding: .25rem .4rem; border-bottom: 1px solid var(--border);
}

/* ── Filters, cards, events ──────────────────────────────── */
.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 1rem; align-items: flex-start; }
.filters input, .filters select { width: auto; min-width: 10rem; flex: 0 1 auto; }
.filters select[multiple] { min-height: 5.5rem; padding: .2rem; }
.filters input[type="number"] { min-width: 6rem; }
.filters .inline { align-self: center; }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem;
         grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); }
.card { padding: .6rem .75rem; background: var(--surface);
        border: 1px solid var(--border); border-radius: 8px; }
.card header { display: grid; gap: .1rem; margin-bottom: .3rem; }
.card.is-selected { border-color: var(--accent); }
/* A catalog card picked from #results narrows the list to itself — see
   rpgmFocusCatalogCard in base.html — until the search box is refocused. */
.is-hidden { display: none; }
.small { font-size: .8rem; }
/* .conditions is the same wrapping row of .chip badges, on the character sheet. */
.chips, .conditions { display: flex; flex-wrap: wrap; gap: .25rem; margin: .35rem 0 0; padding: 0; }
.chip.subtle { background: color-mix(in srgb, var(--border) 60%, transparent); }

.events { list-style: none; margin: 0; padding: 0; display: grid; gap: .2rem; }
.events li { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem;
             padding: .35rem .4rem; border-bottom: 1px solid var(--border); }
.events time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .8rem; }
.inline { display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; }
.inline input[type="checkbox"] { width: auto; }
.stack { display: grid; gap: .5rem; max-width: 30rem; margin: 0 0 1.25rem; }
.stack label { display: grid; gap: .2rem; font-size: .85rem; color: var(--muted); }
/* Ability scores: each field is short enough that a single column wastes most of
   the row, and there are six of them — worth the width a name/race dropdown
   wouldn't be. auto-fit rather than a fixed 2: the max-width keeps it at two
   columns everywhere the fields actually fit, but it still collapses to one
   rather than truncating on anything narrower — never a horizontal scrollbar,
   the same rule every other multi-column layout in this file follows. */
.stack.two-col { grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); max-width: 26rem; }
.ability-field { display: grid; gap: .2rem; align-content: start; }
.toggle-row { padding: .4rem 0; border-bottom: 1px solid var(--border); }
.feature-list { list-style: none; margin: .25rem 0 0 1.25rem; padding: 0; display: grid; gap: .15rem; }
.notice { padding: .5rem .75rem; border-radius: 8px;
          background: color-mix(in srgb, var(--accent) 15%, transparent); }
.slots { list-style: none; margin: 0; padding: 0; display: grid; gap: .2rem; }
.slots li { display: flex; align-items: baseline; gap: .6rem;
            padding: .3rem .4rem; border-bottom: 1px solid var(--border); }
.slots li span:first-child { min-width: 6rem; color: var(--muted); }
.notice.error { background: color-mix(in srgb, crimson 18%, transparent); }
.steps { list-style: none; margin: 0 0 1.25rem; padding: 0; display: flex; flex-wrap: wrap; gap: .35rem; }
.steps li { display: flex; align-items: center; gap: .35rem; padding: .25rem .6rem;
            border: 1px solid var(--border); border-radius: 999px;
            font-size: .8rem; color: var(--muted); }
.steps .step-index { display: inline-grid; place-items: center; width: 1.2rem; height: 1.2rem;
                     border-radius: 50%; background: var(--border); font-size: .7rem; }
.steps li.is-current { border-color: var(--accent); color: var(--text); }
.steps li.is-done { color: var(--text); }
.steps li.is-done .step-index { background: var(--accent); color: #17130a; }
fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0 0 1rem; padding: .75rem; }
legend { padding: 0 .35rem; color: var(--muted); font-size: .85rem; }
.wizard-actions { display: flex; gap: .5rem; margin-top: 1rem; }
.review { list-style: none; margin: 0; padding: 0; display: grid; gap: .2rem; }
.review li { display: flex; justify-content: space-between; gap: 1rem;
             padding: .3rem .4rem; border-bottom: 1px solid var(--border); }

/* ── NPC profiles ────────────────────────────────────────── */
/* A rolled value is only half the sheet — the table text behind it is what tells
   a GM how to play the NPC, so it sits on the same line rather than in a tooltip. */
.attrs { list-style: none; margin: 0; padding: 0; display: grid; gap: .15rem; }
.attrs li { display: flex; flex-wrap: wrap; align-items: baseline; gap: .4rem;
            padding: .3rem .4rem; border-bottom: 1px solid var(--border); }
.attr-label { min-width: 6.5rem; color: var(--muted); font-size: .8rem; }

.roster-title { margin: 1.25rem 0 .5rem; font-size: 1rem; }
.roll { margin: .5rem 0 .5rem; }
.roll summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.roll .stack { margin-top: .5rem; }

.portrait-row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-start; }
.portrait { width: 14rem; max-width: 100%; border-radius: 8px; border: 1px solid var(--border); }
.portrait-row .stack { flex: 1 1 20rem; max-width: none; }

blockquote { margin: .25rem 0; padding: .2rem .75rem; border-left: 2px solid var(--accent); color: var(--text); }
pre { margin: .25rem 0; padding: .5rem .6rem; background: var(--surface);
      border: 1px solid var(--border); border-radius: 6px; font-size: .78rem;
      white-space: pre-wrap; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .6rem; }
.form-grid label { display: grid; gap: .2rem; font-size: .85rem; color: var(--muted); }
.form-grid label.wide { grid-column: 1 / -1; }
.form-grid label.inline { display: inline-flex; }

/* ── Chronicle review ────────────────────────────────────── */
/* A stage takes minutes, so its log is the only sign of life the GM has. */
.job { padding: .6rem .75rem; border: 1px solid var(--border); border-radius: 8px;
       background: var(--surface); margin: 0 0 1rem; }
.job-failed { border-color: crimson; }
.job-log { max-height: 16rem; overflow-y: auto; margin: .35rem 0 0; }

.artifact { margin: .35rem 0; padding: .35rem .5rem;
            border: 1px solid var(--border); border-radius: 8px; }
.artifact summary { cursor: pointer; }
.artifact textarea { margin: .5rem 0; }

textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; }
.stack.wide { max-width: none; }

/* ── Token sprite picker ─────────────────────────────────── */
/* A monster's token art is chosen by looking at it, not by filename. */
.sprite-picker summary { cursor: pointer; font-size: .8rem; color: var(--muted); }
.sprite { width: 2rem; height: 2rem; object-fit: contain; vertical-align: middle; }
.sprite-grid { display: flex; flex-wrap: wrap; gap: .2rem; margin-top: .35rem;
               max-height: 12rem; overflow-y: auto; }
.sprite-choice { padding: .15rem; line-height: 0; background: var(--bg); }
.sprite-choice.is-chosen { border-color: var(--accent); }

/* ── Monster stat block ──────────────────────────────────── */
.stat-block { display: grid; gap: .9rem; }
.stat-block h3 { margin: 0; font-size: .95rem; }
.stat-block .feature-list li { margin-bottom: .35rem; }

/* ── Habitat bestiary ─────────────────────────────────────────────────────────
   Stacked collapsible terrains. The section is a real card rather than a bare
   <details> because several sit one under another and, unstyled, a run of them
   reads as one undifferentiated list. */
.habitat {
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); margin: 0 0 .6rem; padding: .5rem .8rem;
}
.habitat > summary { cursor: pointer; display: flex; gap: .5rem; align-items: baseline; }
.habitat[open] > summary { margin-bottom: .5rem; border-bottom: 1px solid var(--border); padding-bottom: .5rem; }
.habitat-actions { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin: .4rem 0; }

/* The add-a-monster search sits at the foot of each section, set apart from the
   monsters already placed above it. */
.habitat-add {
  margin-top: .75rem; padding-top: .6rem;
  border-top: 1px dashed var(--border);
}
.habitat-add h3 { margin: 0 0 .4rem; font-size: .95rem; }

/* ── Pairing an agent ────────────────────────────────────────────────────────
   A consent screen is read once, under mild pressure, on whatever device is to
   hand — so it is one column, generously spaced, with the code field big enough
   to check a typed code against the one on screen. */

.device-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.device-form input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.25rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.6rem 0.8rem;
  min-width: 12ch;
}

.device-capabilities {
  margin: 1rem 0 1.5rem;
  padding-left: 1.2rem;
  line-height: 1.7;
  max-width: 60ch;
}

.device-note {
  max-width: 60ch;
  opacity: 0.8;
  font-size: 0.95rem;
  line-height: 1.6;
}

.device-cancel {
  opacity: 0.75;
}
