:root {
  --bg: #f4efe4;
  --panel: #fffaf0;
  --ink: #2b2420;
  --muted: #685c52;
  --line: #e0d5c2;
  --accent: #8a3b12;
  --accent-ink: #fff;
  --claim: #2f6b3a;
  --sell: #735810;
  --contested: #9b2c2c;
  --contested-ink: #fff;
  --chip: #efe6d4;
  --radius: 10px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1815;
    --panel: #26221e;
    --ink: #ece4d6;
    --muted: #a3968a;
    --line: #3a342d;
    --accent: #d27a45;
    --accent-ink: #1b1815;
    --claim: #6fbf7d;
    --sell: #d9b54a;
    --contested: #e88585;
    --contested-ink: #1b1815;
    --chip: #332d27;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }

a, a:visited { color: var(--accent); }

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand-title { font-family: Georgia, serif; font-size: 1.2rem; font-weight: 700; }
.session { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; color: var(--muted); }
.demo-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.session strong { color: var(--ink); }

main { max-width: 960px; margin: 0 auto; padding: 16px; }

.announcement {
  max-width: 960px;
  margin: 16px auto 0;
  padding: 12px 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  border: 1px solid var(--accent);
  border-left-width: 4px;
  border-radius: var(--radius);
  background: var(--panel);
}
/* Keep the banner inside the page's side margins on narrow screens. */
@media (max-width: 992px) { .announcement { margin: 16px 16px 0; } }
.announcement strong { color: var(--accent); }
.announcement p { margin: 4px 0 0; white-space: pre-wrap; }

h2 { font-family: Georgia, serif; margin: 0 0 4px; }
h3 { margin: 0 0 8px; font-size: 1.05rem; }
h4 { margin: 16px 0 8px; font-size: 0.95rem; color: var(--muted); }
.treasure-total { margin-bottom: 4px; }
.treasure-total strong { font-family: Georgia, serif; font-size: 1.15rem; }
.hint { color: var(--muted); margin: 0 0 12px; font-size: 0.92rem; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

/* Login */
.login { text-align: center; padding: 32px 16px; }
.login-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
  margin: 20px auto 0;
}
.login-error { color: var(--contested); min-height: 1.5em; margin: 8px 0 0; }
.login-hint { margin: 0; color: var(--muted); font-style: italic; }
.demo-hint { max-width: 420px; margin: 16px auto 0; padding-top: 12px; border-top: 1px solid var(--line); }

/* Tabs: two rows. On narrow screens a row scrolls sideways instead of
   squashing labels. */
.tabs { margin-bottom: 16px; }
.tab-row {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs button {
  white-space: nowrap;
  flex-shrink: 0;
  border: 0;
  background: none;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.badge {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 6px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.8rem;
  text-align: center;
}

/* Forms */
.item-form { display: grid; grid-template-columns: 2fr 1fr 0.7fr 1fr; gap: 8px; }
.item-form .notes, .item-form .checkbox-field { grid-column: 1 / -1; }
.checkbox-field { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-field input { width: auto; margin: 0; accent-color: var(--accent); }
.checkbox-field:has(input:disabled) { opacity: 0.5; cursor: default; }
.quantity { color: var(--muted); font-weight: 600; }
.attuned-count { font-weight: 400; }
.attuned-count.over { color: var(--contested); font-weight: 600; }
.coin-weight { margin: 8px 0 0; }
.item-form .actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
textarea { resize: vertical; min-height: 2.6em; }
label.field { display: flex; flex-direction: column; gap: 2px; font-size: 0.85rem; color: var(--muted); }

button.primary, button.secondary, button.small {
  border-radius: 8px;
  cursor: pointer;
  padding: 8px 14px;
  border: 1px solid var(--accent);
}
button.primary { background: var(--accent); color: var(--accent-ink); }
button.secondary { background: none; color: var(--accent); }
button.small { padding: 4px 10px; font-size: 0.88rem; background: none; border-color: var(--line); }
button.small:hover { border-color: var(--accent); }
/* Entries that can be reordered keep their arrows in a strip down the right
   edge: up arrow in the top corner, down arrow in the bottom corner. */
.item.movable { position: relative; padding-right: 48px; min-height: 64px; }
.move-buttons {
  position: absolute;
  top: 6px;
  right: 6px;
  bottom: 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
button.small.arrow { padding: 2px 8px; line-height: 1.2; }
button.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; }
button:disabled { opacity: 0.5; cursor: default; }

.gold-stats { display: flex; flex-wrap: wrap; gap: 8px 40px; margin-bottom: 12px; }
.coin-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 8px;
  align-items: end;
}
.send-coins { margin-top: 8px; }
.send-coin-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.gold-amount { font-size: 1.6rem; font-family: Georgia, serif; font-weight: 700; }

/* Item lists */
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  justify-content: space-between;
}
.item-main { min-width: 0; flex: 1 1 260px; }
.item-name { font-weight: 600; }
.item-meta { color: var(--muted); font-size: 0.88rem; }
.item-notes { font-size: 0.9rem; margin-top: 2px; white-space: pre-wrap; }
.item-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.empty { color: var(--muted); font-style: italic; margin: 0; }

.tag {
  display: inline-block;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  background: var(--chip);
  color: var(--muted);
  margin-left: 6px;
  vertical-align: middle;
}
.tag.attuned { color: var(--claim); font-weight: 600; }

.votes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.vote {
  font-size: 0.8rem;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--muted);
}
.vote.claim { color: var(--claim); font-weight: 600; }
.vote.sell { color: var(--sell); font-weight: 600; }
.vote.me { outline: 1px solid var(--line); }

button.small.claim[aria-pressed="true"] { background: var(--claim); color: var(--panel); border-color: var(--claim); }
button.small.sell[aria-pressed="true"] { background: var(--sell); color: var(--panel); border-color: var(--sell); }

.panel.contested { border-color: var(--contested); }
.panel.contested h3 { color: var(--contested); }

.pool-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.pool-summary strong { font-family: Georgia, serif; font-size: 1.15rem; }

.lifestyle-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}
.lifestyle-option {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.lifestyle-option input { width: auto; margin: 0; grid-row: span 2; accent-color: var(--accent); }
.lifestyle-option:has(input:checked) { border-color: var(--accent); background: var(--chip); }
.lifestyle-name { font-weight: 600; }
/* Continued Work: the three short options share the top row and the two
   with notes share the bottom row, each row filling the full width. */
.work-options { grid-template-columns: repeat(6, 1fr); }
.work-options .lifestyle-option { grid-column: span 2; }
.work-options .lifestyle-option.with-note { grid-column: span 3; }
.work-options .lifestyle-option { align-items: start; align-content: start; }
.work-options .lifestyle-option input { margin-top: 4px; }
.lifestyle-option.with-note input { grid-row: span 3; }
.option-note { grid-column: 2; font-size: 0.85rem; margin-top: 4px; }
.lifestyle-note { margin: 12px 0 0; }

.afford-result strong { font-family: Georgia, serif; font-size: 1.5rem; display: block; }
.afford-result p { margin: 4px 0 0; }

.picker { max-width: 220px; margin-bottom: 12px; }
h3.spaced { margin-top: 16px; }

.edit-dialog {
  width: min(560px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  padding: 16px;
}
.edit-dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.edit-dialog .actions { gap: 8px; }
.confirm-dialog { width: min(420px, calc(100% - 32px)); }
.confirm-dialog p { margin: 0 0 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.ages-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.ages-form .field { width: 200px; }

.recipient-list { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0 12px; }
.recipient { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.recipient input { width: auto; margin: 0; accent-color: var(--accent); }
.edit-dialog .field textarea { margin-top: 2px; }

.offer .item-notes { margin: 4px 0; }
.counter {
  margin-top: 8px;
  padding: 8px 10px;
  border-left: 3px solid var(--line);
  background: var(--chip);
  border-radius: 0 8px 8px 0;
}
.counter.pending { border-left-color: var(--accent); }
.counter .item-actions { margin-top: 6px; }

.panel.dm-notes { border-style: dashed; }

.activity-list { list-style: none; margin: 0 0 8px; padding: 0; }
.activity-entry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.activity-entry:last-child { border-bottom: none; }
.activity-text { flex: 1 1 260px; min-width: 0; overflow-wrap: anywhere; }
.activity-time { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.activity-entry.undone .activity-text { color: var(--muted); }
.activity-tag { color: var(--muted); }
.activity-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.offsite-warning { color: var(--contested); margin: 4px 0 8px; }
.backup-groups { display: flex; flex-direction: column; gap: 8px; }
.backup-group summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.backup-group .items { margin-top: 4px; }
.backup-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.panel textarea + .dialog-actions { margin-top: 8px; }

.verdict {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  border-left: 4px solid var(--line);
  background: var(--chip);
}
.verdict strong { font-family: Georgia, serif; font-size: 1.15rem; display: block; }
.verdict p { margin: 4px 0 0; }
.verdict.good { border-left-color: var(--claim); }
.verdict.good strong { color: var(--claim); }
.verdict.bad { border-left-color: var(--contested); }
.verdict.bad strong { color: var(--contested); }

/* Friends and Allies: toggle buttons, highlighted when chosen. */
.ally-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}
.ally-count { margin: 0 0 8px; font-weight: 600; }
.ally-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  cursor: pointer;
}
.ally-option:hover:not(:disabled) { border-color: var(--accent); }
.ally-option[aria-pressed="true"] { border-color: var(--accent); background: var(--chip); box-shadow: inset 0 0 0 1px var(--accent); }
.ally-option[aria-pressed="true"] .lifestyle-name::before { content: "✓ "; color: var(--accent); }

.debt-form { display: flex; gap: 8px; align-items: end; margin-top: 12px; }
.debt-form textarea { flex: 1; min-width: 0; }

.sold-form { display: flex; gap: 6px; align-items: center; }
.sold-form input { width: 110px; padding: 4px 8px; }

.toast {
  position: fixed;
  /* Undo the browser's default popover placement and border. */
  inset: auto;
  margin: 0;
  border: none;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 8px;
  max-width: calc(100% - 32px);
}
.toast.error { background: var(--contested); color: var(--contested-ink); }

@media (max-width: 600px) {
  .tab-row { gap: 0; }
  .work-options .lifestyle-option,
  .work-options .lifestyle-option.with-note { grid-column: 1 / -1; }
  .tabs button { padding: 10px 6px; font-size: 0.9rem; }
  .coin-form { grid-template-columns: 1fr 1fr; }
  .coin-form button { grid-column: 1 / -1; justify-self: start; }
  .item-form { grid-template-columns: 1fr 1fr; }
  .item-form .name { grid-column: 1 / -1; }
}

/* Downtime: a horizontal timeline that scrolls sideways, then the event list. */
.downtime-form { grid-template-columns: 2fr 1fr 1fr; }
.panel-heading { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; justify-content: space-between; }
.timeline {
  overflow-x: auto;
  margin: 8px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
.timeline-track { position: relative; height: 92px; min-width: 100%; }
.timeline-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  padding: 2px 4px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
}
.timeline-event {
  position: absolute;
  top: 26px;
  height: 56px;
  margin-left: 1px;
  padding: 4px 6px;
  overflow: hidden;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--chip);
  font-size: 0.85rem;
  line-height: 1.3;
  user-select: none;
}
.timeline-event.movable { cursor: grab; touch-action: none; }
.timeline-event.movable:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.timeline-event.dragging { cursor: grabbing; z-index: 1; box-shadow: 0 2px 8px rgb(0 0 0 / 25%); opacity: 0.9; }
.timeline-event.locked {
  border-style: dashed;
  border-color: var(--muted);
  background: repeating-linear-gradient(135deg, var(--chip) 0 6px, var(--panel) 6px 12px);
}
.timeline-title, .timeline-days { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timeline-title { font-weight: 600; }
.timeline-days { color: var(--muted); font-size: 0.78rem; }
.gap-row { border-style: dashed; padding: 6px 12px; }
.downtime-event.locked { border-style: dashed; }

@media (max-width: 600px) {
  .downtime-form { grid-template-columns: 1fr 1fr; }
}
.send-dialog form { display: flex; flex-direction: column; gap: 10px; }

/* Continued Work income */
.option-income { grid-column: 2; margin-top: 4px; color: var(--ink); font-weight: 600; white-space: pre-line; }
.dm-income { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin: 4px 0 8px; }
.income-form { display: flex; flex-direction: column; gap: 10px; min-width: min(420px, 80vw); }
.income-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.income-modes, .income-fields { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.income-modes { grid-template-columns: 1fr; gap: 4px; }
.income-total { margin: 0; font-weight: 600; }
/* The option's own parts lay out in the card's grid; its description box
   sits under them. */
.option-label { display: contents; cursor: pointer; }
.lifestyle-option:has(.option-label) { cursor: default; }
.work-title { grid-column: 2; margin-top: 8px; padding: 6px 8px; font-size: 0.9rem; }
.work-title-text { margin: 0 0 4px; }
/* The DM's Future Plans: the option's description sits right under its name. */
.dm-work-name { margin-bottom: 0; }

/* The DM's Friends and Allies options */
.ally-count.over { color: var(--contested); }
.max-allies-form, .ally-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 12px; }
.max-allies-form input { width: 90px; }
.ally-form { margin: 12px 0 0; }
.ally-form .field { flex: 1 1 200px; }
.ally-form .dialog-actions { flex-basis: 100%; }
.credit { margin-top: 16px; }

/* Welcome, invite, and admin pages */
a.brand-title { color: inherit; text-decoration: none; }
.create-form { display: flex; flex-direction: column; gap: 10px; max-width: 360px; margin: 0 auto; text-align: left; }
.create-form .field { width: 100%; }
.create-form input { width: 100%; box-sizing: border-box; font-size: 1rem; }
.players-new-link { margin-top: 8px; }
.demo-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.demo-tools select { max-width: 11rem; }
.admin-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding: 8px 16px; background: var(--chip); border-bottom: 1px solid var(--line); }
.admin-bar[hidden] { display: none; }
.admin-bar.editing { border-bottom: 3px solid var(--contested); }
.admin-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.item-name.code { font-family: Consolas, Menlo, monospace; letter-spacing: 0.04em; }
.link-row { display: flex; gap: 6px; margin-top: 6px; }
.link-row input { flex: 1; min-width: 0; font-size: 0.85rem; }
.former-sheet h4 { margin: 12px 0 4px; }
.former-sheet p { margin: 4px 0; }
.edit-dialog .dm-notes { margin-top: 12px; }
.stay-logged-in { justify-content: center; }
.distribute { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-top: 12px; }
.distribute:empty { display: none; }
.settings-locks { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
