:root {
  --navy: #1f4e78;
  --navy-light: #2e75b6;
  --gray: #d9d9d9;
  --gray-dark: #808080;
  --yellow: #fffcc;
  --input-fill: #fffacd;
}

* { box-sizing: border-box; }

body {
  font-family: Arial, Helvetica, sans-serif;
  margin: 0;
  background: #f4f6f8;
  color: #222;
}

.topbar {
  background: var(--navy);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.topbar h1 { margin: 0; font-size: 20px; }
.topbar h1 .version {
  font-size: 12px;
  font-weight: normal;
  opacity: 0.75;
  margin-left: 4px;
}

.mod-status { font-size: 14px; }
.mod-status button {
  margin-left: 10px;
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  background: var(--navy-light);
  color: #fff;
  cursor: pointer;
}
.mod-status button:hover { background: #3a86c9; }

.tabs {
  display: flex;
  background: #fff;
  border-bottom: 1px solid #ddd;
  overflow-x: auto;
}
.tab-btn {
  padding: 12px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  color: #555;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tab-btn.active {
  color: var(--navy);
  border-bottom-color: var(--navy);
}

main { padding: 20px; max-width: 1200px; margin: 0 auto; }

.hint { color: #666; font-size: 13px; }

/* ---- Grid page ---- */
.pool-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.pool-header h2 { margin: 0; color: var(--navy); }
.edit-badge {
  background: #2e7d32;
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  padding: 3px 10px;
  border-radius: 12px;
}
.team-label {
  font-weight: bold;
  color: var(--navy);
  font-size: 18px;
  padding: 2px 12px;
  min-width: 140px;
  display: block;
  width: fit-content;
  margin: 0 auto 10px auto;
  text-align: center;
}

.grid-wrap {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
}
.vteam {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-weight: bold;
  color: var(--navy);
  font-size: 18px;
  text-align: center;
  padding: 8px 4px;
}

table.squares {
  border-collapse: collapse;
  width: 100%;
}
table.squares td {
  border: 1px solid #b7b7b7;
  width: 42px;
  height: 42px;
  text-align: center;
  font-weight: bold;
  font-size: 15px;
  position: relative;
}
table.squares td.filled { background: #eaf3ff; }
table.squares td.empty-square { background: #fff; color: #bbb; }
table.squares td .sq-num {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 10px;
  font-weight: normal;
  color: #aaa;
}
table.squares td.filled .sq-num { color: #6b93c9; }
table.squares td .sq-init {
  display: block;
  padding-top: 8px;
}
table.squares td.corner-label {
  background: #ddd;
  color: #111;
  font-size: 13px;
}
table.squares td.corner-blank { background: #ddd; }
table.squares td.edge-blank { background: #fff; }

.winners-section {
  margin-top: 24px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 16px;
}
.winners-section h3 { margin-top: 0; color: var(--navy); }
.players-updated {
  font-size: 12px;
  font-weight: normal;
  color: #888;
}
table.winners {
  border-collapse: collapse;
  width: 100%;
}
table.winners th, table.winners td {
  border: 1px solid #ccc;
  padding: 6px 10px;
  text-align: center;
  font-size: 13px;
}
table.winners th { background: var(--navy); color: #fff; }
table.winners input {
  width: 60px;
  padding: 4px;
  text-align: center;
}
table.winners button {
  padding: 4px 10px;
  border: none;
  background: var(--navy-light);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

/* ---- Roster ---- */
table.roster-table {
  border-collapse: collapse;
  width: 100%;
  table-layout: fixed;
  background: #fff;
}
table.roster-table th, table.roster-table td {
  border: 1px solid #ccc;
  padding: 8px 12px;
  text-align: left;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
table.roster-table th { background: var(--navy); color: #fff; }
table.roster-table tr:nth-child(even) { background: #f7f9fb; }
#tab-roster h3 { color: var(--navy); margin-top: 24px; margin-bottom: 8px; }
#tab-roster h3:first-child { margin-top: 0; }
.grand-total {
  margin-top: 20px;
  padding: 12px 16px;
  background: #fff8e1;
  border: 1px solid #f0c14b;
  border-radius: 6px;
  font-size: 16px;
}
.pdf-btn {
  padding: 6px 14px;
  border: none;
  background: var(--navy);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

/* ---- Click to print (downloads a .pdf directly, no OS print dialog) ----
   #printArea is built fresh by app.js on demand with one pool's grid + player
   list. It's hidden on screen (display: none) at rest. While a PDF is being
   generated, app.js adds .rendering, which lays it out off-screen (not
   display:none, so html2canvas can capture it) at a fixed width matching a
   printable page, then removes it again once the PDF has been captured. */
.print-only { display: none; }
.print-only.rendering {
  display: block;
  position: absolute;
  left: -10000px;
  top: 0;
  width: 900px;
  background: #fff;
  padding: 24px;
  border: 3px solid var(--navy);
  box-sizing: border-box;
}
.print-pool-section { page-break-after: always; page-break-inside: avoid; }

/* Flyer-style banner/footer — hidden on-screen (the plain h2 title covers that
   case), shown only in the PDF-capture output for a more polished look. Negative
   margins bleed the navy bars to the edge of the .rendering container's padding
   (24px) so they read as a full-width header/footer rather than an inset box. */
.flyer-banner, .flyer-footer { display: none; }
.rendering .pool-header { display: none; }
/* Payout key — print-only badge in the top-left corner of the blue banner, on a
   white tile like the logo so it stays legible against the navy background. */
.payout-corner {
  display: none;
  position: absolute;
  top: 12px;
  left: 16px;
  background: #fff;
  border-radius: 6px;
  padding: 6px 8px;
}
.rendering .payout-corner { display: block; }
.payout-corner-title {
  font-size: 9px;
  font-weight: bold;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: center;
  margin-bottom: 3px;
}
.qcross {
  display: grid;
  grid-template-columns: repeat(3, 34px);
  grid-template-rows: repeat(3, 24px);
}
.qcell {
  border: 1px solid #000;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: bold;
  color: #000;
  text-align: center;
  line-height: 1.1;
}
.qcell.empty { border: none; }
.rendering .flyer-banner {
  display: flex;
  position: relative;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: var(--navy);
  color: #fff;
  text-align: center;
  padding: 16px 20px;
  margin: -24px -24px 20px -24px;
}
/* Logo centered above the eyebrow/title/date so the whole banner reads as one
   centered block down the middle of the page. */
.flyer-logo {
  width: 68px;
  height: 68px;
  flex: none;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  padding: 4px;
}
.flyer-titles { flex: none; }
.flyer-eyebrow {
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 2px;
  text-transform: uppercase;
  opacity: 0.85;
  margin-bottom: 4px;
}
.flyer-title {
  font-size: 30px;
  font-weight: bold;
}
.flyer-date {
  font-size: 13px;
  opacity: 0.9;
  margin-top: 4px;
}

.rendering .flyer-footer {
  display: block;
  background: var(--navy);
  color: #fff;
  text-align: center;
  font-size: 11px;
  letter-spacing: 1px;
  padding: 8px 20px;
  margin: 20px -24px -24px -24px;
}

/* html2canvas (used to capture #printArea for the PDF) doesn't reliably support
   CSS writing-mode — the vertical "TEAM" side label came out mirrored/garbled in
   testing. While rendering for capture, swap it for a plain rotate() transform on
   normal horizontal text instead, which html2canvas handles correctly. The .vteam
   box gets a fixed width so the grid layout doesn't shift (transforms don't affect
   layout size, only what's painted). */
.rendering .vteam {
  writing-mode: horizontal-tb;
  transform: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  padding: 0;
}
.rendering .vteam span {
  display: inline-block;
  white-space: nowrap;
  transform: rotate(-90deg);
}

/* Compact player list on the printed Players page — one table listing all 100
   boxes for the pool, split into 4 side-by-side Box/Int./Name column groups of 25
   rows each, so every box number (filled or not) fits on a single printed page. */
table.players-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 10px;
}
table.players-table th, table.players-table td {
  border: 1px solid #999;
  padding: 2px 6px;
  text-align: left;
}
table.players-table th {
  background: #f0f0f0;
  font-weight: bold;
}
table.players-table th.box-col, table.players-table td.box-col {
  text-align: right;
}

table.payment-summary-table {
  border-collapse: collapse;
  width: 100%;
  background: #fff;
  margin-top: 8px;
}
table.payment-summary-table th, table.payment-summary-table td {
  border: 1px solid #ccc;
  padding: 8px 12px;
  text-align: center;
  font-size: 13px;
}
table.payment-summary-table th { background: var(--navy); color: #fff; }
table.payment-summary-table tr.payment-summary-total { background: #fff8e1; }

/* ---- Moderator input ---- */
.mod-pool-select {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
  background: #fff;
  padding: 12px 16px;
  border-radius: 6px;
  border: 1px solid #ddd;
}
.mod-pool-select label { font-size: 13px; font-weight: bold; color: #444; }
.mod-pool-select select, .mod-pool-select input {
  padding: 6px 8px;
  margin-left: 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.admin-tools {
  background: #fff8e1;
  border: 1px solid #f0c14b;
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 16px;
}
.admin-tools h3 { margin: 0 0 6px 0; color: var(--navy); font-size: 15px; }
.admin-tools-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.admin-tools-row button {
  padding: 6px 14px;
  border: none;
  background: var(--navy);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
}
.admin-tools-divider {
  width: 1px;
  height: 24px;
  background: #ddd;
}
#importResult { margin-top: 8px; white-space: pre-line; }
.danger-zone { background: #fdecea; border-color: #c0392b; }
.danger-zone h3 { color: #c0392b; }
.danger-btn {
  padding: 6px 14px;
  border: none;
  background: #c0392b;
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
}
#resetResult { margin-top: 8px; }
.mod-pool-select button, .mod-table button {
  padding: 6px 14px;
  border: none;
  background: var(--navy);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
}
.mod-table button.delete-btn {
  background: #c0392b;
  margin-left: 4px;
}
.mod-table button.delete-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

table.mod-table {
  border-collapse: collapse;
  width: 100%;
  background: #fff;
}
table.mod-table th, table.mod-table td {
  border: 1px solid #ccc;
  padding: 6px 8px;
  text-align: center;
  font-size: 13px;
}
table.mod-table th { background: var(--navy); color: #fff; position: sticky; top: 0; }
table.mod-table input[type="text"], table.mod-table input[type="email"], table.mod-table input[type="tel"] {
  width: 100%;
  border: 1px solid #ddd;
  padding: 4px;
  background: var(--input-fill);
}
table.mod-table input[type="text"].initials { text-align: center; }
table.mod-table input[type="text"].input-error {
  border: 2px solid #c0392b;
  background: #fdecea;
}
table.mod-table tr.error-row td {
  background: #fdecea;
  color: #c0392b;
  text-align: left;
  font-size: 12px;
  padding: 6px 10px;
}
table.mod-table tbody { display: block; max-height: 500px; overflow-y: auto; }
table.mod-table thead, table.mod-table tbody tr { display: table; width: 100%; table-layout: fixed; }

/* ---- Modal ---- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-box {
  background: #fff;
  padding: 24px;
  border-radius: 8px;
  width: 320px;
}
.modal-box h3 { margin-top: 0; color: var(--navy); }
.modal-box input {
  width: 100%;
  padding: 8px;
  margin: 10px 0;
  border: 1px solid #ccc;
  border-radius: 4px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions button {
  padding: 6px 14px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
#modSubmitBtn { background: var(--navy); color: #fff; }
#modCancelBtn { background: #eee; }
.error-text { color: #c0392b; font-size: 13px; min-height: 16px; }
