/* Whose Serve - a clay court at the club: chalk-white paper, terracotta clay, a dark green scorer's hut, a yellow
 * ball. Dark mode is the court under floodlights: deep green night, darker clay, lines still bright. */
:root {
  --bg: #f4efe4; --bg-2: #e9e1d0; --card: #fffbf3; --ink: #1c2a22; --ink-2: #4d5a51; --line: #d8cdb8;
  --accent: #23593b; --accent-ink: #ffffff; --accent-2: #b4532c;
  --clay: #a84f2b; --clay-out: #84391c; --chalk: #fff8ee; --net: #1c2a22; --net-shadow: rgba(0, 0, 0, 0.22);
  --ball: #e3e94f; --ball-ink: #1c2a22; --them: #fff8ee; --them-ink: #1c2a22; --ring: #1c2a22; --x: #8f1414;
  --hut: #23593b; --hut-ink: #f4efe4;
  --tone-warm: #f7dccb; --tone-warm-ink: #7a2e0e; --tone-neutral: #e6e2d8; --tone-neutral-ink: #343a36; --tone-cool: #d6e3ef; --tone-cool-ink: #1d3c5c; --tone-unclear: #ece4f2; --tone-unclear-ink: #4b2c66;
  --v-wait: #7a4b06; --v-you-carry: #9a3412; --v-they-carry: #1d4f7a; --v-even: #1f6b3d; --v-ink: #ffffff;
  --warn-bg: #fbe8e5; --warn-ink: #8a1c1c; --note-bg: #fbf0d9; --note-ink: #6b3d05; --ok-bg: #e3efe5; --ok-ink: #1d5630;
  --care-bg: #fde9e4; --care-ink: #7f1d1d; --care-edge: #c2410c;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: "Avenir Next Condensed", "Arial Narrow", "Roboto Condensed", "Helvetica Neue", var(--sans);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0e1712; --bg-2: #15211a; --card: #142019; --ink: #ecebe2; --ink-2: #aab5ad; --line: #2a3a30;
  --accent: #8fd6a8; --accent-ink: #0b1a11; --accent-2: #f0a27c;
  --clay: #8f4426; --clay-out: #5f2c18; --chalk: #f6efe2; --net: #0b0f0c; --net-shadow: rgba(0, 0, 0, 0.45);
  --ball: #e3e94f; --ball-ink: #1c2a22; --them: #f6efe2; --them-ink: #1c2a22; --ring: #f6efe2; --x: #ffb4a8;
  --hut: #1e3a29; --hut-ink: #ecebe2;
  --tone-warm: #4a2414; --tone-warm-ink: #ffd2bb; --tone-neutral: #2b332e; --tone-neutral-ink: #e2e6e1; --tone-cool: #17304a; --tone-cool-ink: #c7defa; --tone-unclear: #33233f; --tone-unclear-ink: #e6d4f5;
  --v-wait: #ffd08a; --v-you-carry: #ffb38f; --v-they-carry: #a9cdf5; --v-even: #9fe2b6; --v-ink: #101511;
  --warn-bg: #3a1716; --warn-ink: #ffcdc7; --note-bg: #352812; --note-ink: #ffdca3; --ok-bg: #12301c; --ok-ink: #b9ecc8;
  --care-bg: #3d1a14; --care-ink: #ffd5cb; --care-edge: #f08a5d;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); overflow-x: hidden; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--display); line-height: 1.15; overflow-wrap: anywhere; letter-spacing: 0.01em; }
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.small { font-size: 0.88rem; }
.muted { color: var(--ink-2); }
.mono { font-family: var(--mono); }

/* Header: the scorer's hut */
.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--hut); color: var(--hut-ink); flex-wrap: wrap; border-bottom: 4px solid var(--clay); }
.bar .back { color: #d9e4dc; text-decoration: none; font-size: 0.9rem; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 1.15rem; flex: 1; min-width: 0; font-family: var(--display); letter-spacing: 0.03em; }
.logo { width: 28px; height: 28px; flex: none; }
.lg-clay { fill: #c4643a; }
.lg-net { stroke: #fff8ee; stroke-width: 2; }
.lg-ball { fill: #e3e94f; stroke: #1c2a22; stroke-width: 0.8; }
.session { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.bar .pill { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.35); color: #f4efe4; }
.bar .pill.solid { background: #e3e94f; border-color: #e3e94f; color: #1c2a22; }

/* Buttons */
.pill { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 6px 14px; font: 600 0.88rem var(--sans); cursor: pointer; text-decoration: none; }
.pill:hover:not(:disabled) { border-color: var(--accent); }
.pill.solid { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pill.ghost { cursor: default; }
.pill.big { padding: 10px 22px; font-size: 1rem; }
.pill.tiny { padding: 3px 10px; font-size: 0.8rem; }
.pill:disabled { opacity: 0.55; cursor: not-allowed; }
.chip { border: 1px solid var(--accent-2); background: transparent; color: var(--ink); border-radius: 999px; padding: 5px 12px; font: 0.86rem var(--sans); cursor: pointer; }
.chip.on { background: var(--accent-2); color: #ffffff; }
:root[data-theme="dark"] .chip.on { color: #1c1410; }

/* Layout */
main { max-width: 1180px; margin: 0 auto; padding: 0 16px 40px; }
.hero { padding: 22px 0 8px; }
.kicker { font-size: 0.86rem; color: var(--ink-2); margin: 0 0 8px; max-width: 780px; }
.note-src { font-style: italic; }
.hero h1 { font-size: clamp(1.7rem, 4.6vw, 2.8rem); margin: 4px 0 10px; max-width: 860px; text-transform: none; }
.lede { max-width: 780px; margin: 0 0 12px; }
.samples { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.layout { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; margin-top: 16px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-top: 16px; min-width: 0; }
.layout .panel { margin-top: 0; }
.ph { font-size: 1.3rem; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.step-no { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--ball); color: var(--ball-ink); border: 1px solid var(--ball-ink); font: 700 0.85rem var(--sans); flex: none; }
.lbl { display: block; font-size: 0.82rem; font-weight: 600; margin: 8px 0 4px; color: var(--ink-2); }
input, select, textarea { width: 100%; font: 0.95rem var(--sans); color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; min-width: 0; }
textarea { font-family: var(--mono); font-size: 0.84rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.three { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 10px; }
.fmt { margin: 6px 0; }
.drop { border: 1px dashed var(--line); border-radius: 6px; padding: 8px; margin-top: 6px; }
.drop.over { border-color: var(--accent); background: var(--bg-2); }
.filelbl { color: var(--accent); text-decoration: underline; cursor: pointer; }
.note { background: var(--note-bg); color: var(--note-ink); border-radius: 6px; padding: 6px 10px; }
.gate { background: var(--note-bg); color: var(--note-ink); border-radius: 6px; padding: 8px 10px; }
.runrow { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 12px; }

/* The court */
.court-scroll { overflow-x: auto; border-radius: 10px; -webkit-overflow-scrolling: touch; }
.court { display: block; width: 100%; height: auto; }
.c-out { fill: var(--clay-out); }
.c-clay { fill: var(--clay); }
.c-line { stroke: var(--chalk); stroke-width: 2.5; }
.c-line.thin { stroke-width: 1.2; opacity: 0.75; }
.c-net { stroke: var(--net); stroke-width: 4; }
.c-net-shadow { stroke: var(--net-shadow); stroke-width: 3; }
.c-side { fill: var(--chalk); font: 700 12px var(--sans); letter-spacing: 0.14em; }
.c-change { stroke: var(--chalk); stroke-width: 1.4; stroke-dasharray: 4 5; opacity: 0.8; }
.c-rally { fill: var(--chalk); font: 700 11px var(--mono); }
.c-shot { fill: none; stroke: var(--chalk); stroke-width: 1.6; opacity: 0.85; }
.c-double { fill: none; stroke: var(--ball); stroke-width: 1.6; stroke-dasharray: 3 3; opacity: 0.95; }
.b-dot { stroke: var(--ring); stroke-width: 1.2; }
.b-you .b-dot { fill: var(--ball); }
.b-them .b-dot { fill: var(--them); }
.b-ring { fill: none; stroke: var(--chalk); stroke-width: 2; }
.b-q { fill: var(--chalk); font: 800 12px var(--sans); }
.b-x { stroke: var(--chalk); stroke-width: 3.2; stroke-linecap: round; }
.b-call .b-dot { stroke: var(--x); stroke-width: 2.2; }
.c-turn { fill: var(--chalk); font: 700 12px var(--sans); }
.empty { font-style: italic; margin: 6px 0; }
.legend { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.key { display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--ink); flex: none; font: 800 0.7rem var(--sans); }
.k-them { background: var(--them); }
.k-you { background: var(--ball); }
.k-ring { background: transparent; border: 2px solid var(--ink); width: 16px; height: 16px; }
.k-q { border-radius: 3px; background: var(--clay); color: var(--chalk); border-color: var(--clay); }
.k-x { border-radius: 3px; background: var(--clay); border-color: var(--clay); position: relative; }
.k-x::before, .k-x::after { content: ""; position: absolute; left: 2px; right: 2px; top: 6px; height: 2px; background: var(--chalk); transform: rotate(45deg); }
.k-x::after { transform: rotate(-45deg); }

/* Carry meter and tally */
.meter-host { margin-top: 12px; }
.carry-lab { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 10px; margin-bottom: 4px; font-weight: 600; }
.carry-est { margin: 4px 0 0; font-style: italic; }
.carry { position: relative; height: 18px; border-radius: 9px; background: var(--them); border: 1px solid var(--ink); overflow: hidden; }
.carry-you { position: absolute; left: 0; top: 0; bottom: 0; background: var(--ball); border-right: 1px solid var(--ink); }
.carry-net { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 3px; margin-left: -1px; background: var(--net); }
:root[data-theme="dark"] .carry-net { background: var(--clay); }
.carry-tick { position: absolute; top: 0; bottom: 0; width: 0; border-left: 2px dotted var(--clay-out); }
.tally { width: 100%; border-collapse: collapse; margin-top: 10px; }
.tally th, .tally td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.tally th:first-child { text-align: left; font-weight: 400; color: var(--ink-2); }
.tally thead th { font-family: var(--display); font-size: 0.95rem; color: var(--ink); font-weight: 700; }
.tally td.lead { font-weight: 800; color: var(--accent); }

/* Line calls */
.calls { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.call { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; background: var(--care-bg); color: var(--care-ink); border-left: 4px solid var(--care-edge); border-radius: 6px; padding: 7px 10px; }
.call b { font-family: var(--display); letter-spacing: 0.02em; }
.call q { font-style: italic; overflow-wrap: anywhere; }
.calls .clear { background: var(--ok-bg); color: var(--ok-ink); border-radius: 6px; padding: 7px 10px; }

/* Badges */
.badge { display: inline-block; border-radius: 4px; padding: 3px 10px; font: 700 0.82rem var(--sans); background: var(--line); color: var(--ink); white-space: nowrap; }
.badge.v-wait { background: var(--v-wait); color: var(--v-ink); }
.badge.v-you-carry { background: var(--v-you-carry); color: var(--v-ink); }
.badge.v-they-carry { background: var(--v-they-carry); color: var(--v-ink); }
.badge.v-even { background: var(--v-even); color: var(--v-ink); }

/* Progress */
.progress h3 { margin: 0 0 8px; }
.steps { list-style: none; padding: 0; margin: 0; }
.step { color: var(--ink-2); padding: 2px 0; }
.step.active { color: var(--ink); font-weight: 600; }
.step.done { color: var(--ok-ink); }
.step-ic { font-family: var(--mono); display: inline-block; width: 1em; }
.raw { white-space: pre-wrap; font-family: var(--mono); font-size: 0.82rem; max-height: 340px; overflow: auto; }

/* Result */
.res-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.res-head h2 { margin: 0; font-size: 1.45rem; min-width: 0; }
.summary { font-size: 1.05rem; }
.care { background: var(--care-bg); color: var(--care-ink); border-left: 5px solid var(--care-edge); border-radius: 6px; padding: 10px 12px; margin: 10px 0; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols h3, .result h3 { font-size: 1.12rem; margin: 18px 0 6px; }
.plain { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.signals { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.sig { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; }
.sig-head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-bottom: 3px; }
.sig-who { font: 700 0.72rem var(--sans); text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-2); }
.sig q { font-style: italic; overflow-wrap: anywhere; }
.tone { font: 700 0.72rem var(--sans); border-radius: 4px; padding: 2px 7px; text-transform: uppercase; letter-spacing: 0.06em; }
.tone-warm { background: var(--tone-warm); color: var(--tone-warm-ink); }
.tone-neutral { background: var(--tone-neutral); color: var(--tone-neutral-ink); }
.tone-cool { background: var(--tone-cool); color: var(--tone-cool-ink); }
.tone-unclear { background: var(--tone-unclear); color: var(--tone-unclear-ink); }
.sig p { margin: 2px 0 0; }
.returns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.ret { background: var(--bg); border: 1px solid var(--line); border-top: 5px solid var(--ball); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ret.s-warm { border-top-color: var(--clay); }
.ret.s-direct { border-top-color: var(--accent); }
.ret-name { font-family: var(--display); font-weight: 700; font-size: 1.02rem; }
.ret-text { font-size: 0.98rem; margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.ret-why { font-size: 0.84rem; color: var(--ink-2); margin: 0; }
.ret-fit { font: 600 0.76rem var(--mono); color: var(--ink-2); }
.ret .pill { align-self: flex-start; }
.ask { font-family: var(--display); font-size: 1.05rem; margin: 0; }
.none { color: var(--ink-2); font-style: italic; list-style: none; }
.recon { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.recon li { border-radius: 6px; padding: 6px 10px; background: var(--ok-bg); color: var(--ok-ink); font-size: 0.9rem; }
.recon li.warn { background: var(--warn-bg); color: var(--warn-ink); }
.recon li.note { background: var(--note-bg); color: var(--note-ink); }
.recon li.none { font-style: normal; }
.exports, .cardrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.loop { margin-top: 12px; }

/* History */
.hist { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 8px; }
.hrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.hinfo { display: flex; flex-direction: column; flex: 1; min-width: 0; }

/* Footer, toasts */
.foot { max-width: 1180px; margin: 0 auto; padding: 10px 16px 40px; color: var(--ink-2); font-size: 0.86rem; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--card); color: var(--ink); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 6px; padding: 8px 12px; font-size: 0.9rem; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); transition: opacity 0.5s; }
.toast.err { border-left-color: var(--care-edge); }
.toast.gone { opacity: 0; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .returns { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
  .bar { gap: 8px; }
}
@media print {
  .bar, .samples, .askbox, .histbox, .exports, .loop, .toasts, .foot { display: none !important; }
  body { background: #fff; }
}
