:root {
  --bg: #121417;
  --panel: #1b1f24;
  --panel-2: #232830;
  --line: #333a44;
  --text: #e6e1d6;
  --muted: #9a958b;
  --accent: #c9a24a;
  --accent-ink: #1a1408;
  --danger: #c0574b;
  --ok: #6f9a6a;
  --radius: 6px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 Georgia, "Times New Roman", serif;
}

.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-bottom: 64px; }

.masthead { border-bottom: 1px solid var(--line); background: #0d0f11; }
.masthead .wrap { display: flex; align-items: center; justify-content: space-between; min-height: 52px; gap: 16px; }
.brand { font-variant: small-caps; letter-spacing: .12em; color: var(--accent); font-size: 1.1rem; }

a { color: var(--accent); }
h1 { font-size: 2rem; margin: 32px 0 4px; font-weight: normal; }
h2 { font-size: 1.15rem; margin: 32px 0 12px; font-variant: small-caps; letter-spacing: .06em; color: var(--accent); font-weight: normal; }
h3 { font-size: 1rem; margin: 24px 0 8px; font-weight: normal; color: var(--muted); }
.when { margin: 0; color: var(--muted); font-size: 1.1rem; }
.muted { color: var(--muted); }

.flash { padding: 10px 14px; border-radius: var(--radius); margin: 16px 0 0; border: 1px solid; }
.flash-ok { border-color: var(--ok); background: #1b2a1c; }
.flash-error { border-color: var(--danger); background: #2e1b19; }

/* Forms */
input[type=text], input[type=password], input[type=number] {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
}
input:focus-visible, button:focus-visible, .card:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

button {
  padding: 8px 14px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: bold; padding: 10px 20px; }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); }
button.link { background: none; border: none; color: var(--accent); padding: 0; text-decoration: underline; }

form.inline { display: inline; }
.stack > * + * { margin-top: 8px; }
.narrow { max-width: 360px; }
.grid-form { display: grid; grid-template-columns: 2fr 1.5fr auto auto; gap: 12px; align-items: end; margin-bottom: 16px; }
.grid-form label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: .9rem; }
.grid-form input[type=number] { width: 6em; }
@media (max-width: 640px) { .grid-form { grid-template-columns: 1fr; } }

/* Choice cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px 12px 40px;
  cursor: pointer;
}
.card-main input { position: absolute; left: 14px; top: 16px; accent-color: var(--accent); }
.card:hover { border-color: var(--muted); }
.card:has(input:checked) { border-color: var(--accent); background: #262116; }
.card-title { font-size: 1.1rem; }
.card-blurb { color: var(--muted); font-size: .9rem; }
.card-tag { color: var(--danger); font-size: .85rem; margin-top: 4px; }
.card.taken .card-main { opacity: .55; cursor: not-allowed; }
.card-none { border-style: dashed; }
.card-more {
  margin: 0 10px 10px 40px;
  align-self: flex-start;
  padding: 4px 10px;
  font-size: .85rem;
  background: transparent;
  color: var(--accent);
  border-color: #4a4128;
}
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip {
  font-size: .75rem;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: system-ui, sans-serif;
}

.savebar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  margin-top: 24px;
  padding: 12px 0;
  background: linear-gradient(transparent, var(--bg) 30%);
}
.savebar-hint { color: var(--accent); font-size: .9rem; }

/* Details dialog */
dialog.details {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
dialog.details[open] { display: flex; flex-direction: column; }
dialog.details::backdrop { background: rgba(5, 6, 8, .75); }
dialog.details > header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
}
dialog.details h3 { margin: 0; font-size: 1.6rem; color: var(--text); }
.details-tagline { margin: 2px 0 0; color: var(--accent); font-style: italic; }
dialog.details .close { font-size: 1.4rem; line-height: 1; padding: 2px 10px; background: transparent; }
.details-body { overflow-y: auto; padding: 4px 20px 16px; }
.details-body h4 { margin: 20px 0 6px; font-variant: small-caps; letter-spacing: .05em; color: var(--accent); font-weight: normal; font-size: 1.05rem; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 12px 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
@media (max-width: 520px) { .facts { grid-template-columns: 1fr; } .facts dd { margin-bottom: 6px; } }
.abilities { margin: 0; padding-left: 18px; }
.abilities li { margin: 4px 0; }
.abilities strong { color: var(--text); font-weight: bold; }
.questions { margin: 0; padding-left: 18px; color: var(--muted); font-style: italic; }
dialog.details > footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
}
dialog.details > footer .card-tag { margin: 0 auto 0 0; }
html:has(dialog[open]) { overflow: hidden; }

/* Phones */
@media (max-width: 560px) {
  h1 { font-size: 1.7rem; margin-top: 24px; }

  /* Compact cards: text on the left, Details button on the right. */
  .cards { grid-template-columns: 1fr; gap: 8px; }
  .card { flex-direction: row; align-items: flex-start; }
  .card-main { padding: 10px 8px 10px 40px; }
  .card-main input { top: 14px; }
  .card-more { margin: 10px 10px 10px 0; padding: 6px 12px; }
  .chips { margin-top: 4px; }

  .savebar { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .savebar .primary { flex: 1; }
  .savebar:has(.savebar-hint:not([hidden])) { flex-wrap: wrap; }
  .savebar-hint { width: 100%; text-align: center; }

  /* Details become a bottom sheet. */
  dialog.details {
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: 14px 14px 0 0;
  }
  dialog.details > header { padding: 16px 16px 10px; }
  .details-body { padding: 4px 16px 16px; }
  dialog.details > footer { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
  dialog.details > footer .primary { flex: 1; }
  dialog.details > footer .card-tag { flex: 1; }
}

/* Tables */
.roster { width: 100%; border-collapse: collapse; }
.roster th, .roster td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.roster th { color: var(--muted); font-weight: normal; font-size: .9rem; }
.m-only { display: none; }
@media (max-width: 640px) {
  .m-only { display: inline; }
  .seats thead { display: none; }
  .seats tr {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "seat reset" "name reset" "pb pb" "crew crew" "link link";
    gap: 2px 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
  }
  .seats td { display: block; border: none; padding: 0; min-width: 0; }
  .seats .c-seat { grid-area: seat; color: var(--muted); font-size: .85rem; }
  .seats .c-name { grid-area: name; font-size: 1.1rem; }
  .seats .c-pb { grid-area: pb; }
  .seats .c-crew { grid-area: crew; }
  .seats .c-link { grid-area: link; padding-top: 8px; }
  .seats .c-reset { grid-area: reset; align-self: center; }
  .seats [data-label]::before { content: attr(data-label) ": "; color: var(--muted); }
  .seats .c-link .link-row { max-width: none; }
}

.link-row { display: flex; gap: 8px; align-items: center; min-width: 0; }
.url { font-family: ui-monospace, monospace; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.seats .link-row { max-width: 320px; }

/* Crew tally */
.tally { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; max-width: 560px; }
.tally li { display: grid; grid-template-columns: 7em 1fr 2em; gap: 10px; align-items: center; }
.tally-bar { height: 10px; background: var(--panel-2); border-radius: 5px; overflow: hidden; }
.tally-bar span { display: block; height: 100%; background: var(--muted); }
.tally li.leading .tally-label { color: var(--accent); }
.tally li.leading .tally-bar span { background: var(--accent); }
.tally-count { text-align: right; font-variant-numeric: tabular-nums; }
