:root {
  --bg: #f2f5fa;
  --surface: #ffffff;
  --ink: #14233d;
  --muted: #5d6b82;
  --line: #d3dbe8;
  --brand: #1d4f91;       /* royal blue */
  --brand-dark: #12305a;  /* navy: header, scoreboard */
  --gold: #f5b700;
  --gold-ink: #2b2100;
  --gold-text: #8a6400;   /* gold dark enough to read as text */
  --danger: #c62828;
  --open: #ffffff;
  --mine: #fff0b3;
  --mine-ink: #3d2f00;
  --held: #e4e8ef;
  --held-ink: #7a869a;
  --sold: #e8f0fb;
  --sold-ink: #12305a;
  --win: #12305a;
  --win-ink: #f5b700;
  --me: #e0a100;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.15; margin: 0; }
.hidden { display: none !important; }

/* ------------------------------------------------------------ layout */
.top {
  background: var(--brand-dark);
  color: #ffffff;
  border-bottom: 4px solid var(--gold);
  padding: 14px 16px;
}
.top .inner { max-width: 1100px; margin: 0 auto; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.top h1 { font-size: 1.35rem; letter-spacing: 0.01em; }
/* Group logo (or initials badge) at the start of every header. */
.top .brand-logo { height: 44px; width: 44px; flex: none; object-fit: contain; background: #fff; border-radius: 10px; padding: 3px; }
.top.compact .brand-logo { height: 36px; width: 36px; border-radius: 8px; }
.top .badge-initials { display: inline-flex; align-items: center; justify-content: center; background: var(--gold); color: var(--gold-ink); font-weight: 800; font-size: 0.85rem; letter-spacing: 0.02em; padding: 0 4px; width: auto; min-width: 44px; }
.top.compact .badge-initials { min-width: 36px; font-size: 0.75rem; }
.top .brand-logo.badge-initials { width: auto; padding: 0 6px; white-space: nowrap; }
.about { white-space: pre-line; }
@media (max-width: 640px) { .has-cart .top .brand-logo { display: none; } }
.top .sub { opacity: 0.85; font-size: 0.9rem; }
.top .spacer { flex: 1; }
.top .who { font-size: 0.9rem; opacity: 0.9; }
.top button, .top .top-btn { background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.35); color: #fff; border-radius: 8px; padding: 6px 10px; cursor: pointer; text-decoration: none; font-size: 0.95rem; line-height: 1.2; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { font-size: 1.1rem; margin-bottom: 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }

/* Quiet links for helpers at the bottom of the public page. */
.staff-links { max-width: 1100px; margin: 8px auto 24px; padding: 0 16px; font-size: 0.75rem; color: #9aa6b8; }
.staff-links a { color: inherit; }

/* Sign-up table: keep the chrome slim so the grid gets the room. */
.top.compact { padding: 8px 16px; }
.top.compact h1 { font-size: 1.15rem; }
.top.compact .sub { font-size: 0.8rem; }
.helper-bar { display: flex; gap: 8px 16px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.helper-bar .tabs { margin-bottom: 0; padding-bottom: 0; }
.helper-bar .hint { font-size: 0.8rem; color: var(--muted); }
.card.tight { padding: 8px; }
.helper main { padding-top: 10px; padding-bottom: 10px; }
/* The current order lives in the header, so the grid can use the full height. */
.cart-inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: rgba(255,255,255,0.12); border-radius: 12px; padding: 4px 4px 4px 14px; }
.cart-inline .sum { font-weight: 700; font-size: 1.05rem; }
.cart-inline .timer { font-variant-numeric: tabular-nums; opacity: 0.85; font-size: 0.9rem; }
.cart-inline .timer.low { color: var(--gold); opacity: 1; font-weight: 700; }
.cart-inline .btn { min-height: 40px; padding: 6px 12px; }
.cart-inline .btn.ghost { color: #fff; border-color: rgba(255,255,255,0.35); }
/* On narrower screens, make room for the order by hiding the title and name. */
@media (max-width: 1000px) {
  .has-cart .top .title-block, .has-cart .top .who { display: none; }
}
.cart-inline .btn.primary { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); font-size: 1.05rem; padding: 6px 16px; }

/* ------------------------------------------------------------ controls */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.amount + .btn, .amount + a.btn { margin-top: 4px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.big { font-size: 1.15rem; padding: 14px 20px; min-height: 56px; }
.btn.sm { min-height: 34px; padding: 5px 10px; font-size: 0.875rem; }

label.field { display: block; }
label.field > span { display: block; font-size: 0.875rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=tel], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  min-height: 44px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 3px solid rgba(29,79,145,0.35); outline-offset: 1px; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1 1 0; min-width: 90px; }
.seg button[aria-pressed=true] { background: var(--brand); color: #fff; border-color: var(--brand); }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.tabs button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; white-space: nowrap; cursor: pointer; font-weight: 600; min-height: 40px;
}
.tabs button[aria-selected=true] { background: var(--brand-dark); color: #fff; border-color: var(--brand-dark); }
.tabs .count { font-weight: 400; opacity: 0.75; margin-left: 4px; }

.msg { padding: 10px 12px; border-radius: 10px; background: #fff4e5; border: 1px solid #f5c98b; }
.msg.error { background: #fdecec; border-color: #f3a6a6; }
.msg.ok { background: #e9f2ea; border-color: #a9cfae; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow); z-index: 50; max-width: calc(100% - 32px); text-align: center;
}

/* ------------------------------------------------------------ the grid */
.board-wrap { overflow-x: auto; }
.board {
  /* fitBoard() sets --cw/--ch (square width/height in px) to fit the screen. */
  position: relative;
  display: grid;
  grid-template-columns: 28px 30px repeat(10, var(--cw, minmax(0, 1fr)));
  grid-template-rows: auto 30px repeat(10, var(--ch, 48px));
  justify-content: center;
  gap: 3px;
  user-select: none;
  -webkit-user-select: none;
}
.board .team-top {
  grid-column: 3 / span 10; grid-row: 1;
  text-align: center; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em;
  padding: 4px 0; color: var(--brand);
}
.board .team-side {
  grid-column: 1; grid-row: 3 / span 10;
  writing-mode: vertical-rl; transform: rotate(180deg);
  text-align: center; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--gold-text);
}
.board .digit {
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.05rem; border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.board .digit.col { background: var(--brand); color: #fff; }
.board .digit.row { background: var(--gold); color: var(--gold-ink); }
.board .digit.blank { background: transparent; color: var(--muted); }
.board .digit.hit { box-shadow: 0 0 0 3px var(--ink) inset; }

.sq {
  position: relative;
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  min-width: 0;
  font-family: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  border: 1px solid var(--line);
  background: var(--open);
  border-radius: 6px;
  padding: 2px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 0.72rem; line-height: 1.1;
  overflow: hidden; word-break: break-word;
  cursor: default;
}
button.sq { cursor: pointer; }
.sq .num { position: absolute; top: 2px; left: 4px; font-size: 0.6rem; color: var(--muted); }
.sq.open { background: var(--open); }
.sq.sold { background: var(--sold); color: var(--sold-ink); font-weight: 600; }
.sq.held { background: var(--held); color: var(--held-ink); }
/* Online order waiting for payment to be confirmed. */
.sq.pending { background: repeating-linear-gradient(135deg, var(--held), var(--held) 6px, #f4f6fa 6px, #f4f6fa 12px); color: var(--held-ink); font-style: italic; }
.sq.mine { background: var(--mine); color: var(--mine-ink); border-color: var(--gold); font-weight: 700; }
.sq.me { box-shadow: 0 0 0 3px var(--me) inset; }
.sq.win { background: var(--win); color: var(--win-ink); border-color: var(--win); font-weight: 800; }
.sq .badges { position: absolute; right: 2px; bottom: 2px; display: flex; gap: 2px; }
.sq .badge { background: var(--gold); color: var(--gold-ink); border-radius: 4px; font-size: 0.6rem; font-weight: 800; padding: 0 3px; }
.sq.busy { opacity: 0.5; }

/* ------------------------------------------------------------ branding tools */
.preview .digit { display: flex; align-items: center; justify-content: center; font-weight: 800; border-radius: 6px; min-height: 24px; }
.preview .digit.col { background: var(--brand); color: #fff; }
.preview .digit.row { background: var(--gold); color: var(--gold-ink); }
.preview .top { border-bottom-width: 3px; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.color-pick { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; padding: 4px 10px 4px 4px; border-radius: 10px; border: 2px solid transparent; cursor: pointer; }
.color-pick.active { border-color: var(--brand); }
.color-pick input[type=color] { width: 44px; height: 36px; border: 1px solid var(--line); border-radius: 8px; padding: 0; background: none; }
.cropper input[type=range] { width: 100%; max-width: 320px; height: 32px; }
.crop-view { width: 100%; max-width: 320px; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 12px; touch-action: none; cursor: grab; display: block; }
textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; min-height: 90px; resize: vertical; }

/* ------------------------------------------------------------ scores */
.scores { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.qbox { background: var(--brand-dark); color: #fff; border-radius: 10px; padding: 8px 10px; text-align: center; }
.qbox .q { font-size: 0.75rem; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.08em; }
.qbox .s { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.qbox.pending { background: var(--q-pending, #3b5070); }
.qbox.pending .s { opacity: 0.5; }
.live { margin-top: 8px; font-size: 0.9rem; }

/* ------------------------------------------------------------ modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(16, 24, 40, 0.55); z-index: 40;
  display: flex; align-items: flex-start; justify-content: center; padding: 16px; overflow-y: auto;
}
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 720px; padding: 20px; margin: auto 0; }
.modal h2 { font-size: 1.3rem; margin-bottom: 4px; }
.pay { display: grid; grid-template-columns: 200px 1fr; gap: 16px; align-items: center; }
.pay .qr { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.pay .qr svg { display: block; width: 100%; height: auto; }
.pay img { width: 100%; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
.amount { font-size: 2.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.memo { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); padding: 4px 8px; border-radius: 6px; display: inline-block; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.linkbox { word-break: break-all; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); padding: 8px 10px; border-radius: 8px; }

/* ------------------------------------------------------------ admin tables */
table { width: 100%; border-collapse: collapse; font-size: 0.925rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.stat .k { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat .v { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; background: var(--bg); }
.pill.open { background: var(--sold, #e6eefc); color: var(--brand); }
.pill.drawn { background: var(--sold); color: var(--sold-ink); }
.pill.refund { background: #fdecec; color: #a11; }
.login { max-width: 420px; margin: 40px auto; }

@media (max-width: 640px) {
  /* Order bar fits on one line: smaller pieces, no title/Home while picking. */
  .top .inner { flex-wrap: nowrap; }
  .has-cart .top .top-btn { display: none; }
  .cart-inline { gap: 6px; padding: 3px 3px 3px 10px; flex-wrap: nowrap; }
  .cart-inline .sum { font-size: 0.9rem; white-space: nowrap; }
  .cart-inline .timer { font-size: 0.75rem; white-space: nowrap; }
  .cart-inline .btn { min-height: 36px; padding: 4px 9px; font-size: 0.85rem; white-space: nowrap; }
  .cart-inline .btn.primary { font-size: 0.9rem; padding: 4px 12px; }
  /* Small squares: a check mark instead of the word "Picked". */
  .sq .pick { font-size: 0; }
  .sq .pick::after { content: '✓'; font-size: 1rem; }
  main { padding: 12px; }
  .card { padding: 12px; }
  .board { grid-template-columns: 16px 20px repeat(10, var(--cw, minmax(0, 1fr))); grid-template-rows: auto 22px repeat(10, var(--ch, 30px)); gap: 2px; }
  .board .digit { font-size: 0.85rem; border-radius: 4px; }
  .board .team-top, .board .team-side { font-size: 0.75rem; }
  .sq { font-size: 0.5rem; padding: 1px; border-radius: 4px; }
  .sq .num { display: none; }
  .sq .badge { font-size: 0.5rem; padding: 0 2px; }
  .pay { grid-template-columns: 1fr; }
  .pay img, .pay .qr { max-width: 220px; margin: 0 auto; display: block; }
  .form-grid { grid-template-columns: 1fr; }
  .scores { grid-template-columns: repeat(2, 1fr); }
  .amount { font-size: 2rem; }
}
