:root {
  --bg: #f4efe6;
  --card: #fffdf9;
  --ink: #261f1a;
  --muted: #7b7064;
  --line: #e3d9ca;
  --accent: #7a2e1f;
  --accent-ink: #fff8f2;
  --accent-soft: #f3e1d8;
  --warn: #c2410c;
  --danger: #b91c1c;
  --danger-ink: #ffffff;
  --danger-soft: #fde8e8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(38, 31, 26, 0.06), 0 4px 14px rgba(38, 31, 26, 0.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161311;
    --card: #211c19;
    --ink: #f1eae1;
    --muted: #a39788;
    --line: #372f29;
    --accent: #e0846c;
    --accent-ink: #1d0f0a;
    --accent-soft: #3a231b;
    --warn: #fb923c;
    --danger: #ef4444;
    --danger-ink: #1a0505;
    --danger-soft: #3b1414;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 "Atkinson Hyperlegible", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
body.is-dragging { cursor: grabbing; user-select: none; -webkit-user-select: none; }
main { max-width: 1320px; margin: 0 auto; padding: 20px 16px 96px; }
main.narrow { max-width: 620px; }
a { color: var(--accent); }
.eyebrow a { color: inherit; text-decoration: none; }
.sub { color: var(--muted); margin: 6px 0 18px; }

h1, h2, h3 { font-family: Fraunces, Georgia, serif; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: clamp(26px, 6vw, 36px); line-height: 1.1; }
h2 { font-size: 17px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
h2 .muted { font-family: "Atkinson Hyperlegible", sans-serif; font-size: 13px; font-weight: 400; }
h3 { font-size: 16px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); margin: 0 0 2px; }
.muted { color: var(--muted); font-size: 13px; }

.top { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 16px; }
.top > div:first-child { min-width: 0; }
.top h1 { overflow-wrap: anywhere; }
.top-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.live::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #2f8a5b; margin-right: 6px; vertical-align: 1px; }
.pill.offline::before { background: var(--muted); }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.btn { background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 10px 14px; border-radius: 10px; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.small { font-size: 13px; padding: 7px 11px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }

/* ----- Tier tabs ----- */
.tabs { display: grid; grid-template-columns: repeat(var(--tiers, 3), minmax(0, 1fr)); gap: 6px; margin-bottom: 14px; }
.tabs button {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 9px 8px;
  font-family: Fraunces, Georgia, serif; font-weight: 700; font-size: 16px; text-align: center;
}
.tabs button .left { display: block; font: 400 12px/1.3 "Atkinson Hyperlegible", sans-serif; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tabs button[aria-selected="true"] .left { color: inherit; opacity: 0.85; }

/* ----- Board -----
   Phone: unseated players, then the DMs, then the tables; either pool folds down to its heading.
   Wider: the unseated players and DMs in a sidebar that stays put while the tables scroll. */
.board { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.pools { display: grid; gap: 12px; align-content: start; }
.tables { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); align-content: start; }
@media (min-width: 760px) {
  .board { grid-template-columns: minmax(240px, 300px) minmax(0, 1fr); align-items: start; gap: 14px; }
  .pools { display: grid; gap: 12px; align-content: start; position: sticky; top: 12px; max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain; }
}
@media (min-width: 1600px) {
  main:not(.narrow) { max-width: 1680px; }
}

.pool h2, .table header { margin-bottom: 8px; }
.pool.folded h2 { margin-bottom: 0; }
.fold-head { display: block; }
.fold { all: unset; box-sizing: border-box; display: flex; align-items: baseline; gap: 8px; width: 100%; cursor: pointer; font: inherit; color: inherit; border-radius: 6px; padding: 2px 0; -webkit-tap-highlight-color: transparent; }
.fold .muted { margin-left: auto; }
.fold:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.chev { width: 8px; height: 8px; flex: none; align-self: center; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-2px) rotate(45deg); transition: transform 0.15s; opacity: 0.6; }
.fold[aria-expanded="false"] .chev { transform: rotate(-45deg); }
/* A bigger target on touch screens, where the heading is the whole control */
@media (pointer: coarse) { .fold { min-height: 40px; align-items: center; } .fold .muted { align-self: center; } }
@media (prefers-reduced-motion: reduce) { .chev { transition: none; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 36px; align-content: flex-start; }
.placeholder { color: var(--muted); font-size: 13px; padding: 8px 2px; }

.table header { display: flex; align-items: center; gap: 8px; }
.table header h3 { flex: 1; }
.seats { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }
.seats.over { color: var(--warn); font-weight: 700; }
.remove { width: 28px; height: 28px; border-radius: 8px; color: var(--muted); font-size: 18px; line-height: 1; }
.remove:hover { background: var(--accent-soft); color: var(--accent); }

.dm-slot { border: 1px dashed var(--line); border-radius: 10px; padding: 4px; margin-bottom: 8px; min-height: 40px; display: flex; align-items: center; }
.dm-slot.empty { padding-left: 10px; }
.dm-slot.empty .muted { color: var(--warn); }

.balance { display: flex; flex-wrap: wrap; gap: 4px 8px; min-height: 22px; align-items: center; margin-bottom: 8px; }
.tally { display: inline-flex; align-items: center; gap: 3px; font-size: 13px; font-variant-numeric: tabular-nums; }
.tally.many b { color: var(--warn); }

.add-table {
  border: 2px dashed var(--line); border-radius: var(--radius); min-height: 120px; color: var(--muted);
  font-weight: 700; font-size: 15px;
}
.add-table:hover { border-color: var(--accent); color: var(--accent); }
.add-table small { display: block; margin-top: 4px; font-size: 12px; font-weight: 400; color: var(--muted); }

/* Where the dragged or picked chip can go */
.drop-here { outline: 2px solid var(--accent); outline-offset: 2px; background: var(--accent-soft); }
.picking .can-drop { outline: 2px dashed var(--accent); outline-offset: 2px; cursor: pointer; }

/* ----- Chips ----- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line); font-weight: 700; font-size: 14px;
  cursor: grab; user-select: none; -webkit-user-select: none; max-width: 100%;
}
.chip .text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.chip .name, .chip .detail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .detail { font-size: 11.5px; font-weight: 400; color: var(--muted); max-width: 34ch; }
.chip:has(.detail) { border-radius: 18px; padding-top: 3px; padding-bottom: 3px; }
.chip.selected { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent); }
.chip.dragging { opacity: 0.35; }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.grip { display: inline-flex; touch-action: none; -webkit-touch-callout: none; }
.drag-ghost { position: fixed; z-index: 30; pointer-events: none; margin: 0; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22); background: var(--card); }

/* Class icon: the SVG as a white mask on a disc of the class's color */
.cls {
  position: relative; display: inline-block; width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: var(--c);
}
.cls::after {
  content: ""; position: absolute; inset: 4px; background: #fff;
  -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat;
}
.cls.small { width: 22px; height: 22px; }
.cls.small::after { inset: 3px; }
.cls.dm-badge {
  background: var(--ink); color: var(--bg); font-size: 10px; font-weight: 700; letter-spacing: 0.02em;
  display: inline-grid; place-items: center;
}
.cls.dm-badge::after { content: none; }

.hint { color: var(--muted); font-size: 13px; text-align: center; margin: 18px 0 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 700;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 40;
}
.toast.show { opacity: 1; }

/* ----- Tap-to-move bar ----- */
.picking-bar {
  position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(560px, calc(100% - 24px)); z-index: 25; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--ink); color: var(--bg); padding: 8px 8px 8px 16px; border-radius: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.picking-bar .btn.ghost { color: var(--bg); border-color: rgba(255, 255, 255, 0.35); flex: none; }

/* ----- Share sheet ----- */
.sheet { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); display: grid; align-items: end; justify-items: center; z-index: 35; }
.sheet > .card {
  width: 100%; max-width: 620px; max-height: 85dvh; overflow-y: auto; border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
@media (min-width: 760px) { .sheet { align-items: center; } .sheet > .card { border-radius: 20px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.share-h { margin: 14px 0 2px; }
.share-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.share-row > div { flex: 1; min-width: 0; }
.share-row small { display: block; color: var(--muted); font-size: 12px; }
.share-row code { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----- DM view ----- */
.dm-wait { text-align: center; padding: 28px 16px; }
.dm-table-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 10px; }
.dm-table-head h2 { font-size: clamp(20px, 5vw, 26px); }
.balance.big { gap: 6px 12px; margin-bottom: 12px; }
.balance.big .tally { font-size: 15px; }
.roster { list-style: none; margin: 0; padding: 0; }
.roster li { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-top: 1px solid var(--line); font-size: 17px; }
.roster .cls { width: 36px; height: 36px; }
.roster .cls::after { inset: 6px; }
.roster .name { font-weight: 700; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.roster li.fresh { animation: fresh 2.4s ease-out; }
@keyframes fresh { from { background: var(--accent-soft); } to { background: transparent; } }

/* ----- Landing ----- */
.mine { list-style: none; padding: 0; margin: 8px 0 0; }
.mine li { padding: 8px 0; border-top: 1px solid var(--line); }
#mine h2 { margin-top: 28px; }

/* ----- Forms ----- */
input:not([type="checkbox"]), select, textarea {
  font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { width: 100%; resize: vertical; font-size: 13px; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.field { display: grid; gap: 4px; font-weight: 700; font-size: 14px; margin: 0 0 12px; }
fieldset.field { border: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; }
fieldset.field legend { padding: 0; margin-bottom: 6px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; font-size: 14px; cursor: pointer; white-space: nowrap; }
.link { color: var(--accent); text-decoration: underline; padding: 0; font-weight: 700; }
.warn { color: var(--warn); }
.add-row { display: flex; gap: 6px; margin-top: 10px; }
.add-row .add-name { flex: 1 1 0; width: 0; }
.add-row select { max-width: 40%; }
.pool .add-row { padding-top: 10px; border-top: 1px dashed var(--line); }
.create { margin: 18px 0 10px; }
.create .field input { width: 100%; }

/* ----- People: unknown class, waitlist, characters ----- */
.cls.unknown { background: var(--muted); color: var(--card); font-weight: 700; font-size: 15px; display: inline-grid; place-items: center; }
.cls.unknown::after { content: none; }
.chip.waitlist { border-style: dashed; }
.chip.waitlist .name::after { content: " · WL"; color: var(--muted); font-weight: 400; font-size: 12px; }
.who { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.character { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

/* ----- Edit event ----- */
.lists { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); align-items: start; }
.lists h2 { margin-bottom: 6px; }
.lists .import { grid-column: 1 / -1; }
/* The event's own settings first, across the top: name, seats and tiers side by side when there's room */
.lists .settings { grid-column: 1 / -1; display: grid; gap: 0 20px; grid-template-columns: minmax(0, 1fr); }
.lists .settings > h2, .lists .settings > .danger { grid-column: 1 / -1; }
.lists .settings .field input:not([type="checkbox"]) { width: 100%; }
@media (min-width: 760px) { .lists .settings { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 2fr); } }
.lists .import p { margin: 0 0 8px; }
.preview { list-style: none; margin: 10px 0; padding: 0; max-height: 360px; overflow-y: auto; }
.preview li { display: flex; align-items: center; gap: 10px; padding: 6px 2px; border-top: 1px solid var(--line); }
.preview li.known { opacity: 0.5; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.tag.warn { background: transparent; border: 1px solid var(--warn); color: var(--warn); }
.tag.known { background: var(--bg); color: var(--muted); }
.people { list-style: none; margin: 0; padding: 0; }
.person { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.person .name-input { font-weight: 700; padding: 4px 8px; width: 100%; }
.person select { flex: none; }
.person .where { font-size: 12px; min-width: 60px; }
.person.waitlist .name-input { border-style: dashed; }
@media (max-width: 520px) {
  /* Icon, name and remove on one line; class, level, waitlist and seat underneath */
  .person .who { flex-basis: calc(100% - 80px); }
  .person .remove { order: 1; }
  .person select, .person .level, .person .check, .person .where { order: 2; }
}
.share-tier { margin: 10px 0 0; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* DM view: name over character */
.roster .who .name { flex: none; }
.level { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.level input { width: 4.2em; padding: 4px 6px; }
.apl { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; font-variant-numeric: tabular-nums; }
.dm-table-stats { display: inline-flex; align-items: center; gap: 10px; }
.danger { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.danger-btn { background: transparent; color: var(--warn); border: 1px solid var(--warn); }
.danger-btn:hover { background: var(--warn); color: var(--card); }
form.inline { display: inline; }
[hidden] { display: none !important; }
#account .btn { display: inline-block; text-decoration: none; }
a.btn { text-decoration: none; display: inline-block; }

/* ----- Danger dialog: deleting the event, removing a tier with people in it ----- */
.danger-dialog {
  width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; overflow: auto;
  border: 3px solid var(--danger); border-radius: 16px; background: var(--card); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.danger-dialog::backdrop { background: rgba(60, 0, 0, 0.55); }
.danger-band {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px; background: var(--danger); color: var(--danger-ink);
  font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; font-size: 14px;
}
.danger-body { padding: 16px 18px 18px; display: grid; gap: 12px; }
.danger-body h2 { font-size: 22px; display: block; overflow-wrap: anywhere; }
.danger-body p { margin: 0; }
.danger-losses { margin: 0; padding: 10px 14px 10px 32px; background: var(--danger-soft); border-radius: 10px; color: var(--danger); font-weight: 700; }
.danger-losses li + li { margin-top: 4px; }
.danger-type { display: grid; gap: 6px; font-size: 14px; }
.danger-type b { overflow-wrap: anywhere; }
.danger-type input { width: 100%; font: inherit; padding: 10px 12px; border-radius: 10px; border: 2px solid var(--line); background: var(--bg); color: var(--ink); }
.danger-type input:focus { outline: none; border-color: var(--danger); }
.danger-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.danger-go { background: var(--danger); color: var(--danger-ink); }
.danger-go:disabled { opacity: 0.4; cursor: not-allowed; }
@media (max-width: 420px) { .danger-actions .btn { flex: 1 1 auto; } }
