:root {
  /* VSTX brand (from velocitysportstexas.com) */
  --black: #161616;
  --lime: #B9D332;
  --lime-dark: #8fa61c;
  --sky: #87CEFA;
  --green: var(--lime);
  --green-dark: #161616;
  --green-tint: #eef5c8;
  --me: var(--lime);
  --passer: var(--sky);
  --ink: #1b1b1b;
  --muted: #5e5e5e;
  --line: #d6d6d6;
  --card: #ffffff;
  --page: #f7f7f7;
  --radius: 4px;
  --ctrl-h: 38px;
  --heading: "Cabin", Arial, sans-serif;
  font-family: "Josefin Sans", Arial, sans-serif;
  color: var(--ink);
  background: var(--page);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- header ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; background: var(--black); color: #f7f7f7; border-bottom: 4px solid var(--lime);
  padding-top: max(8px, env(safe-area-inset-top));
  flex: 0 0 auto;
}
.topbar h1 { font-family: var(--heading); font-size: 17px; margin: 0; font-weight: 700; line-height: 1.2; text-transform: uppercase; letter-spacing: 1px; }
.topbar .team { margin: 2px 0 0; font-size: 13px; color: var(--lime); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.top-actions { display: flex; gap: 6px; }
.link-btn { background: transparent; color: #f7f7f7; border: 1px solid rgba(255,255,255,.5); border-radius: var(--radius); padding: 4px 10px; font-size: 13px; min-height: 34px; text-transform: uppercase; letter-spacing: .5px; }

main { flex: 1 1 auto; width: 100%; max-width: 560px; margin: 0 auto; padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; min-height: 0; }

/* ---------- buttons ---------- */
button {
  font: inherit; font-size: 14px; min-height: var(--ctrl-h); padding: 4px 8px;
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); color: var(--ink);
  cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
button.active { background: var(--lime); border-color: var(--lime); color: var(--black); font-weight: 700; }

/* ---------- setup ---------- */
#setup { overflow-y: auto; }
h2 { font-family: var(--heading); text-transform: uppercase; letter-spacing: 1px; font-size: 16px; font-weight: 700; margin: 12px 0 8px; display: flex; align-items: center; gap: 8px; }
.step { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--lime); color: var(--black); font-size: 12px; font-weight: 700; }
.cards { display: grid; gap: 8px; }
.card { text-align: left; padding: 10px 12px; display: block; width: 100%; }
.card strong { font-family: var(--heading); font-size: 18px; letter-spacing: 1px; display: block; margin-bottom: 2px; }
.card span { color: var(--muted); font-size: 14px; line-height: 1.35; }
.card.active span { color: var(--black); }
.card.active { font-weight: 400; }
.pos-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.pos-grid button { min-height: 44px; }
.toggle { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; font-size: 14px; color: var(--muted); }
.toggle input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--lime-dark); }

/* ---------- trainer: fills the screen, court takes what's left ---------- */
#trainer { flex: 1 1 auto; display: flex; flex-direction: column; gap: 6px; min-height: 0; }
#trainer[hidden] { display: none; }
.panel { display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; }

.ctrl-row { display: flex; align-items: center; gap: 6px; }
.ctrl-label { font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.tabs { display: grid; gap: 4px; flex: 1 1 auto; min-width: 0; }
.tabs.rot { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.tabs.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tabs.phases { grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr)); }
.tabs button { padding: 2px; }
.next, .play { flex: 0 0 auto; padding: 4px 10px; }
.play { background: var(--black); border-color: var(--black); color: var(--lime); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }

.info {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px; font-size: 14px; line-height: 1.4;
}
.info .when { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--black); background: var(--lime); padding: 2px 7px; border-radius: 5px; margin-right: 6px; vertical-align: 1px; }
.info .warn { color: #8a3b12; }

.timeline { display: flex; gap: 3px; flex-wrap: wrap; align-items: center; }
.timeline span { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: #ebe9e2; color: var(--muted); }
.timeline span.on { background: var(--black); color: var(--lime); font-weight: 600; }
.timeline span.arrow { background: none; padding: 0; }

.overlap { font-size: 13px; color: var(--muted); line-height: 1.35; }
.overlap:empty { display: none; }
.overlap strong { color: var(--ink); font-weight: 600; }

.court-wrap { flex: 1 1 0; min-height: 200px; position: relative; }
#court { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#court text { font-family: inherit; }

/* ---------- help ---------- */
.help { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; font-size: 14px; line-height: 1.5; }
.help p { margin: 8px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.dot.me { background: var(--me); border: 2px solid var(--black); }
.dot.passer { background: var(--passer); }
.dot.other { background: #fff; border: 1px solid #888; }
.dot.ghost { border: 1.5px dashed var(--ink); }
/* while help is open, let the page scroll */
body.help-open #trainer { overflow-y: auto; }
body.help-open .court-wrap { display: none; }

/* ---------- small phones: tighten further ---------- */
@media (max-height: 700px) {
  :root { --ctrl-h: 34px; }
  .topbar .team { display: none; }
  .info { font-size: 13px; padding: 6px 8px; }
  .timeline { display: none; }
}

/* ---------- wide screens: controls left, court right ---------- */
@media (min-width: 820px) and (min-aspect-ratio: 1/1) {
  main { max-width: 1100px; padding: 12px 20px; }
  #trainer { flex-direction: row; gap: 20px; }
  .panel { width: 380px; flex: 0 0 380px; overflow-y: auto; }
  .court-wrap { min-height: 0; }
  :root { --ctrl-h: 40px; }
  .info { font-size: 15px; }
  body.help-open .court-wrap { display: block; }
}

@media (prefers-color-scheme: dark) {
  :root { --ink: #f1f1f1; --muted: #b0b0b0; --line: #3a3a3a; --card: #222; --page: #111; }
  .timeline span { background: #2c2c2a; }
  .timeline span.on { background: var(--lime); color: var(--black); }
  .play { background: var(--lime); color: var(--black); border-color: var(--lime); }
  .info .when { color: var(--black); }
  .dot.other { background: #232321; }
}

.panel > .tabs { flex: 0 0 auto; }

.help h3 { font-family: var(--heading); text-transform: uppercase; letter-spacing: 1px; font-size: 15px; margin: 8px 0 4px; }
.help ul { margin: 6px 0; padding-left: 18px; }
.help li { margin: 4px 0; }
.help .src { font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.dot.ring { border: 2.5px solid #6f8a12; }
.sq { display: inline-block; width: 14px; height: 11px; margin-right: 5px; vertical-align: -1px; }
.sq.area { background: rgba(185, 211, 50, 0.45); border: 1.5px dashed #6f8a12; }
.text-btn { min-height: 0; padding: 0; border: none; background: none; color: var(--ink); text-decoration: underline; font-size: inherit; font-weight: 600; }
.overlap .area { white-space: nowrap; }
.overlap .ok { font-weight: 700; color: var(--ink); }

@media (max-height: 700px) {
  .court-wrap { min-height: 170px; }
  .overlap .area { display: none; }
}
