/* HANDS — warm porcelain theme
   background radial #fffdf4 → #f8ead0 · text #46350f · headings #8a5a00 */
:root {
  --porcelain: #fffdf4;
  --cream: #f8ead0;
  --ink: #46350f;
  --brass: #8a5a00;
  --brass-soft: rgba(138, 90, 0, 0.28);
  --red: #c44444;
  --green: #6aa050;
  --panel: rgba(255, 253, 244, 0.78);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Roboto Mono", monospace;
  --sans: -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: radial-gradient(120% 90% at 50% 38%, var(--porcelain) 0%, var(--cream) 100%);
}
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#ui { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#ui.hidden-ui > * { opacity: 0; pointer-events: none !important; }
#ui > * { transition: opacity 0.25s ease; }
#overlay { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }

/* ---------- top bar ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  background: linear-gradient(to bottom, rgba(255,253,244,0.9), rgba(255,253,244,0));
  pointer-events: auto;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark { color: var(--brass); font-size: 18px; }
.brand-name { font-weight: 800; letter-spacing: 0.22em; color: var(--brass); font-size: 17px; }
.brand-sub { font-size: 11px; opacity: 0.65; letter-spacing: 0.06em; }
.tabs { display: flex; gap: 6px; margin-left: 8px; }
.tab {
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.04em;
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--brass-soft); background: rgba(255,253,244,0.55); color: var(--ink);
  transition: all 0.2s ease;
}
.tab:hover { border-color: var(--brass); }
.tab.active { background: var(--brass); color: var(--porcelain); border-color: var(--brass); font-weight: 700; }
.transport { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.tbtn {
  font-family: var(--mono); font-size: 12px; color: var(--ink);
  border: 1px solid var(--brass-soft); background: rgba(255,253,244,0.65);
  border-radius: 8px; padding: 6px 9px; cursor: pointer; transition: all 0.15s ease;
}
.tbtn:hover { border-color: var(--brass); background: var(--porcelain); }
.tbtn.on { background: var(--brass); color: var(--porcelain); border-color: var(--brass); }
select.tbtn { padding: 5px 6px; }

/* ---------- telemetry ---------- */
.telemetry {
  position: absolute; top: 64px; left: 16px; min-width: 232px;
  background: var(--panel); border: 1px solid var(--brass-soft); border-radius: 12px;
  padding: 12px 14px; pointer-events: auto; backdrop-filter: blur(6px);
  box-shadow: 0 6px 24px rgba(70, 53, 15, 0.08);
}
.telemetry h3 { font-size: 11px; letter-spacing: 0.18em; color: var(--brass); margin-bottom: 8px; }
.trow { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; padding: 3px 0; }
.trow .k { opacity: 0.7; }
.trow .v { font-family: var(--mono); font-weight: 700; color: var(--brass); font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 10px; }
.trow .v.good { color: var(--green); }
.trow .v.bad { color: var(--red); }
.tbar { height: 4px; background: rgba(138,90,0,0.14); border-radius: 2px; margin: 4px 0 8px; overflow: hidden; }
.tbar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brass), #c99b3f); border-radius: 2px; transition: width 0.2s linear; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.chip {
  font-family: var(--mono); font-size: 10px; padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--brass-soft); background: rgba(255,253,244,0.7);
}
.chip.ok { color: var(--green); border-color: rgba(106,160,80,0.5); }
.chip.fail { color: var(--red); border-color: rgba(196,68,68,0.5); }
.verbose-block { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--brass-soft); font-family: var(--mono); font-size: 10px; line-height: 1.7; opacity: 0.85; white-space: pre-wrap; }

/* ---------- stopwatch ---------- */
#timer {
  position: absolute; top: 64px; right: 16px; text-align: right;
  background: var(--panel); border: 1px solid var(--brass-soft); border-radius: 12px;
  padding: 10px 16px; backdrop-filter: blur(6px); pointer-events: auto;
}
#timer-value { display: block; font-family: var(--mono); font-size: 34px; font-weight: 800; color: var(--brass); font-variant-numeric: tabular-nums; line-height: 1; }
#timer-label { display: block; font-size: 9px; letter-spacing: 0.22em; opacity: 0.6; margin-top: 4px; }

/* ---------- ops log + caption ---------- */
.opslog {
  position: absolute; left: 16px; bottom: 52px; width: min(430px, 44vw);
  font-family: var(--mono); font-size: 11px; line-height: 1.75;
  color: var(--ink); pointer-events: none;
}
.opslog .line { opacity: 0; transform: translateY(4px); transition: all 0.3s ease; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opslog .line.show { opacity: 0.88; transform: translateY(0); }
.opslog .line .p { color: var(--brass); font-weight: 700; }
.opslog .line.ok .p { color: var(--green); }
.caption {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  font-size: 13px; letter-spacing: 0.05em; color: var(--ink);
  background: var(--panel); border: 1px solid var(--brass-soft); border-radius: 999px;
  padding: 7px 20px; backdrop-filter: blur(6px); pointer-events: none;
  opacity: 0; transition: opacity 0.4s ease; max-width: 80vw; text-align: center;
}
.caption.show { opacity: 1; }
.caption b { color: var(--brass); }

/* ---------- parameter panel ---------- */
#parampanel {
  position: absolute; top: 64px; right: 16px; width: 300px; max-height: calc(100vh - 130px);
  background: var(--panel); border: 1px solid var(--brass-soft); border-radius: 12px;
  backdrop-filter: blur(8px); pointer-events: auto; display: flex; flex-direction: column;
  box-shadow: 0 10px 34px rgba(70, 53, 15, 0.12); overflow: hidden;
}
.pp-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--brass-soft);
  font-size: 11px; letter-spacing: 0.2em; color: var(--brass); font-weight: 700;
}
#pp-body { overflow-y: auto; padding: 10px 14px; }
.pp-foot { padding: 8px 14px; border-top: 1px solid var(--brass-soft); }
.pgroup { font-size: 10px; letter-spacing: 0.18em; color: var(--brass); margin: 10px 0 4px; font-weight: 700; }
.pctl { margin-bottom: 8px; }
.pctl label { display: flex; justify-content: space-between; font-size: 11px; margin-bottom: 2px; }
.pctl label .val { font-family: var(--mono); color: var(--brass); font-weight: 700; }
.pctl input[type="range"] { width: 100%; accent-color: var(--brass); height: 18px; cursor: pointer; }
.pctl select { width: 100%; font-family: var(--mono); font-size: 11px; padding: 4px; border: 1px solid var(--brass-soft); border-radius: 6px; background: var(--porcelain); color: var(--ink); }

/* ---------- debug / toast / help ---------- */
#debug {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  font-family: var(--mono); font-size: 11px; line-height: 1.8;
  background: rgba(70, 53, 15, 0.85); color: var(--porcelain);
  border-radius: 10px; padding: 12px 16px; pointer-events: auto; white-space: pre;
}
#toast {
  position: absolute; top: 70px; left: 50%; transform: translateX(-50%);
  font-family: var(--mono); font-size: 12px; color: var(--porcelain);
  background: rgba(138, 90, 0, 0.92); border-radius: 999px; padding: 8px 18px;
  opacity: 0; transition: opacity 0.3s ease; pointer-events: none;
}
#toast.show { opacity: 1; }
#helpbar {
  position: absolute; bottom: 0; left: 0; right: 0; display: flex; gap: 14px; justify-content: center;
  font-family: var(--mono); font-size: 10px; color: var(--ink); opacity: 0.55;
  padding: 7px 10px; background: linear-gradient(to top, rgba(248,234,208,0.85), rgba(248,234,208,0));
  pointer-events: none; flex-wrap: wrap;
}

/* ---------- overlay: device labels & check cards ---------- */
.dev-label {
  position: absolute; transform: translate(-50%, -130%);
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; color: var(--brass);
  background: rgba(255,253,244,0.8); border: 1px solid var(--brass-soft);
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.check-card {
  position: absolute; width: 168px; transform: translate(-50%, -100%) translateY(6px);
  background: var(--panel); border: 1px solid var(--brass-soft); border-radius: 10px;
  padding: 9px 11px; backdrop-filter: blur(6px);
  box-shadow: 0 8px 26px rgba(70,53,15,0.14);
  opacity: 0; transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  font-size: 10px;
}
.check-card.show { opacity: 1; transform: translate(-50%, -100%) translateY(-8px); }
.check-card h4 { font-family: var(--mono); font-size: 11px; color: var(--brass); letter-spacing: 0.08em; margin-bottom: 5px; display: flex; justify-content: space-between; }
.check-card h4 .st { color: var(--green); }
.check-card .cc-row { display: flex; justify-content: space-between; font-family: var(--mono); padding: 1.5px 0; }
.check-card .cc-row .k { opacity: 0.65; }
.check-card .cc-row .v { font-weight: 700; padding-left: 8px; white-space: nowrap; }

/* root-cause panel */
#rootcause {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(0.96);
  width: min(460px, 86vw); background: var(--panel); border: 1px solid var(--brass);
  border-radius: 14px; padding: 20px 24px; backdrop-filter: blur(10px);
  box-shadow: 0 18px 60px rgba(70,53,15,0.2);
  opacity: 0; pointer-events: none; transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.22,1,0.36,1);
}
#rootcause.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
#rootcause h2 { font-size: 13px; letter-spacing: 0.2em; color: var(--brass); margin-bottom: 10px; }
#rootcause p { font-size: 13px; line-height: 1.7; margin-bottom: 6px; }
#rootcause p b { color: var(--brass); }
#rootcause .rc-action { font-family: var(--mono); font-size: 11px; background: rgba(138,90,0,0.09); border-left: 3px solid var(--brass); padding: 8px 12px; border-radius: 0 8px 8px 0; margin-top: 8px; }
#rootcause button { margin-top: 12px; }

.hidden { display: none !important; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .brand-sub { display: none; }
  #topbar { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .telemetry { top: auto; bottom: 60px; left: 10px; min-width: 190px; padding: 9px 11px; }
  .opslog { display: none; }
  #timer { top: auto; bottom: 60px; right: 10px; padding: 7px 12px; }
  #timer-value { font-size: 24px; }
  #parampanel { width: min(300px, 92vw); right: 8px; top: 96px; }
  #helpbar { display: none; }
  .check-card { width: 140px; font-size: 9px; }
}
