:root {
  --bg: #ECEFF1;
  --text: #37474F;
  --input-bg: #CFD8DC;
  --border: #90A4AE;
  --btn-a: #CFD8DC;
  --btn-b: #B0BEC5;
  --btn-hover-a: #B0BEC5;
  --btn-hover-b: #90A4AE;
  --checked-a: #A5D6A7;
  --checked-b: #81C784;
  --checked-border: #66BB6A;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: #D9DFE3; color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif; font-size: 13px; }
#window { width: min(980px, 100vw); margin: 18px auto 8px; background: var(--bg); border: 1px solid #B0BEC5; border-radius: 10px; overflow: hidden; box-shadow: 0 12px 40px rgba(0,0,0,0.18); }
#titlebar { position: relative; height: 28px; background: linear-gradient(#ECECEC, #DCDCDC); border-bottom: 1px solid #C6C6C6; text-align: center; line-height: 28px; font-size: 13px; font-weight: 600; color: #4A4A4A; }
#titlebar h1.title { font: inherit; margin: 0; display: inline; }
#titlebar .dots { position: absolute; left: 10px; top: 8px; display: flex; gap: 7px; }
#titlebar .dots i { width: 12px; height: 12px; border-radius: 50%; display: block; }
#titlebar .dots i:nth-child(1) { background: #FF5F57; } #titlebar .dots i:nth-child(2) { background: #FEBC2E; } #titlebar .dots i:nth-child(3) { background: #28C840; }
#app { padding: 8px 8px 4px; display: flex; flex-direction: column; gap: 6px; }
#viewer { position: relative; height: 400px; background: #fff; border: 1px solid #CFD8DC; overflow: hidden; }
#viewer canvas { display: block; width: 100%; height: 100%; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl { color: #000; font-size: 12px; font-family: Arial, Helvetica, sans-serif; white-space: nowrap; }
.lbl.title { font-weight: 700; font-size: 13px; }
.lbl.box { color: #5D4037; font-size: 11px; }
.lbl.force { background: rgba(255,255,255,0.55); padding: 1px 4px; border-radius: 2px; font-size: 12px; }
#viewer-hint { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); color: #78909C; font-size: 15px; text-align: center; pointer-events: none; }
#viewer-help { position: absolute; right: 8px; bottom: 6px; z-index: 5; font-size: 11px; color: #78909C; pointer-events: none; background: rgba(255,255,255,0.9); padding: 2px 6px; border-radius: 3px; }
#colorbar { position: absolute; right: 14px; top: 60px; width: 90px; color: #000; font-family: Arial, sans-serif; font-size: 11px; }
#colorbar .cb-title { text-align: center; margin-bottom: 4px; }
#colorbar .cb-body { position: relative; height: 220px; }
#colorbar .cb-gradient { position: absolute; left: 0; top: 0; width: 22px; height: 100%; border: 1px solid #999; background: linear-gradient(to top, #000080, #0000ff, #00ffff, #80ff00, #ffff00, #ff8000, #ff0000, #800000); }
#colorbar .cb-ticks { position: absolute; left: 28px; top: 0; height: 100%; }
#colorbar .cb-ticks span { position: absolute; transform: translateY(-50%); }
.row { display: flex; gap: 8px; align-items: center; }
.row.buttons > * { flex: 1; }
.row.buttons .menu-anchor { position: relative; display: flex; }
.row.buttons .menu-anchor .btn { flex: 1; }
.btn { background: linear-gradient(var(--btn-a), var(--btn-b)); color: #000; font-size: 15px; padding: 10px; border: 2px solid var(--border); border-radius: 0; cursor: pointer; font-family: inherit; white-space: nowrap; }
.btn:hover { background: linear-gradient(var(--btn-hover-a), var(--btn-hover-b)); }
.btn:active { background: linear-gradient(#90A4AE, #78909C); }
.btn.checked { background: linear-gradient(var(--checked-a), var(--checked-b)); border-color: var(--checked-border); }
.btn:disabled { color: #78909C; cursor: default; }
.btn.small-btn { font-size: 12px; padding: 3px 8px; }
.menu { position: absolute; left: 0; top: 100%; z-index: 20; min-width: 400px; background: #fff; border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0,0,0,0.2); padding: 4px 0; }
.menu-section { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: #78909C; padding: 6px 12px 2px; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 6px 12px; font: inherit; font-size: 13px; color: #263238; cursor: pointer; }
.menu-item:hover { background: #ECEFF1; }
.menu-item small { color: #78909C; }
.menu-row { display: flex; align-items: stretch; }
.menu-row .menu-item { flex: 1; min-width: 0; }
.menu-live { flex: none; align-self: center; margin-right: 8px; background: #fff; border: 1px solid var(--border); border-radius: 3px; padding: 2px 7px; font: inherit; font-size: 11px; color: #546E7A; cursor: pointer; white-space: nowrap; }
.menu-live:hover { background: #ECEFF1; color: #263238; }
.bbox-grid { display: grid; grid-template-columns: auto repeat(6, 1fr); gap: 6px 8px; align-items: center; }
.bbox-grid label { white-space: nowrap; }
.text { background: var(--input-bg); border: 1px solid var(--border); padding: 5px; border-radius: 4px; font: inherit; font-size: 13px; color: #000; min-width: 0; width: 100%; }
.text:focus { outline: none; border-color: #607D8B; background: var(--bg); }
/* keyboard focus only (mouse users see the paper's look unchanged) */
.btn:focus-visible, .menu-item:focus-visible, .menu-live:focus-visible, select:focus-visible, input[type=range]:focus-visible { outline: 2px solid #1E88E5; outline-offset: 1px; }
.text.small { width: 66px; } .text.xsmall { width: 50px; }
#force-dir { width: 110px; }
#backend-url { width: 170px; }
select { font: inherit; font-size: 13px; padding: 3px 6px; }
.slider-label { text-align: center; font-weight: 700; }
.slider-wrap { padding: 0 2px; }
input[type=range] { width: 100%; accent-color: #78909C; }
.row.options label { white-space: nowrap; }
.row.options .btn { flex: 1; }
.row.advanced { flex-wrap: wrap; gap: 6px 8px; }
.row.advanced label { white-space: nowrap; }
#statusbar { display: flex; align-items: center; gap: 8px; font-size: 12px; padding-top: 2px; }
#status { flex: 1; min-height: 16px; }
#status.error { color: #C62828; }
#progress { width: 140px; height: 10px; border: 1px solid var(--border); border-radius: 3px; background: var(--input-bg); overflow: hidden; position: relative; }
#progress .bar { position: absolute; top: 0; bottom: 0; width: 35%; background: #81C784; animation: slide 1.1s linear infinite; }
@keyframes slide { from { left: -35%; } to { left: 100%; } }
.hidden { display: none !important; }
#footer { display: block; width: min(980px, 100vw); margin: 0 auto 30px; font-size: 12px; color: #455A64; text-align: center; padding: 0 8px; }
#footer a { color: #37474F; }
.nojs { padding: 40px; text-align: center; color: #78909C; }
#viewer canvas { touch-action: none; }
.menu { max-width: calc(100vw - 32px); }

/* Tablets */
@media (max-width: 900px) {
  .btn { font-size: 14px; padding: 9px 6px; white-space: normal; }
  #viewer { height: 360px; }
}

/* Phones */
@media (max-width: 600px) {
  #window { margin: 0; border-radius: 0; border-left: 0; border-right: 0; }
  #app { padding: 6px 6px 4px; }
  #viewer { height: 300px; }
  .row.buttons { display: grid; grid-template-columns: 1fr 1fr; }
  .row.buttons .menu-anchor { display: flex; }
  .btn { font-size: 13px; padding: 9px 4px; white-space: normal; line-height: 1.15; }
  .bbox-grid { grid-template-columns: repeat(3, 1fr); gap: 4px 6px; }
  .bbox-grid label { grid-column: 1 / -1; margin-top: 2px; font-size: 12px; }
  /* 16px inputs stop iOS Safari from auto-zooming into fields */
  .text, select { font-size: 16px; padding: 6px 5px; }
  #force-dir { width: 100px; }
  .row.options { flex-wrap: wrap; gap: 6px; }
  .row.options .btn { flex: 1 1 45%; }
  .row.options select { flex: 1 1 40%; min-width: 0; }
  .row.advanced .text.small, .row.advanced .text.xsmall { width: 60px; }
  #backend-url { width: 100%; }
  .menu { left: 0; right: 0; min-width: 0; }
  #statusbar { flex-wrap: wrap; }
  #status { flex-basis: 100%; }
  #footer { font-size: 11px; margin-bottom: 20px; }
  #viewer-help { font-size: 10px; right: 4px; bottom: 4px; }
  /* smaller colour bar so it does not cover the model on phones */
  #colorbar { width: 64px; top: 8px; right: 8px; font-size: 10px; }
  #colorbar .cb-body { height: 130px; }
  #colorbar .cb-gradient { width: 14px; }
  #colorbar .cb-ticks { left: 18px; }
}

/* Coarse pointers (touch): bigger tap targets */
@media (pointer: coarse) {
  .btn { min-height: 40px; }
  input[type=range] { height: 32px; }
}
#footer [data-offline] { display: block; margin-top: 3px; }
#footer [data-offline]:empty { display: none; }

/* bug-report notice at the top of the page */
.bug-banner { margin: 0; padding: 7px 16px; background: #fff8e1; border-bottom: 1px solid #f0d98a; color: #4a3b00; font-size: .88rem; line-height: 1.45; text-align: center; overflow-wrap: anywhere; }
