:root { --bg: rgba(10, 24, 16, 0.78); --bg2: rgba(16, 36, 24, 0.94); --fg: #f2f7f2; --mut: #a9c2ae; --acc: #ffd23f; --pri: #2fb35a; --bad: #ff6b5b; --r: 14px;
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px); --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1a10; color: var(--fg); font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#app { position: fixed; inset: 0; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button, select, input { font: inherit; color: inherit; }
button { background: rgba(255, 255, 255, 0.12); border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 12px; padding: 10px 14px; cursor: pointer; min-height: 44px; }
button:active { transform: scale(0.97); }
button.primary { background: var(--pri); border-color: #43d673; font-weight: 700; }
button:disabled { opacity: 0.45; }
select, input[type=number] { background: rgba(0, 0, 0, 0.35); border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 10px; padding: 8px; min-height: 40px; }
input[type=number] { width: 5em; }
.hidden { display: none !important; }
.small { font-size: 12.5px; color: var(--mut); }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.row.wrap { flex-wrap: wrap; }
.row > button { flex: 1; }
.inl { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; }
.x { background: none; border: 0; font-size: 20px; min-height: 36px; padding: 4px 10px; flex: 0 !important; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.15); margin-left: 8px; }
.badge.high { background: #1f8f47; } .badge.medium { background: #9a7a12; } .badge.low { background: #9b3a2e; }

#hud { position: absolute; top: calc(8px + var(--st)); left: calc(8px + var(--sl)); right: calc(290px + var(--sr)); display: flex; gap: 8px; pointer-events: none; align-items: flex-start; }
.hudcard.wind { flex: none; }
@media (orientation: portrait) and (max-width: 640px) { #hud { top: calc(58px + var(--st)); right: calc(8px + var(--sr)); } #hud .hudcard:first-child { flex: 1; } .menu { top: calc(56px + var(--st)); } }
.hudcard { background: var(--bg); border-radius: var(--r); padding: 7px 12px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.hudcard .h1 { font-size: 16px; } .hudcard .h1 span { color: var(--mut); font-size: 13px; }
.hudcard .h2 { font-size: 13px; color: #dfe9df; }
.wind { display: flex; align-items: center; gap: 6px; font-size: 13px; }
#windArrow { display: inline-block; font-size: 20px; color: #7fd0ff; transition: transform .3s; }
#topBtns { position: absolute; top: calc(8px + var(--st)); right: calc(8px + var(--sr)); display: flex; gap: 6px; }
#topBtns button { background: var(--bg); padding: 8px 10px; min-height: 40px; }
.menu { position: absolute; top: calc(56px + var(--st)); right: calc(8px + var(--sr)); background: var(--bg2); border-radius: var(--r); padding: 6px; display: flex; flex-direction: column; gap: 4px; z-index: 30; min-width: 200px; }
.menu button { text-align: left; background: none; border: 0; }

#toast { position: absolute; top: 34%; left: 50%; transform: translateX(-50%); background: var(--bg2); padding: 14px 20px; border-radius: var(--r); font-size: 18px; font-weight: 700; text-align: center; z-index: 40; max-width: 88vw; box-shadow: 0 6px 30px rgba(0,0,0,.4); }
#toast small { display: block; font-weight: 400; font-size: 13px; color: var(--mut); margin-top: 4px; }
#toast .row { justify-content: center; }

#controls { position: absolute; left: 0; right: 0; bottom: 0; padding: 6px calc(8px + var(--sr)) calc(8px + var(--sb)) calc(8px + var(--sl)); background: linear-gradient(transparent, rgba(5, 15, 8, 0.85) 30%); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: 0 0 auto; min-height: 38px; padding: 6px 12px; font-weight: 600; background: rgba(0, 0, 0, 0.45); }
.chips button.on { background: var(--acc); color: #1a1a1a; border-color: var(--acc); }
.chips button small { display: block; font-size: 10px; font-weight: 400; opacity: 0.8; }
.row.main button { font-weight: 600; }
.row.main .aim { flex: 0 0 52px; font-size: 18px; }

#stats { position: absolute; left: calc(8px + var(--sl)); right: calc(8px + var(--sr)); bottom: calc(126px + var(--sb)); background: var(--bg); border-radius: var(--r); padding: 10px 12px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.sthead { display: flex; align-items: center; }
.sthead b { flex: 1; }
.stgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px 10px; margin-top: 6px; }
.stgrid div { display: flex; flex-direction: column; }
.stgrid span { font-size: 11px; color: var(--mut); text-transform: uppercase; letter-spacing: .03em; }
.stgrid b { font-size: 19px; }
.stgrid b small { font-size: 12px; font-weight: 500; color: var(--mut); }
.strow { display: flex; gap: 8px; margin-top: 8px; }
.strow:empty { display: none; }
.strow button { flex: 1; }

.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 82%; overflow: auto; background: var(--bg2); border-radius: 18px 18px 0 0; padding: 12px 14px calc(14px + var(--sb)); z-index: 20; box-shadow: 0 -8px 30px rgba(0, 0, 0, .4); }
.shhead { display: flex; align-items: center; justify-content: space-between; font-size: 17px; margin-bottom: 6px; position: sticky; top: -12px; background: var(--bg2); padding-top: 4px; }
.sliders label { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; margin: 8px 0; font-size: 14px; }
.sliders input { grid-column: 1 / 3; width: 100%; accent-color: var(--acc); }
.sliders output { font-weight: 700; color: var(--acc); }
.form label { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 10px 0; font-size: 14px; }
.help h4 { margin: 12px 0 4px; color: var(--acc); } .help p, .help li { font-size: 14px; color: #dbe7dc; } .help ul { padding-left: 18px; }

.full { position: absolute; inset: 0; background: #050a07; z-index: 25; display: flex; flex-direction: column; }
.capview, .repwrap { position: relative; flex: 1; min-height: 0; background: #000; }
#capVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#capOv { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.capbar { padding: 8px 12px calc(10px + var(--sb)); background: var(--bg2); max-height: 55%; overflow: auto; }
.status { font-weight: 700; font-size: 16px; }
.status.ok { color: #6be38f; } .status.warn { color: var(--acc); } .status.bad { color: var(--bad); }
#repCv { width: 100%; height: 100%; object-fit: contain; display: block; }
.repwrap { display: flex; align-items: center; justify-content: center; }
#repSlider { flex: 3; accent-color: var(--acc); }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 6px 0; }
.metrics div { background: rgba(255,255,255,.06); border-radius: 10px; padding: 6px 8px; }
.metrics span { display: block; font-size: 11px; color: var(--mut); }
.metrics b { font-size: 17px; }
.vidbox { background: #000; border-radius: 12px; overflow: hidden; margin: 8px 0; }
#vidFirst { width: 100%; display: block; max-height: 36vh; object-fit: contain; cursor: crosshair; }
.vidbox .small { padding: 6px 10px; }
.hiddenvid { position: absolute; width: 2px; height: 2px; opacity: 0; pointer-events: none; }
.filebtn { position: relative; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; flex: 1; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.18); border-radius: 12px; padding: 10px 14px; min-height: 44px; cursor: pointer; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.prog { height: 6px; background: rgba(255,255,255,.1); border-radius: 3px; overflow: hidden; }
#vidProg { height: 100%; width: 0; background: var(--acc); transition: width .15s; }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 6px; text-align: right; border-bottom: 1px solid rgba(255,255,255,.08); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--mut); font-weight: 600; font-size: 12px; }
td.under { color: #6be38f; font-weight: 700; } td.over { color: #ff9c8f; }
tr.tot td { font-weight: 800; border-top: 2px solid rgba(255,255,255,.25); }

/* landscape phones / tablets: panels to the side */
@media (orientation: landscape) and (max-height: 600px) {
  #controls { left: auto; width: min(420px, 48vw); background: none; }
  #controls .chips { background: rgba(5,15,8,.6); border-radius: 12px; }
  #stats { right: auto; width: min(380px, 46vw); bottom: calc(8px + var(--sb)); top: auto; }
  .stgrid b { font-size: 16px; }
  .sheet { left: auto; top: 0; width: min(440px, 55vw); max-height: none; border-radius: 18px 0 0 18px; }
  .full { flex-direction: row; }
  .capbar { width: min(360px, 42vw); max-height: none; }
  #hud { right: calc(290px + var(--sr)); }
}
@media (min-width: 900px) and (orientation: landscape) {
  #stats { right: auto; width: 400px; }
  #controls { left: auto; width: 520px; background: none; }
  .sheet { left: auto; top: 0; width: 460px; max-height: none; border-radius: 18px 0 0 18px; }
  .full { flex-direction: row; } .capbar { width: 400px; max-height: none; }
}

/* ===== big-screen display mode (read from 3–5 m) ===== */
body.display { --dz: 1.6; }
body.display #hud, body.display #topBtns, body.display .menu, body.display #stats, body.display #controls, body.display #toast, body.display .sheet, body.display #disp > * { zoom: var(--dz); }
body.display #btnCam, body.display #btnVideo { display: none; }
body.display #controls { left: auto; right: 0; width: 560px; background: none; }
body.display #controls .chips { background: rgba(5,15,8,.6); border-radius: 12px; flex-wrap: wrap; overflow: visible; justify-content: flex-end; }
body.display #controls .chips button small { display: none; }
body.display #controls .row.main { justify-content: flex-end; }
body.display #controls .row.main > button { flex: 0 0 auto; }
body.display #hud { right: 250px; flex-wrap: wrap; }
body.display #hud .hudcard:first-child { flex: 0 0 auto; white-space: nowrap; }
body.display .hudcard .h1 b { font-size: 26px; } body.display .hudcard .h1 { font-size: 18px; } body.display .hudcard .h2 { font-size: 18px; }
body.display #stats { left: 8px; right: auto; width: 440px; bottom: 8px; top: auto; }
body.display #stats .stgrid b { font-size: 24px; }
body.display #toast { font-size: 24px; }
body.display .sheet { left: auto; top: 0; width: 520px; max-height: none; border-radius: 18px 0 0 18px; }
#hud .dlink { display: flex; gap: 8px; align-items: center; background: var(--bg); border-radius: 99px; padding: 4px 6px 4px 14px; font-weight: 700; font-size: 15px; white-space: nowrap; pointer-events: auto; align-self: center; }
#hud .dlink button { min-height: 32px; padding: 4px 10px; border-radius: 99px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: #999; display: inline-block; flex: 0 0 auto; }
[data-state=connected] .dot { background: #3ee07a; box-shadow: 0 0 10px #3ee07a; }
[data-state=waiting] .dot, [data-state=connecting] .dot, [data-state=notfound] .dot { background: var(--acc); animation: blink 1.2s infinite; }
[data-state=offline] .dot, [data-state=error] .dot { background: var(--bad); }
@keyframes blink { 50% { opacity: .3; } }
#disp .dpair { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: flex; gap: 22px; align-items: center; background: var(--bg2); border-radius: 20px; padding: 20px; z-index: 18; box-shadow: 0 10px 50px rgba(0,0,0,.5); max-width: 760px; }
#disp .dpl canvas { width: 250px; height: 250px; border-radius: 10px; display: block; image-rendering: pixelated; }
#disp .dpr { min-width: 300px; }
#disp .dptitle { font-size: 22px; font-weight: 800; }
#disp ol { padding-left: 20px; font-size: 16px; } #disp ol li { margin: 6px 0; }
#disp .dcode { font: 800 54px/1.1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 6px; color: var(--acc); margin: 6px 0; }
#disp .dmsg { font-size: 14px; margin: 6px 0; color: var(--mut); max-width: 360px; } #disp .dmsg.offline, #disp .dmsg.error { color: var(--bad); font-weight: 600; }
#disp .dthumb { position: absolute; top: 120px; left: 8px; background: var(--bg); border-radius: 12px; padding: 6px; z-index: 12; }
#disp .dthumb img { width: 240px; display: block; border-radius: 8px; } #disp .dthumb span { display: block; font-weight: 700; font-size: 15px; padding: 4px 2px 0; }
#disp .dnav { position: absolute; top: 8px; right: 8px; margin-top: 52px; display: flex; gap: 6px; z-index: 11; }
#disp .dnav button { background: var(--bg); min-height: 38px; padding: 6px 10px; }
#disp .dkeys { position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%); font-size: 11px; color: rgba(255,255,255,.55); white-space: nowrap; pointer-events: none; }
body.display #topBtns { z-index: 11; }

/* ===== phone-as-camera mode ===== */
body.remote { overflow: auto; }
#remote { position: fixed; inset: 0; display: flex; flex-direction: column; }
.rjoin { padding: calc(18px + var(--st)) 18px 18px; max-width: 520px; margin: 0 auto; width: 100%; overflow: auto; }
.rjoin h2 { margin: 6px 0 10px; }
.rjoin input#rCode { flex: 1; font: 800 30px ui-monospace, Menlo, Consolas, monospace; letter-spacing: 4px; text-transform: uppercase; text-align: center; padding: 10px; background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.25); border-radius: 12px; min-width: 0; }
.rscan { position: relative; background: #000; border-radius: 14px; overflow: hidden; padding-bottom: 8px; text-align: center; }
.rscan video { width: 100%; max-height: 50vh; object-fit: cover; display: block; }
.rcam { position: absolute; inset: 0; display: flex; flex-direction: column; }
.rcam .capview { flex: 1; }
.rcam .capview canvas { touch-action: none; }
.rcam .capview video, .rcam .capview canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.rtop { position: absolute; top: calc(8px + var(--st)); left: 8px; right: 8px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; pointer-events: none; }
.rconn { display: flex; gap: 8px; align-items: center; background: var(--bg); border-radius: 99px; padding: 6px 12px; font-size: 13px; font-weight: 600; max-width: 100%; }
.rlock { background: rgba(0,0,0,.6); border-radius: 99px; padding: 8px 16px; font-size: 20px; font-weight: 800; }
.rlock[data-state=locked] { background: #1f8f47; } .rlock[data-state=impact] { background: #2f6fd6; } .rlock[data-state=search] { color: var(--acc); } .rlock[data-state=none], .rlock[data-state=bad] { color: #ff9a8f; }
.rpanel { background: var(--bg2); padding: 8px 12px calc(10px + var(--sb)); max-height: 55%; overflow: auto; }
.rlast { margin: 4px 0; }
.rnums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rnums div { background: rgba(255,255,255,.07); border-radius: 10px; padding: 6px 8px; } .rnums span { display: block; font-size: 11px; color: var(--mut); } .rnums b { font-size: 16px; white-space: nowrap; }
@media (orientation: landscape) and (max-height: 560px) { .rcam { flex-direction: row; } .rpanel { width: 360px; max-height: none; } }
/* display: scorecard / history readable from across the room */
body.display #sheetScore, body.display #sheetHistory { width: 660px; }
body.display #sheetScore table, body.display #sheetHistory table { font-size: 16px; }
body.display #sheetScore td, body.display #sheetScore th { padding: 7px 4px; font-size: inherit; }
