/* Boat GPS Tracker, styled to the Bosham Sailing Club brand guidelines:
   white as the principal neutral space, BSC navy for structure and text, BSC red sparingly for emphasis.
   No other brand colours (the gold is for embroidery only). The logo is the supplied file, img/bsc-logo.png,
   used unchanged and only on white, at a size where the SAILING CLUB descriptor stays legible. */
:root {
  --navy: #253E77; --red: #EC2825; --white: #FFFFFF;
  --panel: rgba(255, 255, 255, .96); --line: rgba(37, 62, 119, .24); --tint: rgba(37, 62, 119, .08); --tint2: rgba(37, 62, 119, .15);
  --ink: var(--navy); --dim: #586A96; --accent: var(--navy);
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--white); }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }
#bar :focus-visible, .top :focus-visible { outline-color: var(--white); }
[hidden] { display: none !important; }
a { color: inherit; }

.badge { font-size: 11px; font-weight: 700; letter-spacing: .06em; padding: 3px 8px; border-radius: 99px; background: var(--white); color: var(--navy); border: 1px solid var(--navy); white-space: nowrap; }
.badge.live { background: var(--red); color: var(--white); border-color: var(--red); }
.badge.replay { background: var(--white); color: var(--navy); }
.badge.scheduled { background: var(--navy); color: var(--white); border-color: var(--white); }

/* ---------- viewer layout ---------- */
body.viewer { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; overscroll-behavior: none; }
#bar { display: flex; align-items: center; gap: 10px; padding: calc(6px + var(--sat)) calc(12px + var(--sar)) 6px calc(12px + var(--sal)); background: var(--navy); color: var(--white); min-height: 44px; }
#bar .club { display: flex; align-items: center; text-decoration: none; font-weight: 600; font-size: 14px; white-space: nowrap; min-height: 32px; }
#bar h1 { font-size: 15px; font-weight: 500; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--white); }
.conn { font-size: 12px; white-space: nowrap; display: flex; align-items: center; gap: 5px; }
.conn::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--white); border: 2px solid var(--white); box-sizing: border-box; }
.conn.wait::before { background: transparent; }
.conn.off::before { background: var(--red); }

#stage { position: relative; flex: 1; min-height: 0; background: #dfe6e8; }
#m2d { position: absolute; inset: 0; }
#m2d[hidden] { display: none; }
#stage > canvas, #touch { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#c3dLabels { pointer-events: none; }
#touch { touch-action: none; cursor: grab; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#touch:active { cursor: grabbing; }
#touch:focus-visible { outline-offset: -4px; }

#notice { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); max-width: min(92%, 520px); background: var(--panel); border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; font-size: 14px; text-align: center; z-index: 4; box-shadow: none; }
#demo { position: absolute; top: 10px; left: calc(10px + var(--sal)); background: var(--navy); color: var(--white); font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 6px; z-index: 3; max-width: 60%; }
#attrib { position: absolute; left: calc(6px + var(--sal)); bottom: 6px; font-size: 11px; background: rgba(255, 255, 255, .88); color: var(--navy); padding: 2px 7px; border-radius: 4px; z-index: 2; max-width: 70%; }
#attrib a { color: var(--navy); }

#viewctl { position: absolute; right: calc(10px + var(--sar)); top: 10px; z-index: 5; display: flex; flex-direction: column; gap: 6px; width: 176px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; backdrop-filter: blur(6px); }
#viewctl button, .transport button, #fleetToggle, .seg button { min-height: 40px; background: var(--white); border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; font-size: 14px; }
#viewctl button:hover, .transport button:hover { background: var(--tint); }
.seg { display: flex; }
#viewctl .seg button, .transport .seg button { flex: 1; border-radius: 0; margin-left: -1px; padding: 0 6px; }
#viewctl .seg button:first-child, .transport .seg button:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
#viewctl .seg button:last-child, .transport .seg button:last-child { border-radius: 0 8px 8px 0; }
#viewctl .seg button[aria-pressed="true"], .transport .seg button[aria-pressed="true"] { background: var(--navy); color: var(--white); border-color: var(--navy); font-weight: 700; position: relative; }
.row { display: flex; gap: 6px; }
.row button { flex: 1; padding: 0 2px; min-width: 0; white-space: nowrap; font-size: 13px; }
#viewctl > *, #viewctl .seg button, #viewctl select { min-width: 0; max-width: 100%; }
.field { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim); }
.field span { flex: none; width: 52px; }
.field select { flex: 1; min-width: 0; min-height: 36px; background: var(--white); border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; font-size: 13px; color: var(--ink); }
#more summary { font-size: 12px; color: var(--dim); cursor: pointer; padding: 6px 2px; }
#more[open] { display: flex; flex-direction: column; gap: 6px; }
.perf { font: 11px ui-monospace, Menlo, monospace; color: var(--dim); margin: 0; white-space: pre-wrap; }
body.is2d .only3d { display: none; }

#fleet { position: absolute; left: calc(10px + var(--sal)); top: 44px; bottom: 30px; width: 290px; z-index: 5; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(6px); overflow: hidden; }
/* The club logo sits at the top of the fleet panel on screens with room for it at a legible size. */
#brand { display: block; flex: none; height: 118px; width: auto; align-self: center; margin: 16px 16px 12px; }
#brandWrap { display: flex; justify-content: center; border-bottom: 1px solid var(--line); background: var(--white); }
@media (max-width: 760px), (max-height: 640px) { #brandWrap { display: none; } }
#fleet.collapsed { bottom: auto; }
#fleet.collapsed #fleetBody { display: none; }
#fleetToggle { display: flex; justify-content: space-between; align-items: center; border: 0; border-radius: 0; background: transparent; font-weight: 600; width: 100%; min-height: 44px; }
.chev { width: 9px; height: 9px; border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink); transform: rotate(-135deg); margin: 4px 6px 0; transition: transform .15s; }
#fleet.collapsed .chev { transform: rotate(45deg); margin-top: -4px; }
#fleetBody { display: flex; flex-direction: column; min-height: 0; flex: 1; border-top: 1px solid var(--line); }
#search { margin: 8px; min-height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--white); padding: 0 10px; font-size: 16px; }
#boats { list-style: none; margin: 0; padding: 0 0 6px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
#boats li { display: flex; align-items: stretch; border-top: 1px solid var(--tint2); }
#boats .pick { flex: 1; min-width: 0; display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; text-align: left; background: none; border: 0; padding: 7px 8px; min-height: 44px; font-size: 13px; }
#boats .pick[aria-pressed="true"] { background: var(--tint2); box-shadow: inset 4px 0 0 var(--navy); }
#boats .sw { width: 12px; height: 12px; border-radius: 3px; }
#boats .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#boats .who b { font-weight: 600; }
#boats .spd { color: var(--dim); font-variant-numeric: tabular-nums; font-size: 12px; }
#boats .spd.stale { color: var(--red); font-weight: 600; }
#boats .fol { flex: none; width: 44px; background: none; border: 0; border-left: 1px solid var(--tint2); font-size: 16px; color: var(--dim); }
#boats .fol[aria-pressed="true"] { color: var(--white); background: var(--navy); }
#details:empty { display: none; }
#details { border-top: 1px solid var(--line); padding: 8px 10px; font-size: 13px; max-height: 40%; overflow-y: auto; }
#details .card + .card { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
#details h2 { font-size: 14px; margin: 0 0 4px; display: flex; align-items: center; gap: 6px; }
#details h2 i { width: 10px; height: 10px; border-radius: 2px; flex: none; }
#details dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px 8px; margin: 0; }
#details dt { font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--dim); }
#details dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }
#details .stale { color: var(--red); }
#details .acts { display: flex; gap: 6px; margin-top: 6px; }
#details .acts button { min-height: 34px; font-size: 12px; background: var(--white); border: 1px solid var(--line); border-radius: 7px; padding: 0 10px; }

#playbar { background: var(--white); border-top: 2px solid var(--navy); padding: 6px calc(12px + var(--sar)) calc(8px + var(--sab)) calc(12px + var(--sal)); display: flex; flex-direction: column; gap: 4px; }
.timeline { display: flex; align-items: center; gap: 8px; }
.timeline .mark { font-size: 11px; color: var(--dim); white-space: nowrap; font-variant-numeric: tabular-nums; }
#scrub { flex: 1; min-width: 0; height: 32px; accent-color: var(--accent); margin: 0; }
.transport { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#play { width: 48px; min-height: 44px; border-radius: 50%; background: var(--red); color: var(--white); border: 0; font-size: 17px; flex: none; }
.clock { display: flex; flex-direction: column; line-height: 1.15; min-width: 92px; }
#elapsed { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
#wall { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }
.rates { flex: 1; max-width: 320px; }
.rates.muted button { opacity: .45; }
#goLive { background: var(--red); color: var(--white); border: 0; font-weight: 700; }
.transport #play:hover, .transport #goLive:hover { background: #c81f1c; }

@media (max-width: 760px) {
  #viewctl { width: 148px; padding: 6px; gap: 5px; top: 6px; right: calc(6px + var(--sar)); }
  #viewctl button, .seg button { min-height: 38px; font-size: 13px; }
  #viewctl .row button { padding: 0 2px; font-size: 12px; }
  .field span { width: auto; }
  #demo { left: calc(6px + var(--sal)); max-width: calc(100% - 168px); font-size: 11px; }
  /* The fleet becomes a bottom sheet, within thumb reach above the playback bar. */
  #fleet { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 62%; border-radius: 14px 14px 0 0; border-left: 0; border-right: 0; border-bottom: 0; }
  #fleet.collapsed { max-height: none; bottom: 0; }
  #fleetToggle { order: -2; }
  #details { order: -1; max-height: 30vh; }
  #attrib { bottom: auto; top: 6px; font-size: 10px; max-width: calc(100% - 168px); }
  #demo { top: 28px; }
  #notice { top: 44px; }
  .rates { order: 5; flex-basis: 100%; max-width: none; }
  .clock { flex: 1; }
}
@media (max-height: 480px) and (orientation: landscape) {
  #bar { min-height: 34px; padding-top: calc(2px + var(--sat)); padding-bottom: 2px; }
  #playbar { flex-direction: row; align-items: center; gap: 10px; padding-top: 3px; padding-bottom: calc(3px + var(--sab)); }
  .timeline { flex: 1; }
  .rates { order: 0; flex-basis: auto; max-width: 230px; }
  .clock { flex: none; }
  #fleet { left: calc(6px + var(--sal)); right: auto; width: 270px; top: 6px; bottom: 6px; max-height: none; border-radius: 12px; border: 1px solid var(--line); }
  #fleet.collapsed { bottom: auto; }
  #attrib { top: auto; }
  #viewctl { flex-direction: row; flex-wrap: wrap; width: 300px; }
  #viewctl > * { flex: 1 1 130px; }
  #attrib { bottom: 6px; left: auto; right: calc(6px + var(--sar)); }
  #demo { left: 290px; }
}
@media (prefers-reduced-motion: reduce) { .chev { transition: none; } }

/* ---------- race list ---------- */
body.list { min-height: 100%; background: var(--white); }
.wrap { max-width: 860px; margin: 0 auto; padding: calc(28px + var(--sat)) calc(18px + var(--sar)) calc(40px + var(--sab)) calc(18px + var(--sal)); }
/* Primary logo on white, with clear space around it of at least the descriptor's height. */
.masthead { padding: 12px 12px 20px; border-bottom: 2px solid var(--navy); margin-bottom: 22px; }
.masthead img { display: block; height: 150px; width: auto; }
.list h1 { font-size: 26px; margin: 0 0 4px; color: var(--navy); }
.lede { color: var(--dim); margin: 2px 0 22px; }
.list h2 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--navy); margin: 26px 0 8px; }
.races { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.races a { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; background: var(--white); border: 1px solid var(--line); border-left: 4px solid var(--navy); border-radius: 8px; padding: 14px 16px; text-decoration: none; }
.races a:hover { background: var(--tint); }
.races strong { font-size: 16px; }
.races small { color: var(--dim); grid-column: 1; }
.races .badge { grid-row: 1 / span 2; grid-column: 2; }
.empty { color: var(--dim); }
.foot { margin-top: 36px; font-size: 13px; color: var(--dim); }
.foot a { color: var(--navy); }
@media (max-width: 480px) { .masthead img { height: 124px; } }
