:root{
  /* Seamless background with the 3D view */
  --bg0:#111111;
  --bg1:#111111;
  --card:rgba(255,255,255,.06);
  --card2:rgba(255,255,255,.08);
  --stroke:rgba(255,255,255,.10);
  --stroke2:rgba(255,255,255,.14);
  --text:#e9eefc;
  --muted:rgba(233,238,252,.72);
  --muted2:rgba(233,238,252,.55);
  --accent:#7c3aed; /* violet */
  --accent2:#22c55e; /* green */
  --warn:#f59e0b;
  --danger:#ef4444;
  --radius:8px;
  --shadow: 0 18px 55px rgba(0,0,0,.45);
  --shadow2: 0 10px 30px rgba(0,0,0,.35);
  --font: "Roboto", system-ui, -apple-system, Segoe UI, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family:var(--font);
  color:var(--text);
  background: linear-gradient(180deg, var(--bg0), var(--bg1));
  min-height: 100svh;
  display:flex;
  flex-direction:column;
  overflow:hidden; /* simple mode no scroll */
}

/* Make buttons feel native on mobile */
button, .btn, .tab, .logoImgOnly{ user-select:none; -webkit-user-select:none; -webkit-tap-highlight-color: transparent; }

body[data-mode="advanced"]{ overflow:auto; }

.hidden{display:none!important}

/* --------- Rotate hint (mobile landscape) ---------- */
.rotateHint{
  position:fixed; inset:0;
  display:none;
  align-items:center; justify-content:center;
  background:rgba(0,0,0,.72);
  backdrop-filter: blur(8px);
  z-index:60;
}
.rotateHintInner{
  display:flex; align-items:center; gap:12px;
  padding:16px 18px;
  border:1px solid var(--stroke);
  border-radius:16px;
  background:rgba(255,255,255,.06);
}
.rotateIcon{font-size:24px; opacity:.9}
.rotateText{font-size:14px; color:var(--muted)}

@media (orientation: landscape) and (max-width: 980px){
  .rotateHint{ display:flex; }
}

/* --------- Connect screen ---------- */
.connectScreen{
  position:fixed; inset:0;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  gap:16px;
  z-index:50;
  background: var(--bg0);
}
.connectLogo{
  width:min(420px, 78vw);
  height:auto;
  filter: drop-shadow(0 10px 24px rgba(0,0,0,.45));
}
.hintText{ color:var(--muted); font-size:13px; max-width: 90vw; text-align:center; }
.connectLoader{
  width:56px; height:56px;
  display:flex; align-items:center; justify-content:center;
}
.spinnerLg{
  width:42px; height:42px;
  border:3px solid rgba(255,255,255,.22);
  border-top-color: rgba(255,255,255,.9);
  border-radius: 999px;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }


/* --------- Toast ---------- */
.toast{
  position:fixed;
  left:50%;
  bottom:22px;
  transform:translateX(-50%);
  padding:10px 14px;
  border-radius:999px;
  background:rgba(0,0,0,.72);
  color:#fff;
  border:1px solid rgba(255,255,255,.14);
  font-weight:700;
  font-size:13px;
  z-index:60;
  backdrop-filter: blur(8px);
}

/* show connect screen only when simple AND not connected */
body[data-mode="simple"]:not(.connected) #connectScreen{ display:flex; }
body.connected #connectScreen{ display:none; }
body[data-mode="advanced"] #connectScreen{ display:none; }

/* while connect screen is visible, hide the rest of the UI */
body[data-mode="simple"]:not(.connected) .header,
body[data-mode="simple"]:not(.connected) .screen{ display:none; }

/* --------- Header ---------- */
.header{
  position:sticky;
  top:0;
  z-index:20;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:12px 14px;
  background:rgba(17,17,17,.78);
  border-bottom:1px solid rgba(255,255,255,.06);
  backdrop-filter: blur(10px);
}
.headerLeft{ display:flex; align-items:center; gap:6px; min-width:0; }
.headerStateBlock{ display:flex; align-items:baseline; gap:0px; white-space:nowrap; }
.logoImgOnly{
  width:46px;
  height:auto;
  display:block;
  cursor:pointer;
  user-select:none;
  -webkit-tap-highlight-color: transparent;
  filter: drop-shadow(0 10px 20px rgba(0,0,0,.45));
}
.stateStrong{ font-weight:900; letter-spacing:.6px; font-size:20px; margin-left:10px; line-height:1; text-transform:uppercase; }
.stateConf{ color:var(--muted); font-size:14px; }

.headerRight{ display:flex; justify-content:flex-end; }
.battery{ display:flex; align-items:center; gap:8px; }
.batteryText{ font-weight:700; font-size:13px; color:var(--text); }

.batteryIcon{ display:flex; align-items:center; }
.batteryBody{
  width:22px; height:12px;
  border:1px solid rgba(255,255,255,.24);
  border-radius:3px;
  overflow:hidden;
  background:rgba(255,255,255,.06);
}
.batteryFill{ height:100%; width:50%; background:linear-gradient(90deg, rgba(34,197,94,.95), rgba(124,58,237,.8)); }
.batteryTip{ width:3px; height:7px; margin-left:2px; border-radius:2px; background:rgba(255,255,255,.24); }

/* --------- Main layout ---------- */
.screen{
  flex: 1 1 auto;
  min-height: 0;
  height:auto;
  display:flex;
  flex-direction:column;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

body[data-mode="advanced"] .screen{
  height:auto;
  min-height: 0;
}

.anchorArea{
  flex: 1 1 auto;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  gap:12px;
  padding:10px 14px;
}

.viewerWrap{
  width:min(520px, 92vw);
  aspect-ratio: 1 / 1;
  position:relative;
  overflow:hidden;
}

.viewer{
  width:100%;
  height:100%;
  border-radius: 0;
  background: transparent;
  border:none;
  box-shadow: none;
  overflow:hidden;
  position:relative;
}
.viewer canvas{ width:100%!important; height:100%!important; display:block; }

.viewerActions{
  position:absolute;
  left:50%;
  bottom:12px;
  transform:translateX(-50%);
  width:calc(100% - 24px);
  display:flex;
  flex-direction:column;
  gap:10px;
  pointer-events:none;
}
.viewerActions .btn{ pointer-events:auto; }



/* --------- Info table (under 3D) ---------- */
.infoTable{
  width:min(520px, 92vw);
  margin-top: 2px;
  border-radius: 0;
  background: transparent;
  border: 0;
  overflow:hidden;
  font-size: 12px;
}

.trow{
  display:grid;
  grid-template-columns: 1fr 1.4fr;
  gap:10px;
  padding:10px 0;
  border-bottom:1px dashed rgba(255,255,255,.10);
}

.trow:last-child{ border-bottom:none; }
.trow.advOnly{ display:none; }
body[data-mode="advanced"] .trow.advOnly{ display:grid; }
.tcell.label{ color: rgba(255,255,255,.72); }
.tcell.value{ display:flex; align-items:center; gap:8px; justify-content:flex-end; }
.muted{ color: var(--muted); font-weight:700; }

.helpIcon{
  width:22px; height:22px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.04);
  color: var(--muted);
  font-weight: 900;
  cursor:pointer;
}

.popover{
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  width: min(520px, 92vw);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(10px);
  padding: 12px 14px;
  z-index: 55;
}
.popoverTitle{ font-weight:900; margin-bottom:6px; }
.popoverText{ color: var(--muted); font-size: 13px; line-height:1.35; }

.chipRow{
  width:min(520px, 92vw);
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  justify-content:center;
  padding: 2px 0;
}
.chip{
  padding:6px 10px;
  border-radius:999px;
  background:rgba(255,255,255,.05);
  border:1px solid rgba(255,255,255,.08);
  font-size:12px;
  color:var(--muted);
}

.metaRow{
  width:min(520px, 92vw);
  display:flex;
  justify-content:space-between;
  gap:10px;
  padding: 2px 4px;
}
.metaItem{
  color:var(--muted);
  font-size:13px;
}

.healthRow{
  width:min(520px, 92vw);
  display:flex;
  gap:10px;
  justify-content:flex-start;
}
.healthPill{
  padding:6px 10px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.05);
  font-size:12px;
  color:var(--muted);
}

.bottomBar{
  padding: 12px 14px 16px;
  display:flex;
  flex-direction:column;
  gap:0;
}

/* --------- Buttons ---------- */
.btn{
  border:1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.04);
  color: var(--text);
  border-radius: 8px;
  padding: 12px 14px;
  font-weight: 700;
  letter-spacing: .2px;
  cursor:pointer;
  box-shadow: var(--shadow2);
}
.btn:disabled{
  opacity:.35;
  cursor:default;
  box-shadow:none;
}
.btn:hover{ border-color: rgba(255,255,255,.18); }
.btn:active{ transform: translateY(1px); }
.btnWide{ width: min(520px, 92vw); }
.btnXL{ padding: 14px 16px; font-size: 15px; border-radius: 8px; }

.btnPrimary{
  border:1px solid rgba(124,58,237,.50);
  background: linear-gradient(135deg, rgba(124,58,237,.95), rgba(59,130,246,.60));
}
.btnGhost{
  background: rgba(255,255,255,.03);
}
.btnWarn{
  border:1px solid rgba(245,158,11,.55);
  background: linear-gradient(135deg, rgba(245,158,11,.90), rgba(239,68,68,.55));
}

/* --------- Advanced panel ---------- */
.advPanel{
  display:none;
  padding: 10px 14px 18px;

  box-sizing: border-box;
  overflow-x: hidden;
}
body[data-mode="advanced"] .advPanel{ display:block; min-height: fit-content;}

/* Advanced mode: no bottom action bar (calibrate lives only in Simple mode) */
body[data-mode="advanced"] .bottomBar{ display:none; }

.tabs{
  display:flex;
  width:100%;
  max-width:720px;
  margin: 0 auto;
  box-sizing: border-box;
  gap:0;
  padding: 6px 0 0;
  border-bottom: 2px solid rgba(255,255,255,.10);
  background: transparent;
}

.tab{
  appearance:none;
  background: transparent;
  border: 0;
  color: rgba(255,255,255,.70);
  font-size: 12px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: .4px;

  /* evenly fit width */
  flex: 1 1 0;
  text-align:center;

  padding: 10px 12px;
  border-top: 2px solid transparent;
  border-bottom: 2px solid transparent;
  cursor:pointer;

  box-sizing: border-box;
}

.tab.active {
  color: rgba(255, 255, 255, .98);
  border-top-width: 3px;
  border-top-color: rgba(255, 255, 255, .92);
  border-left: 1px solid rgba(255, 255, 255, .10);
  border-right: 1px solid rgba(255, 255, 255, .10);
  border-bottom: 2px solid #111111;
  margin-bottom: -2px;
  padding-left: 20px;
  padding-right: 20px;
}

.tabPanels{
  width:100%;
  max-width:720px;
  margin: 12px auto 0;
  box-sizing: border-box;
}
.tabPanel{ display:none; }
.tabPanel.active{ display:block; }

.kvRow{ display:flex; align-items:center; justify-content:space-between; gap:10px; }
.kvGrid{
  margin-top: 10px;
  border-top:1px solid rgba(255,255,255,.10);
  display:grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap:0 14px;
}
.kvGrid .kv:nth-last-child(-n+2){ border-bottom:0; }
.kvGrid.compact{ grid-template-columns: repeat(2, minmax(0,1fr)); }
.kv{
  border:0;
  background: transparent;
  border-radius: 0;
  padding: 10px 0;
  border-bottom:1px dashed rgba(255,255,255,.10);
}
.k{ font-size: 12px; color: var(--muted2); font-weight: 700; }
.v{ font-size: 13px; font-weight: 800; margin-top: 4px; }

.rowTop{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap:10px;
  align-items:center;
}

.rowBtns{ display:flex; gap:10px; justify-content:flex-end; }

.divider{ height:1px; background: rgba(255,255,255,.08); margin: 14px 0; }
.sectionTitle{ margin-top: 14px; font-size: 12px; color: var(--muted2); font-weight: 800; letter-spacing: .6px; text-transform: uppercase; }

.formGrid{ display:grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap:10px; margin-top: 10px; }
.field{
  border:0;
  background: transparent;
  border-radius: 0;
  padding: 10px 0;
  display:flex;
  flex-direction:column;
  gap:6px;
  border-bottom:1px dashed rgba(255,255,255,.10);
}

.field.inline{ flex-direction:row; align-items:center; justify-content:space-between; }
.field span{ font-size: 12px; color: var(--muted2); font-weight: 800; }
.field input, .field select{
  width:100%;
  padding: 6px;
  border-radius: 6px;
  border: 0;
  background: #222;
  color: var(--text);
  outline:none;
}
.field.inline input{ width: auto; }
.help{ font-size: 11px; color: var(--muted2); }

.pill{
  padding: 10px 12px;
  border-radius: 999px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.04);
  color: var(--muted);
  font-weight: 800;
  font-size: 12px;
}

.log{
  border:1px solid rgba(255,255,255,.08);
  background: rgba(0,0,0,.25);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 180px;
  max-height: 360px;
  overflow:auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  color: rgba(233,238,252,.88);

  margin-top: 10px;
}

.statusRow{ display:flex; gap:10px; margin-top:8px; margin-bottom:10px; flex-wrap:wrap; }

@media (max-width: 520px){
  .header{ grid-template-columns: 54px 1fr 1fr; }
  .formGrid{ grid-template-columns: 1fr; }
  .kvGrid{ grid-template-columns: 1fr; }
}

.tab:hover{ color: rgba(255,255,255,.90); }

.rowTop .btn{ width:100%; }

.rowBtns.row2{ display:grid; grid-template-columns: 1fr 1fr; gap:10px; }

.statusText{ color: rgba(255,255,255,.70); font-size: 12px; }

.timeBox{ padding:10px 0; border-bottom:0; }

/* Let the floating buttons (and their shadow) render fully */
.viewerWrap{
  overflow: visible;
}

/* Use left/right padding instead of translateX centering to avoid clipping */
.viewerActions{
  left: 12px;
  right: 12px;
  width: auto;
  transform: none;
  box-sizing: border-box;
}

/* Buttons inside viewerActions must fit the container (override .btnWide fixed width) */
.viewerActions .btnWide,
.viewerActions .btn{
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  white-space: normal;
  text-transform: uppercase;
}


.rowTop.rowCenter{ justify-content:center; }
.btnCenter{ margin-left:auto; margin-right:auto; display:inline-flex; }


/* 3-button rows: left / center / right */
.rowTop.rowTriplet{ display:grid; grid-template-columns: 1fr auto 1fr; align-items:center; gap:12px; }
.rowTop.rowTriplet > :nth-child(1){ justify-self:start; }
.rowTop.rowTriplet > :nth-child(2){ justify-self:center; }
.rowTop.rowTriplet > :nth-child(3){ justify-self:end; }


/* Allow pointer gestures on the 3D canvas without page scrolling */
#viewer, #viewer canvas{ touch-action:none; }

#viewer canvas{ cursor: grab; }
#viewer canvas:active{ cursor: grabbing; }

#btnLogo{ touch-action: manipulation; user-select:none; -webkit-user-select:none; -webkit-tap-highlight-color: transparent; }


/* Make key action buttons the same width (fits "Normal Rate") */
#btnRecordToggle,
#btnCfgApply,
#btnDebugToggle,
#btnPullToggle{
  min-width: 12ch;
  justify-content: center;
}


/* Config: storage labels smaller */
#tabConfig #tagStorageLbl,
#tabConfig #hubStorageLbl{
  font-size: 0.9em;
  opacity: 0.85;
}

/* Config: add a little vertical spacing between download row and clear row */


/* Config: bottom download + clear rows should fill 2-column grid like original clear buttons */
#tabConfig .rowBtns.row2 .btn{
  width: 100%;
  justify-content: center;
}

/* Space between Download row and Clear row */
#tabConfig .rowBtns.row2 + .rowBtns.row2{
  margin-top: 8px;
}
