:root {
  /* USO brand: black and white identity, teal #0D9488 accent, Inter. */
  --bg: #0a0a0b;
  --panel: #141416;
  --panel-2: #1c1c1f;
  --line: #2a2a2e;
  --text: #f9f9f9;
  --muted: #a1a5b7;
  --brand: #0d9488;
  --accent: #14b8a6;
  --accent-ink: #ffffff;
  --danger: #ef4444;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  border-color: #3a4a60;
}

button.active,
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.brand-title {
  font-weight: 600;
  font-size: 15px;
}

.badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 6px;
  border-radius: 4px;
  background: #3b2f0b;
  color: #facc15;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-left: 16px;
}

.tab {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.tab.active {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
  font-weight: 600;
}

.study {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.study-info {
  color: var(--muted);
}

.segmented {
  display: flex;
}

.segmented button {
  border-radius: 0;
}

.segmented button:first-child {
  border-radius: 6px 0 0 6px;
}

.segmented button:last-child {
  border-radius: 0 6px 6px 0;
  border-left: 0;
}

main {
  position: relative;
  min-height: 0;
}

.tab-panel {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}

.tab-panel.active {
  display: flex;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.group {
  display: flex;
  gap: 4px;
}

.field {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.field input[type='range'] {
  accent-color: var(--accent);
  width: 120px;
}

/* Takes the leftover space and gets cut short instead of wrapping the toolbar to a second row. */
.hint {
  flex: 1 1 0;
  min-width: 0;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
  font-size: 12px;
}

.grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
  background: var(--line);
}

.cell {
  position: relative;
  background: #000;
  min-height: 0;
  min-width: 0;
}

.label {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 2;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  pointer-events: none;
  padding-left: 8px;
  border-left: 3px solid #64748b;
}

.label.axial {
  border-color: rgb(239, 68, 68);
}

.label.coronal {
  border-color: rgb(34, 197, 94);
}

.label.sagittal {
  border-color: rgb(59, 130, 246);
}

.viewport,
.canvas-host {
  position: absolute;
  inset: 0;
}

.canvas-host canvas {
  display: block;
  touch-action: none;
}

.pano-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 34%) 1fr;
  grid-template-rows: 1.15fr 1fr;
  gap: 2px;
  background: var(--line);
}

.axial-ref {
  grid-row: 1 / span 2;
}

.cross {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
}

.axial-ref .canvas-host {
  cursor: crosshair;
}

.statusbar {
  display: flex;
  gap: 16px;
  padding: 6px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
}

.disclaimer {
  margin-left: auto;
  color: #b9a35a;
}

.loader {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(5, 8, 12, 0.92);
  z-index: 50;
}

.loader.hidden {
  display: none;
}

.loader-card {
  width: min(420px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.loader-title {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 14px;
}

.bar {
  height: 6px;
  border-radius: 3px;
  background: var(--panel-2);
  overflow: hidden;
}

#loader-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.15s;
}

.loader-text {
  margin-top: 10px;
  color: var(--muted);
}

.loader.error .loader-title {
  color: var(--danger);
}

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
  }

  .study {
    margin-left: 0;
    width: 100%;
    justify-content: space-between;
  }

  .hint {
    display: none;
  }

  .pano-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr 1fr;
  }

  .axial-ref {
    grid-row: auto;
  }
}

.hidden {
  display: none !important;
}

.landing-card,
.feedback-card {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.landing-card h1 {
  font-size: 22px;
  line-height: 1.25;
  margin: 20px 0 6px;
}

.lead {
  color: var(--muted);
  margin: 0 0 20px;
}

.dropzone {
  border: 1.5px dashed #34465e;
  border-radius: 12px;
  padding: 22px 18px;
  text-align: center;
  background: var(--panel-2);
  transition: border-color 0.15s, background 0.15s;
}

.dropzone.dragging {
  border-color: var(--accent);
  background: #0f2a2a;
}

.drop-title {
  margin-bottom: 14px;
}

.drop-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.privacy {
  margin-top: 14px;
  font-size: 12px;
  color: #9fd8cf;
}

.or {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  margin: 16px 0;
}

.or::before,
.or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.demo {
  width: 100%;
  padding: 10px;
}

.demo small {
  color: var(--muted);
}

.fineprint {
  margin: 14px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}

.loader-actions {
  margin-top: 14px;
}

.feedback-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.feedback-head h2 {
  font-size: 18px;
  margin: 0;
}

.feedback-head button {
  background: transparent;
  border: 0;
  font-size: 16px;
  color: var(--muted);
}

.fb-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
  color: var(--muted);
}

.fb-field textarea,
.fb-field input {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  resize: vertical;
}

.stars {
  display: flex;
  gap: 4px;
}

.stars button {
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  color: #3a4a60;
}

.stars button.on {
  color: #facc15;
}

.fb-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

.fb-status {
  margin-top: 10px;
  color: #9fd8cf;
  min-height: 1em;
}

textarea,
input[type='text'] {
  font: inherit;
}

.patient-chip {
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 100vw);
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.45);
  transform: translateX(100%);
  transition: transform 0.2s ease;
  padding: 20px 20px 16px;
}

.info-panel.open {
  transform: none;
}

.info-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.info-head h2 {
  margin: 0;
  font-size: 16px;
}

.info-head button {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 16px;
}

.info-body {
  flex: 1;
  overflow: auto;
  margin-top: 8px;
}

.info-body h3 {
  margin: 18px 0 8px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.info-body dl {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 6px 14px;
  margin: 0;
}

.info-body dt {
  color: var(--muted);
}

.info-body dd {
  margin: 0;
  overflow-wrap: anywhere;
}

main {
  display: grid;
  grid-template-columns: 76px 1fr;
}

.panels {
  position: relative;
  min-height: 0;
  min-width: 0;
}

.tool-rail {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 6px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.tool-rail button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 2px;
  font-size: 11px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.tool-rail button:hover {
  background: var(--panel-2);
  color: var(--text);
}

.tool-rail button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.tool-rail .ico {
  font-size: 17px;
  line-height: 1.1;
}

.rail-sep {
  height: 1px;
  background: var(--line);
  margin: 6px 4px;
}

.tb-sep {
  width: 1px;
  align-self: stretch;
  background: var(--line);
}

.tb-title {
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

/* Fixed width so moving a slider ("0 mm" -> "5.5 mm") never reflows the toolbar. */
.toolbar .val {
  min-width: 4.6em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.views3d button {
  padding: 5px 8px;
}

/* Brand header and module switch */
.brand-logo {
  height: 22px;
  width: auto;
  display: block;
}

.brand-divider {
  width: 1px;
  height: 20px;
  background: var(--line);
}

.brand-title {
  font-weight: 600;
  letter-spacing: -0.01em;
}

button.active,
button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--accent-ink);
}

.tool-rail button.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.modules {
  display: flex;
  gap: 4px;
  margin-left: 20px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}

.modules .tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px 6px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.modules .tab b {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: inherit;
}

.modules .tab small {
  display: block;
  font-size: 11px;
  opacity: 0.75;
}

.modules .module-ico {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 16px;
}

.modules .tab:hover {
  color: var(--text);
  background: var(--panel);
}

.modules .tab.active {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 10px rgba(13, 148, 136, 0.35);
}

.modules .tab.active .module-ico {
  background: rgba(255, 255, 255, 0.18);
}

.tb-title,
.info-body h3 {
  color: var(--accent);
}

.brand-title,
.study button,
.badge {
  white-space: nowrap;
}

.study-info {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 22vw;
  min-width: 0;
}

.study {
  min-width: 0;
}

@media (max-width: 1500px) {
  .modules .tab small {
    display: none;
  }
}

@media (max-width: 1600px) {
  .study-info {
    display: none;
  }
}

/* Three modules: drop the module icons on laptop widths so the header fits. */
@media (max-width: 1360px) {
  .modules .module-ico {
    display: none;
  }
}

/* TMJ module: axial on the left, right/left sections side by side to compare. */
.tmj-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 34%) 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
  background: var(--line);
}

.tmj-axial {
  grid-row: 1 / span 2;
}

.tmj-axial .canvas-host {
  cursor: crosshair;
}

.label.tmj-sag {
  border-color: #f97316;
}

.label.tmj-cor {
  border-color: #38bdf8;
}

.tmj-instructions {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(13, 148, 136, 0.9);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  pointer-events: none;
}

.tmj-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}

.toolbar .dim {
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 900px) {
  .tmj-layout {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1.4fr 1fr 1fr;
  }

  .tmj-axial {
    grid-row: auto;
    grid-column: 1 / span 2;
  }
}

/* The closed info panel sits off-screen to the right; it must not make the page scroll sideways. */
html {
  overflow-x: hidden;
}

/* MPR orientation letters, pinned to the middle of each viewport edge. */
.orient {
  position: absolute;
  z-index: 2;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(10, 10, 11, 0.75);
  color: #f9f9f9;
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
}

.orient:empty {
  display: none;
}

.orient-left {
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
}

.orient-right {
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}

.orient-top {
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
}

.orient-bottom {
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
}

/* Header actions: the study info is an icon, "Abrir estudio" must always stay visible. */
.study > * {
  flex-shrink: 0;
}

.study .patient-chip,
.study .study-info {
  flex-shrink: 1;
  min-width: 0;
}

.icon-button {
  width: 34px;
  padding: 6px 0;
  font-size: 17px;
  line-height: 1;
}

/* Laptop widths: shorter sliders so each module's controls fit in one row. */
@media (max-width: 1400px) {
  .field input[type='range'] {
    width: 88px;
  }

  .toolbar .dim {
    display: none;
  }
}

/* Full-screen states (expired link, processing, errors): no progress bar unless loading. */
.loader.state .bar {
  display: none;
}

.loader.state.working .bar {
  display: block;
}

.loader.state.working #loader-bar {
  width: 40% !important;
  animation: indeterminate 1.4s ease-in-out infinite;
}

@keyframes indeterminate {
  0% {
    margin-left: -40%;
  }
  100% {
    margin-left: 100%;
  }
}

.loader-actions {
  display: flex;
  gap: 8px;
}

.local-open {
  margin-top: 4px;
}

.local-open summary {
  cursor: pointer;
  color: var(--muted);
  padding: 8px 0;
}

.local-open .dropzone {
  margin-top: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 48px;
  transform: translateX(-50%);
  max-width: min(480px, calc(100vw - 32px));
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 60;
}

/* Shown while the persistent notice is the only thing in the footer. */
.statusbar .disclaimer {
  opacity: 0.9;
}

/* While the panoramic worker is busy: keep the UI live, hint at the work in progress. */
#tab-pano.busy .toolbar::after {
  content: 'Calculando…';
  margin-left: auto;
  color: var(--accent);
  font-size: 12px;
}

/* ------------------------------------------------------------------------------------------
   Phone layout (ENG-1418). Desktop is untouched: everything below lives in media queries,
   apart from the defaults that keep the phone-only controls out of the desktop layout.
   ------------------------------------------------------------------------------------------ */
.mobile-bar,
.view-switch,
.btn-ico {
  display: none;
}

.view-switch {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
}

.view-switch button {
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 7px 6px;
  font-size: 12.5px;
}

.view-switch button.active {
  background: var(--brand);
  color: #fff;
}

/* Compact: phones in portrait, and short screens (a phone in landscape). */
@media (max-width: 760px), (max-height: 500px) {
  html,
  body {
    height: 100dvh;
    max-width: 100vw;
  }

  body {
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .btn-label {
    display: none;
  }

  .btn-ico {
    display: inline;
    font-size: 17px;
    line-height: 1;
  }

  #zip-download {
    width: 36px;
    padding: 6px 0;
  }

  .icon-button {
    width: 36px;
  }

  .study-info,
  .brand-divider,
  .modules .tab small,
  .modules .module-ico {
    display: none;
  }

  /* Header: logo and actions on one line, then the module switch. */
  .brand-logo {
    height: 18px;
  }

  .patient-chip {
    max-width: 100%;
    min-width: 0;
  }

  .modules .tab {
    flex: 1 1 0;
    justify-content: center;
    padding: 6px 8px;
    text-align: center;
  }

  .modules .tab b {
    font-size: 13px;
    white-space: nowrap;
  }

  /* "Ajustes": the per-module controls become a collapsible panel, closed by default. */
  .mobile-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 6px 8px;
    padding: 6px 10px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
  }

  .mobile-bar .view-switch {
    display: flex;
    flex: 1 1 220px;
    min-width: 0;
  }

  body:not([data-module='mpr']) #mpr-switch {
    display: none;
  }

  .settings-toggle {
    flex: 0 0 auto;
    padding: 6px 12px;
  }

  body.settings-open .settings-toggle {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
  }

  .toolbar {
    display: none;
  }

  body.settings-open .tab-panel.active .toolbar {
    display: grid;
    flex: 0 1 auto;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
    align-content: start;
    gap: 10px 16px;
    padding: 10px 12px;
    max-height: 55%;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .toolbar .field {
    width: 100%;
    min-width: 0;
    justify-content: space-between;
  }

  .toolbar .field select {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 60%;
  }

  .toolbar .field input[type='range'] {
    flex: 1 1 60px;
    width: auto;
    min-width: 0;
  }

  .toolbar .group,
  .toolbar .tb-title,
  .toolbar > button {
    grid-column: 1 / -1;
  }

  .toolbar .group button {
    flex: 1 1 0;
  }

  .views3d {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .toolbar .tb-sep,
  .toolbar .hint,
  .toolbar .dim {
    display: none;
  }

  #tab-pano.busy .toolbar::after {
    grid-column: 1 / -1;
    margin-left: 0;
  }

  /* MPR: one large viewport at a time (chosen with the selector in the bar). */
  .grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .grid > .cell {
    grid-area: 1 / 1;
  }

  .grid > .cell:not(.mobile-active) {
    visibility: hidden;
    pointer-events: none;
  }

  .statusbar {
    flex-wrap: wrap;
    gap: 2px 12px;
    padding: 5px 12px calc(5px + env(safe-area-inset-bottom));
    font-size: 11.5px;
  }

  .disclaimer {
    margin-left: 0;
    flex: 1 1 auto;
    min-width: 0;
  }

  .info-panel {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .toast {
    bottom: calc(64px + env(safe-area-inset-bottom));
  }
}

/* Phone in portrait. */
@media (max-width: 760px) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
  }

  .brand {
    grid-column: 1;
    grid-row: 1;
  }

  .study {
    display: contents;
  }

  #info-open {
    grid-column: 2;
    grid-row: 1;
  }

  #zip-download,
  #open-other {
    grid-column: 3;
    grid-row: 1;
  }

  .modules {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    margin: 0;
    gap: 2px;
    padding: 3px;
    border-radius: 10px;
  }

  .patient-chip {
    grid-column: 1 / -1;
    grid-row: 3;
    justify-self: start;
    display: block;
    font-size: 12px;
    padding: 3px 10px;
  }

  /* Tools: a horizontally scrollable bar under the image. */
  main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .mobile-bar {
    order: 1;
  }

  .panels {
    order: 2;
  }

  .tool-rail {
    order: 3;
    flex-direction: row;
    align-items: stretch;
    gap: 2px;
    padding: 6px 8px;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-top: 1px solid var(--line);
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .tool-rail::-webkit-scrollbar {
    display: none;
  }

  .tool-rail button {
    flex: 0 0 auto;
    min-width: 58px;
    padding: 6px 8px;
  }

  .rail-sep {
    flex: 0 0 1px;
    height: auto;
    margin: 4px 4px;
  }

  /* Panoramic: axial trace, panoramic, then one cross section at a time. */
  .pano-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1.1fr) minmax(0, 0.9fr) minmax(0, 1fr);
  }

  .cross {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .cross > .cell {
    grid-area: 1 / 1;
  }

  .cross > .cell:not(.mobile-active) {
    visibility: hidden;
    pointer-events: none;
  }

  /* TMJ: the axial on top, one section at a time below. */
  .tmj-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1.1fr) minmax(0, 1fr);
  }

  .tmj-layout > .tmj-axial {
    grid-area: 1 / 1;
  }

  .tmj-layout > .cell:not(.tmj-axial) {
    grid-area: 2 / 1;
  }

  .tmj-layout > .cell:not(.tmj-axial):not(.mobile-active) {
    visibility: hidden;
    pointer-events: none;
  }

  .brand-title {
    display: none;
  }

  .float-switch button {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 7px 10px;
  }

  .float-switch {
    display: flex;
    grid-area: 2 / 1;
    align-self: end;
    justify-self: center;
    z-index: 3;
    margin-bottom: 8px;
    max-width: calc(100% - 16px);
    background: rgba(10, 10, 11, 0.88);
  }

  .cross > .float-switch {
    grid-area: 1 / 1;
  }
}

/* Short screens wider than a phone (landscape): keep the desktop arrangement, compacted. */
@media (max-height: 500px) and (min-width: 761px) {
  .topbar {
    flex-wrap: nowrap;
    gap: 10px;
    padding: 4px 10px;
  }

  .brand-title {
    display: none;
  }

  .modules {
    margin-left: 0;
    padding: 2px;
  }

  .modules .tab {
    flex: 0 0 auto;
    padding: 4px 12px;
  }

  .study {
    width: auto;
    margin-left: auto;
    gap: 8px;
  }

  .patient-chip {
    max-width: 220px;
  }

  main {
    grid-template-columns: 96px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .mobile-bar {
    grid-column: 2;
    grid-row: 1;
  }

  .panels {
    grid-column: 2;
    grid-row: 2;
  }

  .tool-rail {
    grid-column: 1;
    grid-row: 1 / span 2;
  }

  .tool-rail {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-content: start;
    gap: 2px;
    padding: 4px;
  }

  .tool-rail button {
    padding: 4px 0;
    font-size: 10px;
  }

  .tool-rail .ico {
    font-size: 15px;
  }

  .rail-sep {
    grid-column: 1 / -1;
    margin: 2px 4px;
  }

  .mobile-bar {
    flex-wrap: nowrap;
    padding: 4px 10px;
  }

  .statusbar {
    padding-top: 3px;
    padding-bottom: calc(3px + env(safe-area-inset-bottom));
  }
}
