:root {
  --bg: #f4f5f2; --ink: #1d2320; --muted: #5d6762; --line: #d5d9d4; --card: #ffffff;
  --accent: #e8590c; --hud: rgba(16, 22, 20, .72); --hud-ink: #f3f6f4;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.page { max-width: 1100px; margin: 0 auto; padding: 10px 16px; }
h1 { font-size: 16px; margin: 0 0 8px; color: #0b4fb3; }
.lead { display: none; }

/* ---- viewer ---- */
.s3d { position: relative; border-radius: 10px; overflow: hidden; background: #0e1512; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.s3d-view { position: relative; height: min(68vh, 620px); min-height: 360px; touch-action: none; }
.s3d-view canvas { display: block; width: 100%; height: 100%; }
.s3d-labels { position: absolute; inset: 0; pointer-events: none; z-index: 0; } /* own stacking context: three.js labels stay under the runner labels */
.s3d-hud { position: absolute; color: var(--hud-ink); background: var(--hud); border-radius: 8px; padding: 6px 10px; backdrop-filter: blur(4px); }
.s3d-clock { top: 10px; left: 10px; }
.s3d-clock b { font: 600 26px/1 ui-monospace, "SF Mono", Consolas, monospace; letter-spacing: .5px; display: block; }
.s3d-clock span { font-size: 11px; opacity: .8; }
.s3d-loc { bottom: 8px; left: 10px; font-size: 11px; padding: 3px 8px; opacity: .9; }
.s3d-attr { position: absolute; bottom: 6px; right: 8px; font-size: 10px; color: #fff; text-shadow: 0 0 3px #000; opacity: .85; max-width: 60%; text-align: right; }
.s3d-loading { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 15px; background: rgba(10,14,12,.35); transition: opacity .6s; pointer-events: none; }

.s3d-board { top: 10px; right: 10px; width: 290px; max-height: calc(min(68vh, 620px) - 60px); overflow-y: auto; overflow-x: hidden; padding: 4px 0; font-size: 12px; }
.s3d-board table { border-collapse: collapse; width: 100%; }
.s3d-board td { padding: 2px 6px; white-space: nowrap; }
.s3d-board tr { cursor: pointer; }
.s3d-board tr:hover, .s3d-board tr.sel { background: rgba(255,255,255,.14); }
.s3d-board .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.s3d-board .nm { max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
.s3d-board .gap { text-align: right; font-variant-numeric: tabular-nums; }
.s3d-board .fin { color: #9be39b; }
.s3d-board .pos { opacity: .6; text-align: right; }

/* ---- labels in 3D ---- */
.s3d-runner { font-size: 11px; color: #fff; background: rgba(0,0,0,.62); padding: 1px 6px; border-radius: 9px; border-left: 4px solid; white-space: nowrap; transform: translateY(-4px); }
.s3d-runner.sel { font-weight: 700; background: rgba(0,0,0,.85); }
.s3d-split { font-size: 11px; font-weight: 600; color: #222; background: rgba(255,255,255,.9); padding: 1px 6px; border-radius: 4px; white-space: nowrap; }
.s3d-place { font-size: 13px; font-weight: 600; color: #fff; text-shadow: 0 0 4px #000, 0 0 2px #000; white-space: nowrap; letter-spacing: .3px; }
.s3d-place.water { color: #d8ecff; font-style: italic; font-weight: 500; }

/* ---- control bar ---- */
.s3d-bar { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; padding: 8px 10px; background: #18201c; color: #e8ece9; font-size: 13px; }
.s3d-bar button, .s3d-bar select { font: inherit; color: inherit; background: #2a3430; border: 1px solid #3c4843; border-radius: 6px; padding: 5px 9px; cursor: pointer; }
.s3d-bar button:hover { background: #34403b; }
.s3d-play { min-width: 44px; font-size: 15px !important; }
.s3d-time { flex: 1 1 200px; accent-color: var(--accent); min-width: 140px; }
.s3d-seg { display: inline-flex; }
.s3d-seg button { border-radius: 0; margin-left: -1px; }
.s3d-seg button:first-child { border-radius: 6px 0 0 6px; }
.s3d-seg button:last-child { border-radius: 0 6px 6px 0; }
.s3d-seg button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.s3d-check { display: inline-flex; gap: 4px; align-items: center; cursor: pointer; }

/* ---- picker ---- */
.picker { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.picker button { font: inherit; font-size: 13px; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
.picker button:hover { border-color: #999; }
.add { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.add input { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; width: 240px; max-width: 70vw; }

@media (max-width: 640px) {
  .page { padding: 0 0 10px; }
  h1 { display: none; }                 /* phones: the 3D view gets the whole width and most of the height */
  .s3d { border-radius: 0; }
  .s3d-view { height: calc(100vh - 118px); height: calc(100svh - 118px); min-height: 380px; } /* all but the control bar */
  .picker { padding: 0 10px; }
  .s3d-board { position: static; width: auto; max-height: none; border-radius: 0; backdrop-filter: none; background: #202925; font-size: 12px; }
  .s3d-board .nm { max-width: 55vw; }
  .s3d-clock b { font-size: 20px; }
  .s3d-runner { font-size: 13px; padding: 2px 7px; }
  .s3d-rlabels .s3d-dot { width: 14px; height: 14px; }   /* DOT_R = 7 in stoltzen3d.js */
  .s3d-rlabels .s3d-split { font-size: 11px; }
  .s3d-loc { display: none; }
}

/* ---- runner labels (screen space, with leader lines) ---- */
.s3d-leaders { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; z-index: 1; }
.s3d-leaders line { stroke-width: 1.2; opacity: .9; }
.s3d-rlabels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }
.s3d-rlabels .s3d-runner { position: absolute; left: 0; top: 0; transform: none; will-change: transform; }
.s3d-runner em { font-style: normal; opacity: .8; margin-left: 4px; font-variant-numeric: tabular-nums; }
.s3d-rlabels .s3d-split { position: absolute; left: 0; top: 0; font-size: 10px; font-weight: 500; padding: 1px 5px; background: rgba(255,255,255,.6); color: #333; opacity: .8; z-index: 0; }
.s3d-leaders line.split { stroke: rgba(255,255,255,.6); stroke-width: 1; }
.s3d-rlabels .s3d-runner { z-index: 1; }

.s3d-rlabels .s3d-runner { pointer-events: auto; cursor: pointer; }
.s3d-rlabels .s3d-runner:hover { background: rgba(0,0,0,.85); }

/* ---- video export ---- */
.s3d-video { background: var(--accent) !important; border-color: var(--accent) !important; color: #fff; font-weight: 600; }
.s3d-modal { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(8,12,10,.72); }
.s3d-modal[hidden] { display: none; }
.s3d-card { background: #1b2420; color: #eef2ef; border-radius: 12px; padding: 18px 20px; width: min(420px, 90%); max-height: 94%; overflow: auto; text-align: center; font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.s3d-card p { opacity: .8; margin: 10px 0; }
.s3d-card video { width: auto; max-width: 100%; max-height: 52vh; border-radius: 8px; background: #000; display: block; margin: 0 auto 12px; }
.s3d-prog { height: 8px; background: #2c3833; border-radius: 4px; overflow: hidden; margin: 12px 0 6px; }
.s3d-prog i { display: block; height: 100%; width: 0; background: var(--accent); }
.s3d-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 6px; }
.s3d-card button, .s3d-card a { font: inherit; color: #fff; background: #2a3430; border: 1px solid #3c4843; border-radius: 6px; padding: 7px 14px; cursor: pointer; text-decoration: none; }
.s3d-card .s3d-share, .s3d-card .s3d-dl { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.s3d-card small { opacity: .6; }

.s3d-axis { font-size: 10px; color: #56605a; white-space: nowrap; transform: translateY(0); }

.s3d-rlabels .s3d-dot { position: absolute; left: 0; top: 0; width: 10px; height: 10px; border-radius: 50%; z-index: 3; will-change: transform; }

@media (max-width: 640px) { .s3d-labels .s3d-split.prof { writing-mode: vertical-rl; transform-origin: center; padding: 5px 1px; } }

.s3d-bar .s3d-field { max-width: 150px; }
.s3d-rlabels .s3d-tip { position: absolute; left: 0; top: 0; z-index: 5; font-size: 12px; color: #fff; background: rgba(12,16,14,.85); padding: 3px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none; }
.s3d-tip b { font-weight: 700; margin-right: 4px; }
.s3d-tip span { display: block; font-size: 11px; opacity: .75; }

/* compact control bar on phones: everything on three rows */
.s3d-video .sm { display: none; }
@media (max-width: 640px) {
  .s3d-bar { gap: 6px 6px; padding: 7px 8px; font-size: 12px; }
  .s3d-bar button, .s3d-bar select { padding: 5px 7px; }
  .s3d-bar .s3d-field { max-width: 104px; }
  .s3d-check { gap: 3px; }
  .s3d-video .lg { display: none; } .s3d-video .sm { display: inline; }
}

/* the main athlete's years (stat.php: "mot deg selv" etc.) */
.s3d-years { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; width: 100%; font-size: 13px; }
.s3d-years b { margin-right: 4px; }
.s3d-years button { padding: 3px 8px; opacity: .55; }
.s3d-years button.on { opacity: 1; border-color: #e8590c; box-shadow: inset 0 0 0 1px #e8590c; font-weight: 600; }
.s3d-years small { color: var(--muted); font-weight: 400; }
.s3d-note { width: 100%; font-size: 12px; color: var(--muted); }
.s3d-tip .s3d-tip-add { pointer-events: auto; display: block; margin-top: 4px; font: inherit; font-size: 12px; color: #fff; background: #e8590c; border: 0; border-radius: 4px; padding: 3px 8px; cursor: pointer; }
/* after the terrain: a small status pill (results loading / error) instead of the dimmed overlay */
.s3d-loading.data { inset: auto; left: 50%; top: 14px; transform: translateX(-50%); background: rgba(10,14,12,.78); padding: 7px 14px; border-radius: 18px; font-size: 14px; max-width: 90%; text-align: center; }

/* loading: spinner, file count, slow-server note */
.s3d-spin { display: inline-block; width: 13px; height: 13px; margin-right: 8px; vertical-align: -2px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: s3dspin .8s linear infinite; }
@keyframes s3dspin { to { transform: rotate(360deg); } }
.s3d-loading small { opacity: .7; margin-left: 4px; }
.s3d-loading small.slow { display: block; margin: 4px 0 0; }
.s3d-card .s3d-url { width: 100%; box-sizing: border-box; margin: 12px 0 4px; font: 13px system-ui, sans-serif; padding: 7px 8px; border-radius: 6px; border: 1px solid #3c4843; background: #10161392; color: #eef2ef; }
/* caption under the clock: who is shown and the field */
.s3d-what { font-size: 12px; line-height: 1.35; margin-top: 4px; max-width: 46vw; }
.s3d-what:empty { display: none; }
.s3d-what div:first-child { font-weight: 600; }
@media (max-width: 640px) { .s3d-what { font-size: 11px; max-width: 58vw; } }
