* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: system-ui, "Segoe UI", sans-serif;
  background: #17181b; color: #ededed;
  overflow: hidden;
}

/* ===== Themed scrollbars (match the dark UI) — applies to every scroll
   container: #tools, #palette, track/category lists, chat, score card, etc. ===== */
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.18) transparent; } /* Firefox */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.16); border-radius: 8px;
  border: 2px solid transparent; background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.30); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }

.screen { display: none; width: 100%; height: 100%; }
.screen.active { display: flex; }

/* ===== App shell — Geist/Linear minimal: hairline borders, grey-on-grey, one accent ===== */
#menu, #lobby { align-items: stretch; justify-content: flex-start; gap: 0; background: #17181b; }

/* Persistent brand rail (identical on menu + lobby) */
.rail {
  flex-shrink: 0; width: 300px; display: flex; flex-direction: column; gap: 20px;
  padding: 22px 18px; background: #1c1d20; border-right: 1px solid rgba(255,255,255,0.11);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-logo {
  font-size: 22px; width: 40px; height: 40px; flex-shrink: 0; display: grid; place-items: center;
  background: #26272b; border: 1px solid rgba(255,255,255,0.10); border-radius: 10px;
}
.brand-name { font-size: 18px; font-weight: 600; letter-spacing: -0.3px; color: #ededed; }
.brand-name b { color: #6fd3a6; font-weight: 600; }
.rail-tagline { margin: 0; font-size: 13px; line-height: 1.5; color: #6b7078; }

.rail-section { display: flex; flex-direction: column; min-height: 0; flex: 1; gap: 10px; }
.rail-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: #6b7078;
}
.rail-head button { height: 24px; width: 24px; padding: 0; font-size: 12px; background: #232428; border: 1px solid rgba(255,255,255,0.11); border-radius: 6px; color: #8a8f98; }
.rail-head button:hover { background: #2c2d31; color: #ededed; }
.rail-foot { display: flex; flex-direction: column; gap: 2px; margin-top: auto; }
.rail-foot .ghost { justify-content: flex-start; color: #8a8f98; }
.rail-foot .ghost:hover { color: #ededed; background: rgba(255,255,255,0.04); }

/* Open-games list (menu rail) */
.lobby-list { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; flex: 1; min-height: 0; }
.lobby-row { background: #1f2024; border: 1px solid rgba(255,255,255,0.10); border-radius: 8px; padding: 9px 10px; }
.lobby-row .lr-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.lobby-row .lr-name { font-weight: 500; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lobby-row .lr-count { color: #8a8f98; font-size: 12px; white-space: nowrap; }
.lobby-row .lr-sub { color: #62666d; font-size: 12px; margin: 2px 0 8px; }
.lobby-row .lr-sub .live { color: #6fd3a6; }
.lobby-row button { width: 100%; height: 30px; font-size: 12px; }
.lobby-empty { color: #62666d; font-size: 12.5px; text-align: center; padding: 16px 6px; line-height: 1.5; }

/* Focused main column */
/* `safe center`: vertically center when it fits, but fall back to top-aligned (not
   clipped-and-unreachable) the moment content is taller than the viewport. */
.stage-main { flex: 1; min-width: 0; display: flex; align-items: safe center; justify-content: center; padding: 15px 28px; overflow-y: auto; }
.content { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 11px; }
/* Menu: present the form as a contained, centered card so it reads as intentional on
   wide screens (instead of a narrow column floating off-center next to the rail). */
#menu .content { max-width: 430px; background: #1b1c21; border: 1px solid rgba(255,255,255,0.06); border-radius: 16px; padding: 22px 24px; }
#menu .stage-main { padding: 24px; }
/* Wide screens: float the rail as a left overlay so the start card centers in the FULL
   viewport (not in the off-centre area beside the rail). Only above a width where the
   centred 430px card can't reach the ~300px rail, so they never overlap. */
@media (min-width: 1200px) {
  #menu { position: relative; }
  #menu > .rail { position: absolute; top: 0; left: 0; bottom: 0; }
}
.screen-title { margin: 0 0 4px; font-size: 21px; font-weight: 600; letter-spacing: -0.4px; color: #ededed; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.big { height: 46px; font-size: 15px; }

/* Lobby main specifics */
.lobby-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.eyebrow { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: #6b7078; margin-bottom: 6px; }
.lobby-top #lobbyCode { font-size: 30px; letter-spacing: 7px; color: #ededed; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.lobby-top #copyLink { flex-shrink: 0; white-space: nowrap; }
/* Each lobby section is a card: a lifted surface over the page so the setup reads as
   discrete panels instead of one dense form. */
.block {
  display: flex; flex-direction: column; gap: 7px;
  background: #1f2024; border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px; padding: 11px 14px;
}
.block-head { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: #6b7078; margin-bottom: 1px; }
/* Sub-grouping inside the Rules block: a small muted label with a hairline divider
   so related toggles read as one set (Gameplay vs Lobby & maps). */
.rules-group { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: #5a5f66; margin-top: 3px; padding-top: 8px; border-top: 1px solid rgba(255,255,255,0.07); }
.rules-group:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }

/* Inside a lobby card, every control row reads as one inline rhythm: label on the
   left, switch/select on the right, comfortable touch height. */
#lobby .block .switch-row, #lobby .block .field {
  flex-direction: row; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 30px; padding: 0;
}
#lobby .block .field > span { color: #c9ccd1; font-weight: 400; font-size: 14px; }
#lobby .block .field select { width: auto; min-width: 128px; height: 33px; }
/* Nested items sit a shade lighter than their card so they stay legible. */
#playerList li { background: #26272b; }

/* Course hero card: the one deliberate green-leak surface (daily-card border
   token) anchored by a real hole-1 canvas — the page's single image panel. */
.course-card { border-color: rgba(111,211,166,0.22); }
#mapThumb {
  display: block; width: 100%; height: auto; background: #46b35a;
  border-radius: 8px; border: 1px solid rgba(255,255,255,0.10);
}
.map-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.map-row .map-info { min-width: 0; flex: 1; }
/* The missing mid type step: 30px code → 18px course name → 14px body. */
.map-name { font-weight: 600; font-size: 18px; letter-spacing: -0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vote-sec { display: flex; flex-direction: column; gap: 7px; }
.suggest-row { padding-top: 2px; }
.course-msg { text-align: left; min-height: 0; }
.course-msg:empty { display: none; }

/* Bots: a divider-topped sub-section of the Players card (no card of its own). */
#botsBlock { display: flex; flex-direction: column; gap: 7px; border-top: 1px solid rgba(255,255,255,0.07); padding-top: 9px; }

/* Sticky action bar: Start (or the guest waiting status) + the live "Next: …"
   line, pinned to the bottom of .stage-main (the sole scroller) on every device. */
.lobby-actions {
  position: sticky; bottom: 0; z-index: 3;
  display: flex; align-items: center; gap: 14px;
  background: rgba(23,24,27,0.93);
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
}
.lobby-actions .la-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
#lobbyStatus { font-size: 14px; font-weight: 600; color: #ededed; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lobby-actions #startBtn { flex-shrink: 0; min-width: 170px; }
.lobby-actions .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Lobby: stacked on phones, two columns on wide screens so the desktop uses the
   available width instead of a thin centered strip. */
.lobby-cols { display: flex; flex-direction: column; gap: 14px; }
.lobby-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
@media (min-width: 1000px) {
  #lobby .content { max-width: 880px; }
  /* Course hero takes the wider track; Players + Rules stack in the narrower one. */
  .lobby-cols { display: grid; grid-template-columns: 1.15fr 1fr; gap: 22px; align-items: start; }
}
/* 761-999px (e.g. iPad portrait): single column, but a real card width — not the
   380px phone strip the base .content max-width would otherwise impose. */
@media (min-width: 761px) and (max-width: 999px) {
  #lobby .content { max-width: 640px; }
}

@media (max-width: 760px) {
  #menu, #lobby { flex-direction: column; }
  .rail { width: 100%; border-right: none; border-bottom: 1px solid rgba(255,255,255,0.11); max-height: 40vh; }
  /* Lobby on a phone: ONE scrolling page (#lobby is the scroller) — content
     first, chat below it, Leave last — and the action bar pinned to the REAL
     viewport bottom (fixed, since sticky-in-.stage-main would pin mid-screen
     above the rail). The rail's bottom padding keeps Leave clear of the bar. */
  #lobby { overflow-y: auto; }
  #lobby .stage-main { flex: none; overflow: visible; }
  #lobby .rail {
    order: 2; flex: none; max-height: none;
    border-bottom: none; border-top: 1px solid rgba(255,255,255,0.11);
    padding-bottom: calc(86px + env(safe-area-inset-bottom));
  }
  #lobby .rail .chat-log { max-height: 38vh; }
  .lobby-actions { position: fixed; left: 0; right: 0; bottom: 0; padding-left: 14px; padding-right: 14px; }
  .lobby-actions .sub { display: none; }                       /* status line only on phones */
  .lobby-actions #startBtn { min-width: 0; flex: 0 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* Top-align (not vertical-center) so a tall lobby column scrolls cleanly
     instead of having its top clipped by flex centering. */
  .stage-main { padding: 22px; justify-content: flex-start; }
}
.panel {
  background: #1f2024; border: 1px solid rgba(255,255,255,0.10); border-radius: 12px;
  padding: 24px; width: min(360px, 92vw); box-shadow: none;
  display: flex; flex-direction: column; gap: 14px;
}
.panel h1 { margin: 0 0 6px; font-size: 22px; font-weight: 600; text-align: center; display: flex; align-items: center; justify-content: center; gap: 9px; letter-spacing: -0.3px; }
.panel h1 .logo { font-size: 22px; }
.panel h2 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.3px; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 12px; letter-spacing: 0; color: #8a8f98; font-weight: 500; }
input, select {
  background: #232428; border: 1px solid rgba(255,255,255,0.10); color: #ededed;
  height: 40px; padding: 0 12px; border-radius: 8px; font-size: 14px; width: 100%;
}
input::placeholder { color: #5b5f66; }
select { cursor: pointer; }
input:focus, select:focus { outline: none; border-color: #6fd3a6; box-shadow: 0 0 0 3px rgba(111,211,166,0.12); }
/* Segmented toggle (aim style) */
.segmented { display: flex; background: #232428; border: 1px solid rgba(255,255,255,0.10); border-radius: 9px; padding: 4px; gap: 4px; }
.segmented input { display: none; }
.segmented label {
  flex: 1; text-align: center; padding: 8px 6px; border-radius: 6px; cursor: pointer;
  font-size: 14px; color: #8a8f98; transition: all 0.12s; user-select: none;
}
.segmented label:hover { color: #ededed; background: rgba(255,255,255,0.04); }
.segmented input:checked + label { background: #6fd3a6; color: #06281a; font-weight: 600; }

/* Toggle switch (sound) */
.switch-row { display: flex; align-items: center; justify-content: space-between; font-size: 14px; color: #c9ccd1; cursor: pointer; }
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: #3a3b40; border-radius: 24px; transition: 0.18s;
}
.switch .slider::before {
  content: ''; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px;
  background: #ededed; border-radius: 50%; transition: 0.18s;
}
.switch input:checked + .slider { background: #6fd3a6; }
.switch input:checked + .slider::before { transform: translateX(18px); background: #06281a; }

button {
  background: #26272b; border: 1px solid rgba(255,255,255,0.10); color: #ededed; height: 40px; padding: 0 14px;
  border-radius: 8px; font-weight: 500; font-size: 14px; cursor: pointer; transition: background 0.12s, border-color 0.12s;
}
button:hover { background: #2e2f33; border-color: rgba(255,255,255,0.16); }
button.primary { background: #6fd3a6; color: #06281a; border-color: transparent; font-weight: 600; }
button.primary:hover { background: #7fe0b4; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.menu-buttons { display: flex; flex-direction: column; gap: 10px; }
.course-row { display: flex; gap: 8px; align-items: stretch; }
.icon-btn { width: 40px; flex-shrink: 0; padding: 0; font-size: 16px; background: #232428; border: 1px solid rgba(255,255,255,0.10); display: flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: #2c2d31; border-color: rgba(255,255,255,0.18); }
/* Drop the base button's fixed 40px height so these stretch to the taller
   picker (align-items: stretch) and line up flush with it. */
.course-row .icon-btn { height: auto; }

/* Course picker — opens the gallery; a tidy two-line field with a Change cue. */
.course-pick {
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  height: auto; min-height: 48px; padding: 7px 12px; text-align: left;
  background: #232428; border: 1px solid rgba(255,255,255,0.10);
}
.course-pick:hover { background: #2a2b2f; border-color: #6fd3a6; box-shadow: 0 0 0 3px rgba(111,211,166,0.10); }
.course-pick .cp-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.course-pick .cp-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.course-pick .cp-sub { font-size: 12px; color: #8a8f98; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.course-pick .cp-act { flex-shrink: 0; font-size: 12px; font-weight: 600; color: #6fd3a6; white-space: nowrap; }

.join-row { display: flex; gap: 8px; }
.join-row #joinCode { flex: 1; text-transform: uppercase; letter-spacing: 2px; }
.join-row #joinBtn { width: 92px; flex-shrink: 0; }

/* labelled divider */
.divider { display: flex; align-items: center; gap: 10px; color: #5b5f66; font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; margin: 2px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: rgba(255,255,255,0.11); }

.secondary { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 2px; }
.ghost {
  background: transparent; border: none; color: #8a8f98; height: auto; padding: 8px 10px; font-size: 14px;
  font-weight: 500; text-decoration: none; border-radius: 8px; display: inline-flex; align-items: center; gap: 8px;
}
.ghost:hover { color: #ededed; background: rgba(255,255,255,0.05); border: none; }

/* In-game settings button + range */
.hud-btn {
  position: absolute; bottom: 18px; right: 18px; width: 42px; height: 42px; padding: 0;
  background: rgba(10,15,22,0.6); border-radius: 10px; font-size: 20px; line-height: 1;
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
}
.hud-btn:hover { background: rgba(20,30,44,0.9); }
input[type="range"] { -webkit-appearance: none; appearance: none; height: 6px; background: #3a3b40; border-radius: 3px; padding: 0; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #6fd3a6; cursor: pointer; }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border: none; border-radius: 50%; background: #6fd3a6; cursor: pointer; }
.join-row input { text-transform: uppercase; letter-spacing: 3px; text-align: center; }
.join-row button { white-space: nowrap; }
.link { color: #6fd3a6; text-decoration: none; text-align: center; font-size: 14px; margin-top: 4px; }
.link:hover { text-decoration: underline; }
.msg { min-height: 18px; font-size: 13px; color: #e0a04a; text-align: center; }
.sub { font-size: 13px; color: #8a8f98; }

.code-box { font-size: 18px; text-align: center; }
/* Wrap into 2 columns when there's room (e.g. a full 8-seat lobby), so a stack of
   bots doesn't run the column twice as long as the rules beside it. 130px keeps
   two columns alive even in the narrower right grid track at ~1000px viewports. */
#playerList { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
#playerList li { background: #26272b; border: 1px solid rgba(255,255,255,0.08); padding: 8px 10px; border-radius: 8px; display: flex; gap: 9px; align-items: center; font-size: 13px; min-width: 0; }
#playerList li .pname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Empty seats hold the card at full 8-player size so it never resizes as people
   join — and double as the recruiting affordance (tap to copy the invite link). */
#playerList li.seat-empty { background: transparent; border-style: dashed; border-color: rgba(255,255,255,0.09); justify-content: center; cursor: pointer; }
#playerList li.seat-empty .pname { color: #50555d; font-size: 12px; }
#playerList li.seat-empty:hover { border-color: rgba(111,211,166,0.4); }
#playerList li.seat-empty:hover .pname { color: #8a8f98; }
.host-tag { margin-left: auto; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: #6fd3a6; }
/* Neutral grey — a blue tag × 7 bots out-saturates the single green accent. */
.bot-tag { margin-left: auto; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: #9aa0a8; }
.host-tag + .bot-tag { margin-left: 7px; }
.swatch { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
/* Host-only per-seat kick: small square, pushed to the row's right edge. */
.pkick { margin-left: auto; flex-shrink: 0; width: 26px; height: 26px; padding: 0; font-size: 11px; line-height: 1; color: #8a8f98; background: #232428; border: 1px solid rgba(255,255,255,0.10); border-radius: 6px; cursor: pointer; }
.pkick:hover { background: #3a2326; color: #e8503a; border-color: rgba(232,80,58,0.4); }
@media (pointer: coarse) { .pkick { width: 34px; height: 34px; } }

/* Host-only controls, seen by a joiner: a "Host only" tag on the Rules header
   and a clearly LOCKED (not just faded) look on every disabled control. */
.lock-tag { margin-left: 7px; font-size: 10px; font-weight: 600; letter-spacing: 0.5px; color: #e0a04a; }
.switch-row:has(input:disabled) { cursor: not-allowed; opacity: 0.7; }
.field:has(select:disabled) { opacity: 0.7; }
select:disabled { cursor: not-allowed; }
/* A locked toggle must read inert — muted grey, never the bright accent, even
   when the setting is on (knob still shows the on/off position). */
.switch input:disabled + .slider { background: #34353a; cursor: not-allowed; }
.switch input:disabled:checked + .slider { background: rgba(111,211,166,0.30); }
.switch input:disabled + .slider::before { background: #9aa0a8; }
/* A locked primary button (Start, for a guest) reads grey, not faded green. */
button.primary:disabled { background: #2a2b2f; color: #8a8f98; border-color: rgba(255,255,255,0.08); opacity: 0.9; }

/* ===== Next-map vote board (lobby) ===== */
.vote-actions { display: flex; gap: 6px; }
.mini {
  height: 30px; padding: 0 10px; font-size: 12px; font-weight: 500;
  text-transform: none; letter-spacing: 0; color: #ededed;
  background: #232428; border: 1px solid rgba(255,255,255,0.10);
}
.mini:hover { background: #2c2d31; }
/* No inner scroller: the 12-candidate cap bounds growth and the sticky action
   bar keeps Start reachable, so the list grows and the page scrolls. Full-width
   rows — two 210px columns left no room for the name + tag + vote button. */
.vote-list { display: flex; flex-direction: column; gap: 6px; }
.vote-list:empty { display: none; }
.vote-row {
  display: flex; align-items: center; gap: 10px;
  background: #26272b; border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px; padding: 8px 10px; font-size: 13px;
}
.vote-row.voted { border-color: #6fd3a6; background: #1c2a23; }
.vote-row.lead { border-color: rgba(111,211,166,0.55); }
/* The name always keeps a readable floor; the meta tags shrink/clip first. */
.vote-row .vname { flex: 1; min-width: 64px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vote-row .vmeta { color: #8a8f98; font-size: 12px; white-space: nowrap; display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; }
.vote-row .vtag { color: #6fd3a6; font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px; }
.vote-row .vby { color: #62666d; font-size: 11px; max-width: 84px; overflow: hidden; text-overflow: ellipsis; }
.vote-row .vbtn {
  flex-shrink: 0; height: 30px; min-width: 50px; padding: 0 10px; font-size: 13px;
  font-variant-numeric: tabular-nums; background: #2e2f33; /* one step lighter than the row, so it reads as a control */
}
.vote-row.voted .vbtn { background: #6fd3a6; color: #06281a; border-color: transparent; font-weight: 600; }
.vote-row .vrm { flex-shrink: 0; width: 30px; height: 30px; padding: 0; font-size: 12px; color: #8a8f98; background: #232428; }
.vote-row .vrm:hover { background: #3a2326; color: #e8503a; border-color: rgba(232,80,58,0.4); }
/* Touch: bump the small vote controls to a comfortable tap target. */
@media (pointer: coarse) {
  .mini, .vote-row .vbtn { height: 38px; }
  .vote-row .vrm { width: 38px; height: 38px; }
}

/* ===== Playforia map browser (matches the menu/lobby grey theme) ===== */
#browser { background: #17181b; align-items: stretch; justify-content: center; }
.browser-panel {
  width: 100%; max-width: 1000px; height: 100%; display: flex; flex-direction: column; padding: 18px;
}
.browser-head { display: flex; align-items: center; gap: 14px; }
.browser-head h2 { margin: 0; font-size: 22px; white-space: nowrap; }
.browser-head input { flex: 1; }
.browser-head button { white-space: nowrap; }
.browser-body { flex: 1; min-height: 0; display: flex; gap: 14px; margin-top: 14px; }
.cat-tabs { display: flex; flex-direction: column; gap: 6px; width: 170px; flex-shrink: 0; overflow-y: auto; }
.cat-tab {
  background: #1f2024; border: 1px solid rgba(255,255,255,0.10); border-radius: 8px; padding: 10px 12px;
  cursor: pointer; font-size: 14px; text-align: left; color: #ededed;
}
.cat-tab:hover { background: #26272b; }
.cat-tab.sel { background: #6fd3a6; color: #06281a; font-weight: 600; }
.cat-tab .cnt { float: right; opacity: 0.7; font-size: 12px; }
/* Divider between our gallery and the Playforia import library. Works in the
   vertical sidebar and the horizontal tab strip used on narrow screens. */
.cat-sep {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px;
  color: #5b5f66; padding: 8px 4px 4px; white-space: nowrap; flex-shrink: 0; align-self: center;
}
.track-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding-right: 6px; }
.track-row {
  display: flex; align-items: center; gap: 12px; background: #1f2024; border: 1px solid rgba(255,255,255,0.10);
  border-radius: 8px; padding: 9px 12px; font-size: 14px;
}
.track-row:hover { background: #26272b; }
.track-row .tname { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-row .tauthor { color: #8a8f98; font-size: 12px; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.track-row .tpar { color: #f0c419; font-size: 12px; min-width: 44px; }
.track-row button { padding: 6px 12px; }
.track-row.set { border-color: #6fd3a6; }
.browser-empty { color: #62666d; padding: 20px; text-align: center; }

/* ===== Game ===== */
#game { background: #17181b; }
#stage { position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
canvas {
  background: #46b35a;
  border-radius: 12px;
  box-shadow: 0 18px 60px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.06);
  cursor: crosshair;
  touch-action: none;               /* let pointer capture own drags */
  /* width/height set by JS (fitCanvas) to fill the stage, aspect-preserved */
}
/* Portrait phones (fitCanvas): the board turned a quarter, centred in the stage. */
canvas.rotated { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-90deg); }

.hud {
  position: absolute; top: 14px; padding: 8px 12px;
  background: rgba(10,15,22,0.55); border-radius: 8px; font-size: 14px;
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px); /* board reads through */
  pointer-events: none;
}
#hudTopLeft { left: 14px; }
.hud-holename { color: #6fd3a6; font-weight: 700; font-style: italic; }
#shotClock { left: 50%; transform: translateX(-50%); top: 14px; font-size: 16px; font-weight: 700; display: none; }
#shotClock.show { display: block; }
#shotClock.low { color: #e8503a; }
#hudTopRight { right: 14px; color: #8a8f98; }

/* Persistent right-side scoreboard (includes the whose-turn indicator). */
#scorePanel {
  right: 14px; top: 14px; padding: 10px 12px; min-width: 200px; max-width: 260px;
  display: flex; flex-direction: column; gap: 6px;
}
.sp-head { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: #8a8f98; display: flex; justify-content: space-between; align-items: center; }
.sp-head kbd { font-size: 10px; }
#scoreRows { display: flex; flex-direction: column; gap: 3px; }
.sp-row {
  display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 6px;
  border-radius: 6px; opacity: 0.8;
}
.sp-row.turn { opacity: 1; background: rgba(111,211,166,0.16); box-shadow: inset 2px 0 0 #6fd3a6; }
.sp-row .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.sp-row .pturn { width: 8px; color: #6fd3a6; font-weight: 700; }
.sp-row .pname { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-row .pstrokes { color: #c8d4de; font-variant-numeric: tabular-nums; font-size: 12px; }
.sp-row .ptopar { color: #8a8f98; font-variant-numeric: tabular-nums; min-width: 22px; text-align: right; }
.sp-row.sunk .pname { color: #6fd3a6; }
.sp-row.me .pname { font-weight: 700; }
.sp-row .plate { font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: #ffcf6b; background: rgba(255,159,92,0.16); border-radius: 4px; padding: 1px 4px; margin-left: 4px; vertical-align: middle; }
kbd { background: #2e2f33; border-radius: 4px; padding: 1px 6px; font-size: 12px; }

.banner {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  font-size: 26px; font-weight: 700; padding: 10px 22px; border-radius: 10px;
  background: rgba(10,15,22,0.6); opacity: 0; transition: opacity 0.25s;
  pointer-events: none; text-align: center;
}
.banner.show { opacity: 1; }

#powerbar {
  position: absolute; left: 18px; bottom: 18px; width: 200px; height: 16px;
  background: rgba(0,0,0,0.45); border-radius: 8px; overflow: hidden;
  border: 1px solid rgba(255,255,255,0.2);
}
#powerfill { height: 100%; width: 0%; background: linear-gradient(90deg,#6fd3a6,#f0c419,#e8503a); }

#scoreOverlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(8,12,18,0.82);
}
#scoreOverlay.show { display: flex; }
#scoreCard { background: #1f2024; padding: 22px; border-radius: 12px; max-width: 92%; overflow: auto; }

table { border-collapse: collapse; font-size: 14px; }
th, td { padding: 6px 10px; text-align: center; border: 1px solid rgba(255,255,255,0.10); }
th { background: #1c1d20; color: #8a8f98; }
td.name { text-align: left; white-space: nowrap; }
tr.me td { background: #243c2c; }

#gameOverHint { text-align: center; }
.overlay {
  position: absolute; inset: 0; display: none; z-index: 20;
  align-items: center; justify-content: center; background: rgba(8,12,18,0.85);
  overflow-y: auto; overscroll-behavior: contain;
}
.overlay > .panel { margin: auto; }   /* centred, but scrollable when taller than the screen */
.overlay.show { display: flex; }

/* ===== Daily Challenge card (menu) ===== */
.daily-card { background: linear-gradient(180deg, #1d2733, #182029); border: 1px solid rgba(111,211,166,0.25); border-radius: 12px; padding: 12px 13px; margin-bottom: 14px; }
.daily-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 14px; color: #eaf6ef; }
.daily-date { font-size: 12px; font-weight: 500; color: #6fd3a6; font-variant-numeric: tabular-nums; }
.daily-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 10px; }
/* height: auto overrides the global `button { height: 40px }` — without it the two-line
   content (title + par) overflows the fixed 40px and the par crashes into the bottom. */
.daily-play { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; height: auto; padding: 11px 13px; border-radius: 9px; background: #232e29; border: 1px solid rgba(111,211,166,0.22); color: #ededed; cursor: pointer; text-align: left; line-height: 1.2; }
.daily-play:hover:not(:disabled) { background: #294036; border-color: #6fd3a6; }
.daily-play:disabled { opacity: 0.5; cursor: default; }
.daily-play .dp-title { font-weight: 600; font-size: 14px; line-height: 1.2; }
.daily-play .dp-sub { font-size: 12px; color: #9aa3ad; line-height: 1.2; font-variant-numeric: tabular-nums; }
.daily-foot { display: flex; align-items: center; gap: 10px; margin-top: 9px; }
.daily-foot .sub { flex: 1; min-width: 0; font-size: 11px; line-height: 1.3; }   /* take remaining space + wrap within it */
#dailyBoardBtn { flex-shrink: 0; white-space: nowrap; }                            /* button keeps its size; label never wraps */
/* Daily leaderboard modal */
.board-panel { width: min(420px, 92vw); }
.board-tabs { display: flex; gap: 6px; margin: 10px 0; }
.board-tab { flex: 1; height: 32px; border-radius: 8px; background: #232428; border: 1px solid rgba(255,255,255,0.10); color: #cfd3d8; cursor: pointer; font-size: 13px; }
.board-tab.active { background: #6fd3a6; color: #06281a; border-color: transparent; font-weight: 600; }
.board-list { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.board-row { display: flex; align-items: center; gap: 10px; background: #26272b; border: 1px solid rgba(255,255,255,0.07); border-radius: 8px; padding: 7px 11px; font-size: 13px; }
.board-row .br-rank { width: 22px; color: #8a8f98; font-variant-numeric: tabular-nums; }
.board-row .br-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-row .br-score { font-weight: 600; font-variant-numeric: tabular-nums; }
.board-empty { color: #8a8f98; font-size: 13px; text-align: center; padding: 18px 0; }

.preview-panel { width: auto; max-width: 92vw; }
.preview-panel h2 { text-align: center; }
#previewCanvas {
  width: min(680px, 84vw); height: auto; background: #46b35a;
  border-radius: 8px; image-rendering: auto; display: block;
}
.preview-panel .menu-buttons { flex-direction: row; flex-wrap: wrap; justify-content: center; }
.preview-panel .menu-buttons button { flex: 1; min-width: 120px; }
.preview-nav { display: flex; align-items: center; justify-content: center; gap: 14px; }
.preview-nav button { padding: 6px 14px; }
.preview-nav span { font-size: 14px; color: #8a8f98; min-width: 130px; text-align: center; }

/* ===== Chat (lives in the lobby rail) ===== */
.chat-log { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1; min-height: 0; }
.chat-log:empty::before { content: 'No messages yet — say hi'; color: #62666d; font-style: italic; font-size: 13px; }
.chat-msg { font-size: 13px; line-height: 1.45; word-break: break-word; color: #c9ccd1; }
.chat-msg .cm-name { font-weight: 600; color: #6fd3a6; margin-right: 4px; }
.chat-msg.system { color: #62666d; font-style: italic; }
.chat-entry { display: flex; gap: 8px; margin-top: 2px; flex-shrink: 0; }
.chat-entry input { flex: 1; min-width: 0; }
.chat-entry button { flex-shrink: 0; padding: 0 14px; }

/* In-game transient feed (bottom-left, fades) + Enter-to-open input bar. */
#chatFeed {
  position: absolute; left: 18px; bottom: 76px; width: min(360px, 42%);
  display: flex; flex-direction: column; gap: 4px; pointer-events: none; z-index: 4;
}
#chatFeed .chat-msg {
  align-self: flex-start; max-width: 100%;
  background: rgba(10,15,22,0.72); border-radius: 8px; padding: 4px 9px;
  opacity: 1; transition: opacity 0.5s;
}
#chatFeed .chat-msg.fade { opacity: 0; }
#chatBar { position: absolute; left: 18px; bottom: 44px; width: min(360px, 42%); z-index: 6; display: flex; gap: 6px; }
#chatBar[hidden] { display: none; }
#chatBar input {
  flex: 1; min-width: 0; height: 38px; background: rgba(10,15,22,0.92);
  border: 1px solid #6fd3a6; border-radius: 8px; color: #ededed; padding: 0 12px; font-size: 14px;
}
#chatBar #chatClose {
  flex-shrink: 0; width: 38px; height: 38px; padding: 0; font-size: 15px;
  background: rgba(10,15,22,0.92); border: 1px solid rgba(255,255,255,0.18); border-radius: 8px;
}

/* ===== Touch / mobile ===== */
/* On-screen controls for touch players (Tab/Enter have no key on a phone). */
#touchControls { position: absolute; right: 70px; bottom: 18px; display: none; gap: 10px; z-index: 6; }
#touchControls button {
  width: 42px; height: 42px; padding: 0; font-size: 19px; line-height: 1;
  background: rgba(10,15,22,0.6); border-radius: 10px;
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
}
#touchControls button:hover { background: rgba(20,30,44,0.9); }

/* Coarse pointers (touch): reveal touch controls, hide keyboard-only hints. */
@media (pointer: coarse) {
  #touchControls { display: flex; }
  kbd { display: none; }
}

/* Keep bottom-anchored chrome clear of the iOS home indicator / gesture bar.
   env() is 0 on desktop / non-notched devices, so this is a no-op there. */
@supports (padding: env(safe-area-inset-bottom)) {
  .hud-btn { bottom: calc(18px + env(safe-area-inset-bottom)); }
  #touchControls { bottom: calc(18px + env(safe-area-inset-bottom)); }
  #powerbar { bottom: calc(18px + env(safe-area-inset-bottom)); }
  #chatBar { bottom: calc(44px + env(safe-area-inset-bottom)); }
  #chatFeed { bottom: calc(76px + env(safe-area-inset-bottom)); }
}

/* Narrow screens: stop the absolutely-positioned HUD from overlapping, stack
   the lobby share row, and collapse the map-browser sidebar above the list. */
@media (max-width: 760px) {
  .lobby-top { flex-wrap: wrap; }

  .browser-head { flex-wrap: wrap; }
  .browser-head h2 { width: 100%; }
  .browser-body { flex-direction: column; gap: 10px; }
  .cat-tabs { width: 100%; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; gap: 6px; padding-bottom: 4px; }
  .cat-tab { white-space: nowrap; flex-shrink: 0; }
  .cat-tab .cnt { float: none; margin-left: 6px; }

  /* Map rows: name gets its own full line and the action buttons split the row
     below it — otherwise name + author + par + 2 buttons collide on a phone and
     the name collapses to an ellipsis. */
  .track-row { flex-wrap: wrap; row-gap: 8px; }
  .track-row .tname { flex: 1 1 100%; }
  .track-row .tauthor { max-width: none; }
  .track-row button { flex: 1 1 calc(50% - 4px); }
}

/* In-game HUD on touch (ANY orientation — incl. landscape phones wider than
   760px) OR narrow screens: tuck the chrome into the corners and make the
   scoreboard a compact, glanceable strip so it covers as little of the board
   as possible. Gated on pointer:coarse so landscape phones actually get it
   (a plain max-width:760px never matches a landscape phone). */
@media (pointer: coarse), (max-width: 760px) {
  #hudTopLeft { left: 10px; top: 10px; font-size: 12px; padding: 6px 9px; }
  #powerbar { left: 10px; width: 40vw; max-width: 200px; }
  #chatFeed, #chatBar { left: 10px; width: min(70vw, 360px); }

  /* Compact scoreboard: drop the header row and the turn-arrow column, cap
     names — whose-turn is still shown by the row highlight. ~half the width. */
  #scorePanel { right: 10px; top: 10px; min-width: 0; width: fit-content; max-width: 40vw; padding: 6px 8px; gap: 2px; }
  .sp-head { display: none; }
  .sp-row { font-size: 11px; padding: 2px 6px; gap: 6px; }
  .sp-row .pturn { display: none; }
  .sp-row .dot { width: 8px; height: 8px; }
  .sp-row .pname { flex: 0 1 auto; max-width: 84px; }
}

@media (orientation: portrait) and (max-width: 760px) {
  #hudTopLeft { max-width: calc(58vw - 20px); line-height: 1.35; }
  #scorePanel { max-width: 40vw; }
}
@media (pointer: coarse) {
  #lobbyListRefresh { width: 36px; height: 36px; }
  .kofi-inline { padding: 12px 0 4px; }
}
.ds-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ===== Replays ===== */
#replayBar { position: absolute; left: 10px; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 7; display: flex; align-items: center; gap: 8px;
  padding: 6px 6px 6px 12px; border-radius: 10px; background: rgba(10,15,22,0.72); backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  font-size: 13px; font-weight: 600; color: #eaf6ef; max-width: calc(100% - 180px); }
#replayBar[hidden] { display: none; }
#replayWho { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#replayExit, #replaySpeed { width: 34px; height: 34px; padding: 0; flex: none; }
#replaySpeed { width: 40px; font-size: 12px; font-variant-numeric: tabular-nums; }
.replaying #powerbar, .replaying #chatBtn, .replaying #chatBar { display: none !important; }
.replaying canvas { cursor: default; }
.br-watch { width: 34px; height: 30px; padding: 0; font-size: 12px; flex: none; }
#dailyBoardMsg:empty { display: none; }
#dailyBoardMsg { margin-top: 8px; text-align: center; }

/* /daily: nothing but a "teeing up" screen until the round (or the menu, if you already
   played or it failed) is ready — the client drops .boot-daily. */
.boot-daily .screen { visibility: hidden; }
.boot-daily body::after { content: "⛳ Teeing up today's daily…"; position: fixed; inset: 0; display: grid; place-items: center; font: 600 16px/1.4 system-ui, sans-serif; color: #9aa3ad; }

/* ===== Daily as the front door ===== */
.daily-sub-row { display: flex; align-items: baseline; gap: 10px; margin-top: 3px; }
.daily-theme { flex: 1; min-width: 0; font-size: 13px; color: #9aa3ad; min-height: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.daily-next { flex: none; font-size: 12px; color: #6fd3a6; font-variant-numeric: tabular-nums; }
.daily-next-result { font-size: 12px; color: #9aa3ad; margin: 0 0 8px; font-variant-numeric: tabular-nums; }
.daily-next-result:empty { display: none; }
.daily-hero { height: auto; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; width: 100%; margin-top: 10px; padding: 13px 15px; border-radius: 10px; background: #6fd3a6; border: none; color: #10261b; cursor: pointer; text-align: left; }
.daily-hero:hover:not(:disabled) { background: #85e0b7; }
.daily-hero:disabled { opacity: 0.55; cursor: default; }
.daily-hero .dp-title { font-weight: 700; font-size: 16px; }
.daily-hero .dp-sub { font-size: 12px; color: #1f4633; font-variant-numeric: tabular-nums; }
.daily-more { display: contents; }
.daily-foot .mini .dp-sub { color: #9aa3ad; font-size: 11px; }
.board-tabs:empty { display: none; }
.daily-share { margin: 12px 0 4px; padding: 12px; border-radius: 10px; background: #182029; border: 1px solid rgba(111,211,166,0.25); text-align: center; }
.ds-head { font-weight: 600; color: #eaf6ef; margin-bottom: 8px; }
.ds-head b { color: #6fd3a6; }
.ds-text { margin: 0 0 10px; font: 15px/1.5 ui-monospace, monospace; white-space: pre-wrap; color: #ededed; }
/* Phones: the thing you came to do goes first; lobbies and tools go below it. */
@media (max-width: 760px) {
  #menu > .stage-main { order: -1; }
  #menu > .rail { border-bottom: none; border-top: 1px solid rgba(255,255,255,0.11); }
}
.ds-name { display: flex; gap: 8px; margin: 0 0 6px; }
.ds-name[hidden] { display: none; }
.ds-change { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; }   /* display:flex would otherwise beat the hidden attribute */
.ds-name input { flex: 1; min-width: 0; }
#dailyNameMsg { min-height: 0; margin-bottom: 8px; font-size: 12px; }
#dailyNameMsg:empty { display: none; }
.rail-foot .kofi { color: #f0b37e; }
.kofi-inline { display: block; margin-top: 10px; font-size: 12px; color: #9aa3ad; text-decoration: none; }
.kofi-inline:hover { color: #f0b37e; }
