:root {
  color-scheme: light;
  --navy: #2b3a4a;
  --navy-light: #364758;
  --blue: #0070ba;
  --blue-dark: #005a96;
  --blue-pale: #e6f1f8;
  --rule: #1d3fd1;
  --amber: #f7b50c;
  --bg: #f3f4f6;
  --card: #ffffff;
  --stripe: #eeeeee;
  --text: #333b44;
  --muted: #667180;
  --line: #d9dde2;
  --grey-pill: #e2e4e7;
  --grey-pill-text: #5b6570;
  --unavailable-pill: #b4bac1;
  --danger: #b3261e;
  --shadow: 0 1px 3px rgb(20 30 45 / .12), 0 4px 14px rgb(20 30 45 / .06);
  /* --navy and --blue also work as backgrounds in both themes. These are their uses as text and icons. */
  --heading: #2b3a4a;
  --link: #0070ba;
  --known: #005a96;
  --hover: #e3e5e8;
  --danger-pale: #fbeeed;
  --selector-bg: #f3f3f3;
  --option-disabled: #cfcfcf;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --blue-pale: #233a4d;
  --rule: #4f73ff;
  --bg: #12181f;
  --card: #1c242d;
  --stripe: #232c36;
  --text: #e3e7eb;
  --muted: #9aa5b1;
  --line: #38434f;
  --grey-pill: #333e4a;
  --grey-pill-text: #c2cad2;
  --unavailable-pill: #4a5561;
  --danger: #f28b82;
  --shadow: 0 1px 3px rgb(0 0 0 / .4), 0 4px 14px rgb(0 0 0 / .25);
  --heading: #e8ecf0;
  --link: #5db2ec;
  --known: #7cc1f0;
  --hover: #2b3642;
  --danger-pale: #3a2322;
  --selector-bg: #171e25;
  --option-disabled: #46515c;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1 { font-size: 1.25rem; font-weight: 700; margin: 0; }
h2 { font-size: 1.2rem; margin: 0 0 2px; color: var(--heading); }
.muted { color: var(--muted); font-weight: 400; }
.error { color: var(--danger); margin: 8px 0 0; min-height: 1.4em; }
.note { color: var(--muted); font-size: .9rem; margin: 10px 0; }

button, input { font: inherit; color: inherit; }
button { min-height: 44px; padding: 0 16px; border: 0; border-radius: 10px; background: var(--stripe); font-weight: 500; cursor: pointer; }
button:hover:not(:disabled) { background: var(--hover); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--blue); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--blue-dark); }
button.danger { width: 100%; margin-top: 10px; background: none; border: 1px solid var(--danger); color: var(--danger); }
button.danger:hover:not(:disabled) { background: var(--danger-pale); }
button.icon { width: 44px; flex: none; padding: 0; font-size: 1.4rem; color: var(--link); }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

input { min-height: 44px; width: 100%; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
input:disabled { background: var(--stripe); color: var(--muted); }
input[type="checkbox"], input[type="radio"] { width: 18px; min-height: 18px; margin: 0; accent-color: var(--blue); }
label, .label { display: block; font-weight: 600; margin: 14px 0 6px; }
label.check { display: inline-flex; gap: 8px; align-items: center; font-weight: 400; min-height: 40px; margin: 0 16px 0 0; cursor: pointer; }

/* ---------- sign in ---------- */

.signin { width: min(420px, calc(100vw - 24px)); margin: 8vh auto 24px; padding: 28px 24px 20px; background: var(--card); border-radius: 16px; box-shadow: 0 8px 30px rgb(0 0 0 / .3); }
.signin h1 { color: var(--heading); font-size: 1.5rem; margin-bottom: 4px; }
.signin p.muted { margin-top: 0; }
.signin button { width: 100%; margin-top: 18px; }
body:has(#signin:not([hidden])) { background: var(--navy); }

/* ---------- page frame: navy side bar on a wide screen, top bar on a phone ---------- */

.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; background: var(--navy); color: #fff; }
.side h1 { padding: 26px 24px 28px; }
.tabs { display: flex; flex-direction: column; }
.tab { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 0 24px 0 20px; border-left: 4px solid transparent; border-radius: 0; background: none; color: #fff; font-size: .95rem; text-align: left; }
.tab svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tab:hover:not(:disabled) { background: var(--navy-light); }
.tab[aria-current="page"] { border-left-color: var(--amber); background: var(--navy-light); color: var(--amber); }
.side-out { margin-top: auto; margin-bottom: 16px; }
#theme-toggle { margin-bottom: 0; }
.side-out + .side-out { margin-top: 0; }
.content { min-width: 0; padding: 16px 20px 40px; }
.content > section:not(#times) { max-width: 1180px; }

/* ---------- date and filter bar ---------- */

.controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 10px 12px; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); }
.sun { display: flex; align-items: center; gap: 10px; margin: 0 0 0 4px; color: var(--muted); font-size: 1.25rem; font-weight: 300; font-variant-numeric: tabular-nums; }
.sun svg { width: 34px; height: 34px; flex: none; }
.sun .rays { fill: none; stroke: var(--amber); stroke-width: 2; stroke-linecap: round; }
.sun .disc { fill: #fff; stroke: var(--amber); stroke-width: 2; }
.sun .half { fill: var(--amber); }

.tools { display: flex; flex-wrap: wrap; align-items: stretch; gap: 6px; }
button.tool, label.tool { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; margin: 0; padding: 0 12px; border-radius: 8px; background: var(--stripe); color: var(--text); font-size: .82rem; font-weight: 500; letter-spacing: .03em; text-transform: uppercase; cursor: pointer; }
.tool:hover { background: var(--hover); }
.tool svg { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--link); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
button.tool.arrow { justify-content: center; width: 40px; padding: 0; color: var(--link); font-size: 1.4rem; }
.date-tool { position: relative; }
.date-tool:focus-within { outline: 2px solid var(--link); outline-offset: 2px; }
.date-tool input { position: absolute; inset: 0; min-height: 0; padding: 0; border: 0; background: none; opacity: 0; cursor: pointer; }
#missing-clubs { margin: 12px 4px 0; }

/* ---------- course selector ---------- */

dialog.selector { width: min(760px, calc(100vw - 24px)); padding: 0; overflow-y: auto; }
.selector-head { position: relative; padding: 22px 24px 20px; }
dialog.selector:focus { outline: none; }
button.selector-close, button.selector-close:hover:not(:disabled) { position: absolute; top: 8px; right: 8px; border-radius: 0; background: none; color: var(--muted); }
.selector-close ~ * { padding-right: 36px; }
.selector-head h2 { color: var(--text); font-size: .95rem; letter-spacing: .04em; }
.selector-head p { margin: 6px 0 0; color: var(--muted); }
.selector-options { display: flex; flex-direction: column; gap: 14px; padding: 18px 24px 22px; background: var(--selector-bg); }
.course-group { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.course-group h3 { flex-basis: 100%; margin: 0; color: var(--muted); font-size: .78rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
a.course-option { display: inline-flex; align-items: center; text-decoration: none; }
a.course-option:hover { background: var(--blue-dark); }
button.course-option, a.course-option { align-self: flex-start; min-height: 40px; padding: 0 10px; border-radius: 6px; background: linear-gradient(to right, #4a9fd8, var(--blue)); color: #fff; font-size: .82rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
button.course-option:hover:not(:disabled) { background: var(--blue-dark); }
button.course-option:disabled { background: var(--option-disabled); opacity: 1; }

/* ---------- tee sheet ---------- */

.course { margin-top: 16px; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.course summary { display: flex; align-items: center; gap: 12px; padding: 13px 16px; background: var(--blue); color: #fff; font-weight: 600; cursor: pointer; list-style: none; }
.course summary::-webkit-details-marker { display: none; }
.course summary::after { content: ""; width: 8px; height: 8px; flex: none; margin: -3px 3px 0 2px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.course[open] summary::after { margin-top: 3px; transform: rotate(-135deg); }
.course summary .name { flex: 1; min-width: 0; }
.course summary .muted { color: #fff; font-size: .88rem; }
.course .release { margin: 0; padding: 8px 16px; background: var(--amber); color: var(--navy); font-size: .9rem; font-weight: 500; }
.course .notice { margin: 0; padding: 14px 16px; color: var(--muted); }
.club-notices { padding: 10px 16px; border-top: 1px solid #fff; background: var(--blue); color: #fff; font-size: .9rem; }
.club-notices p { margin: 0; }
.club-notices p + p { margin-top: 8px; }
.sun-bar { margin: 0; padding: 6px 16px; background: var(--amber); color: var(--navy); font-size: .9rem; font-weight: 500; text-align: center; }
.sun-bar::before { content: "\2600\FE0E"; margin-right: 6px; }
.sun-bar.dark { background: var(--navy); color: #fff; }

.slot { display: grid; grid-template-columns: 72px minmax(0, 1fr) 152px; align-items: stretch; width: 100%; min-height: 58px; padding: 0; border: 0; border-radius: 0; background: var(--card); color: inherit; font-weight: 400; text-align: left; text-decoration: none; }
.slot:nth-child(even) { background: var(--stripe); }
button.slot, a.slot { cursor: pointer; }
button.slot:hover:not(:disabled), a.slot:hover { background: var(--blue-pale); }
.slot .time { display: flex; flex-direction: column; padding: 9px 0 9px 10px; border-right: 3px solid var(--rule); color: var(--heading); font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.slot .time .detail { color: var(--muted); font-size: .68rem; font-weight: 400; }
.person.known { color: var(--known); font-weight: 600; }
.mark { display: inline-block; margin-left: 6px; padding: 0 5px; border-radius: 4px; background: var(--grey-pill); color: var(--grey-pill-text); font-size: .68rem; font-weight: 600; }
.mark.buddy-mark { background: var(--blue-pale); color: var(--known); }
.slot .who { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 20px; align-content: center; padding: 8px 16px; overflow-wrap: anywhere; }
.slot .who .muted { grid-column: 1 / -1; }
.slot .state { align-self: center; min-width: 136px; margin: 8px; padding: 10px 12px; border-radius: 8px; background: var(--grey-pill); color: var(--grey-pill-text); font-size: .75rem; font-weight: 700; letter-spacing: .07em; text-align: center; text-transform: uppercase; }
.slot.empty .state { background: var(--blue); color: #fff; }
.slot.empty:hover .state { background: var(--blue-dark); }
.slot.mine { box-shadow: inset 4px 0 0 var(--amber); }
.slot.mine .state { background: var(--amber); color: var(--navy); }
.slot.part .state { background: var(--card); box-shadow: inset 0 0 0 1px var(--link); color: var(--link); }
.slot.onePerDay .state, .slot.closed .state { background: var(--unavailable-pill); color: #fff; }

/* ---------- bookings ---------- */

button.booking { display: block; width: 100%; height: auto; margin-top: 12px; padding: 14px 16px; background: var(--card); border-left: 4px solid var(--amber); border-radius: 14px; box-shadow: var(--shadow); font-weight: 400; text-align: left; }
button.booking:hover:not(:disabled) { background: var(--blue-pale); }
.booking strong { display: block; color: var(--heading); }
.booking .who { color: var(--muted); font-size: .9rem; }
button.booking.message { border-left-color: var(--line); }
button.booking.message.unread { border-left-color: var(--amber); }
.mark.new-mark { background: var(--amber); color: var(--navy); }
.message-body { margin: 12px 0 0; max-height: 60dvh; overflow-y: auto; overflow-wrap: anywhere; white-space: pre-line; }
.empty-state { padding: 32px 20px; text-align: center; color: var(--muted); }

/* ---------- book / edit sheet ---------- */

dialog { width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 22px; border: 0; border-radius: 16px; background: var(--card); color: var(--text); box-shadow: 0 16px 50px rgb(0 0 0 / .35); }
dialog::backdrop { background: rgb(25 35 48 / .6); }
#sheet-sub { margin: 0; }
fieldset { border: 0; padding: 0; margin: 14px 0 0; }
legend { font-weight: 600; padding: 0; margin-bottom: 2px; }

.partner-row { display: grid; grid-template-columns: 68px minmax(0, 1fr); align-items: center; gap: 8px; margin: 0 0 6px; color: var(--muted); font-size: .88rem; font-weight: 500; }
.partner-row input { color: var(--text); font-size: 15px; font-weight: 400; }

.buddy-picker { max-height: 208px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; }
.buddy-picker:empty { display: none; }
button.buddy { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 6px 12px; border-radius: 0; background: var(--card); font-weight: 400; text-align: left; }
button.buddy + button.buddy { border-top: 1px solid var(--line); }
button.buddy:hover:not(:disabled) { background: var(--blue-pale); }
.buddy .avatar { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--navy); color: #fff; font-size: .72rem; font-weight: 700; }
.buddy .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.buddy .tick { width: 22px; height: 22px; flex: none; border: 1px solid var(--line); border-radius: 50%; color: #fff; font-size: .8rem; font-weight: 700; line-height: 20px; text-align: center; }
button.buddy[aria-pressed="true"] { background: var(--blue-pale); }
.buddy[aria-pressed="true"] .tick { border-color: var(--blue); background: var(--blue); }
.buddy[aria-pressed="true"] .tick::before { content: "\2713"; }
.buddy-status { font-size: .9rem; margin: 0; }

.buddy-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 10px 14px; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); }
.buddy-row .avatar { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--navy); color: #fff; font-size: .72rem; font-weight: 700; }
.buddy-row .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.buddy-clubs { display: block; font-size: .82rem; }
.buddy-row button.danger { width: auto; margin: 0; }
.panel { margin-top: 16px; padding: 16px; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); }

.rules-body { margin-top: 10px; max-height: 60dvh; overflow-y: auto; overflow-wrap: anywhere; }
.rules-body p { margin: 0 0 10px; }
dialog .note { margin: 12px 0 0; }
.actions { display: flex; gap: 8px; margin-top: 10px; }
.actions button { flex: 1; }

.toast { position: fixed; left: 12px; right: 12px; bottom: 16px; z-index: 5; max-width: 560px; margin: 0 auto; padding: 12px 16px; border-radius: 12px; background: var(--navy); color: #fff; box-shadow: var(--shadow); }

/* ---------- phone ---------- */

@media (max-width: 800px) {
  .shell { display: block; min-height: 0; }
  .side { position: static; flex-flow: row wrap; align-items: center; height: auto; }
  .side h1 { flex: 1; padding: 12px 14px; }
  .side-out { order: 2; width: auto; min-height: 44px; margin: 0; padding: 0 14px; border: 0; font-size: .88rem; }
  .side-out svg { display: none; }
  .tabs { order: 3; flex-direction: row; width: 100%; }
  .tab:not(.side-out) { flex: 1; justify-content: center; min-width: 0; min-height: 44px; padding: 0 3px; border-left: 0; border-bottom: 3px solid transparent; font-size: .74rem; line-height: 1.15; text-align: center; }
  .tab:not(.side-out) svg { display: none; }
  .tab[aria-current="page"] { border-bottom-color: var(--amber); }
  .content { padding: 10px 10px 32px; }
  .tools { width: 100%; }
  .date-tool { flex: 1; justify-content: center; }
  #course-button { flex: 1 1 100%; justify-content: center; }
  label.tool.check { flex: 1 1 100%; justify-content: center; }
  .selector-head, .selector-options { padding-left: 16px; padding-right: 16px; }
  .slot { grid-template-columns: 58px minmax(0, 1fr) 112px; }
  .slot .time { padding-left: 8px; font-size: .95rem; }
  .slot .who { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 7px 8px 7px 10px; font-size: .85rem; }
  .slot .state { min-width: 78px; margin: 6px 6px 6px 0; padding: 9px 8px; font-size: .68rem; letter-spacing: .04em; }
}
