:root {
  --bg: #f6f2ea;
  --surface: #fffdf8;
  --surface-2: #efe8db;
  --text: #2a2420;
  --muted: #6e6359;
  --border: #ddd2c0;
  --accent: #8c2f2b;
  --accent-text: #fff;
  --ok: #2f6b3a;
  --veil: #9a6a12;
  --line: #a3302b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17140f;
    --surface: #211d17;
    --surface-2: #2b261e;
    --text: #ece5d8;
    --muted: #a99d8c;
    --border: #3a3329;
    --accent: #dc7a72;
    --accent-text: #1a1310;
    --ok: #7cc48a;
    --veil: #e0b04f;
    --line: #ef7a72;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #17140f; --surface: #211d17; --surface-2: #2b261e; --text: #ece5d8;
  --muted: #a99d8c; --border: #3a3329; --accent: #dc7a72; --accent-text: #1a1310;
  --ok: #7cc48a; --veil: #e0b04f; --line: #ef7a72; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 Inter, system-ui, sans-serif;
}
h1, h2, h3, .brand { font-family: Cinzel, Georgia, serif; letter-spacing: .02em; }
h1 { font-size: 1.7rem; margin: 0 0 .25rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .25rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: .85rem; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { font-size: 1.25rem; font-weight: 700; text-decoration: none; color: var(--text); }
#account { display: flex; align-items: center; gap: 10px; min-width: 0; }
#account img { width: 28px; height: 28px; border-radius: 50%; }
#account .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }

main { max-width: 900px; margin: 0 auto; padding: 24px 16px 64px; }

button, .btn {
  font: inherit; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 8px;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--line); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
a.card { display: block; text-decoration: none; color: inherit; }
a.card:hover { border-color: var(--accent); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

.badge {
  display: inline-block; font-size: .75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.dm { color: var(--accent); border-color: var(--accent); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 16px 0 20px; overflow-x: auto; }
.tabs a {
  padding: 8px 12px; text-decoration: none; color: var(--muted); white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a.active { color: var(--text); border-color: var(--accent); font-weight: 600; }

.hero { text-align: center; padding: 48px 0; }
.hero h1 { font-size: 2.4rem; }
.hero p { max-width: 520px; margin: 8px auto 24px; }

label { display: block; font-weight: 500; margin-bottom: 4px; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field + .field { margin-top: 12px; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 2px; }

dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { padding: 20px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: .9rem; max-width: 100%;
  overflow-wrap: anywhere;
}
.chip button { border: 0; background: none; padding: 0 2px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; font-size: .85rem; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.num { text-align: center; width: 64px; }

.rating { display: flex; gap: 4px; flex-wrap: wrap; }
.rating input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.rating label {
  margin: 0; font-weight: 500; font-size: .85rem; padding: 3px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); color: var(--muted);
}
.rating input:focus-visible + label { outline: 2px solid var(--accent); }
.rating input[value="ok"]:checked + label { color: var(--ok); border-color: var(--ok); }
.rating input[value="veil"]:checked + label { color: var(--veil); border-color: var(--veil); }
.rating input[value="line"]:checked + label { color: var(--line); border-color: var(--line); }
.t-ok { color: var(--ok); } .t-veil { color: var(--veil); } .t-line { color: var(--line); font-weight: 600; }

.topic-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; }
.error { color: var(--line); }

@media (max-width: 560px) {
  h1 { font-size: 1.4rem; }
  .hero h1 { font-size: 1.9rem; }
  #account .name { display: none; }
}

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.kpi-label { font-size: .85rem; color: var(--muted); }
.kpi-value { font-size: 1.9rem; font-weight: 600; line-height: 1.2; margin-top: 4px; overflow-wrap: anywhere; }
.kpi-sub { font-size: .8rem; color: var(--muted); margin-top: 4px; }
#account a { white-space: nowrap; }

/* ----- character builder & sheet ----- */
a.btn { display: inline-block; text-decoration: none; color: var(--text); }
a.btn.primary { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }
.builder { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; margin-top: 12px; }
.builder-summary { position: sticky; top: 12px; }
@media (max-width: 820px) {
  .builder { grid-template-columns: minmax(0, 1fr); }
  .builder-summary { position: static; order: -1; width: 100%; max-width: none; }
}
.builder select { margin-top: 2px; }
details.feature { border-top: 1px solid var(--border); padding: 6px 0; }
details.feature summary { cursor: pointer; font-weight: 500; }
details.feature .pre { margin-top: 6px; }
.checks { display: grid; gap: 4px 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
label.check { display: flex; gap: 6px; align-items: center; font-weight: 400; margin: 0; }
label.check input { width: auto; flex: none; }
/* Welcome screen (age + terms): a readable column on every screen size; long check labels wrap beside their box. */
.age-form { width: 100%; max-width: 440px; margin: 0 auto; text-align: left; box-sizing: border-box; }
.age-form label.check { align-items: flex-start; gap: 10px; line-height: 1.45; }
.age-form label.check input { margin: 3px 0 0; width: 18px; height: 18px; }
.age-form .hint { margin: -4px 0 4px 28px; }
.age-form .hint.flush { margin-left: 0; }
.age-form .field { margin: 0; }
/* First and last name side by side, stacked on narrow phones. */
.name-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.name-pair .field { margin: 0; min-width: 0; }
@media (max-width: 400px) { .name-pair { grid-template-columns: 1fr; } }
.age-form .primary { width: 100%; }
.age-form .link { display: block; margin: 10px auto 0; }
.hero h1, .hero p { overflow-wrap: anywhere; } /* long email addresses on narrow phones */
@media (max-width: 400px) { .hero h1 { font-size: 1.6rem; } }
.option-list { max-height: 360px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; }
.option { padding: 6px 0; border-bottom: 1px solid var(--border); }
.option:last-child { border-bottom: 0; }
.option details.feature { border: 0; padding: 2px 0 0; }
.option details.feature summary { font-weight: 400; font-size: .8rem; color: var(--muted); }
.source-row { padding: 6px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
table.scores td, table.scores th { padding: 4px 6px; }
.sheet h4 { margin: 12px 0 4px; font-size: .85rem; color: var(--muted); font-weight: 600; }
.scores-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.score { text-align: center; border: 1px solid var(--border); border-radius: 8px; padding: 4px 0; }
.score-label { font-size: .7rem; color: var(--muted); font-weight: 600; }
.score-mod { font-size: 1.1rem; font-weight: 600; }
.score-val { font-size: .75rem; color: var(--muted); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 8px; }
.stat-row > div { border: 1px solid var(--border); border-radius: 8px; padding: 4px 6px; text-align: center; }
.stat-row span { display: block; font-size: .7rem; color: var(--muted); }
.mini-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px 8px; font-size: .8rem; color: var(--muted); }
.mini-grid.skills { grid-template-columns: repeat(2, 1fr); }
.mini-grid .prof { color: var(--text); font-weight: 600; }
.mini-grid .prof::before { content: "● "; color: var(--accent); }
.char-name { text-decoration: none; color: inherit; }
.char-name:hover h3 { color: var(--accent); }
table.scores th.num, table.scores td.num { width: auto; }
table.scores abbr { text-decoration: none; font-weight: 600; }
.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand img { display: block; }
.hero-logo { display: block; margin: 0 auto 12px; }
#account a.name { color: var(--text); text-decoration: none; }
#account a.name:hover { text-decoration: underline; }
#account a img { display: block; }

/* Header: brand left, dice button centered, account (with Admin) right */
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; }
.topbar .brand { justify-self: start; }
#header-center { justify-self: center; }
#account { justify-self: end; }
a.btn.admin-btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; font-weight: 600; }
a.btn.admin-btn:hover { background: var(--surface-2); }
@media (max-width: 640px) {
  .topbar { grid-template-columns: 1fr auto; row-gap: 8px; }
  #header-center { grid-column: 1 / -1; grid-row: 2; }
  #header-center:empty { display: none; }
}
button.btn-mini { font-size: .75rem; padding: 3px 7px; border-radius: 6px; }
.rsvp button { padding: 5px 12px; }

/* Co-DM permissions, tag filters */
.perm-row { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; }
.perm-row label.check { font-size: .8rem; color: var(--muted); }
button.chip { cursor: pointer; font: inherit; font-size: .85rem; color: var(--text); }
button.chip.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* Chat */
.chat-box { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 8px 12px;
  height: min(60vh, 520px); overflow-y: auto; }
.msg { padding: 6px 0; border-bottom: 1px solid var(--border); }
.msg:last-child { border-bottom: 0; }
.msg-head { font-size: .9rem; }
.msg .pre { margin-top: 2px; }
.msg-actions { display: flex; gap: 10px; margin-top: 2px; }
.msg.mine .msg-head strong { color: var(--accent); }
.chat-compose { margin-top: 8px; align-items: flex-end; }
.chat-compose textarea { min-height: 44px; }
#account a.help-link { color: var(--muted); text-decoration: none; font-size: .85rem; }
#account a.help-link:hover { color: var(--text); text-decoration: underline; }

/* Dice tray: the d20 button sits in the header center next to Admin */
#header-center { display: flex; align-items: center; gap: 8px; }
.dice-btn { display: inline-flex; align-items: center; justify-content: center; padding: 5px 8px; color: var(--accent); }
.dice-btn:hover, .dice-btn[aria-expanded="true"] { background: var(--surface-2); }
.dice-tray {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 50;
  width: min(360px, calc(100vw - 32px)); max-height: calc(100vh - 80px); overflow: auto;
  box-shadow: 0 12px 32px rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 10px;
}
.dice-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.die { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; color: var(--accent); }
.die span { font-size: .75rem; color: var(--text); font-weight: 600; }
.die:hover { background: var(--surface-2); }
.dice-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.stepper { display: inline-flex; align-items: center; gap: 6px; margin-left: 4px; }
.stepper button { padding: 1px 9px; }
.stepper strong { min-width: 2ch; text-align: center; }
.dice-log { display: flex; flex-direction: column; gap: 4px; border-top: 1px solid var(--border); padding-top: 8px; }
.dice-log > div { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.dice-log > div strong { color: var(--text); }
.dice-log > div.latest strong { font-size: 1.3rem; color: var(--accent); }
@media (max-width: 640px) { .dice-tray { top: 104px; } }

/* Character equipment, coins and attacks */
table.inventory td { vertical-align: top; }
.coins { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.coins label { display: flex; flex-direction: column; gap: 2px; margin: 0; }
.coins input { width: 76px; }
.attacks { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; }

/* Play tracking on the character sheet */
.play h4 { margin: 12px 0 4px; }
.hp-box { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.hp-box > div:first-child { display: flex; align-items: baseline; gap: 6px; }
.hp-now { font-size: 1.8rem; }
.play-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.slot-label { min-width: 2.5rem; }
input.pip { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.chip.toggle { position: relative; cursor: pointer; user-select: none; }
.chip.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.chip.toggle.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chip.toggle:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Feature switches: notices for users, badges for admins, the Admin → Features table */
.off-note { border-style: dashed; color: var(--muted); }
.badge.off-badge { background: transparent; border: 1px dashed var(--muted); color: var(--muted); font-size: .7rem; font-weight: 500; }
table.features td { vertical-align: top; }
table.features td:first-child { width: 60%; }
.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; margin: 0; }

/* Text kept when an admin signed you out */
.drafts-banner { max-width: 900px; margin: 12px auto 0; border-color: var(--accent); }

/* Scheduled maintenance banner, under the header on every page */
.maint-banner {
  padding: 8px 16px; text-align: center; font-size: .9rem;
  background: var(--accent); color: var(--accent-text);
}
.maint-banner .maint-msg { display: block; font-size: .85rem; opacity: .9; }

/* What's new */
.patch-note ul { margin: .5rem 0 .25rem; padding-left: 1.2rem; }
.patch-note li { margin: .2rem 0; }
.new-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-left: 4px; vertical-align: super; }

/* Admin: two labelled tab rows (Site, Inbox) */
.admin-nav { margin: 16px 0 20px; }
.admin-nav .tabs { margin: 0; align-items: center; overflow-y: hidden; }
.admin-nav .tabs + .tabs { margin-top: 4px; }
.tabs-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); min-width: 4.5rem; padding-right: 4px; }

/* Accessibility: visible keyboard focus everywhere, a skip link, and calmer motion when asked */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.skip-link {
  position: absolute; left: 8px; top: -48px; z-index: 100; padding: 8px 14px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: 8px; }
#app:focus { outline: none; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* Printing a character sheet (Print button, or the browser's print / Save as PDF) */
@media print {
  :root, :root[data-theme="dark"], :root:not([data-theme="light"]) {
    --bg: #fff; --surface: #fff; --surface-2: #f3f3f3; --text: #000; --muted: #444; --border: #bbb;
    --accent: #6d1f1b; --accent-text: #fff; --shadow: none;
  }
  body { background: #fff; color: #000; font-size: 11pt; }
  header.topbar, nav.tabs, .maint-banner, .drafts-banner, .skip-link, #toast, .dice-tray, .no-print,
  #app > a.small, #tab > a.small, button, .btn, .hp-box .row, .chip button { display: none !important; }
  main { max-width: none; padding: 0; }
  .builder { display: flex; flex-direction: column; gap: 10px; }
  .builder-summary { position: static; order: -1; }
  .builder-form { gap: 10px; }
  .chip.toggle:not(.on) { display: none; }
  .play h4:has(+ .chips:not(:has(.on))) { display: none; }
  .card { box-shadow: none; border: 1px solid #bbb; break-inside: avoid; padding: 10px 12px; }
  details.feature { break-inside: avoid; }
  details.feature > summary { list-style: none; font-weight: 600; }
  details.feature > summary::-webkit-details-marker { display: none; }
  a { color: #000; text-decoration: none; }
  input.pip { accent-color: #000; }
}

/* Initiative tracker */
.tracker { margin-bottom: 16px; }
.tracker-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.tracker-list li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); }
.tracker-list li.active { border-color: var(--accent); background: var(--surface-2); box-shadow: inset 4px 0 0 var(--accent); font-weight: 600; }
.tracker-list .trk-init { width: 64px; }
.tracker-list .trk-init-val { width: 2.5rem; text-align: center; font-weight: 700; }
.tracker-list .trk-name { flex: 1; min-width: 0; }
.tracker-list .trk-hp { width: 68px; }
.trk-form { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.trk-form input { width: 76px; }
.trk-form input[name="name"] { flex: 1; min-width: 140px; }

/* First-time guides */
.guide { border-color: var(--accent); }
.guide-steps { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.guide-steps li { display: flex; gap: 8px; align-items: baseline; }
.guide-steps li.done { color: var(--muted); }
.guide-steps li.done > span:nth-child(2) { text-decoration: line-through; }
.guide-check { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 18px; height: 18px;
  border: 1.5px solid var(--border); border-radius: 50%; font-size: 12px; line-height: 1; }
.guide-steps li.done .guide-check { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Sign-in: one centred stack, provider buttons the same width */
.auth-buttons { display: flex; flex-direction: column; align-items: stretch; gap: 10px; width: min(300px, 100%); margin: 0 auto; }
.auth-buttons > button:not(.link) { min-height: 44px; font-weight: 600; }
.auth-buttons > button.link { align-self: center; margin-top: 4px; padding: 8px 4px; }

/* Touch screens: text-style buttons get a bigger tap area without changing how they look */
@media (pointer: coarse) {
  button.link { padding: 8px 4px; margin: -8px -4px; }
  .tabs a { padding-top: 11px; padding-bottom: 11px; }
}

/* ---------- Layout fixes for phone, tablet and desktop ---------- */
select { max-width: 100%; text-overflow: ellipsis; }
.brand { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.brand img { flex: none; }
#account .btn-mini, #account a { white-space: nowrap; }
#welcome-guide:not(:empty) { display: block; margin-top: 16px; }
/* Member role pickers in the Config tab's Table card keep their labels readable. */
#tab table select[data-role] { min-width: 7.5rem; }

@media (max-width: 480px) {
  /* Signed in, the header holds the logo, Admin, Help and Sign out: the logo alone stands in for the name. */
  .topbar:has(#account:not(:empty)) .brand-text { display: none; }
  .topbar { padding: 10px 12px; }
  #account { gap: 8px; }
  a.btn.admin-btn { padding: 5px 10px; }
  .home-actions > * { flex: 1 1 auto; text-align: center; }
  /* Initiative tracker: the monster name gets its own line. */
  .trk-form input[name="name"] { flex-basis: 100%; }
  .trk-form input { flex: 1 1 64px; width: auto; }
  /* Admin → Features: each feature becomes a small card instead of a squeezed three-column row. */
  table.features thead { display: none; }
  table.features tr { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); align-items: center; }
  table.features td { display: block; padding: 0; border: 0; width: auto !important; }
  table.features td:first-child { grid-column: 1 / -1; }
  table.features td:last-child select { width: 100%; }
}

@media (pointer: coarse) {
  .chips button, button.chip { min-height: 36px; }
  .brand, #account a.help-link { padding: 6px 0; }
}
@media (pointer: coarse) {
  #account .btn-mini, a.btn.admin-btn, .dice-btn { min-height: 38px; display: inline-flex; align-items: center; }
}
@media (max-width: 640px) {
  /* Signed in, everything fits on one header row (logo, dice, account), so the dice no longer takes a second row. */
  .topbar:has(#account:not(:empty)) { grid-template-columns: auto 1fr auto; }
  .topbar:has(#account:not(:empty)) #header-center { grid-column: auto; grid-row: auto; justify-self: center; }
  .topbar:has(#account:not(:empty)) ~ .dice-tray, .dice-tray { top: 64px; }
}

/* "Find a date" polls on the Calendar tab. */
.poll-options { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.poll-opt { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.poll-opt.best { border-color: var(--accent); }
.poll-opt.past { opacity: .6; }
.poll-when { flex: 1 1 240px; min-width: 0; overflow-wrap: anywhere; }
.poll-actions { gap: 8px; align-items: center; }
.poll-vote { gap: 4px; flex-wrap: nowrap; }
.poll-vote button { padding: 6px 10px; font-size: .9rem; }
.poll-row input[type="date"] { min-width: 0; }
@media (max-width: 480px) {
  .poll-actions, .poll-vote { width: 100%; }
  .poll-vote button { flex: 1; }
}

/* Loot tab. */
.coin-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.coin { text-align: center; padding: 8px 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.coin-n { font-size: 1.25rem; font-weight: 600; overflow-wrap: anywhere; }
.coin-inputs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.coin-inputs .field { margin: 0; min-width: 0; }
.loot-item { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.loot-main { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }
.loot-actions { gap: 6px; align-items: center; }
.loot-actions button[data-qty] { padding: 4px 10px; }
@media (max-width: 520px) {
  .coin-row, .coin-inputs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Wiki tab. */
.wiki-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.wiki-card { display: block; padding: 10px 12px; text-decoration: none; color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.wiki-card:hover, .wiki-card:focus-visible { border-color: var(--accent); }
.wiki-card .small { margin-top: 2px; }
.wiki-summary { font-style: italic; color: var(--muted); margin: 10px 0 0; }
.wiki-body { margin-top: 10px; overflow-wrap: anywhere; line-height: 1.6; }
.wiki-body p { margin: 0 0 10px; }
.wiki-body h4 { margin: 14px 0 6px; }
.wiki-body ul { margin: 0 0 10px; padding-left: 1.25rem; }
.wiki-secret { margin-top: 14px; padding: 10px 12px; border: 1px dashed var(--accent); border-radius: 8px; background: var(--surface-2); overflow-wrap: anywhere; }
.wiki-secret p { margin: 6px 0 0; }
.wiki-missing { color: var(--muted); text-decoration: underline dotted; }

/* Example campaign: banner for visitors, card on the home page. */
.demo-banner { margin-top: 8px; padding: 10px 12px; border: 1px solid var(--accent); border-radius: 8px; background: var(--surface-2); font-size: .9rem; line-height: 1.5; }
.demo-card { margin-top: 12px; border-color: var(--accent); }

/* Sessions: "Previously on…", timeline, attendance. */
.previously { border-left: 4px solid var(--accent); }
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 4px 0 12px 12px; }
.timeline li::before { content: ""; position: absolute; left: -25px; top: 9px; width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
.timeline li.milestone::before { background: var(--accent); }
.timeline li.setup::before { background: var(--surface); border: 2px solid var(--muted); width: 6px; height: 6px; }
.tl-body { overflow-wrap: anywhere; }
.attend-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 16px; }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 4px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); }

/* Character sheet: level-up prompt. */
.levelup { margin-top: 12px; border-color: var(--accent); }

/* Handouts tab. */
.handout-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.handout-card { display: flex; flex-direction: column; gap: 6px; padding: 8px; text-align: left; cursor: pointer; font: inherit; color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.handout-card:hover, .handout-card:focus-visible { border-color: var(--accent); }
.handout-thumb { aspect-ratio: 4 / 3; border-radius: 6px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.handout-thumb img { width: 100%; height: 100%; object-fit: cover; }
.handout-pdf { font-weight: 700; letter-spacing: .1em; color: var(--accent); border: 2px solid var(--accent); border-radius: 4px; padding: 6px 10px; }
.handout-dialog { max-width: 900px; }
.handout-full { display: block; max-width: 100%; height: auto; max-height: 70vh; margin: 8px auto 0; border-radius: 6px; }
.handout-viewers { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }

/* Checklists folded to a link, and "Don't remind me" kept well away from "Hide" (opposite corner of the card). */
.guide-folded { margin: 12px 0 0; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.guide-folded .link { font-weight: 600; }
.guide-never { margin: 14px 0 0; padding-top: 10px; border-top: 1px solid var(--border); }

/* Front page for signed-out visitors. */
.landing { max-width: 980px; margin: 8px auto 40px; padding: 0 0 8px; }
.landing h2 { font-size: 1.5rem; }
.landing-features { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 12px; }
.landing-features .card h3 { margin: 0; }
.landing-previews { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-top: 12px; pointer-events: none; }
.landing-steps { max-width: 620px; margin: 12px auto 16px; padding-left: 1.4rem; line-height: 1.6; }
.landing-steps li { margin-bottom: 8px; }

/* Game night: two columns on wide screens (initiative and party | notes and handouts), one on phones. */
.game-night { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; margin-top: 12px; align-items: start; }
@media (max-width: 860px) { .game-night { grid-template-columns: 1fr; } }
.gn-pc { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.gn-pc:last-child { border-bottom: 0; }
.gn-pc-main { flex: 1 1 200px; min-width: 0; }
.gn-hp { font-size: 1.1rem; font-weight: 600; margin-top: 2px; }
.gn-hp-tools { gap: 6px; }
.gn-hp-tools input { width: 4.5rem; }
.gn-handout { padding: 6px 0; border-bottom: 1px solid var(--border); gap: 8px; }
.gn-handout:last-child { border-bottom: 0; }
.gn-handout img { border-radius: 4px; object-fit: cover; }
#gn-notes { width: 100%; font: inherit; line-height: 1.5; }

/* Initiative tracker: monster stat blocks (DM only). */
.statblock { max-width: 640px; line-height: 1.5; overflow-wrap: anywhere; }
.statblock hr { border: 0; border-top: 2px solid var(--accent); margin: 8px 0; }
.statblock h4 { margin: 14px 0 4px; color: var(--accent); border-bottom: 1px solid var(--border); }
.statblock p { margin: 0 0 6px; }
.statblock-abilities { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; text-align: center; margin: 8px 0; font-size: .9rem; }
@media (max-width: 420px) { .statblock-abilities { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.trk-form { flex-wrap: wrap; }

/* Signed out: Log in / Sign up in the header and on the front page; the forms open in a pop-up. */
#account [data-auth] + [data-auth] { margin-left: 6px; }
.hero-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.hero-actions button { min-width: 130px; }
.auth-dialog { position: relative; width: min(400px, calc(100vw - 48px)); padding: 20px; box-sizing: border-box; }
.auth-dialog #auth-form { padding: 0; }
.auth-dialog h2 { margin: 0 0 14px; padding-right: 32px; }
.auth-close { position: absolute; top: 14px; right: 12px; background: none; border: 0; font-size: 1.1rem; color: var(--muted); cursor: pointer; padding: 4px 8px; }
.auth-dialog .auth-buttons { margin: 0; }
.auth-or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; margin: 14px 0 10px; }
.auth-or::before, .auth-or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* Campaign book: readable on screen, each part on a new page when printed. */
.book { max-width: 760px; margin: 12px auto 0; line-height: 1.6; overflow-wrap: anywhere; }
.book h2 { border-bottom: 2px solid var(--accent); padding-bottom: 4px; margin: 0 0 12px; }
.book h3 { margin: 18px 0 4px; }
.book h4 { margin: 14px 0 4px; }
.book-cover { text-align: center; padding: 40px 0 32px; }
.book-cover h1 { font-size: 2.4rem; margin: 12px 0; }
.book-section { margin-top: 40px; }
.book-entry { margin-bottom: 14px; }
.book-kind { color: var(--accent); }
.book-credit { margin-top: 40px; }
@media print {
  body.printing-book #c-head, body.printing-book #app > a.small { display: none !important; }
  .book { max-width: none; margin: 0; font-size: 11pt; }
  .book-cover { min-height: 85vh; display: flex; flex-direction: column; justify-content: center; }
  .book-section { break-before: page; margin-top: 0; }
  .book-entry { break-inside: avoid; }
  .book h2, .book h3, .book h4 { break-after: avoid; }
}

/* Log in / Sign up pop-up: one column the full width of a narrower dialog. */
dialog.auth-modal { width: min(420px, calc(100vw - 32px)); }
dialog.auth-modal .auth-dialog { width: 100%; padding: 24px; }
.auth-dialog .auth-buttons { width: 100%; }
.auth-dialog .auth-close { top: 18px; right: 14px; }
.auth-dialog #auth-form > .primary { width: 100%; min-height: 44px; font-weight: 600; }
.auth-dialog > p.small { text-align: center; }
@media (max-width: 400px) { dialog.auth-modal .auth-dialog { padding: 18px; } }
