/*
  Bracket Maker. Loaded after the PDF tools' stylesheet (../pdf_tools/app.css),
  whose segmented switch, fields and checkbox rows it shares. Plain CSS, not
  built by Tailwind. The form uses the site's theme tokens; the bracket
  itself (.bm-paper, the printed .bm-sheet) is ink on white, like paper, in
  dark mode too. Box sizes must match SIZE in layout.js.
*/

.bm, .bm-blank {
  --pdft-line: var(--color-base-300);
  --pdft-accent: var(--color-primary);
}
/* Ink colours: the board, the previews and the printed sheets (which sit outside .bm). */
.bm, .bm-blank, .bm-sheet {
  --bm-ink: #1d1b22;
  --bm-soft: #6b6a75;
  --bm-line: #9c9ba6;
  --bm-edge: #c9c8d0;
  --bm-rule: #e6e5ea;
  --bm-pick: #eef2fd;
  --bm-win: #1f4fb8;
}
.bm [hidden], .bm-blank [hidden] { display: none !important; }
.bm-alert { padding: 1rem; border: 1px dashed var(--color-base-300); border-radius: 0.75rem; color: var(--muted); }

/* ---- Settings ---- */
.bm-panel {
  min-width: 0;
  padding: 1rem;
  border: 1px solid var(--color-base-300);
  border-radius: 0.875rem;
  background: var(--color-base-100);
}
@media (min-width: 40rem) { .bm-panel { padding: 1.25rem; } }

.bm-form { display: grid; gap: 1.1rem 2rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 52rem) { .bm-form { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); } }
.bm-form-main, .bm-form-side { display: flex; flex-direction: column; gap: 1.1rem; min-width: 0; }
.bm-fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.bm-fieldset > .pdft-check + .pdft-check, .bm-fieldset > .pdft-check + .pdft-field, .bm-fieldset > .pdft-field + .pdft-check { margin-top: 0.15rem; }
.bm-fieldset legend { float: left; width: 100%; padding: 0 0 0.45rem; }
.bm-fieldset legend + * { clear: both; }
.bm-optional { font-weight: 400; color: var(--muted); }
.bm-label-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.bm-entrants { min-height: 10.5rem; font-size: 0.875rem; line-height: 1.5; resize: vertical; }

/* Long segment labels wrap rather than push the switch off a phone screen. */
.bm-seg label { flex: 1 1 0; min-width: 0; }
.bm-seg span { height: 100%; display: flex; align-items: center; justify-content: center; white-space: normal; line-height: 1.25; }
.bm-seg-small { width: fit-content; max-width: 100%; }
.bm-seg-small label { flex: 0 1 auto; }
.bm-seg-small span { padding-inline: 0.75rem; }
.bm-seg input:disabled + span { opacity: 0.4; cursor: not-allowed; }

/* ---- Bar above the bracket ---- */
.bm-view { margin-top: 1.25rem; min-width: 0; }
.bm-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem 1rem; }
.bm-summary { font-size: 0.9375rem; font-weight: 600; }
.bm-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.bm-status { min-height: 1.35rem; margin: 0.35rem 0 0.4rem; font-size: 0.875rem; color: var(--muted); }
.bm-board { min-height: 8rem; }
.bm-loading, .bm-empty {
  padding: 2.5rem 1rem;
  border: 1px dashed var(--color-base-300);
  border-radius: 0.875rem;
  text-align: center;
  color: var(--muted);
}

.bm-section + .bm-section { margin-top: 1.25rem; }
.bm-section-title { margin: 0 0 0.5rem; font-size: 1rem; font-weight: 650; }
.bm-scroll { overflow-x: auto; overscroll-behavior-x: contain; border-radius: 0.875rem; }
.bm-scroll:focus { outline: none; }
.bm-paper {
  width: max-content;
  padding: 0.75rem 1rem 1rem;
  border: 1px solid var(--color-base-300);
  border-radius: 0.875rem;
  background: #fff;
  color: var(--bm-ink);
}

/* ---- The bracket (screen and paper) ---- */
.bm-tree { position: relative; font-size: 12.5px; line-height: 1.2; color: var(--bm-ink); }
.bm-lines { position: absolute; inset: 0; overflow: visible; }
.bm-lines path { fill: none; stroke: var(--bm-line); stroke-width: 1.25; }
.bm-head {
  position: absolute;
  top: 0;
  height: 18px;
  overflow: hidden;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--bm-soft);
}
.bm-match {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--bm-edge);
  border-radius: 6px;
  background: #fff;
}
.bm-match.is-bye { border-style: dashed; opacity: 0.6; }
.bm-match.is-ready { border-color: #8e8d99; }
.bm-num, .bm-caption {
  position: absolute;
  left: 2px;
  top: -14px;
  font-size: 9.5px;
  font-weight: 600;
  line-height: 12px;
  color: var(--bm-soft);
  white-space: nowrap;
}
.bm-caption { top: -30px; font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; }
.bm-slot {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: stretch;
}
.bm-slot + .bm-slot { border-top: 1px solid var(--bm-rule); }
.bm-seed { align-self: center; padding-left: 4px; font-size: 9.5px; font-variant-numeric: tabular-nums; color: var(--bm-soft); }
.bm-name {
  display: block;
  min-width: 0;
  overflow: hidden;
  padding: 0 4px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  white-space: nowrap;
  text-overflow: ellipsis;
  align-self: center;
}
button.bm-name { align-self: stretch; cursor: pointer; border-radius: 3px; }
button.bm-name:hover { background: var(--bm-pick); }
button.bm-name:focus-visible { outline: 2px solid var(--bm-win); outline-offset: -2px; }
.bm-slot.is-winner .bm-name { font-weight: 700; color: #000; }
.bm-slot.is-winner .bm-seed { color: var(--bm-ink); }
.bm-slot.is-loser .bm-name { color: #8a8994; }
.bm-slot.is-bye .bm-name, .bm-slot.is-hint .bm-name { font-style: italic; color: var(--bm-soft); }
.bm-slot.is-hint .bm-name { font-size: 10.5px; }
.bm-score {
  box-sizing: border-box;
  align-self: center;
  width: 32px;
  height: 17px;
  margin-right: 3px;
  padding: 0 2px;
  border: 1px solid var(--bm-edge);
  border-radius: 3px;
  background: #fff;
  color: var(--bm-ink);
  font: inherit;
  font-size: 11.5px;
  line-height: 15px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
input.bm-score:focus-visible { outline: 2px solid var(--bm-win); outline-offset: 0; }
.bm-slot.is-winner .bm-score { font-weight: 700; }
.bm-skip {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgb(255 255 255 / 0.86);
  font-size: 11px;
  font-style: italic;
  color: var(--bm-soft);
}
.bm-champ {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  padding: 0 8px;
  border: 2px solid var(--bm-ink);
  border-radius: 6px;
  background: #fff;
  font-size: 13.5px;
  font-weight: 700;
}
.bm-champ.is-crowned { background: #fff8e1; border-color: #b48a1d; }

/* ---- Round robin on the page ---- */
.bm-robin { display: grid; gap: 1.25rem; min-width: 0; }
.bm-table-wrap { overflow-x: auto; }
.bm-table { border-collapse: collapse; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.bm-table th, .bm-table td { padding: 0.35rem 0.55rem; border-bottom: 1px solid var(--color-base-300); text-align: center; }
.bm-table thead th { font-size: 0.75rem; font-weight: 650; color: var(--muted); }
.bm-table .is-name { max-width: 15rem; overflow: hidden; text-align: left; white-space: nowrap; text-overflow: ellipsis; font-weight: 600; }
.bm-table .is-name .bm-seed { display: inline-block; width: 1.6rem; padding: 0; }
.bm-table .is-points { font-weight: 700; }
.bm-table-caption { caption-side: top; padding-bottom: 0.5rem; text-align: left; font-size: 0.9375rem; font-weight: 650; }
.bm-cross td { min-width: 2.4rem; font-size: 0.8125rem; }
.bm-cross td.is-self { background: var(--color-base-200); }
.bm-cross-details > summary { cursor: pointer; font-weight: 600; }
.bm-cross-details[open] > summary { margin-bottom: 0.75rem; }

.bm-rounds { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr)); }
.bm-round { min-width: 0; padding: 0.75rem; border: 1px solid var(--color-base-300); border-radius: 0.75rem; background: var(--color-base-100); }
.bm-round-name { margin: 0 0 0.45rem; font-size: 0.9375rem; font-weight: 650; }
.bm-games { display: flex; flex-direction: column; gap: 0.3rem; margin: 0; padding: 0; list-style: none; }
.bm-game {
  display: grid;
  grid-template-columns: 2.1rem minmax(0, 1fr) auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.875rem;
}
.bm-game .bm-num { position: static; font-size: 0.6875rem; color: var(--muted); }
.bm-side { display: flex; align-items: center; gap: 0.25rem; min-width: 0; }
.bm-vs + .bm-side { justify-content: flex-end; }
.bm-vs + .bm-side .bm-name { text-align: right; }
.bm-robin .bm-name { padding: 0.2rem 0.35rem; border: 1px solid transparent; border-radius: 0.4rem; }
.bm-robin button.bm-name:hover { background: color-mix(in oklab, var(--color-primary) 10%, transparent); }
.bm-robin button.bm-name:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 0; }
.bm-robin .bm-side.is-winner .bm-name { font-weight: 700; background: color-mix(in oklab, var(--color-primary) 14%, transparent); }
.bm-robin .bm-side.is-loser .bm-name { color: var(--muted); }
.bm-robin .bm-score { width: 2.3rem; height: 1.6rem; margin: 0; border-color: var(--color-base-300); background: var(--color-base-100); color: var(--color-base-content); font-size: 0.8125rem; }
.bm-vs { font-size: 0.75rem; color: var(--muted); }
.bm-draw {
  padding: 0.15rem 0.45rem;
  border: 1px solid var(--color-base-300);
  border-radius: 0.4rem;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}
.bm-draw:hover { color: var(--color-base-content); }
.bm-draw:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 1px; }
.bm-draw.is-on { border-color: var(--color-base-content); background: var(--color-base-content); color: var(--color-base-100); }
.bm-drawn { font-size: 0.75rem; color: var(--muted); }
.bm-sits { margin: 0.45rem 0 0; font-size: 0.8125rem; color: var(--muted); }

/* ---- Previews ---- */
.bm-preview { margin-top: 1rem; }
.bm-preview > summary { cursor: pointer; font-weight: 600; font-size: 0.9375rem; }
.bm-thumbs { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: 0.75rem; }
.bm-thumb { position: relative; flex: none; margin: 0; overflow: hidden; border: 1px solid var(--color-base-300); border-radius: 4px; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.12); }
.bm-thumb .bm-sheet { position: absolute; top: 0; left: 0; transform-origin: 0 0; overflow: hidden; }

/* ---- Blank brackets ---- */
.bm-blank { display: grid; gap: 1.5rem; margin-top: 2rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 62rem) { .bm-blank { grid-template-columns: minmax(0, 1fr) auto; align-items: start; } }
.bm-blank-grid { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem 1.5rem; margin-top: 1.25rem; }
.bm-blank-checks { display: flex; flex-direction: column; gap: 0.45rem; }
.bm-blank-thumbs { margin-top: 0; }

/* ---- Copy below the tool ---- */
.bm-copy-table { overflow-x: auto; border: 1px solid var(--color-base-300); border-radius: 0.875rem; }
.bm-copy-table th, .bm-copy-table td { font-size: 0.875rem; white-space: nowrap; }

/* ---- Printed sheets (also drawn small as previews) ---- */
.bm-sheet {
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-direction: column;
  background: #fff;
  color: #111;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.bm-sheet-head { flex: none; height: 46px; display: flex; align-items: baseline; justify-content: space-between; gap: 16px; border-bottom: 1.5px solid #111; overflow: hidden; }
.bm-sheet-title { margin: 0; overflow: hidden; font-size: 20px; font-weight: 750; line-height: 34px; white-space: nowrap; text-overflow: ellipsis; }
.bm-sheet-title.is-line { flex: 1; max-width: 60%; border-bottom: 1px solid #777; font-size: 11px; font-weight: 600; color: #555; line-height: 30px; }
.bm-sheet-meta { flex: none; margin: 0; font-size: 11px; color: #555; }
.bm-sheet-body { flex: none; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.bm-scale-box { position: relative; flex: none; }
.bm-scale { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.bm-sheet-section + .bm-sheet-section { margin-top: 26px; }
.bm-sheet-section-title { height: 26px; margin: 0; font-size: 13px; font-weight: 700; line-height: 20px; }
.bm-sheet-foot { flex: none; height: 20px; margin-top: auto; font-size: 8.5px; line-height: 20px; text-align: right; color: #888; }
.bm-sheet .bm-tree { --bm-line: #777; --bm-edge: #9a9aa2; }
.bm-sheet .bm-match.is-bye { opacity: 0.55; }

/* A round robin flows over as many pages as it needs. */
.bm-sheet.is-flow { display: block; font-size: 12px; }
.bm-sheet.is-flow .bm-sheet-head { margin-bottom: 14px; }
.bm-sheet.is-flow .bm-table-wrap { overflow: visible; margin-bottom: 16px; }
.bm-sheet.is-flow .bm-table { font-size: 11px; }
.bm-sheet.is-flow .bm-table th, .bm-sheet.is-flow .bm-table td { border-color: #bbb; color: #111; padding: 3px 6px; }
.bm-sheet.is-flow .bm-table thead th { color: #444; }
.bm-sheet.is-flow .bm-table-caption { font-size: 12px; }
.bm-sheet.is-flow .bm-cross td.is-self { background: #e9e9ec; }
.bm-flow-title { margin: 6px 0 8px; font-size: 13px; font-weight: 700; break-after: avoid; }
.bm-sheet.is-flow .bm-rounds { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.bm-sheet.is-flow .bm-round { padding: 6px 8px; border-color: #bbb; border-radius: 4px; background: #fff; break-inside: avoid; }
.bm-sheet.is-flow .bm-round-name { font-size: 11.5px; margin-bottom: 4px; }
.bm-sheet.is-flow .bm-game { grid-template-columns: 26px minmax(0, 1fr) auto minmax(0, 1fr) auto; gap: 3px; font-size: 10.5px; }
.bm-sheet.is-flow .bm-game .bm-num { font-size: 8.5px; color: #777; }
.bm-sheet.is-flow .bm-name { padding: 0; }
.bm-sheet.is-flow .bm-side.is-winner .bm-name { font-weight: 700; }
.bm-sheet.is-flow .bm-side.is-loser .bm-name { color: #777; }
.bm-sheet.is-flow .bm-score { width: 26px; height: 15px; margin: 0; font-size: 10px; line-height: 13px; border-color: #999; }
.bm-sheet.is-flow .bm-vs, .bm-sheet.is-flow .bm-drawn, .bm-sheet.is-flow .bm-sits { color: #666; font-size: 9.5px; }
.bm-sheet.is-flow .bm-sheet-foot { margin-top: 12px; }

.bm-print { display: none; }
@media print {
  body > *:not(.bm-print) { display: none !important; }
  html, body { background: #fff !important; }
  .bm-print { display: block; }
  .bm-print .bm-sheet:not(.is-flow) { overflow: hidden; break-after: page; page-break-after: always; }
  .bm-print .bm-sheet:last-child { break-after: auto; page-break-after: auto; }
}
