/* Bracquets.com — platform tennis draw sheet
   Screen: toolbar + scaled letter pages.  Print: letter pages only, no UI. */

@font-face {
  font-family: "BSC Brand";
  src: url("/app/fonts/BarlowSemiCondensed-BoldItalic.ttf") format("truetype");
  font-style: italic;
  font-weight: 700;
  font-display: swap;
}

:root {
  --navy: #14213D;
  --green: #1E7A5A;
  --optic: #D4E157;
  --match: #9CB82E;
  --second: #6B7C99;
  --line: #A9B3C2;
  --ink2: #3D4A5C;
  --chalk: #F4F6F2;
  --ground: #E8ECE6;
  --zoom: 1;
  --brand: "BSC Brand", "Barlow Semi Condensed", "Arial Narrow", Arial, sans-serif;
  --ui: "Barlow", "Segoe UI", system-ui, -apple-system, sans-serif;
  --entry: "Barlow Semi Condensed", "Arial Narrow", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--ground);
  color: var(--navy);
  font-family: var(--ui);
  font-size: 15px;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Toolbar ---------- */
.toolbar {
  position: sticky; top: 0; z-index: 10;
  background: #fff;
  border-bottom: 1px solid #D5DBD2;
  padding: 10px 16px 8px;
}
.toolbar-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
}
.toolbar-row + .toolbar-row { margin-top: 8px; }
.brand img { display: block; height: 30px; width: auto; }
.doc-name { display: flex; align-items: center; gap: 8px; flex: 1 1 280px; min-width: 0; }
.doc-name label {
  font-family: var(--brand); font-style: italic; font-weight: 700;
  font-size: 13px; letter-spacing: 1px; text-transform: uppercase; color: var(--ink2); white-space: nowrap;
}
.doc-name input {
  flex: 1 1 auto; min-width: 0; height: 36px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 6px; font: inherit; color: var(--navy);
}
.doc-name input:focus { outline: 2px solid var(--green); outline-offset: 0; border-color: var(--green); }
.dirty-flag { font-size: 13px; color: #8A5A00; white-space: nowrap; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

button, select {
  min-height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--navy);
  font: 600 14px var(--ui); cursor: pointer;
}
button:hover, select:hover { border-color: var(--second); }
button:focus-visible, select:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
button.primary { background: var(--green); border-color: var(--green); color: #fff; }
button.primary:hover { background: #17664B; }
button.danger { color: #9B1C1C; border-color: #E2B4B4; }
.count {
  display: inline-block; margin-left: 4px; padding: 1px 6px; border-radius: 10px;
  background: var(--chalk); font-size: 12px; color: var(--ink2);
}
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink2); }
.check input { width: 16px; height: 16px; accent-color: var(--green); }

.hint { margin: 8px 0 0; font-size: 13px; color: var(--ink2); }
.hint-ball {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  border: 1.5px solid var(--match); vertical-align: -1px;
}
.status { margin: 4px 0 0; min-height: 18px; font-size: 13px; font-weight: 600; color: var(--green); }
.status.warn { color: #9B1C1C; }

/* ---------- Pages (screen) ---------- */
.sheets {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start;
  gap: 24px; padding: 24px 16px 48px;
}
.frame {
  width: calc(8.5in * var(--zoom));
  height: calc(11in * var(--zoom));
  flex: none;
  box-shadow: 0 1px 2px rgba(20, 33, 61, .12), 0 8px 24px rgba(20, 33, 61, .08);
  background: #fff;
  overflow: hidden;
}
.page {
  position: relative;
  width: 8.5in; height: 11in;     /* 612 x 792 pt: all positions below are in pt */
  background: #fff;
  transform: scale(var(--zoom));
  transform-origin: 0 0;
}
.page > svg.art { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* Inputs sitting on the printed lines */
.page input.fill {
  position: absolute;
  height: 13pt; padding: 0 2pt; margin: 0;
  border: 0; border-radius: 2pt; background: transparent;
  font: 600 9pt/13pt var(--entry);
  color: var(--navy);
  -webkit-appearance: none; appearance: none;
}
.page input.fill:hover { background: rgba(212, 225, 87, .14); }
.page input.fill:focus { outline: 1.5px solid var(--green); outline-offset: 0; background: rgba(212, 225, 87, .22); }
.page input.fill.seed { font-size: 10pt; }
.page input.fill.field { font-size: 9.5pt; }
.page input.fill.at { font-size: 8.5pt; }
.page input.fill.final { font-weight: 700; }
.page input.fill.won { font-weight: 700; }
.page input.fill.score {
  height: 10pt; font: italic 600 7.5pt/10pt var(--entry); color: var(--ink2); letter-spacing: .3pt;
  border-bottom: 0.6pt dotted var(--line); border-radius: 0;
}
.page input.fill.score::placeholder { color: #B9C1CC; }
.page input.fill.bye { color: var(--second); font-style: italic; letter-spacing: .6pt; }
.page input.fill.r-align { text-align: right; }
.page input.title {
  position: absolute; height: 24pt; padding: 0; border: 0; background: transparent;
  font: italic 700 19pt/24pt var(--brand); letter-spacing: .6pt; text-transform: uppercase; color: var(--navy);
}
.page input.title:focus { outline: 1.5px solid var(--green); background: rgba(212, 225, 87, .18); }
.page input.fill::placeholder, .page input.title::placeholder { color: #B9C1CC; }

/* Winner toggle: the ball */
.win-toggle {
  position: absolute; min-height: 0; width: 9pt; height: 9pt; padding: 0;
  border: 1.2pt solid var(--match); border-radius: 50%; background: #fff; cursor: pointer;
}
.win-toggle::after { /* larger tap target without changing the drawn ball */
  content: ""; position: absolute; inset: -6pt;
}
.win-toggle:hover { background: #EEF4CC; }
.win-toggle[aria-pressed="true"] { background: var(--match); }
.win-toggle:focus-visible { outline: 1.5px solid var(--green); outline-offset: 1.5pt; }

/* Host logo area */
.host-logo-slot {
  position: absolute; display: flex; align-items: center; justify-content: center;
  padding: 8pt; border: 0; background: transparent; cursor: pointer; min-height: 0; border-radius: 8pt;
}
.host-logo-slot:hover { background: rgba(212, 225, 87, .12); }
.host-logo-slot img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.host-logo-slot img[hidden] { display: none; }
.page[data-has-logo="true"] .logo-placeholder { display: none; }

/* ---------- Saved dialog ---------- */
dialog {
  width: min(560px, calc(100vw - 32px)); max-height: min(80vh, 720px);
  border: 0; border-radius: 12px; padding: 0; color: var(--navy);
  box-shadow: 0 20px 60px rgba(20, 33, 61, .3);
}
dialog::backdrop { background: rgba(20, 33, 61, .45); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 0; }
.dialog-head h2 { margin: 0; font: italic 700 22px var(--brand); text-transform: uppercase; letter-spacing: .5px; }
.dialog-head button { min-width: 36px; font-size: 20px; }
.dialog-note { margin: 6px 18px 12px; font-size: 13px; color: var(--ink2); }
.saved-list { list-style: none; margin: 0; padding: 0 18px; overflow: auto; max-height: 52vh; }
.saved-list li {
  display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid #E5E9E2;
}
.saved-list li.current .saved-name::after {
  content: "Open"; margin-left: 8px; padding: 1px 6px; border-radius: 10px;
  background: #EEF4CC; color: var(--navy); font-size: 11px; font-weight: 600;
}
.saved-meta { flex: 1 1 auto; min-width: 0; }
.saved-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-date { font-size: 12px; color: var(--ink2); }
.saved-empty { padding: 18px 0; color: var(--ink2); border-top: 1px solid #E5E9E2; }
.dialog-foot { display: flex; justify-content: flex-end; padding: 12px 18px 16px; }
.clear-options { display: flex; flex-direction: column; gap: 10px; padding: 0 18px; }
.clear-option {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 12px 14px; text-align: left; height: auto; border-radius: 8px;
}
.clear-option strong { font-size: 15px; }
.clear-option span { font-weight: 400; font-size: 13px; line-height: 1.4; color: var(--ink2); }
.clear-option.danger strong { color: #9B1C1C; }

@media (max-width: 640px) {
  .toolbar { position: static; padding: 8px 12px; }
  .hint { display: none; }
  .sheets { padding: 16px 8px 32px; gap: 16px; }
}

/* ---------- Print ---------- */
@page { size: letter portrait; margin: 0; }

@media print {
  html, body { background: #fff !important; }
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .app-ui, .win-toggle, .screen-only { display: none !important; }
  .sheets { display: block; padding: 0; margin: 0; gap: 0; }
  .frame {
    width: 8.5in !important; height: 11in !important;
    box-shadow: none; margin: 0; overflow: hidden;
  }
  .frame + .frame { break-before: page; }
  .page { transform: none !important; }
  .page input.fill, .page input.title { background: transparent !important; outline: 0 !important; }
  .page input.fill::placeholder, .page input.title::placeholder { color: transparent; }
  .page input.fill.score { border-bottom: 0; }
  .page input.fill.score:placeholder-shown { visibility: hidden; }
  .host-logo-slot { background: transparent !important; }
  body[data-print="L"] .frame[data-half="R"],
  body[data-print="R"] .frame[data-half="L"] { display: none !important; }
}
