/* One stylesheet on purpose. Order: tokens, masthead, hero, archive, composer, phone. */

:root {
  color-scheme: light;
  --paper: #f4efe8;
  --paper-raised: #fbf8f3;
  --ink: #1c1412;
  --muted: #5e564f;
  --line: #d9d1c7;
  --accent: #8f1d2c;
  --serif: "Fraunces", "Iowan Old Style", Palatino, Georgia, serif;
  --sans: "Instrument Sans", "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  background: #e6e0d6;
  overflow-x: clip;
}

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

button { cursor: pointer; }

p { margin: 0; }

::selection { background: #e7cfc4; }

.sheet {
  min-height: calc(100vh - 32px);
  margin: 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: inset 0 3px 0 var(--accent);
}

.wrap {
  width: min(1120px, calc(100% - 80px));
  margin-inline: auto;
}

.skip {
  position: absolute;
  left: 16px;
  top: -48px;
  z-index: 5;
  background: var(--ink);
  color: var(--paper);
  padding: 8px 12px;
}

.skip:focus { top: 16px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.mast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  border-bottom: 1px solid var(--line);
}

.brand {
  color: inherit;
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 560;
  letter-spacing: -0.04em;
  text-decoration: none;
}

.text-link {
  min-height: 44px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
}

.hero {
  display: grid;
  grid-template-columns: minmax(260px, 0.86fr) minmax(320px, 1.14fr);
  gap: 56px;
  align-items: end;
  padding: 54px 0 28px;
}

h1, .stage-name, .person-name, .tally strong, .figures strong {
  font-family: var(--serif);
  font-weight: 560;
}

h1 {
  margin: 0;
  font-size: clamp(3.6rem, 7vw, 6.6rem);
  line-height: 0.84;
  letter-spacing: -0.045em;
}

.kicker {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.lede {
  max-width: 34rem;
  margin-top: 22px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
}

.hero-actions { margin-top: 26px; }

.primary, .vote {
  min-height: 44px;
  border-radius: 0;
  border: 1px solid var(--ink);
}

.primary {
  padding: 0 18px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 500;
}

.fine {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.figures {
  display: flex;
  gap: 32px;
  margin-top: 36px;
}

.figures strong {
  display: block;
  font-size: 2rem;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.figures span, .role, .aside-copy, .stage-empty, .empty {
  color: var(--muted);
}

.figures span {
  display: block;
  margin-top: 6px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stage-card, .stage-empty {
  border: 1px solid var(--line);
  background: var(--paper-raised);
}

.stage-card {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 22px 18px;
}

.stage-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  flex: 1;
}

.stage-name {
  margin: 0;
  font-size: clamp(2.2rem, 3vw, 3.15rem);
  line-height: 0.92;
  letter-spacing: -0.035em;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.who--lead {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
  min-width: 0;
}

.who--end { align-items: flex-end; text-align: right; }

.ranking { padding: 12px 0 64px; }

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: end;
  padding: 18px 0;
}

.toolbar h2 {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.toolbar p { margin-top: 6px; color: var(--muted); font-size: 0.92rem; }

.toolbar-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: center;
  justify-content: flex-end;
}

.search input {
  width: min(240px, 70vw);
  min-height: 44px;
  padding: 0 2px;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
}

.search input::placeholder { color: var(--muted); }

.sort { display: flex; gap: 16px; }

.sort button, .fields button {
  min-height: 44px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.sort button[aria-pressed="true"], .fields button[aria-pressed="true"] {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

.list { display: grid; }

.row {
  display: grid;
  grid-template-columns: 2.6rem minmax(0, 1fr) 4.6rem max-content;
  gap: 16px;
  align-items: center;
  padding: 14px 8px;
  border-top: 1px solid var(--line);
}

.rank {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
}

.pair {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.who {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.pair .who { flex: 0 1 auto; }
.pair .who--end { flex-direction: row; text-align: left; }

.who-copy { min-width: 0; }

.person-name {
  display: block;
  overflow: hidden;
  font-size: 1.2rem;
  letter-spacing: -0.03em;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.role, .slot-role { display: block; font-size: 0.78rem; }

.cross { color: var(--muted); }

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.who--lead .avatar { width: 72px; height: 72px; font-size: 0.92rem; }

.tally { text-align: right; }

.tally strong {
  display: block;
  color: var(--accent);
  font-size: 1.55rem;
  letter-spacing: -0.04em;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}

.tally--stage strong { font-size: clamp(2.4rem, 4vw, 3.4rem); }

.tally span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.vote {
  padding: 0 12px;
  background: transparent;
  font-weight: 500;
}

.primary:disabled, .vote:disabled {
  border-color: var(--line);
  background: transparent;
  color: var(--muted);
  cursor: default;
}

.stage-card .primary { align-self: flex-start; }

.empty, .stage-empty {
  display: grid;
  place-items: center;
  min-height: 160px;
  padding: 28px;
  text-align: center;
}

.site-footer {
  padding: 18px 0 28px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.86rem;
}

dialog {
  width: min(960px, calc(100vw - 32px));
  height: min(760px, calc(100vh - 32px));
  max-width: calc(100vw - 32px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  box-shadow: none;
}

dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog::backdrop { background: rgba(28, 20, 18, 0.46); }

.composer-head, .composer-status { padding-inline: 22px; }

.composer-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding-top: 22px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.composer-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 4vw, 2.8rem);
  font-weight: 560;
  letter-spacing: -0.04em;
  line-height: 0.9;
}

.composer-status {
  min-height: 1.3em;
  margin: 10px 0 0;
  color: var(--accent);
  font-weight: 500;
}

.composer-body {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  gap: 28px;
  flex: 1;
  min-height: 0;
  padding: 18px 22px 22px;
}

.aside, .picker { min-height: 0; }

.aside {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-right: 22px;
  border-right: 1px solid var(--line);
}

.slots { display: grid; }

.slot {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 72px;
  padding: 8px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  text-align: left;
}

.slot--empty {
  justify-content: flex-start;
  color: var(--muted);
}

.slot .avatar { width: 40px; height: 40px; }

.slot-copy { min-width: 0; flex: 1; }

.slot-name {
  display: block;
  font-family: var(--serif);
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}

.slot-clear {
  min-height: 44px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.aside-copy { line-height: 1.45; font-size: 0.92rem; }

.decision {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.decision p { margin-bottom: 12px; line-height: 1.4; }

.decision .primary { width: 100%; }

.picker { display: flex; flex-direction: column; gap: 8px; }

.picker .search input { width: 100%; }

.fields { display: flex; flex-wrap: wrap; gap: 14px; }

.people {
  display: flex;
  flex-direction: column;
  overflow: auto;
  min-height: 0;
}

.person-pick {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 8px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  text-align: left;
}

.person-pick[aria-pressed="true"] {
  background: #efeae3;
  box-shadow: inset 3px 0 0 var(--accent);
}

.person-pick .avatar { width: 36px; height: 36px; }

.person-pick strong {
  display: block;
  font-weight: 500;
}

.person-pick small { color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(10px);
  padding: 12px 14px;
  border-radius: 0;
  background: var(--ink);
  color: var(--paper);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast[data-show="true"] {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

@media (hover: hover) {
  .primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
  .vote:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
  .row:hover { background: #efeae3; }
  .person-pick:hover { background: #efeae3; }
}

@media (max-width: 860px) {
  .hero {
    grid-template-columns: 1fr;
    gap: 28px;
    align-items: stretch;
    padding-top: 32px;
  }

  .stage-card, .stage-empty { min-height: 0; }
}

@media (max-width: 720px) {
  .sheet {
    margin: 0;
    border: 0;
    min-height: 100vh;
  }

  .wrap { width: min(1120px, calc(100% - 40px)); }

  .toolbar, .composer-body { display: flex; flex-direction: column; }

  .toolbar-tools { justify-content: flex-start; }

  .row {
    grid-template-columns: 2rem minmax(0, 1fr);
    grid-template-areas:
      "rank pair"
      "rank tally"
      "action action";
    gap: 8px 12px;
    padding: 16px 0;
  }

  .rank { grid-area: rank; }
  h1 { font-size: 3.5rem; }
  .stage-name { font-size: 2.35rem; }
  .pair { grid-area: pair; flex-direction: column; align-items: flex-start; gap: 8px; }
  .stage-pair {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  .who--lead,
  .who--end,
  .tally--stage { align-items: flex-start; text-align: left; width: 100%; }
  .cross { display: none; }
  .tally { grid-area: tally; text-align: left; }
  .vote { grid-area: action; justify-self: start; }

  .aside { border-right: 0; padding-right: 0; }

  dialog {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    border: 0;
  }

  .composer-body { overflow: auto; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .toast { transition: none; }
}
