:root {
  --bg: #f3f5f1;
  --card: #ffffff;
  --ink: #17221b;
  --muted: #5d6b62;
  --line: #dde3dc;
  --accent: #1f7a4a;
  --accent-ink: #ffffff;
  --court: #2f6f9f;
  --warn: #b5541c;
  --ok: #1f7a4a;
  --ball: #c7d82a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1a14;
    --card: #17251d;
    --ink: #e9efe9;
    --muted: #9aaba0;
    --line: #2a3b30;
    --accent: #3fb373;
    --accent-ink: #0b130e;
    --court: #6aa9d6;
    --warn: #f08a4b;
    --ok: #4fd18a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.top {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
  border-bottom: 1px solid var(--line);
}
h1 { font-size: 20px; margin: 0 0 8px; letter-spacing: -0.01em; }
h3 { font-size: 14px; margin: 8px 0 0; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; grid-column: 1 / -1; }

.top > * { max-width: 528px; margin-left: auto; margin-right: auto; }
.tabs { display: flex; gap: 4px; background: var(--line); padding: 3px; border-radius: 10px; }
.tabs button { flex: 1; border: 0; background: transparent; color: var(--ink); padding: 8px; border-radius: 8px; font: inherit; font-weight: 600; }
.tabs button[aria-selected="true"] { background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.15); }

main { padding: 12px 16px 32px; max-width: 560px; margin: 0 auto; }
.card { background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 12px; border: 1px solid var(--line); }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 13px; color: var(--muted); }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.field.check > span { color: var(--ink); font-size: 15px; }
.field.inline { flex-direction: row; align-items: center; justify-content: center; gap: 8px; margin-top: 16px; }
.field.inline input { width: 90px; }

input, select, button { font: inherit; color: var(--ink); }
input[type="number"], input:not([type]), select {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg);
}
button { padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-weight: 600; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--warn); }
button.link { padding: 0; border: 0; background: none; color: var(--accent); font-weight: 600; text-decoration: underline; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; border-radius: 0; background: var(--bg); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

.more summary { color: var(--muted); font-size: 14px; margin-bottom: 10px; cursor: pointer; }
.row { display: flex; gap: 8px; align-items: center; }
.row select { flex: 1; }
.grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 10px; margin-top: 12px; }
.grid .field:nth-child(1), .grid .field:nth-child(2) { grid-column: 1 / -1; }
.grid .row { grid-column: 1 / -1; }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
.hint.small { font-size: 12px; margin-top: 8px; }

.serve summary { font-weight: 600; cursor: pointer; }
.serve details[open] summary { margin-bottom: 10px; }
.serve-inputs { margin-top: 0; }
.serve-inputs .field:nth-child(1), .serve-inputs .field:nth-child(2) { grid-column: auto; }
.serve-heights { font-size: 14px; margin: 0 0 8px; }
.serve-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.serve-table th { text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 4px; }
.serve-table td { padding: 8px 4px; border-top: 1px solid var(--line); }
.serve-table tbody tr { cursor: pointer; }
.serve-table tr.sel td { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.serve-table .rec { font-size: 11px; color: var(--muted); }
.vis-toss { color: var(--ok); }
.vis-contact { color: var(--ink); }
.vis-cut { color: var(--warn); }

.result .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stat b { display: block; font-size: 28px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.msgs { list-style: none; padding: 0; margin: 12px 0 0; font-size: 14px; }
.msgs li { padding: 6px 0 6px 22px; position: relative; border-top: 1px solid var(--line); }
.msgs li::before { position: absolute; left: 0; font-weight: 700; }
.msgs li.ok::before { content: "✓"; color: var(--ok); }
.msgs li.warn::before { content: "!"; color: var(--warn); left: 5px; }
.msgs li.info::before { content: "•"; color: var(--muted); left: 4px; }
.result .actions { margin-top: 12px; }
.result .actions button { width: 100%; }

svg { width: 100%; height: auto; display: block; }

.scene { position: relative; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); margin-bottom: 10px; }
.scene-canvas { height: min(72vh, 640px); touch-action: none; }
.scene-canvas canvas { display: block; width: 100%; height: 100%; }
.scene-hud { position: absolute; top: 8px; left: 8px; padding: 4px 8px; border-radius: 8px; background: rgba(15,26,20,.72); color: #fff; font-size: 13px; font-variant-numeric: tabular-nums; }
.scene-bar { display: flex; gap: 6px; padding: 8px; background: var(--card); border-top: 1px solid var(--line); }
.scene-views { flex: 1; }
.scene-views button { padding: 8px 4px; font-size: 14px; }
.scene-toggles { padding-top: 0; border-top: 0; }
.switch { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 2px; white-space: nowrap; font-size: 13px; border: 0; background: none; color: var(--ink); }
.switch .knob { position: relative; flex: 0 0 auto; width: 34px; height: 20px; border-radius: 10px; background: var(--line); transition: background .15s; }
.switch .knob::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.switch.on .knob { background: var(--accent); }
.switch.on .knob::after { transform: translateX(14px); }
.phone-hud { top: auto; }
.scene.phone-mode .scene-canvas { background: #000; }

.level { text-align: center; }
.level .primary { width: 100%; }

/* Full-screen gauge, laid out for a phone held in landscape. */
.overlay { position: fixed; inset: 0; z-index: 10; background: var(--bg); color: var(--ink); overflow: hidden; transition: background .15s; }
.overlay.good { background: #1f7a4a; color: #fff; --muted: #d6f5e3; --line: rgba(255,255,255,.4); }
.overlay.off { background: #3a2414; color: #fff; --muted: #f3cdb4; --line: rgba(255,255,255,.3); }
.rot { position: absolute; inset: 0; display: flex; align-items: center; justify-content: space-around; gap: 4vmin; padding: 4vmin; text-align: center; }
.rot.turn { inset: auto; top: 50%; left: 50%; width: 100vh; height: 100vw; transform: translate(-50%, -50%) rotate(var(--turn)); }
.rot.upright { flex-direction: column; justify-content: center; }
.g-label { font-size: 4vmin; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.big { font-size: 32vmin; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.04em; line-height: 1; margin: 1vmin 0; }
.delta { font-size: 7vmin; font-weight: 700; min-height: 8vmin; }
.target { font-size: 6vmin; color: var(--muted); }
.target b { color: inherit; }
.overlay .target b { color: #fff; }
.g-side { display: flex; flex-direction: column; align-items: center; gap: 2vmin; min-width: 40%; }
.g-side button { margin-top: 2vmin; padding: 12px 28px; font-size: 18px; background: transparent; color: inherit; border-color: var(--line); }
.roll { position: relative; height: 28px; width: 100%; max-width: 260px; margin: 2vmin auto 0; border-radius: 14px; border: 2px solid var(--line); background: rgba(0,0,0,.15); }
.roll::after { content: ""; position: absolute; left: 50%; top: 2px; bottom: 2px; width: 2px; background: var(--muted); transform: translateX(-1px); }
.bubble { position: absolute; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--ball); left: calc(50% - 9px); transition: left .08s linear; }
.rollVal { font-size: 4vmin; color: var(--muted); }
