:root {
  --bg: #0f141b; --panel: #171e27; --panel2: #1f2834; --border: #2a3542; --fg: #e8eef5; --muted: #9aa8b8;
  --accent: #ff8a1f; --accent2: #3aa8ff; --good: #4ade80; --bad: #f87171; --warn: #f5a524;
  --chart-bg: #121820; --chart-fg: #d7dee8; --chart-grid: rgba(255,255,255,0.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 14px/1.4 system-ui, "Segoe UI", Roboto, sans-serif; }
body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
header { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { font-weight: 800; letter-spacing: 0.3px; font-size: 17px; }
nav { display: flex; gap: 4px; }
nav button { background: transparent; color: var(--muted); border: 1px solid transparent; padding: 7px 14px; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 600; }
nav button.active { color: var(--fg); background: var(--panel2); border-color: var(--border); }
.spacer { flex: 1; }
.badge { background: var(--warn); color: #1a1208; border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 700; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
body:not(.admin) .admin-only { display: none !important; }
/* The tree editor: admin mode, or a host page that lets its players edit (window.discmetricsHost.canEdit). */
body:not(.can-edit) .edit-only { display: none !important; }
main { flex: 1; min-height: 0; }
.tab { height: 100%; }
.tab:not(.active) { display: none !important; }

.btn { background: var(--panel2); color: var(--fg); border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: transparent; color: #1a1208; }
.btn.primary:disabled { opacity: 0.4; cursor: default; }
.btn.big { font-size: 17px; padding: 12px 28px; border-radius: 12px; }
.btn.small { padding: 5px 10px; font-weight: 500; font-size: 13px; }
.btn.ghost { background: transparent; }
.chip { background: rgba(15,20,30,0.78); color: #fff; border: 1px solid rgba(255,255,255,0.14); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; backdrop-filter: blur(4px); }
.chip.on { border-color: var(--accent); color: var(--accent); }
select, input[type=number], input[type=text], input:not([type]) { background: var(--panel2); color: var(--fg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font: inherit; }
input[type=number] { width: 64px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 14px; }

/* ---------------- play ---------------- */
#play { display: grid; grid-template-rows: 1fr auto; }
.stage { position: relative; min-height: 0; overflow: hidden; }
.stage canvas { width: 100%; height: 100%; display: block; background: #9ec9ee; touch-action: none; }
.hud-left { position: absolute; left: 14px; top: 14px; display: flex; flex-direction: column; gap: 8px; }
.card { background: rgba(15,20,30,0.8); border: 1px solid rgba(255,255,255,0.12); border-radius: 14px; padding: 10px 14px; color: #fff; backdrop-filter: blur(4px); min-width: 170px; text-align: left; }
.card .big { font-size: 28px; font-weight: 800; line-height: 1.1; }
.card .sub { color: #c9d4e0; font-size: 12.5px; }
.card.wind { display: flex; align-items: center; gap: 10px; }
.card.wind .arrow { font-size: 26px; width: 30px; text-align: center; transition: transform 0.3s; color: #7dd3fc; }
button.card { font: inherit; cursor: pointer; }
.hint { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); background: rgba(15,20,30,0.7); padding: 6px 12px; border-radius: 999px; font-size: 13px; pointer-events: none; white-space: nowrap; }
.view-btns { position: absolute; left: 14px; bottom: 14px; display: flex; gap: 6px; flex-wrap: wrap; }
/* whose photo and map the course is drawn from: shown, never in the way of a tap (the links are in Round's dialog) */
.credits { position: absolute; right: 8px; bottom: 3px; max-width: 55%; text-align: right; font-size: 10px; line-height: 1.35; color: rgba(255,255,255,0.75); text-shadow: 0 1px 2px rgba(0,0,0,0.8); pointer-events: none; }
.credits div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dialog-credits { font-size: 11.5px; color: var(--muted); margin: 4px 0 0; }
.dialog-credits a { color: inherit; }
@media (max-width: 700px) { .credits { max-width: 60%; font-size: 9px; } }
.toast { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); background: rgba(15,20,30,0.88); border: 1px solid rgba(255,255,255,0.14); border-radius: 14px; padding: 12px 18px; text-align: center; display: none; max-width: min(92%, 560px); backdrop-filter: blur(4px); pointer-events: none; }
.toast.show { display: block; }
.toast .big { font-size: 22px; font-weight: 800; }
.toast .rel { color: #c9d4e0; font-size: 12.5px; margin-top: 4px; }
.small-toast { left: auto; right: 12px; transform: none; bottom: 12px; padding: 6px 10px; font-size: 12.5px; }
.center-card { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(15,20,30,0.92); border: 1px solid rgba(255,255,255,0.16); border-radius: 18px; padding: 22px 28px; text-align: center; min-width: 300px; }
.center-card .big { font-size: 34px; font-weight: 800; }
.center-card .row { justify-content: center; margin-top: 14px; }

.controls { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-top: 1px solid var(--border); flex-wrap: wrap; }
.controls .push { flex: 1 0 0; }
.controls #btnSetup, .controls #btnThrow { flex: none; }
.ctl-group { display: flex; align-items: center; gap: 8px; }
.lbl { color: var(--muted); font-size: 12.5px; }
.auto-badge { font-size: 11px; background: #23415f; color: #9fd0ff; border-radius: 6px; padding: 2px 6px; }
.auto-badge.off { visibility: hidden; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { background: var(--panel2); color: var(--muted); border: 0; padding: 7px 11px; font: inherit; cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: #2b3644; color: var(--fg); box-shadow: inset 0 -2px 0 var(--accent); }
.manual { display: none; gap: 14px; align-items: end; }
.manual.on { display: flex; }
.sl { min-width: 130px; }
.sl .top { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--muted); }
.sl output { color: var(--fg); font-variant-numeric: tabular-nums; }
.sl output.under { color: var(--good); } .sl output.over { color: var(--bad); }
details.more summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
details.more[open] { background: var(--panel2); border: 1px solid var(--border); border-radius: 10px; padding: 8px; position: relative; }
.controls details.more[open] { position: absolute; bottom: 70px; z-index: 5; width: 240px; }
.skill-info { color: var(--muted); font-size: 12.5px; flex: 0 1 220px; min-width: 120px; }
.skill-info.off { display: none; }
@media (max-width: 1600px) { .skill-info { display: none; } }   /* the meter explains itself; keeps Round/Throw on the first row */

/* meter */
.meter-host { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 70px; background: rgba(0,0,0,0.12); cursor: pointer; }
.meter-card { width: min(560px, 92%); background: rgba(15,20,30,0.9); border: 1px solid rgba(255,255,255,0.16); border-radius: 16px; padding: 14px 18px; }
.meter-title { font-weight: 700; margin: 4px 0 6px; }
.meter-title.dim { opacity: 0.35; }
.meter-bar { position: relative; height: 22px; border-radius: 11px; background: #263241; overflow: hidden; }
.meter-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(90deg, #3aa8ff, #4ade80); }
.meter-fill.over { background: linear-gradient(90deg, #3aa8ff, #4ade80 80%, #f87171); }
.meter-100 { position: absolute; top: 0; bottom: 0; left: calc(100% / 1.1); width: 2px; background: rgba(255,255,255,0.55); }
.meter-target { position: absolute; top: -2px; bottom: -2px; width: 4px; margin-left: -2px; background: #ffd400; box-shadow: 0 0 6px #ffd400; }
.meter-marker { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1px; background: #fff; }
.meter-bar.timing { background: linear-gradient(90deg, #f87171, #f5a524 30%, #263241 42%, #263241 58%, #f5a524 70%, #f87171); }
.meter-zone { position: absolute; top: 0; bottom: 0; background: rgba(74,222,128,0.55); }   /* left/width from GREEN (meter.js) */
.meter-needle { position: absolute; top: -3px; bottom: -3px; width: 4px; margin-left: -2px; background: #fff; box-shadow: 0 0 6px #fff; }
.meter-scale { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin: 3px 2px 8px; }
.meter-scale .over { color: var(--bad); }
#mtCancel { float: right; margin-top: -4px; }

/* editor (admin) */
.editor { position: absolute; right: 14px; top: 14px; width: 250px; background: rgba(15,20,30,0.9); border: 1px solid var(--warn); border-radius: 12px; padding: 10px 12px; }
.editor h4 { margin: 0 0 6px; color: var(--warn); font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; }
.editor .row { margin: 6px 0; font-size: 12.5px; }
.editor input[type=number] { width: 54px; }
.editor .note { font-size: 12px; color: var(--muted); }
canvas.editing { cursor: crosshair; }

/* dialogs */
dialog { background: var(--panel); color: var(--fg); border: 1px solid var(--border); border-radius: 16px; padding: 18px 22px; min-width: min(420px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,0.55); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
.setup label { display: grid; grid-template-columns: 120px 1fr; align-items: center; gap: 8px; margin: 8px 0; color: var(--muted); }
.setup input:not([type=checkbox]) { padding: 8px 10px; }
.setup fieldset { border: 1px solid var(--border); border-radius: 10px; margin-top: 10px; }
.setup legend { color: var(--muted); padding: 0 6px; }
.bag { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
.bag label { display: flex; gap: 6px; margin: 0; color: var(--fg); grid-template-columns: none; font-size: 13px; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { padding: 4px 8px; text-align: right; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; }
td.good { color: var(--good); } td.bad { color: var(--bad); }

/* ---------------- lab ---------------- */
.lab-grid { display: grid; grid-template-columns: 320px 1fr; gap: 12px; padding: 12px; height: 100%; }
.lab-side { display: flex; flex-direction: column; gap: 12px; overflow: auto; }
.lab-main { display: grid; grid-template-rows: minmax(260px, 1fr) auto; gap: 12px; min-height: 0; }
.small-stage { border-radius: 12px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.panel h3 { margin: 0 0 8px; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.panel .sl { margin: 6px 0; }
.lab-side select { width: 100%; }
.charts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
canvas.chart { width: 100%; height: 200px; display: block; border-radius: 8px; }
.prose { max-width: 1150px; padding: 16px 20px; overflow: auto; height: 100%; color: #cfd8e3; }
.prose h2 { font-size: 17px; margin: 18px 0 6px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

@media (max-width: 900px) {
  .controls { gap: 10px; padding: 8px 10px; }
  .manual.on { flex-wrap: wrap; }
  .sl { min-width: 120px; }
  .lab-grid { grid-template-columns: 1fr; overflow: auto; }
  .charts, .grid3 { grid-template-columns: 1fr; }
  .card .big { font-size: 22px; }
  .hint { display: none; }
}

/* multiplayer */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.hud-left .player { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.hud-left .score b .dot { margin-left: 8px; }
.center-card .pl { margin: 4px 0; } .center-card .pl.best b { color: var(--accent); }
.center-card .code { letter-spacing: 6px; font-family: ui-monospace, monospace; }
.center-card .note { font-size: 12.5px; color: var(--muted); max-width: 420px; margin: 6px auto 0; }
.center-card a { color: var(--accent); word-break: break-all; }
.setup .row.join { align-items: end; gap: 8px; border-top: 1px solid var(--border); padding-top: 10px; }
.setup .row.join label { flex: 1; }
#sJoin { text-transform: uppercase; letter-spacing: 3px; }

/* putting: no launch slider (the aim point sets it), no extras */
.manual.putting .sl:has(#mLaunch), .manual.putting details.more { display: none; }
