/* Motion Builder - dark theme, tied to Coach HQ's design system.

   Same Fremont Silverwolves colors and structure as Coach HQ (see
   coach_hq_web/src/app.css): navy top bar, royal blue for "selected" and
   structure, burgundy only for the main action button, same font, corner
   radius and button shapes. The difference is the background: near-black
   instead of white, so the green field is the brightest thing on screen. */

:root {
  /* Coach HQ colors */
  --navy: #214293;
  --navy-dark: #162d66;
  --burgundy: #8e2140;       /* Coach HQ's #7f1d34, a touch brighter so it reads on black */
  --burgundy-dark: #7f1d34;

  /* Dark surfaces */
  --bg: #0d1015;             /* page / field area */
  --surface: #151a21;        /* sidebar */
  --surface-2: #1d232c;      /* buttons, inputs */
  --surface-3: #272e39;      /* hover */
  --line: #262d38;
  --ink: #e9ecf1;
  --ink-soft: #98a2af;
  --blue: #6b8fe6;           /* Coach HQ blue, lightened for text/focus on dark */
  --blue-soft: rgba(107, 143, 230, 0.16);
  --danger: #ec8a7f;

  --radius: 12px;
  --radius-sm: 8px;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1); /* quick start, soft landing */
  --topbar-h: 48px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Headings and buttons (and the player labels, drawn in app.js). */
  --font-display: "Barlow Semi Condensed", "Arial Narrow", Arial, sans-serif;

  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  line-height: 1.5;
  background: var(--bg);
  color: var(--ink);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, textarea { font-family: inherit; }

/* Headings and buttons use the condensed sports font, a bit larger and
   tracked out slightly since it's narrower than the body font. Text inputs,
   lists and help text stay in the regular font. */
h1, h2, .brand, .mobile-playbook-header h1,
.primary-btn, .secondary-btn, .small-btn, .ctrl-btn, .topbar-btn,
.mobile-return-btn, .mobile-play-btn, .mobile-tilt-btn,
.recording-step-label, .group-label {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.02em;
}
h1, .brand, .mobile-playbook-header h1 { font-weight: 700; }

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

/* ---------- Top bar (matches Coach HQ's header) ---------- */

.topbar {
  flex-shrink: 0;
  min-height: var(--topbar-h);
  background: linear-gradient(180deg, #2549a1, var(--navy));
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #fff;
  font-size: 1.4rem;
  text-decoration: none;
  white-space: nowrap;
}

.brand-logo {
  height: 28px;
  width: auto;
  display: block;
}

.topbar-link {
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.9rem;
  text-decoration: none;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  white-space: nowrap;
}

.topbar-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.account-slot {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.who {
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-btn {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.topbar-btn:hover { background: rgba(255, 255, 255, 0.18); }

/* ---------- Layout ---------- */

.app {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative; /* the drawer slides out over this area */
}

/* ---------- Sidebar ----------
   Watching plays: a drawer that slides out over the field (☰ button).
   Diagramming (body.editing-mode): docked as a slim panel. */

.sidebar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  width: min(320px, 88vw);
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 1rem 1rem 1.5rem;
  overflow-y: auto;
  transform: translateX(-100%);
  visibility: hidden; /* keeps the hidden drawer out of Tab order */
  transition: transform 0.22s ease, visibility 0s linear 0.22s;
}

body.drawer-open .sidebar {
  transform: none;
  visibility: visible;
  box-shadow: 16px 0 40px rgba(0, 0, 0, 0.5);
  transition: transform 0.22s ease;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  z-index: 25;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

body.drawer-open .drawer-backdrop {
  opacity: 1;
  pointer-events: auto;
}

body.editing-mode .sidebar {
  position: static;
  flex-shrink: 0;
  width: 236px;
  padding: 0.6rem 0.65rem 1rem;
  transform: none;
  visibility: visible;
  box-shadow: none;
  transition: none;
}

body.editing-mode .drawer-btn,
body.editing-mode .drawer-backdrop { display: none; }

/* Tighter spacing in the slim panel. */
body.editing-mode .sidebar-section { margin-bottom: 0.7rem; padding-bottom: 0.7rem; }
body.editing-mode .recording-bar { gap: 0.4rem; }
body.editing-mode .help { font-size: 0.76rem; }

.sidebar-section {
  margin-bottom: 1.1rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--line);
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

/* Section labels use Coach HQ's table-header style: small, uppercase, soft. */
.sidebar-section h2,
.describe-section > summary {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Folders → plays (one step at a time) ---------- */

.browse-sections:not(.show-plays) #playsPanel,
.browse-sections.show-plays #foldersPanel {
  display: none;
}

/* A short slide in the direction you're going. */
.browse-sections.show-plays #playsPanel { animation: browse-in-right 0.2s var(--ease); }
.browse-sections:not(.show-plays) #foldersPanel { animation: browse-in-left 0.2s var(--ease); }

@keyframes browse-in-right { from { opacity: 0; transform: translateX(16px); } }
@keyframes browse-in-left { from { opacity: 0; transform: translateX(-16px); } }

.back-btn {
  display: inline-flex;
  align-items: center;
  margin: -0.2rem 0 0.35rem -0.35rem;
  padding: 0.25rem 0.5rem;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--blue);
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background-color 0.12s var(--ease);
}

.back-btn:hover { background: var(--blue-soft); }

/* The folder's name, as the title of its plays list. */
.sidebar-section h2.plays-panel-title {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: none;
  color: var(--ink);
  white-space: normal;
}

.folder-chevron {
  flex-shrink: 0;
  width: 14px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 1.2rem;
  line-height: 1;
}

.folder-list li.active .folder-chevron { color: #fff; }

.hint {
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin: 0.25rem 0 0.5rem;
}

/* ---------- Folder + play lists ---------- */

.folder-list, .play-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.folder-list li, .play-list li {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 36px;
  padding: 0.2rem 0.25rem 0.2rem 0.15rem;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.12s var(--ease);
}

.folder-list li:hover, .play-list li:hover { background: var(--surface-2); }

.folder-list li.active, .play-list li.active {
  background: var(--navy);
  color: #fff;
  font-weight: 600;
}

.folder-list li.dragging, .play-list li.dragging {
  opacity: 0.5;
  background: var(--surface-3);
}

.folder-name, .play-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-hidden .folder-name { color: var(--ink-soft); }
.folder-hidden.active .folder-name { color: rgba(255, 255, 255, 0.8); }

.row-tag {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ink-soft);
  background: var(--surface-3);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
}

.active .row-tag { background: rgba(255, 255, 255, 0.18); color: #fff; }

.lock-icon {
  flex-shrink: 0;
  font-size: 0.75rem;
  opacity: 0.8;
}

.list-empty {
  color: var(--ink-soft);
  font-size: 0.85rem;
  padding: 0.4rem 0.5rem;
  cursor: default !important;
}

.list-empty:hover { background: none !important; }

/* Drag handle (same ⠿ as Coach HQ) */
.drag-handle {
  flex-shrink: 0;
  width: 18px;
  text-align: center;
  color: var(--ink-soft);
  opacity: 0.45;
  cursor: grab;
  user-select: none;
  touch-action: none;
  font-size: 0.95rem;
  line-height: 1;
}

.drag-handle:hover { opacity: 1; }
.dragging .drag-handle { cursor: grabbing; }
.active .drag-handle { color: #fff; }

/* Small round icon buttons at the end of a row (share link, ⋯ menu).
   Quiet until you hover the row, so the list reads as a clean list of names. */
.share-folder-btn,
.row-menu-btn {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  opacity: 0;
}

.row-menu-btn { font-size: 1.1rem; }

li:hover > .share-folder-btn,
li:hover > .row-menu-btn,
li.active > .share-folder-btn,
li.active > .row-menu-btn,
.row-menu-btn.open,
.share-folder-btn:focus-visible,
.row-menu-btn:focus-visible {
  opacity: 0.85;
}

.share-folder-btn:hover,
.row-menu-btn:hover,
.row-menu-btn.open {
  opacity: 1;
  background: rgba(255, 255, 255, 0.12);
}

.share-folder-btn.copied {
  width: auto;
  padding: 0 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 1;
}

/* Touch screens have no hover, so keep the row buttons visible there. */
@media (hover: none) {
  .share-folder-btn, .row-menu-btn { opacity: 0.7; }
}

/* The ⋯ dropdown (one shared element, positioned by app.js) */
.row-menu {
  position: fixed;
  z-index: 50;
  min-width: 170px;
  padding: 0.3rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}

.row-menu[hidden] { display: none; }

.row-menu button {
  text-align: left;
  background: none;
  border: none;
  border-radius: 4px;
  color: var(--ink);
  font-size: 0.875rem;
  padding: 0.45rem 0.65rem;
  cursor: pointer;
}

.row-menu button:hover { background: var(--surface-3); }
.row-menu button.danger { color: var(--danger); }
.row-menu button.danger:hover { background: rgba(236, 138, 127, 0.12); }

/* ---------- In-app dialog windows (rename, move, delete, ...) ---------- */

.app-dialog {
  width: min(380px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-top: 4px solid var(--navy);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.app-dialog::backdrop { background: rgba(0, 0, 0, 0.55); }

.app-dialog form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.25rem 1.25rem 1.1rem;
}

.app-dialog h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.app-dialog-message {
  margin: -0.35rem 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.app-dialog label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.app-dialog input,
.app-dialog select {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 400;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
}

.app-dialog input:focus,
.app-dialog select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--blue-soft);
}

.app-dialog-error {
  margin: -0.4rem 0 0;
  color: var(--danger);
  font-size: 0.85rem;
}

.app-dialog-error:empty { display: none; }

.app-dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.app-dialog-buttons .primary-btn { width: auto; }

.danger-fill { background: #b3372a; border-color: #b3372a; }
.danger-fill:hover:not(:disabled) { background: #962c21; border-color: #962c21; }

/* ---------- Form controls ---------- */

textarea, .text-input {
  width: 100%;
  resize: vertical;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  padding: 0.5rem 0.65rem;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

textarea:focus, .text-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--blue-soft);
}

.primary-btn, .secondary-btn, .small-btn, .ctrl-btn, .drawer-btn, .topbar-btn {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease),
    color 0.15s var(--ease), transform 0.1s var(--ease), box-shadow 0.15s var(--ease);
}

/* A small "press" on every button. */
:is(.primary-btn, .secondary-btn, .small-btn, .ctrl-btn, .drawer-btn, .topbar-btn,
    .mobile-ctrl-btn, .mobile-return-btn, .mobile-tilt-btn, .mobile-play-item):active:not(:disabled) {
  transform: scale(0.96);
}

:is(.primary-btn, .secondary-btn, .small-btn, .ctrl-btn):disabled {
  opacity: 0.45;
  cursor: default;
}

/* Burgundy is used only for the main action, same rule as Coach HQ. */
.primary-btn {
  width: 100%;
  background: var(--burgundy);
  border-color: var(--burgundy);
  color: #fff;
  font-size: 1.05rem;
  padding: 0.55rem 1rem;
}

.primary-btn:hover:not(:disabled) {
  background: var(--burgundy-dark);
  border-color: var(--burgundy-dark);
  box-shadow: 0 4px 14px rgba(142, 33, 64, 0.35);
}

.secondary-btn, .ctrl-btn {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink);
  font-size: 1rem;
  padding: 0.4rem 0.9rem;
}

.secondary-btn:hover:not(:disabled), .ctrl-btn:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: #38414f;
}

.small-btn {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink);
  padding: 0.25rem 0.6rem;
  font-size: 0.92rem;
}

.small-btn:hover:not(:disabled) { background: var(--surface-3); border-color: #38414f; }

.danger-btn { color: var(--danger); }

.status-msg {
  font-size: 0.8rem;
  color: var(--ink-soft);
  min-height: 1rem;
  margin: 0.4rem 0 0;
}

.status-msg:empty { display: none; }
.status-msg.error { color: var(--danger); }
.status-msg.success { color: #7fcf95; }

/* "How this works" help text - collapsed by default. */
.help {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.help > summary {
  cursor: pointer;
  color: var(--blue);
  font-weight: 600;
  list-style: none;
}

.help > summary::-webkit-details-marker { display: none; }
.help > summary::before { content: "▸ "; }
.help[open] > summary::before { content: "▾ "; }
.help p { margin: 0.45rem 0 0; line-height: 1.45; }
.help strong { color: var(--ink); font-weight: 600; }

/* "Describe a play in words" - a collapsible section. */
.describe-section > summary {
  cursor: pointer;
  list-style: none;
}

.describe-section > summary::-webkit-details-marker { display: none; }
.describe-section > summary::after { content: " ▸"; }
.describe-section[open] > summary::after { content: " ▾"; }
.describe-section[open] > summary { margin-bottom: 0.5rem; }
.describe-section { border-bottom: none; }

/* ---------- Record a play ---------- */

.roster-add-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 0.5rem;
}

.roster-add-row .text-input {
  flex: 1;
  width: auto;
  margin-bottom: 0;
  padding: 0.3rem 0.55rem;
  font-size: 0.8rem;
}

.roster-add-row .small-btn { flex-shrink: 0; }

/* The 6 position buttons in a 3x2 grid so they all fit the side panel. */
.position-add-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.position-add-row .small-btn {
  width: 100%;
  padding: 0.35rem 0.25rem;
  text-align: center;
}

.roster-list {
  list-style: none;
  margin: 0 0 0.6rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.roster-list:empty { display: none; }

.roster-list li {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #1b1f24;
}

.roster-list li button {
  border: none;
  background: rgba(0, 0, 0, 0.2);
  color: inherit;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  line-height: 1;
  cursor: pointer;
  font-size: 11px;
}

.swatch-toggle {
  width: 16px;
  height: 16px;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.35);
  border-radius: 50%;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.15);
}

.swatch-palette {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  gap: 4px;
  padding: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
  z-index: 20;
}

.swatch-palette.visible { display: flex; }

.swatch-option {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  cursor: pointer;
}

/* While recording (or editing) a play, the Folders/Plays/Describe sections
   are hidden to make room for the recording controls. */
#browseSidebarSections.hidden-while-recording,
#describeSidebarSection.hidden-while-recording {
  display: none;
}

/* Setup-only controls, tucked away once recording is underway. */
.recording-setup-only.hidden-while-recording {
  display: none;
}

.recording-bar {
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  margin: 0.25rem 0 0.4rem;
}

.recording-bar.visible { display: flex; }

.recording-step-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #fff;
  background: var(--burgundy);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.6rem;
  align-self: flex-start;
}

.recording-bar .text-input { margin-bottom: 0; }

.control-group {
  display: flex;
  flex-wrap: wrap; /* the checkbox drops below the button in the slim panel */
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 0.5rem;
}

.control-group .secondary-btn { white-space: nowrap; }

.control-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.control-grid .secondary-btn,
.finish-row .secondary-btn {
  padding: 0.45rem 0.25rem;
}

.group-label {
  margin-top: 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}

.finish-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 0.4rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.finish-btn {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
  font-weight: 600;
}

.finish-btn:hover { background: var(--navy-dark); }

.recording-hint { display: none; }
.recording-hint.visible { display: block; }

.pass-timing-option {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.pass-timing-option input { cursor: pointer; accent-color: var(--blue); }

/* "Show movement" + one circle per player color in the recording bar.
   Click a circle to hide that color's next-move lines (slashed = hidden). */
.move-line-toggles {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 2px 0 10px;
}
.move-line-title {
  color: var(--ink);
  font-size: 0.85rem;
  margin-right: 2px;
}
.move-line-dot {
  position: relative;
  width: 20px;
  height: 20px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  cursor: pointer;
  flex: none;
}
.move-line-dot.off { opacity: 0.55; }
.move-line-dot.off::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -3px;
  width: 2px;
  height: 22px;
  margin-left: -1px;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
  transform: rotate(45deg);
}
.move-line-dot:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.shape-draw-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

/* Highlighted while that draw mode is waiting for clicks on the field. */
.shape-draw-btn.active {
  background: var(--navy);
  border-color: var(--blue);
  color: #fff;
  font-weight: 600;
}

#shapesList { margin: 0 0 4px; }

/* ---------- Main (field area) ---------- */

.main {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}

/* The play's controls, inside the navy top bar. Grid (not
   flex+space-between) so the Prev/Play/Next group sits in a fixed, centered
   spot no matter how wide the title gets. */
.main-header {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 4px 12px;
  margin: 5px 0;
  padding: 5px 8px;
  /* A dark box, so the play tools read as separate from the Coach HQ
     logo, link and sign-out around them. */
  background: #0d1015;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
}

/* Buttons on the navy bar: see-through white instead of dark gray. */
.topbar :is(.drawer-btn, .secondary-btn) {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.topbar :is(.drawer-btn, .secondary-btn):hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.35);
}

.topbar .controls {
  background: rgba(0, 0, 0, 0.22);
  border-color: rgba(255, 255, 255, 0.12);
}

.topbar .controls .ctrl-btn { color: #fff; }
.topbar .controls .ctrl-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.14); }

/* Play is white on the navy bar so it stands out. */
.topbar .controls .ctrl-play,
.topbar .controls .ctrl-play:hover:not(:disabled) {
  background: #fff;
  color: var(--navy);
}

.title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  justify-self: start;
  grid-row: 1;
}

.drawer-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1;
}

.drawer-btn:hover { background: var(--surface-3); }
body.drawer-open .topbar .drawer-btn { background: #fff; border-color: #fff; color: var(--navy); }

.main-header h1 {
  font-size: 1.4rem;
  color: #fff;
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: end;
  grid-row: 1;
}

.header-action-hidden { display: none; }

/* Prev / Play / Next as one rounded pill. */
.controls {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  justify-self: center;
  grid-row: 1;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.controls .ctrl-btn {
  background: transparent;
  border-color: transparent;
  border-radius: 999px;
  padding: 0.35rem 0.95rem;
}

.controls .ctrl-btn:hover:not(:disabled) { background: var(--surface-3); border-color: transparent; }

/* Keeps "▶ Play" / "⏸ Pause" from nudging its neighbors when the label swaps. */
#playBtn { min-width: 92px; }

.controls .ctrl-play {
  background: var(--navy);
  color: #fff;
  font-weight: 700;
}

.controls .ctrl-play:hover:not(:disabled) { background: var(--navy-dark); }

/* "Step 2 of 8 — …" as a small label in the field's top-left corner. */
.step-label {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  max-width: calc(100% - 20px);
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(13, 16, 21, 0.72);
  color: #e9ecf1;
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none; /* never blocks dragging a player under it */
}

.step-label:empty { display: none; }

/* Only shown once you're in 3D mode. */
.rotate-controls {
  display: none;
  gap: 8px;
  align-items: center;
  width: 100%;
  margin-bottom: 0.4rem;
}

.rotate-controls.visible { display: flex; }

.hint-inline {
  color: var(--ink-soft);
  font-size: 0.78rem;
  margin-left: 4px;
}

/* ---------- Field (rendered with Three.js on this canvas) ---------- */

.field-stage {
  /* Uses most of the visible height (minus the top bar and header row)
     while still fitting without scrolling. */
  width: min(100%, 1000px, calc((100vh - 150px) * 4 / 3));
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.05), 0 18px 40px rgba(0, 0, 0, 0.45);
  background: #1f4d2c; /* matches the out-of-bounds grass */
  flex-shrink: 0;
  position: relative;
}

/* Full-field mode is wider/shorter (110 x 60 yd) than half-field (4:3). */
.field-stage.full-field {
  width: min(100%, 1100px, calc((100vh - 150px) * 11 / 6));
  aspect-ratio: 11 / 6;
}

/* On laptops/desktops the field gets all the space under the top bar.
   Top-down: its box is exactly the field's shape (set by app.js as
   --field-aspect: the field plus one player-disc of grass), as big as fits,
   centered. 3D: the box fills the whole space. (The phone viewer moves the
   field elsewhere and sizes it itself.) */
.field-area {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  container-type: size;
}

.field-area > .field-stage,
.field-area > .field-stage.full-field {
  flex: none;
  width: min(100cqw, 100cqh * var(--field-aspect, 1.3));
  aspect-ratio: var(--field-aspect, 1.3);
}

body.view-3d .field-area > .field-stage {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}

/* "Pick a play" card in the middle of an empty field. */
.empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  padding: 1.4rem 1.8rem;
  border-radius: var(--radius);
  background: rgba(13, 16, 21, 0.78);
  backdrop-filter: blur(6px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.empty-state[hidden] { display: none; }

.empty-state-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
}

.empty-state .primary-btn { width: auto; }

body.read-only-mode .coach-only { display: none; }

/* A coach's note for the step on screen, overlaid on the field. */
.mobile-step-caption {
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 12px 20px;
  background: rgba(13, 16, 21, 0.8);
  color: #f2f2f2;
  font-size: 15px;
  line-height: 1.4;
  text-align: center;
  max-height: 35%;
  overflow-y: auto;
  /* Read-only text: shouldn't block dragging a player underneath it. */
  pointer-events: none;
}

.mobile-step-caption[hidden] { display: none; }

#fieldCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#fieldCanvas:active { cursor: grabbing; }

/* ---------- Tablet / narrow window ---------- */

/* As the window narrows, drop the less important bits of the top bar
   first: the signed-in email, then the "Motion Builder" name, then the
   Coach HQ link. */
@media (max-width: 1400px) {
  .topbar .who { display: none; }
}

@media (max-width: 1250px) {
  .brand-name { display: none; }
}

/* Narrower laptop windows: title and buttons on one row, Prev/Play/Next
   centered on the row below (the bar gets taller), so nothing squeezes. */
@media (max-width: 1100px) {
  .topbar-link { display: none; }
  .main-header { grid-template-columns: 1fr auto; }
  .title-group { grid-column: 1; grid-row: 1; }
  .header-actions { grid-column: 2; grid-row: 1; }
  .controls { grid-column: 1 / -1; grid-row: 2; }
}

@media (max-width: 800px) {
  .main-header { grid-template-columns: 1fr; justify-items: center; }
  .title-group, .controls, .header-actions { grid-row: auto; grid-column: auto; justify-self: center; }
  /* Too narrow to dock the panel beside the field while diagramming, so it
     sits above the field and the page scrolls. */
  body.editing-mode { height: auto; overflow: auto; }
  body.editing-mode .app { flex-direction: column; }
  body.editing-mode .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--line); }
  body.editing-mode .field-area { flex: none; height: 70vh; }
}

/* =========================================================================
   Read-only mode (Players)
   =========================================================================
   Set by app.js when the signed-in visitor is a Player. Hides every
   editing entry point; browsing/watching plays still works. The database
   enforces the real rule regardless (Row Level Security) -- this just
   keeps editing controls out of a Player's way. */

body.read-only-mode #newFolderBtn,
body.read-only-mode .drag-handle,
body.read-only-mode .row-menu-btn,
body.read-only-mode #recordSidebarSection,
body.read-only-mode #describeSidebarSection,
body.read-only-mode #editPlayBtn {
  display: none;
}

body.read-only-mode .folder-list li,
body.read-only-mode .play-list li {
  padding-left: 0.6rem;
}

/* =========================================================================
   Mobile Viewer Mode
   =========================================================================
   Phone-sized screens (portrait OR landscape) get a separate, read-only
   presentation instead of the desktop editor. The breakpoint uses whichever
   viewport dimension is SMALLER, so a phone rotated to landscape still
   counts as mobile. This must match MOBILE_BREAKPOINT_PX in app.js. */

.mobile-screen { display: none; }

@media (pointer: coarse) and (max-width: 640px), (pointer: coarse) and (max-height: 640px) {
  body { height: auto; overflow: auto; display: block; }

  .app,
  .topbar { display: none; }

  .mobile-screen.active { display: flex; }

  /* Stops two quick taps (stepping through a play) from zooming the page. */
  .mobile-screen button { touch-action: manipulation; }

  /* ---- Playbook screen ---- */

  .mobile-playbook {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
  }

  .mobile-playbook-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1rem;
    background: var(--navy);
  }

  .mobile-playbook-header .brand-logo { height: 24px; }

  .mobile-playbook-header h1 {
    margin: 0;
    color: #fff;
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: -0.01em;
  }

  /* On a phone, just the Sign out button fits next to the title. */
  .mobile-playbook-header .who { display: none; }

  .mobile-folder-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.4rem 1rem 1.5rem;
  }

  .mobile-empty-msg {
    color: var(--ink-soft);
    font-size: 14px;
    padding: 20px 6px;
  }

  .mobile-folder { border-bottom: 1px solid var(--line); }

  .mobile-folder-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: none;
    border: none;
    color: var(--ink);
    font-family: inherit;
    font-size: 17px;
    font-weight: 600;
    padding: 16px 4px;
    cursor: pointer;
    text-align: left;
  }

  .mobile-folder-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-folder-chevron {
    flex-shrink: 0;
    color: var(--ink-soft);
    font-size: 14px;
  }

  .mobile-play-sublist {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 4px 16px;
  }

  .mobile-play-sublist.mobile-empty {
    color: var(--ink-soft);
    font-size: 14px;
    padding: 2px 4px 16px;
  }

  .mobile-play-item {
    text-align: left;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
    font-family: inherit;
    font-size: 15px;
    padding: 15px 14px;
    cursor: pointer;
  }

  .mobile-play-item:active {
    background: var(--navy);
    border-color: var(--navy);
    color: #fff;
  }

  /* ---- Play viewer screen ---- */

  .mobile-viewer {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
  }

  .mobile-viewer-topbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
  }

  .mobile-return-btn {
    flex-shrink: 0;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
  }

  .mobile-return-btn:active { background: var(--surface-3); }

  .mobile-play-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink);
    font-size: 15px;
    font-weight: 700;
    text-align: right;
  }

  .mobile-rotate-hint {
    flex-shrink: 0;
    margin: 0 12px 8px;
    padding: 8px 12px;
    background: var(--blue-soft);
    color: var(--ink);
    font-size: 13px;
    border-radius: var(--radius-sm);
    text-align: center;
  }

  .mobile-rotate-hint[hidden] { display: none; }

  .mobile-field-mount {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
  }

  /* The phone viewer shows the step under its buttons instead. */
  .mobile-field-mount .step-label { display: none; }

  /* On a phone the note lives in the top strip (.mobile-note), never over
     the field. */
  .mobile-field-mount .mobile-step-caption { display: none; }

  /* Portrait: the note gets its own line under "‹ Playbook" and the play
     name. Room for 4 lines is always kept (empty or not), so the field
     never shifts when a step has no note; portrait has plenty of spare
     height, so the field stays the same size. */
  .mobile-viewer-topbar { flex-wrap: wrap; }

  .mobile-note {
    order: 3;
    flex-basis: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(4 * 1.35em + 16px);
    margin: 0;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: #f2f2f2;
    font-size: 14px;
    line-height: 1.35;
    text-align: center;
  }

  .mobile-note:not(:empty) { background: var(--surface-2); }

  /* Sized to fit around the mobile controls (topbar + playback + step label
     + room for the rotate hint so the field doesn't jump size). */
  .mobile-field-mount .field-stage {
    width: min(100%, calc((100vh - 210px) * 4 / 3));
    width: min(100%, calc((100dvh - 210px) * 4 / 3));
    aspect-ratio: 4 / 3;
    max-height: 100%;
  }

  .mobile-field-mount .field-stage.full-field {
    width: min(100%, calc((100vh - 210px) * 11 / 6));
    width: min(100%, calc((100dvh - 210px) * 11 / 6));
    aspect-ratio: 11 / 6;
  }

  .mobile-controls-bar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 10px 16px;
  }

  .mobile-ctrl-btn {
    flex-shrink: 0;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--ink);
    border-radius: 50%;
    width: 52px;
    height: 52px;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .mobile-ctrl-btn:active { background: var(--surface-3); }

  .mobile-ctrl-btn svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
  }

  /* Play is a wide pill with a word on it, clearly different from the
     round step buttons around it. */
  .mobile-play-btn {
    width: auto;
    height: 58px;
    padding: 0 22px 0 18px;
    gap: 6px;
    border-radius: 999px;
    background: var(--navy);
    border-color: var(--navy);
    color: #fff;
    font-size: 17px;
    font-weight: 700;
  }

  .mobile-play-btn svg { width: 24px; height: 24px; }

  /* The restart arrow is an outline icon, not a filled one. */
  .mobile-ctrl-btn svg[fill="none"] { fill: none; }

  .mobile-play-btn:active { background: var(--navy-dark); }

  .mobile-step-label {
    flex-shrink: 0;
    margin: 0;
    text-align: center;
    color: var(--ink-soft);
    font-size: 12px;
    padding: 0 12px 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-tilt-btn {
    flex-shrink: 0;
    display: block;
    margin: 0 auto 10px;
    padding: 7px 18px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--ink);
    font-size: 13px;
    cursor: pointer;
  }

  .mobile-tilt-btn:active { background: var(--surface-3); }
}

/* Landscape phones: height is scarce, so the controls move into a slim
   column beside the field instead of underneath it. Placed after the block
   above so these overrides win when both apply. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 640px) {
  /* #mobileViewer (not .mobile-viewer) so this beats .mobile-screen.active. */
  #mobileViewer {
    display: grid;
    grid-template-columns: 1fr 84px;
    grid-template-rows: auto 1fr auto auto;
    grid-template-areas:
      "topbar topbar"
      "field controls"
      "field tilt"
      "field steplabel";
  }

  .mobile-viewer-topbar {
    grid-area: topbar;
    flex-wrap: nowrap;
    height: 45px; /* fixed, so a note never changes the field's size */
    padding: 5px 10px;
  }

  /* Landscape: the note sits in the top strip between "‹ Playbook" and the
     play name - space that's otherwise empty - up to two lines. */
  .mobile-note {
    order: 0;
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    padding: 2px 10px; /* fits two lines inside the fixed 45px strip */
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    font-size: 12.5px;
    line-height: 15px;
  }

  .mobile-play-name {
    flex: 0 1 auto;
    max-width: 30%;
  }

  .mobile-rotate-hint {
    margin: 0 10px 5px;
    padding: 5px 10px;
  }

  .mobile-field-mount {
    grid-area: field;
    padding: 4px 6px 4px 8px;
  }

  .mobile-controls-bar {
    grid-area: controls;
    flex-direction: column;
    gap: 10px;
    padding: 6px 8px;
  }

  .mobile-ctrl-btn {
    width: 44px;
    height: 44px;
    font-size: 16px;
  }

  /* Narrow side column in landscape: icon only. */
  .mobile-play-btn {
    width: 56px;
    height: 56px;
    padding: 0;
  }

  .mobile-play-btn span { display: none; }

  .mobile-tilt-btn {
    grid-area: tilt;
    width: 100%;
    margin: 0;
    padding: 6px 4px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    line-height: 1.2;
    white-space: normal;
  }

  .mobile-step-label {
    grid-area: steplabel;
    padding: 0 8px 8px;
    white-space: normal;
    line-height: 1.3;
  }

  /* Only the topbar takes height now; the controls sit beside the field. */
  .mobile-field-mount .field-stage {
    width: min(100%, calc((100vh - 46px) * 4 / 3));
    width: min(100%, calc((100dvh - 46px) * 4 / 3));
  }

  .mobile-field-mount .field-stage.full-field {
    width: min(100%, calc((100vh - 46px) * 11 / 6));
    width: min(100%, calc((100dvh - 46px) * 11 / 6));
  }
}

/* ---- Step editing ---- */
.edit-step-hint {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--ink-soft);
}

.step-btn-row {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 6px;
}
.step-btn-row button { white-space: nowrap; }

input[type="checkbox"]:disabled + *,
.pass-timing-option:has(input:disabled) { opacity: 0.45; }

/* Small menu that pops up when you tap a player while editing. */
.player-menu {
  position: fixed;
  z-index: 50;
  min-width: 170px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.player-menu[hidden] { display: none; }
.player-menu-title {
  padding: 4px 8px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}
.player-menu button {
  text-align: left;
  padding: 0.45rem 0.6rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}
.player-menu button:hover { background: var(--surface-3); }

/* A view-only share link (?play=<code>): just the field and the play
   controls - no playbook, no sign-in bits, no editing (see openSharedPlay
   in app.js). */
body.shared-play-mode #drawerBtn,
body.shared-play-mode #sidebar,
body.shared-play-mode #coachHqLink,
body.shared-play-mode .account-slot,
body.shared-play-mode #editPlayBtn,
body.shared-play-mode #lockPlayBtn,
body.shared-play-mode #sharePlayBtn,
body.shared-play-mode #mobileReturnBtn,
body.shared-play-mode #emptyState {
  display: none !important;
}
body.shared-play-mode .brand {
  pointer-events: none;
}
