/* auto-dm. One theme, one layout system, no frameworks and nothing from a CDN.
   Every rule here exists to answer a bug dm-table shipped with: overlapping
   text, unreadable map labels, elements sized by guesswork, and panels tucked
   behind one another. The fixes are structural, not decorative:
     - box-sizing everywhere, and min-height/min-width:0 on every flex/grid child
       so a long string scrolls instead of bursting its column;
     - a z-index scale with names, so nothing is ever "behind" something by
       accident;
     - map labels get a halo and a floor size, so they read on any terrain. */

:root {
  --bg: #12141a;
  --bg-raise: #181b23;
  --bg-sunk: #0d0f14;
  --panel: #1c2029;
  --line: #2a2f3b;
  --line-soft: #232833;
  --text: #e8eaf0;
  --text-dim: #9aa3b4;
  /* Faint is still readable: 3.6:1 looked fine on a desktop monitor and melted
     into the dark on a phone. It now clears AA at 11px on every surface here. */
  --text-faint: #96a1b4;
  --accent: #d8a24a;
  --accent-ink: #1a1206;
  --good: #55b98a;
  --bad: #e0664f;
  --info: #6aa9e0;
  --chat-me: #232c3d;
  --chat-agent: #1b2029;

  /* Named scale. If it must sit on top of something, it uses one of these. */
  --z-base: 1;
  --z-raised: 10;
  --z-sticky: 100;
  --z-overlay: 1000;

  --radius: 10px;
  --radius-sm: 6px;
  --gap: 12px;
  --bar-h: 52px;

  --font: ui-sans-serif, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, monospace;
  --fs-xs: 11px;
  --fs-sm: 12.5px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 19px;

  /* The smallest a map label may go. Anything below this is the bug. */
  --map-label-min: 11px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-md)/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.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;
}

.truncate { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ---------------------------------------------------------------- chrome */

.app, .home, .watch { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.bar {
  display: flex; align-items: center; gap: var(--gap);
  height: var(--bar-h); flex: 0 0 var(--bar-h);
  padding: 0 var(--gap);
  background: var(--bg-raise);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: var(--z-raised);
}
.brand {
  font-weight: 800; letter-spacing: 0.02em; color: var(--text);
  font-size: var(--fs-lg); white-space: nowrap;
}
.brand span { color: var(--accent); }
.campaign-title {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1 1 auto;
}
.campaign-meta { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; color: var(--text-faint); font-size: var(--fs-sm); }
.badge {
  padding: 2px 7px; border-radius: 999px; font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700;
  background: var(--line); color: var(--text-dim);
}
.badge-dm { background: var(--accent); color: var(--accent-ink); }
.badge-player { background: #2b4a68; color: #cfe5ff; }
.badge-spectator { background: #33402f; color: #cfe9c4; }
.badge-guest { background: var(--line); color: var(--text-dim); }
.bar-actions { display: flex; align-items: center; gap: 6px; flex: 0 1 auto; min-width: 0; margin-left: auto; }
.hint { color: var(--text-faint); font-size: var(--fs-sm); }
.conn { color: var(--bad); font-size: var(--fs-sm); flex: 0 0 auto; }
.model { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-faint); }

.ghost {
  background: none; border: 1px solid var(--line); color: var(--text-dim);
  padding: 5px 9px; border-radius: var(--radius-sm); font: inherit; font-size: var(--fs-sm);
  cursor: pointer; white-space: nowrap;
}
.ghost:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }

/* ---------------------------------------------------------------- layout */

/* Three pieces — the menu, the conversation, the panels — arranged twice over.
   On a wide screen the menu heads the panel column and the chat sits beside it.
   On a phone the menu goes to the bottom edge and *chooses* between the chat and
   the panels, because neither is useful at half height: a map you can paint and a
   conversation you can read are the two things a screen has room for, one at a time. */
.split {
  flex: 1 1 auto; min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 42%) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "chat tabs" "chat side";
}
.chat { grid-area: chat; }
.tabs { grid-area: tabs; }
.side { grid-area: side; }

/* On a wide screen the conversation is always there, so it is not a menu item. */
.tab-chat { display: none; }

@media (max-width: 960px) {
  /* Everywhere the two columns would not fit side by side: stack them. The lobby
     does exactly this and nothing more — it has no menu, so it has nothing to
     choose between, and its campaign list is meant to sit under the chat. */
  .split {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(240px, 50%) minmax(0, 1fr);
    grid-template-areas: "chat" "side";
  }

  /* The table screen does something else with the same room. Half a conversation
     above half a map is two things nobody can use on glass, so the menu at the
     bottom edge picks one surface and that surface gets the screen: both live in
     the same cell and the one not chosen is `display: none`, holding no space and
     stealing no scroll. Scoped to the two screens with a menu, because a lobby
     with an inactive chat hidden would hide the passcode field with it. */
  body.screen-dm .split, body.screen-player .split {
    /* One row: the whole screen. The menu used to sit in a band of its own at the
       bottom edge, and it needed two rows to show seven items on a phone — 90px of
       a 844px screen spent on chrome, and the last row of any form sat under it. */
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: none;
  }
  body.screen-dm .chat, body.screen-player .chat,
  body.screen-dm .side, body.screen-player .side { grid-column: 1; grid-row: 1; min-height: 0; }
  body.screen-dm .chat:not(.is-active),
  body.screen-player .chat:not(.is-active) { display: none; }
  body.showing-chat .side { display: none; }
  body.screen-dm .tab-chat, body.screen-player .tab-chat { display: block; }
}

/* A phone bar has room for the campaign, who you are, and the actions. The
   courtesy sentence and the model label are the first to go; then the campaign
   name takes the ellipsis rather than pushing "Sign out" off the edge of the
   screen, and the two long action labels shorten to one word each. Nothing here
   removes a control — the bar measured 450px wide inside a 390px viewport and
   the only thing that ever reached the hidden third was a swipe nobody tried. */
/* Long labels off, short ones on, wide screens the other way round.

   The order matters and was the bug: `.say-short { display: none }` used to sit
   *after* the media query that switches it on, at the same specificity, so the
   later rule won everywhere. Every phone got a spectator link with no word on it
   — a 16px box that was still a live link to a share token, and looked like
   nothing at all. */
.say-short { display: none; }

@media (max-width: 820px) {
  .bar { padding: 0 8px; gap: 8px; min-width: 0; }
  .hint, .model { display: none; }
  .campaign-title {
    font-size: var(--fs-md); min-width: 0; flex: 1 1 auto;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .campaign-meta { flex: 0 0 auto; }
  /* The actions keep their own width and the campaign name gives ground. Shrinking
     three buttons to 16, 43 and 65px did not fit them either — it just made them
     unreadable instead of missing. */
  .bar-actions { flex: 0 0 auto; margin-left: 0; }
  .bar-actions > * { flex: 0 0 auto; white-space: nowrap; }
  .ghost { padding: 5px 7px; }
  .say-long { display: none; }
  .say-short { display: inline; }
}

.chat {
  /* The anchor for the "newest" pill, which belongs to the conversation and not
     to the page — it must sit over the log, not at the bottom of the window. */
  position: relative;
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  border-right: 1px solid var(--line); background: var(--bg-sunk);
}
.jump-latest {
  position: absolute; left: 50%; bottom: 56px; transform: translateX(-50%);
  z-index: var(--z-raised);
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 14px; font-size: var(--fs-sm);
  box-shadow: 0 6px 18px rgba(0,0,0,0.5); cursor: pointer;
}
.jump-latest[hidden] { display: none; }
/* The log and the things that float over its bottom edge. The floaters are here
   rather than in .chat so they sit against the log itself: the composer below can
   be dragged taller, and a pill measured from the bottom of the column would end
   up buried under it. */
.chat-log-wrap { position: relative; flex: 1 1 auto; min-height: 0; display: flex; }
.chat-log {
  flex: 1 1 auto; min-width: 0; min-height: 0; overflow-y: auto;
  padding: var(--gap); padding-bottom: 56px;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}
.working {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  z-index: var(--z-raised); max-width: calc(100% - 24px);
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; margin: 0; font-size: var(--fs-sm); color: var(--text-dim);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}
.working[hidden] { display: none; }
.working-count { color: var(--text-faint); font-family: var(--font-mono); }

.msg { max-width: 76ch; padding: 9px 12px; border-radius: var(--radius); background: var(--chat-agent); border: 1px solid var(--line-soft); }
.msg-you { align-self: flex-end; background: var(--chat-me); }
.msg-who { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.09em; color: var(--text-faint); margin-bottom: 3px; }
/* The body of a chat message is rendered markdown, so it wraps like prose and the
   markup decides where lines break. Raw newlines preserved here is what made an
   agent's list arrive as ragged, indented fragments. */
.msg-body { overflow-wrap: anywhere; }
.msg-body > :first-child { margin-top: 0; }
.msg-body > :last-child { margin-bottom: 0; }
.msg-body p { margin: 0 0 8px; }
.msg-body h4 { margin: 12px 0 6px; font-size: var(--fs-md); color: var(--text); }
.msg-body ul, .msg-body ol { margin: 0 0 8px; padding-left: 22px; }
.msg-body li { margin: 0 0 3px; }
.msg-body code {
  background: var(--bg-sunk); border: 1px solid var(--line-soft); border-radius: 4px;
  padding: 1px 4px; font-family: var(--mono, ui-monospace, monospace); font-size: 0.94em;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-body pre {
  background: var(--bg-sunk); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 10px; margin: 0 0 8px; overflow-x: auto;
}
.msg-body pre code { border: 0; background: none; padding: 0; white-space: pre; }
.msg-body blockquote {
  margin: 0 0 8px; padding: 2px 0 2px 10px; border-left: 3px solid var(--line);
  color: var(--text-dim);
}
.msg-body hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.msg-body table {
  border-collapse: collapse; margin: 0 0 8px; font-size: var(--fs-sm);
  display: block; max-width: 100%; overflow-x: auto;
}
.msg-body th, .msg-body td { border: 1px solid var(--line); padding: 3px 8px; text-align: left; }
.msg-body th { background: var(--bg-sunk); }
/* Reasoning and tool machinery are plain text, not markup: keep their line breaks. */
.msg-think .msg-body, .call-detail { white-space: pre-wrap; }
.msg-refused { border-color: #5a2f2a; background: #2a1c1a; }
.msg-call { border-left: 3px solid var(--info); font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--text-dim); }
.msg-call .ok { color: var(--good); }
.msg-call .no { color: var(--bad); }

/* Room above the chips as well as below. They sit directly under the log with no
   divider, and with none they read as the last line of the conversation and sit
   flush against it — on a phone, where the log ends at the edge of the screen,
   they looked cut off rather than offered. */
.quick { display: flex; gap: 6px; padding: 8px var(--gap) var(--gap); flex-wrap: wrap; }
.chip {
  background: var(--panel); border: 1px solid var(--line); color: var(--text-dim);
  border-radius: 999px; padding: 5px 10px; font: inherit; font-size: var(--fs-sm);
  cursor: pointer; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--text); }

.composer { display: flex; gap: 8px; padding: var(--gap); background: var(--bg-raise); }
/* The line above the box is the handle, so the box itself must not offer a corner
   grip: dragging that drags the textarea sideways, out of the row, and Send follows
   it off the screen. */
.composer textarea {
  flex: 1 1 auto; min-width: 0; resize: none; min-height: 44px;
  background: var(--bg-sunk); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px; font: inherit;
}
.composer textarea:focus { border-color: var(--accent); outline: none; }
.send {
  flex: 0 0 auto; align-self: stretch; min-width: 78px;
  background: var(--accent); color: var(--accent-ink); border: 0;
  border-radius: var(--radius-sm); font: inherit; font-weight: 700; cursor: pointer;
}
.send[disabled] { opacity: 0.55; cursor: progress; }

/* ---------------------------------------------------------------- panels */

.side { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.tabs {
  display: flex; gap: 2px; padding: 6px var(--gap) 0; flex-wrap: wrap;
  background: var(--bg-raise); border-bottom: 1px solid var(--line);
  flex: 0 0 auto; max-width: 100%;
}
/* The menu on a phone is a door, not a strip.

   Two rows of tabs cost 90px of a 844px screen and still did not tell you which
   surface you were on at a glance. Collapsed, it costs one round button in the
   corner where the thumb already is, and that button carries the name of the
   surface you are looking at. Opened, it stacks up the right edge — the side the
   content is against, so the list never covers what you were reading — and it
   closes itself when you choose, because the choosing was the point. */
.menu-fab { display: none; }

@media (max-width: 960px) {
  body.screen-dm .tabs, body.screen-player .tabs {
    position: fixed; right: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    z-index: var(--z-overlay);
    display: none; flex-direction: column; align-items: stretch; gap: 2px;
    min-width: 176px; max-width: 72vw; max-height: min(58svh, 420px);
    overflow-y: auto; overscroll-behavior: contain;
    background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
    padding: 6px; box-shadow: 0 14px 38px rgba(0, 0, 0, 0.58);
  }
  body.menu-open .tabs { display: flex; }

  .tab {
    flex: 0 0 auto; text-align: left; border: 1px solid transparent;
    border-radius: var(--radius-sm); padding: 11px 12px; font-size: var(--fs-md);
  }
  .tab.is-active { background: var(--bg-raise); border-color: var(--line); color: var(--text); }

  .menu-fab {
    display: flex; align-items: center; gap: 7px;
    position: fixed; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: var(--z-overlay);
    background: var(--accent); color: var(--accent-ink); border: 0;
    border-radius: 999px; padding: 12px 16px; font: inherit; font-weight: 700;
    font-size: var(--fs-md); box-shadow: 0 10px 26px rgba(0, 0, 0, 0.55);
    max-width: 62vw;
  }
  .menu-fab .menu-fab-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .menu-fab .menu-fab-glyph { font-size: 1.1em; line-height: 1; }

  /* The scrim: tapping away from the menu closes it, and the dimming is what says
     the rest of the screen is not listening right now. */
  .menu-scrim { display: none; }
  body.menu-open .menu-scrim {
    display: block; position: fixed; inset: 0; z-index: calc(var(--z-overlay) - 1);
    background: rgba(6, 8, 12, 0.42);
  }
}
.tab {
  background: none; border: 1px solid transparent; border-bottom: 0;
  color: var(--text-dim); font: inherit; font-size: var(--fs-md);
  padding: 7px 12px 8px; cursor: pointer;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--bg); border-color: var(--line); color: var(--text); font-weight: 600; }

.panels { flex: 1 1 auto; min-height: 0; position: relative; }
.panel {
  position: absolute; inset: 0; display: none;
  flex-direction: column; min-height: 0; overflow: hidden;
}
.panel.is-active { display: flex; }
.panel > * { min-height: 0; }
.panel-head {
  display: flex; align-items: center; gap: var(--gap);
  padding: 10px var(--gap); border-bottom: 1px solid var(--line-soft); flex: 0 0 auto;
}
.panel-head h2 { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  padding: 7px 12px; border-radius: var(--radius-sm); font: inherit; font-size: var(--fs-sm);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.small { padding: 4px 8px; font-size: var(--fs-xs); }
.btn.danger { color: var(--bad); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.list { padding: var(--gap); overflow-y: auto; flex: 1 1 auto; display: flex; flex-direction: column; gap: 8px; }
.empty { color: var(--text-faint); font-style: italic; padding: var(--gap); }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.form { display: flex; flex-direction: column; gap: 8px; padding: var(--gap); border-top: 1px solid var(--line-soft); }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-xs); color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; flex: 1 1 160px; min-width: 0; }
.form label.narrow { flex: 0 1 84px; }
.form label.grow { flex: 1 1 100%; }
.form input, .form textarea, .form select {
  background: var(--bg-sunk); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 7px 8px; font: inherit; font-size: var(--fs-md);
  text-transform: none; letter-spacing: normal; min-width: 0; width: 100%;
}
.form input:focus, .form textarea:focus { border-color: var(--accent); outline: none; }
.form .check { flex-direction: row; align-items: center; gap: 6px; text-transform: none; font-size: var(--fs-sm); color: var(--text-dim); }
.form-error { color: var(--bad); font-size: var(--fs-sm); }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.home-main { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: var(--gap); display: flex; flex-direction: column; gap: var(--gap); max-width: 900px; width: 100%; margin: 0 auto; }
.campaign-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.campaign-list li { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line-soft); padding: 8px 0; }
.campaign-link { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; color: var(--text); }
.campaign-link:hover { text-decoration: none; }
.campaign-link strong { font-size: var(--fs-lg); }
.campaign-sub { color: var(--text-faint); font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.campaign-status { font-size: var(--fs-xs); color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.07em; }
.campaign-side { flex: 0 0 auto; }

/* ---------------------------------------------------------------- entity rows */

.entity {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 8px 10px; background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
}
.entity-dot {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: var(--fs-xs); font-weight: 700;
  /* The ink follows the disc: app.js picks light or dark from the token colour,
     and a dot with no colour of its own uses this pair (9:1). */
  background: var(--line); color: var(--text);
}
.entity-main { min-width: 0; }
.entity-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* One line, always. A campaign's summary is a paragraph the DM wrote once and the
   lobby is not the place it gets read — the list has to stay a list, so the row is a
   recognisable line and the whole text lives in the title. */
.entity-sub {
  color: var(--text-faint); font-size: var(--fs-sm);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.entity-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

.hpbar { height: 5px; border-radius: 3px; background: #33201f; overflow: hidden; margin-top: 4px; }
.hpbar > i { display: block; height: 100%; background: var(--good); }
.hpbar.low > i { background: var(--bad); }
.hpbar.mid > i { background: var(--accent); }

.abilities { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; margin-top: 8px; }
.ability { background: var(--bg-sunk); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 5px 2px; text-align: center; }
.ability b { display: block; font-size: var(--fs-lg); }
.ability span { font-size: var(--fs-xs); color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.ability em { display: block; font-size: var(--fs-xs); color: var(--accent); font-style: normal; }

.pill { display: inline-block; padding: 1px 7px; margin: 2px 3px 0 0; border-radius: 999px; background: var(--line); color: var(--text-dim); font-size: var(--fs-xs); }
.pill-warn { background: #4a2f2a; color: #ffcdb8; }

.sheet { padding: var(--gap); overflow-y: auto; flex: 1 1 auto; }
.sheet-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.stat { background: var(--bg-sunk); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 8px; }
.stat b { display: block; font-size: var(--fs-xl); }
.stat span { font-size: var(--fs-xs); color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------------------------------------------------------------- map */

.map-frame {
  flex: 1 1 auto; min-height: 0; min-width: 0;
  background: #0a0c10; border-bottom: 1px solid var(--line);
  display: grid; place-items: stretch; overflow: hidden; position: relative;
}
.map-frame svg { display: block; width: 100%; height: 100%; }
/* A finger on the board means "paint here" or "move this figure", never "pan the
   page". Without this the browser claims the gesture after a few pixels, the
   stroke dies half-drawn, and the page scrolls instead — pointer events fire, but
   the drag belongs to the scroller and `pointermove` stops arriving. */
.map-frame svg { touch-action: none; }
.map-frame [data-map-hit], .map-frame [data-token-handle] { touch-action: none; }
.map-empty { padding: var(--gap); color: var(--text-faint); font-style: italic; }
/* Both of these are captions, not controls: they ride on top of the board, and
   anything you cannot click through steals the cells, the corner and the icons
   underneath them. `pointer-events: none` costs nothing and gives the board back. */
.map-titlebar, .map-hint { pointer-events: none; }
.map-titlebar {
  position: absolute; top: 8px; left: 8px; z-index: var(--z-base);
  background: rgba(10, 12, 16, 0.82); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 3px 8px; font-size: var(--fs-sm); color: var(--text-dim);
  max-width: calc(100% - 16px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.map-hint {
  position: absolute; bottom: 8px; left: 8px;
  background: rgba(10, 12, 16, 0.82); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 3px 8px; font-size: var(--fs-xs); color: var(--text-faint);
}

/* The order of battle. It used to stop at 132px, which is four rows: a table of
   seven was unreadable while a third of the screen sat empty. It now takes a
   proper share of the panel, scrolls when it overflows, and you can drag its
   bottom edge taller without touching a stylesheet. */
.strip {
  flex: 0 0 auto; min-height: 104px; max-height: min(72vh, 720px);
  overflow-y: auto;
  padding: 8px var(--gap); background: var(--bg-raise);
  display: flex; flex-direction: column; gap: 4px;
}
/* The divider is the handle. `resize: vertical` puts a small grip in the bottom
   corner of the box, which is (a) nearly invisible and (b) the wrong edge — the
   thing a table wants to move is the line between the board and the order of
   battle, and dragging it should move that line and nothing else. The height is
   remembered per campaign, because every table's screen is a different shape. */
.splitter {
  flex: 0 0 9px; height: 9px; margin: 0; cursor: row-resize; touch-action: none;
  background: var(--bg-sunk); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  position: relative; z-index: 2;
}
.splitter::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 34px; height: 3px;
  transform: translate(-50%, -50%); border-radius: 2px; background: var(--line-strong, #2b3242);
}
.splitter:hover::after, .splitter:focus-visible::after { background: var(--accent); }
.splitter:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
body.is-splitting, body.is-splitting * { cursor: row-resize !important; user-select: none !important; }
.strip-label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); }
.turnrow { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 3px 6px; border-radius: var(--radius-sm); }
.turnrow.is-now { background: #2a2417; outline: 1px solid var(--accent); }
.turnrow .ini { font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--text-dim); text-align: right; }
.turnrow .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turnrow .tag { font-size: var(--fs-xs); color: var(--text-faint); text-transform: uppercase; }

/* Room for the board. The map was a band across the middle with the palette
   stacked underneath it, so a 20x14 map letterboxed into a strip while the space
   to either side sat empty. The board now takes the width and height that are
   actually there, the tools move to a column of their own, and the grip on the
   board's bottom-right corner makes it whatever size the table wants — the SVG
   scales to the box and the pointer math follows it, so a big board is still a
   board you can paint. */
.editor {
  display: grid; gap: 10px; padding: 10px; min-height: 0; flex: 1 1 auto;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-rows: auto minmax(240px, 1fr) auto;
}
/* The undo control sits above the board it belongs to, not buried in the palette
   under a scroll — the moment you want it is the moment after you got it wrong. */
.editor-bar {
  grid-column: 1; grid-row: 1; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.editor-bar .hint { margin: 0; }
/* The board keeps the map's own proportions: `--map-aspect` is set from the
   grid, so the frame is the map and the map is the frame. Without it a 20x14 map
   in a tall box letterboxed itself into black bars and looked broken. */
.editor .map-frame-edit {
  grid-column: 1; grid-row: 2; min-width: 240px; min-height: 240px;
  aspect-ratio: var(--map-aspect, 4 / 3); width: 100%; height: auto; max-height: 100%;
  justify-self: center; align-self: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  resize: both;
}
.editor .palette {
  grid-column: 2; grid-row: 1 / span 3; flex: none; min-height: 0;
  border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
}
/* ---------------------------------------------------------------- session cards */

/* A planned evening is a card with a promise on it, not a row in a list: the DM
   reads it sideways at 10pm the night before, looking for the one that is tomorrow. */
.entity-session { align-items: flex-start; }
.entity-session.is-live { border-color: var(--accent); background: #211c12; }
.session-plan { color: var(--text-dim); font-size: var(--fs-sm); margin: 4px 0 0; }
.session-beats { margin: 6px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 2px; }
.session-beats li { font-size: var(--fs-sm); color: var(--text-dim); }
.entity-session .tag-pill { margin-left: 6px; vertical-align: 1px; }
.entity-session .tag-pill.tag-live, .entity-session.is-live .tag-pill {
  border-color: var(--accent); color: var(--text);
}

/* The map's own settings span the full width: crammed into the board's column,
   the four fields could not shrink to fit and ran off the edge of the screen. */
.editor .form { grid-column: 1 / -1; grid-row: 3; border-top: 0; padding: 0; }
@media (max-width: 900px) {
  /* On a phone the tools go back under the board rather than squeezing it, and the
     diagonal resize grip goes with them: a corner you can catch with a thumb is a
     corner you catch while trying to paint, and on glass there is no hover to warn
     you which pointer you are about to grab. */
  .editor { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(220px, 1fr) auto auto; }
  .editor-bar { grid-column: 1; grid-row: 1; }
  .editor .map-frame-edit { grid-row: 2; }
  .editor .palette { grid-column: 1; grid-row: 3; }
  .editor .form { grid-column: 1; grid-row: 4; }
  .editor .map-frame-edit { resize: none; min-width: 0; }
}
.palette { flex: 0 0 auto; padding: 8px var(--gap); border-top: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: 6px; }
.palette-label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); }
.palette-grid { display: flex; flex-wrap: wrap; gap: 4px; }
.palette-row { display: flex; flex-wrap: wrap; gap: 4px; }
.swatch {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text-dim);
  border-radius: var(--radius-sm); padding: 3px 7px; font-size: var(--fs-xs); cursor: pointer;
}
.swatch.is-active { border-color: var(--accent); color: var(--text); background: #2a2417; }
.swatch i { width: 12px; height: 12px; border-radius: 2px; display: inline-block; border: 1px solid rgba(255,255,255,0.14); }

.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg button { background: var(--panel); border: 1px solid var(--line); color: var(--text-dim); border-radius: var(--radius-sm); padding: 4px 8px; font: inherit; font-size: var(--fs-sm); cursor: pointer; }
.seg button.is-active { border-color: var(--accent); color: var(--text); }

/* ---------------------------------------------------------------- log */

.log { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 6px var(--gap) var(--gap); display: flex; flex-direction: column; gap: 2px; }
.logline { display: grid; grid-template-columns: 64px auto minmax(0, 1fr); gap: 8px; align-items: baseline; font-size: var(--fs-sm); padding: 2px 0; border-bottom: 1px solid rgba(42,47,59,0.5); }
.logline time { color: var(--text-faint); font-family: var(--font-mono); font-size: var(--fs-xs); }
.logline .kind { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); }
.logline .txt { min-width: 0; overflow-wrap: anywhere; }
.kind-roll .kind { color: var(--info); }
.kind-combat .kind { color: var(--accent); }
.kind-damage .kind, .kind-alarm .kind { color: var(--bad); }
.kind-sheet .kind { color: var(--good); }
.kind-objective .kind, .kind-callback .kind { color: #b6a3e0; }

/* ---------------------------------------------------------------- spectator */

.watch-grid {
  flex: 1 1 auto; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 34%);
}
@media (max-width: 900px) { .watch-grid { grid-template-columns: 1fr; grid-template-rows: minmax(240px, 1fr) minmax(0, 1fr); } }
.watch-map { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.map-frame-watch { border-bottom: 1px solid var(--line); }
.watch-side { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-left: 1px solid var(--line); background: var(--bg-raise); }
.watch-block { padding: 10px var(--gap); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; gap: 6px; }
.watch-block.grow { flex: 1 1 auto; border-bottom: 0; }
.watch-block h2 { font-size: var(--fs-md); text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-dim); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); display: inline-block; margin-left: 6px; animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.objs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; max-height: 26vh; overflow-y: auto; }
.objs li { font-size: var(--fs-sm); padding-left: 14px; position: relative; }
.objs li::before { content: ""; position: absolute; left: 0; top: 7px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.log-watch { background: var(--bg-sunk); border-radius: var(--radius-sm); border: 1px solid var(--line-soft); }

/* ---------------------------------------------------------------- rules/dice out */

.rules-out, .dice-out { padding: 0 var(--gap) var(--gap); display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.quote { background: var(--bg-sunk); border-left: 3px solid var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: 8px 10px; }
.quote-src { font-size: var(--fs-xs); color: var(--accent); font-weight: 700; letter-spacing: 0.04em; }
.quote-body { font-size: var(--fs-sm); color: var(--text-dim); margin-top: 3px; }
.rollbig { font-size: 34px; font-weight: 800; font-family: var(--font-mono); }
.rollmeta { font-size: var(--fs-sm); color: var(--text-faint); font-family: var(--font-mono); }

/* ---------------------------------------------------------------- toast */

.toasts { position: fixed; right: 12px; bottom: 12px; z-index: var(--z-overlay); display: flex; flex-direction: column; gap: 6px; max-width: min(360px, 90vw); }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--info); border-radius: var(--radius-sm); padding: 8px 11px; font-size: var(--fs-sm); box-shadow: 0 8px 24px rgba(0,0,0,0.45); }
.toast-bad { border-left-color: var(--bad); }
.toast-good { border-left-color: var(--good); }

/* ---------------------------------------------------------------- live turn */

/* The model takes seconds and the screen used to sit frozen through all of
   them. Reasoning and tool calls now arrive over SSE as the turn runs, so a
   player can see the table's request is being worked on, and a DM can see which
   tools the model reached for — and refuse the next one knowing what it did. */
.msg-think { border-left: 3px solid #4a5470; background: #171b23; }
.msg-think summary { color: var(--text-faint); cursor: pointer; list-style: none; }
.msg-think summary::-webkit-details-marker { display: none; }
.msg-think summary::before { content: "\25B8"; margin-right: 6px; color: var(--text-faint); }
.msg-think[open] summary::before { content: "\25BE"; }
.msg-think .msg-body { font-size: var(--fs-sm); color: var(--text-dim); font-style: italic; margin-top: 6px; }
.msg-think:not([open]) .msg-body { display: none; }
.msg-call.is-pending { border-left-color: var(--accent); opacity: 0.9; }
.msg-call .wait { color: var(--accent); }
/* A chat turn the server has not answered is retried, and the retry says so: an
   unexplained pause reads as a dead app, while "trying again in 4s, try 3" reads as
   a table waiting on a slow gateway. */
.msg-retry { border-style: dashed; color: var(--text-dim); font-size: var(--fs-sm); }

/* The agent asking back. It has to look like a question awaiting an answer, not
   another grey line of transcript, and its options have to look pressable. */
.msg-ask { border-left: 3px solid var(--accent); background: #1b2330; }
.msg-ask .ask-q { font-weight: 600; color: var(--text); }
.ask-options { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.session-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.session-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.session-list .hint { flex-basis: 100%; }
/* The answer while it is still being written carries a caret, so a half-finished
   sentence is never mistaken for the whole of one. */
.msg-stream .msg-body::after { content: "\258C"; margin-left: 2px; color: var(--accent); }
.send.is-busy { opacity: 0.75; }

/* ---------------------------------------------------------------- sheet dialog */

.overlay { position: fixed; inset: 0; z-index: var(--z-overlay); background: rgba(6,8,12,0.74); display: grid; place-items: center; padding: 16px; }
.overlay[hidden] { display: none; }
.modal { width: min(860px, 100%); max-height: min(92vh, 100%); display: flex; flex-direction: column; background: var(--bg-raise); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 18px 60px rgba(0,0,0,0.6); overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--gap); padding: 10px var(--gap); border-bottom: 1px solid var(--line); background: var(--panel); }
.modal-head h2 { font-size: var(--fs-lg); margin: 0; }

/* A sheet is a form you read: named blocks in a fixed order, so the eye goes
   straight to the number it wants and never hunts through a paragraph. */
.sheet-head { padding-bottom: 8px; border-bottom: 1px solid var(--line-soft); }
.sheet-name { font-size: var(--fs-xl); font-weight: 700; }
.sheet-id { font-size: var(--fs-md); color: var(--text-dim); }
.sheet-src { font-size: var(--fs-xs); color: var(--text-faint); font-family: var(--font-mono); }
.sheet-block { margin-top: 14px; }
.sheet-block h3 { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); margin: 0 0 6px; }
.sheet-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; font-size: var(--fs-sm); }
.sheet-dl { margin: 0; display: grid; grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 4px 10px; }
.sheet-dl dt { font-size: var(--fs-sm); font-weight: 600; }
.sheet-dl dd { margin: 0; font-size: var(--fs-sm); color: var(--text-dim); min-width: 0; overflow-wrap: anywhere; }
.ability { position: relative; }
.ability.is-save { border-color: var(--accent); }
.save-dot { position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.sheet-check { border: 1px solid var(--line-soft); border-left: 3px solid var(--good); border-radius: var(--radius-sm); padding: 8px 10px; background: var(--bg-sunk); }
.sheet-check.bad { border-left-color: var(--bad); }
.sheet-check.ok p { font-size: var(--fs-sm); color: var(--text-dim); }
.finding { font-size: var(--fs-sm); color: var(--text-dim); }
.finding .cite { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--accent); margin-left: 4px; }

/* The drag ghost is deliberately translucent: it is a promise, not a save. */
.token-ghost { opacity: 0.55; }
/* The disc goes hollow and red-edged the moment the pointer leaves the board: the
   hand is about to take a figure off the table, and that has to be visible before
   the finger lifts, not explained afterwards. */
.token-ghost.token-off { opacity: 0.4; }
.token-ghost.token-off circle { stroke: #e2705e; stroke-width: 3; stroke-dasharray: 4 3; }

/* ------------------------------------------------------- work in progress */

/* The spinner is the difference between "the agent is thinking" and "the app has
   hung", and before there was no answer to that question. It is currentColor so
   it matches whatever it sits on, and it slows down rather than disappears under
   a reduced-motion preference. */
.spinner {
  display: inline-block; width: 13px; height: 13px; vertical-align: -2px;
  border: 2px solid rgba(255,255,255,0.28); border-top-color: currentColor;
  border-radius: 50%; animation: autodm-spin 0.8s linear infinite;
}
@keyframes autodm-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.6s; }
  .chat-log { scroll-behavior: auto; }
}

/* Tool calls: verdict in the summary, machinery underneath. */
/* One line per call, verdict first. The brief is cut with an ellipsis rather
   than wrapped: an inline span that wraps to a second line reports a bounding box
   covering the tool name beside it, which is both unreadable and a false overlap
   in the layout probe. The whole result is inside, one click away. */
.msg-call summary {
  cursor: pointer; list-style: none; font-family: var(--font-mono); font-size: var(--fs-sm);
  color: var(--text-dim); display: flex; align-items: baseline; gap: 8px; min-width: 0;
}
.msg-call summary::-webkit-details-marker { display: none; }
.msg-call summary::before { content: "\25B8"; margin-right: 6px; color: var(--text-faint); }
.msg-call[open] summary::before { content: "\25BE"; }
.msg-call .call-brief {
  color: var(--text-dim); flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-call.is-pending .call-brief { color: var(--accent); }
.call-detail { margin-top: 6px; border-top: 1px solid var(--line-soft); padding-top: 6px; }
.call-line { font-size: var(--fs-sm); color: var(--text-dim); overflow-wrap: anywhere; }
.call-line.bad { color: var(--bad); }
.call-findings { margin: 4px 0 0; padding-left: 18px; font-size: var(--fs-sm); color: var(--text-dim); }
.call-args { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-faint); overflow-wrap: anywhere; }

/* A token that is already standing on the board, so the palette says so instead
   of quietly teleporting it on a stray click. */
.btn.is-active { border-color: var(--accent); color: var(--text); }
.btn.is-placed { border-style: dashed; }

/* Which map is on the table has to be readable at a glance, because the players
   are always looking at exactly one and the DM has every map open at once. The
   live one is marked and outlined; the one the DM is editing is marked too, and
   the two marks say different things. */
[data-map-select] { display: inline-flex; align-items: center; gap: 6px; }
[data-map-select].is-live { border-color: var(--good); color: var(--text); }
[data-map-select].is-editing { background: var(--bg-raise); }
.map-tag.is-live, .tag.is-live { background: var(--good); color: #08110b; text-transform: uppercase; letter-spacing: 0.04em; }
.map-live { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); }
.btn .tag { margin-left: 4px; font-size: var(--fs-xs); color: var(--text-faint); }

/* ------------------------------------------------------- player links */

/* One row per seat, with the name on it. A wall of bare URLs tells you nothing
   about who gets which, and a DM handing out the wrong key seats a stranger at
   the wrong character. */
.links {
  padding: 10px var(--gap); border-bottom: 1px solid var(--line-soft);
  display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto;
}
.links-label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); }
.linkrow { display: grid; grid-template-columns: 130px minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.link-name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-url {
  font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-dim);
  background: var(--bg-sunk); border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
  padding: 4px 8px; user-select: all; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (max-width: 700px) {
  .linkrow { grid-template-columns: minmax(0, 1fr) auto; }
  .link-name { grid-column: 1 / -1; }
}
.tag.tag-pill { border: 1px solid var(--line); border-radius: 999px; padding: 0 6px; white-space: nowrap; }

/* "Here is the one you asked for" without a scroll hunt. */
.links { max-height: 34vh; overflow-y: auto; }
.is-flash { animation: autodm-flash 1.8s ease-out; }
@keyframes autodm-flash { from { background: #3b3220; } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .is-flash { animation: none; } }

/* A closed <details> hides its content with `content-visibility` here, which
   collapses the box but leaves the children laid out where they were — so the
   tool result's text sits, invisibly, on top of the messages below it, and
   anything measuring painted boxes reports the chat as overlapping. Say the
   plainer thing: closed means not laid out at all. */
.msg-call:not([open]) > .call-detail,
.msg-think:not([open]) > .msg-body { display: none; }

/* A note about the conversation, not a message in it. */
.msg-note {
  margin: 4px 0; padding: 4px 10px; font-size: var(--fs-sm); color: var(--text-faint);
  border: 1px dashed var(--line); border-radius: 999px; align-self: center;
  text-align: center; max-width: 100%;
}

/* ---------------------------------------------------------------- phone panels
   Everything above existed before the menu moved off the bottom edge; these rules
   are what a panel does with a screen it now has to itself. */
@media (max-width: 960px) {
  /* A panel that cannot scroll is a panel whose last control does not exist.
     `.list` used to take the slack and scroll, so a form under it — the Speed
     field, "Plan this session" — was laid out past the bottom of a panel with
     `overflow: hidden` and could not be reached by dragging or by tab. */
  .panel { overflow-y: auto; overscroll-behavior: contain; padding-bottom: 92px; }
  .panel > .list { flex: 0 0 auto; overflow: visible; }
  .panel > .form { border-top: 1px solid var(--line); }
  /* The board and the editor size themselves and must not be scrolled as a whole —
     the map is painted with drags, and a panel that scrolls under a drag paints
     stripes. */
  #panel-table, #panel-maps { overflow: hidden; padding-bottom: 0; }

  /* The token and terrain strips grow with the campaign: forty enemies, or a
     palette of eleven terrains with names, wrapped to four rows and pushed the
     bottom of the editor off the screen, where the map editor's own "overflow:
     hidden" clipped the labels in half — text overlapping text. Given a scroll
     track of its own, the palette stays inside its box. */
  .palette { max-height: 38svh; overflow-y: auto; overscroll-behavior: contain; }
  .palette-row, .palette-grid { align-items: flex-start; }
  .palette-row > .btn, .palette-row > .swatch { max-width: 100%; }

  /* A divider is only worth grabbing on a screen where something else is being
     crowded out, which is exactly what a phone is. */
  .splitter { display: block; }
  .splitter::after { height: 11px; }

  /* The board on a phone was a 240px square in a screen 844px tall. The aspect
     ratio still decides the shape; the room it gets is the room the panel has. */
  .editor {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(280px, 1fr) auto auto auto;
  }
  .editor .splitter { grid-column: 1; grid-row: 3; }
  .editor .palette { grid-column: 1; grid-row: 4; border-top: 1px solid var(--line); }
  .editor .form { grid-column: 1; grid-row: 5; }
  .editor .map-frame-edit { grid-column: 1; grid-row: 2; min-height: 280px; }
  .form .row { flex-wrap: wrap; }
  .form label.narrow { flex: 1 1 96px; }
}

/* The scene, under the order of battle: the figures, their hit points, and the
   buttons that change them. The bar shares the map's health styling so a ghoul at
   6/22 looks the same on the board and in the list — the DM is reading one fact. */
.strip-scene { flex: 0 0 auto; max-height: 34svh; overflow-y: auto; overscroll-behavior: contain; }
.turnrow .hpbar { flex: 1 1 60px; min-width: 48px; margin: 0; align-self: center; }
.turnrow .btn.small { padding: 3px 8px; }

/* The one-line offer above the bestiary: these cards are statblocks wearing name
   tags. It has to be readable at a glance and impossible to mistake for a monster. */
.adopt-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 10px; margin: 0 10px 8px;
  border: 1px solid var(--line); border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.adopt-bar[hidden] { display: none; }
.adopt-text { margin: 0; font-size: 12.5px; color: var(--text); }

/* The order of battle is a 4-column grid (roll, name, bar, tag); the scene adds two
   buttons, and a fifth child in a 4-column grid lands a name in the 26-pixel roll
   column — which is how "Brute 1" became "Br…". Its own columns, with the name
   getting room before the bar does. */
.scene-row {
  grid-template-columns: minmax(88px, 1.2fr) minmax(44px, 1.6fr) auto auto auto;
  gap: 6px;
}
