:root {
  color-scheme: light;
  --paper: #f6f5ed;
  --surface: #fffefa;
  --ink: #202f26;
  --muted: #526058;
  --forest: #244537;
  --forest-dark: #17372a;
  --green: #e7eedf;
  --lime: #e0eda9;
  --line: #d7ddd1;
  --field-line: #788a7d;
  --focus: #235b45;
  --error: #a22f22;
  --font: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1rem / 1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
p,
figure,
dl,
dd {
  margin: 0;
}
h2 {
  font: 400 2rem / 1.13 var(--serif);
  letter-spacing: -0.035em;
}
a {
  color: inherit;
}
button,
input,
textarea,
select {
  font: inherit;
}
button,
summary {
  cursor: pointer;
}
button:disabled {
  cursor: default;
}

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

section[id],
h2[id] {
  scroll-margin-top: 1.5rem;
}

.wrap {
  width: min(72rem, calc(100% - 5rem));
  margin-inline: auto;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  z-index: 1;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.65rem 1rem;
  transform: translateY(-160%);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--forest-dark);
}

.skip-link:focus {
  transform: none;
}

.site-header {
  border-bottom: 1px solid var(--line);
}

.topbar {
  min-height: 4.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0 1.5rem;
}

.brand,
nav a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  text-decoration: none;
}

.brand {
  gap: 0.65rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}
.brand-mark {
  position: relative;
  width: 2rem;
  height: 2rem;
  flex: none;
  border-radius: 0.56rem;
  background: var(--forest);
}

.brand-mark::before {
  position: absolute;
  top: 0.48rem;
  left: 0.48rem;
  width: 0.39rem;
  height: 0.39rem;
  border-radius: 0.11rem;
  background: var(--lime);
  box-shadow:
    0.64rem 0 #f4f6e7,
    0 0.64rem #f4f6e7,
    0.64rem 0.64rem #a8bd92;
  content: "";
}

nav {
  display: flex;
  gap: clamp(0.85rem, 3vw, 2rem);
}
nav a {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}
nav a:hover {
  color: var(--forest-dark);
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.9fr);
  align-items: center;
  gap: clamp(2rem, 7vw, 7rem);
  padding-block: clamp(2.4rem, 4.2vw, 3.75rem) clamp(2.25rem, 3.3vw, 3.35rem);
}

.intro h1 {
  font: 400 clamp(3.3rem, 6vw, 5.85rem) / 0.98 var(--serif);
  letter-spacing: -0.068em;
}

.intro-copy > p:first-of-type {
  max-width: 26em;
  margin-top: 1.25rem;
  color: var(--muted);
  font-size: clamp(1rem, 1.5vw, 1.2rem);
  line-height: 1.5;
}

.local-note {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.12rem;
  color: var(--forest);
  font-size: 0.875rem;
  font-weight: 650;
}

.local-dot {
  width: 0.52rem;
  height: 0.52rem;
  border-radius: 50%;
  background: #507757;
  box-shadow: 0 0 0 0.2rem var(--green);
}

.example {
  display: grid;
  align-content: center;
  gap: 1.2rem;
  padding: clamp(1.15rem, 3vw, 1.8rem);
  border: 1px solid #d2dccc;
  border-radius: 1.3rem;
  background:
    radial-gradient(#cdd9c7 1px, transparent 1px) 0 0 / 13px 13px,
    var(--green);
}

.example figcaption {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.2rem 0.6rem;
}

.example figcaption strong {
  font-size: 1rem;
  letter-spacing: -0.025em;
}
.example-meta,
.example-label {
  color: var(--forest);
  font-size: 0.83rem;
  font-weight: 650;
}
.example-flow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 1.55rem minmax(0, 1fr);
  gap: 0.54rem;
}
.example-flow > div {
  min-width: 0;
}
.example-arrow {
  align-self: center;
  margin-top: 1.5rem;
  position: relative;
  height: 1px;
  background: #64816c;
}
.example-arrow::after {
  position: absolute;
  top: -0.24rem;
  right: 0;
  width: 0.5rem;
  height: 0.5rem;
  transform: rotate(45deg);
  border-top: 1px solid #64816c;
  border-right: 1px solid #64816c;
  content: "";
}

.example-groups {
  display: grid;
  gap: 0.43rem;
  padding: 0;
  margin: 0.44rem 0 0;
  list-style: none;
}
.example-group {
  display: flex;
  flex-wrap: wrap;
  column-gap: 0.6rem;
  padding: 0.55rem 0.6rem;
  border: 1px solid #d2dace;
  border-left: 3px solid var(--tone, #cbd9bd);
  border-radius: 0.48rem;
  background: var(--surface);
  font-size: 0.86rem;
  font-weight: 650;
}

.tone-0 {
  --tone: #b7ca8e;
  --tone-tint: #f0f4e2;
}
.tone-1 {
  --tone: #d8bc83;
  --tone-tint: #fcf4e2;
}
.tone-2 {
  --tone: #aca8cc;
  --tone-tint: #f0edf7;
}
.tone-3 {
  --tone: #c6a291;
  --tone-tint: #f8efe8;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.25fr);
  align-items: start;
  gap: clamp(1.35rem, 3.2vw, 3.15rem);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  background: var(--surface);
}
.setup {
  padding: clamp(1.15rem, 2.7vw, 1.85rem);
}
.setup h2 {
  margin-bottom: 0.9rem;
}
.roster-heading,
.rule-type {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
}
label,
legend,
summary {
  font-size: 0.9rem;
  font-weight: 700;
}
.hint {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}
#roster-hint {
  margin-bottom: 0.55rem;
}

textarea,
input[type="number"],
select {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.53rem 0.7rem;
  border: 1px solid var(--field-line);
  border-radius: 0.52rem;
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
}

textarea {
  background: #fbfbf7;
  resize: vertical;
}
#roster {
  min-height: 8.15rem;
}
textarea::placeholder {
  color: #66746a;
}
[aria-invalid="true"] {
  border-color: var(--error);
}
.roster-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.15rem 0.5rem;
  margin-top: 0.45rem;
}
.roster-meta span:first-child {
  font-variant-numeric: tabular-nums;
}
.error {
  margin-top: 0.4rem;
  color: var(--error);
  overflow-wrap: anywhere;
  font-size: 0.87rem;
  font-weight: 650;
}

fieldset {
  padding: 0;
  border: 0;
  min-width: 0;
  margin: 0;
}
.grouping {
  margin-top: 1.3rem;
}
legend {
  padding: 0;
  margin-bottom: 0.44rem;
}

.mode-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 0.19rem;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  background: #f0f2eb;
}

.mode-picker label {
  position: relative;
  text-align: center;
  cursor: pointer;
}
.mode-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  clip-path: inset(50%);
}
.mode-picker span {
  display: grid;
  min-height: 2.75rem;
  padding: 0.35rem 0.38rem;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 0.47rem;
  color: var(--muted);
  line-height: 1.24;
}

.mode-picker input:checked + span {
  border-color: #b9cbb3;
  background: var(--surface);
  color: var(--forest-dark);
  box-shadow: 0 1px 2px #233c2514;
}

.mode-picker input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}
.numeric-fields,
.rule-people {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 0.65rem;
  margin-top: 0.92rem;
}

.numeric-fields label {
  display: block;
}
.numeric-fields input,
.rule-row select {
  margin-top: 0.29rem;
}
#rounds-hint,
#size-preview {
  margin-top: 0.36rem;
}
#size-preview {
  color: var(--forest);
}

.pairing-rules {
  margin-block: 1.16rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.pairing-rules summary {
  display: flex;
  min-height: 3rem;
  align-items: center;
  gap: 0.62rem;
  list-style: none;
}

.pairing-rules summary::-webkit-details-marker {
  display: none;
}
.pairing-rules summary::after {
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.21rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-0.13rem) rotate(45deg);
  content: "";
}

.pairing-rules[open] summary::after {
  transform: translateY(0.14rem) rotate(225deg);
}
.rule-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}
.rule-editor {
  padding-bottom: 0.9rem;
}
#add-rule {
  margin-top: 0.5rem;
}
#add-rule-hint {
  margin-top: 0.3rem;
}
.rule-row {
  padding: 0.65rem;
  margin-block: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: #f8f9f3;
}
.rule-type {
  align-items: end;
}
.rule-type label {
  flex: 1;
  min-width: 0;
}
.rule-people {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 0.6rem;
}

.button,
.text-button {
  min-height: 2.75rem;
  border-radius: 0.55rem;
  font-weight: 700;
  font-size: 0.88rem;
  line-height: 1.22;
  transition:
    background-color 150ms ease,
    border-color 150ms ease,
    color 150ms ease;
}

.button {
  padding: 0.5rem 0.8rem;
  border: 1px solid transparent;
}
.button.primary {
  width: 100%;
  min-height: 3.15rem;
  background: var(--forest);
  color: white;
  font-size: 1rem;
}

.button.primary:hover:not(:disabled) {
  background: var(--forest-dark);
}
.button.primary:disabled {
  background: #52685b;
}
.button.secondary {
  border-color: var(--field-line);
  background: var(--surface);
  color: var(--forest-dark);
}
.button.secondary:hover:not(:disabled) {
  border-color: var(--forest);
  background: var(--green);
}
.button.secondary:disabled,
.text-button:disabled {
  color: var(--muted);
  opacity: 0.68;
}
.text-button {
  padding-inline: 0.25rem;
  border: 0;
  background: transparent;
  color: var(--forest-dark);
  text-decoration: underline;
  text-underline-offset: 0.22em;
}
.text-button:hover:not(:disabled) {
  color: #35694e;
}

.output {
  min-width: 0;
}
.output-heading {
  min-height: 2.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem 0.8rem;
  margin-block: 0.8rem 0.88rem;
}

.output-heading .hint {
  margin-top: 0.27rem;
}
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.37rem;
}

.empty-state {
  display: grid;
  min-height: 19.25rem;
  align-content: center;
  justify-items: center;
  gap: 1.25rem;
  padding: 1.5rem;
  border: 1px dashed #aebcaa;
  border-radius: 1.1rem;
  background: #eeefe7;
  color: var(--muted);
  text-align: center;
}

.empty-state p {
  max-width: 31ch;
}
.empty-state.has-error {
  border-color: #c99688;
  background: #f9eee8;
  color: var(--error);
}
.empty-state.has-error p {
  max-width: 40ch;
}
.empty-illustration {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.empty-state.has-error .empty-illustration {
  display: none;
}
.empty-illustration span {
  width: 2.72rem;
  height: 3.48rem;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 0.36rem;
  border: 1px solid #b7c5ae;
  border-radius: 0.51rem;
  background: #f7f8ef;
  transform: translateY(0.18rem) rotate(-11deg);
}

.empty-illustration span:nth-child(2) {
  transform: translateY(-0.25rem);
  background: #e1eacb;
}
.empty-illustration span:nth-child(3) {
  transform: translateY(0.18rem) rotate(11deg);
}
.empty-illustration span::before,
.empty-illustration span::after {
  width: 1.2rem;
  height: 0.24rem;
  border-radius: 5rem;
  background: #91a38a;
  content: "";
}

.empty-illustration span::after {
  width: 0.88rem;
  background: #b5c2a9;
}
.copy-status:not(:empty) {
  margin-bottom: 0.7rem;
  color: var(--forest-dark);
  font-size: 0.88rem;
  font-weight: 650;
}
.copy-fallback {
  margin-bottom: 0.8rem;
}
.stats {
  padding: 1rem 1.08rem;
  background: #edf1e5;
}
.stats dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.stats dl > div {
  display: flex;
  flex-direction: column-reverse;
  gap: 0.15rem;
}
.stats dl > div + div {
  padding-left: 1.05rem;
  border-left: 1px solid #ccd7c5;
}
.stats dt {
  color: var(--forest);
  font-size: 0.86rem;
  font-weight: 700;
}
.stats dd {
  font: 400 2.2rem / 1 var(--serif);
  letter-spacing: -0.04em;
}
.stats .hint {
  margin-top: 0.68rem;
}
.round-list {
  display: grid;
  gap: 0.82rem;
  margin-top: 0.76rem;
}
.round-card {
  padding: 0.95rem;
}
.round-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.15rem 0.65rem;
  margin-bottom: 0.64rem;
}
.round-head h3 {
  font: 400 1.52rem / 1.2 var(--serif);
  letter-spacing: -0.035em;
}
.group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr));
  gap: 0.5rem;
}
.group-card {
  min-width: 0;
  padding: 0.6rem 0.68rem;
  border: 1px solid var(--line);
  border-top: 3px solid var(--tone, var(--line));
  border-radius: 0.55rem;
  background: var(--tone-tint, var(--surface));
}

.group-card header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.1rem 0.3rem;
}
.group-card h4 {
  font-size: 0.9rem;
}
.group-card .hint {
  font-size: 0.78rem;
}
.members {
  padding: 0;
  margin: 0.35rem 0 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.members li {
  margin-left: 0.95rem;
  font-size: 0.9rem;
}
.members li::marker {
  color: #5f755e;
}

.guide {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(1.5rem, 5vw, 4rem);
  margin-top: clamp(2.7rem, 6vw, 5.1rem);
  padding-block: clamp(1.5rem, 3vw, 2.75rem) clamp(2rem, 5vw, 4rem);
  border-top: 1px solid var(--line);
}

.guide p {
  max-width: 54ch;
  margin-top: 0.75rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.site-footer {
  padding-block: 1.15rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.86rem;
}
.print-title {
  display: none;
}

@media (max-width: 58rem) {
  .wrap {
    width: calc(100% - 3rem);
  }
  .intro {
    gap: 2rem;
  }
  .workspace {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.21fr);
  }
}

@media (max-width: 44rem) {
  .wrap {
    width: calc(100% - 2rem);
  }
  .topbar {
    min-height: 3.75rem;
    column-gap: 0.65rem;
  }
  .topbar nav {
    gap: 0.72rem;
  }
  .topbar nav a {
    min-width: 2.75rem;
    font-size: 0.82rem;
  }
  .brand {
    font-size: 0.92rem;
  }
  .intro {
    grid-template-columns: 1fr;
    gap: 1.3rem;
    padding-block: 2.1rem 1.65rem;
  }
  .intro h1 {
    font-size: clamp(2.75rem, 10.5vw, 4.5rem);
  }
  .intro-copy > p:first-of-type {
    margin-top: 0.96rem;
  }
  .local-note {
    margin-top: 0.75rem;
  }
  .example {
    gap: 0.7rem;
    padding: 0.9rem 1rem;
  }
  .workspace,
  .guide {
    grid-template-columns: 1fr;
  }
  .workspace {
    gap: 1.25rem;
  }
  .output-heading {
    margin-top: 0;
  }
  .empty-state {
    min-height: 12.5rem;
  }
}

@media (max-width: 24rem) {
  .topbar {
    padding-block: 0.2rem;
  }
  .setup {
    padding-inline: 0.92rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .button,
  .text-button {
    transition: none;
  }
}

@media print {
  :root {
    color-scheme: light;
  }
  body {
    background: white;
    color: black;
  }
  .site-header,
  .site-footer,
  .skip-link,
  .intro,
  .setup,
  .guide,
  .result-actions,
  .copy-status,
  .copy-fallback,
  .empty-state {
    display: none;
  }
  .wrap,
  .workspace {
    display: block;
    width: auto;
  }
  .print-title {
    display: block;
    font: 400 2rem / 1.2 var(--serif);
  }
  .output-heading {
    min-height: auto;
    margin-block: 0.3rem 0.65rem;
  }
  .output-heading h2 {
    display: none;
  }
  .round-list,
  .round-card {
    display: block;
  }
  .round-card {
    margin-top: 0.6rem;
  }
  .stats,
  .round-head,
  .group-card {
    break-inside: avoid;
  }
  .round-head {
    break-after: avoid;
  }
  .stats,
  .round-card,
  .group-card {
    background: white;
    box-shadow: none;
  }
}

:root [hidden] {
  display: none;
}
