/* Shared viewer layout. The drawing gets the room; the thumb bar owns actions. */
body.app { height: 100dvh; overflow: hidden; }
.app .toolbar { flex-direction: row; align-items: center; gap: 8px; padding: 4px 12px; min-height: 52px; flex: none; border-bottom: 1px solid var(--rule); }
.toolbar .button, .toolbar select { min-height: 42px; }
.toolbar .page-picker { min-width: 0; max-width: min(70vw, 28rem); flex: 1; }
.app .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.app .workspace.pro { grid-template-columns: minmax(0, 1fr) 410px; }
.app .stage { height: auto; min-height: 0; }
.stage:not(:has(.empty[hidden])) { background: var(--paper); }
.app .empty { border: 0; background: transparent; width: auto; display: flex; flex-direction: column; align-items: stretch; gap: 10px; }
.empty .button { min-height: 64px; padding: 12px 32px; font-size: 24px; justify-content: center; }
.empty button { min-height: 48px; justify-content: center; }
.scale-prompt { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); min-height: 44px; }
.viewer-bar { flex: none; background: var(--paper); border-top: 1px solid var(--rule); padding: 0 12px max(6px, env(safe-area-inset-bottom)); }
.viewer-bar .status { display: block; height: 24px; line-height: 24px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity .3s; }
.viewer-bar .readout { display: block; padding: 4px 0; white-space: normal; }
.status.faded { opacity: 0; }
.bar-actions { display: flex; gap: 8px; }
.bar-group { display: contents; }
.bar-actions button { justify-content: center; flex: 1; min-width: 0; min-height: 48px; font-size: 17px; white-space: normal; line-height: 1.15; }
.bar-actions .tool { border: 1px solid var(--graphite); background: var(--graphite); color: var(--paper); }
/* While measuring, More keeps its place at the end but gives the measuring buttons the room. */
.measuring #more { flex: 0 0 auto; padding-left: 12px; padding-right: 12px; }
.result-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0 18px; }
.measure-results { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 2px 0 4px; }
.measure-results > span { display: flex; flex-direction: column; }
.result-label { font-size: 12px; color: var(--pencil); }
.measure-results strong { font: 400 18px/1.3 var(--lettering); white-space: nowrap; }
.result-scale { min-height: 36px; padding: 2px 8px; margin: 0 0 6px; font-size: 13px; }
.viewer-sheet { position: fixed; inset: auto 0 0; margin: 0 auto; width: min(100%, 44rem); max-height: 85dvh; padding: 0 18px max(18px, env(safe-area-inset-bottom)); border: 1px solid var(--rule); border-radius: 10px 10px 0 0; overflow-y: auto; }
.sheet-header { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--paper); padding: 12px 0; z-index: 1; border-bottom: 1px solid var(--rule); }
.sheet-header h2 { margin: 0; }
.sheet-setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 58px; border-bottom: 1px solid var(--rule); }
.viewer-sheet button, .viewer-sheet .button, .viewer-sheet .check { min-height: 44px; }
.viewer-sheet .panel { border: 0; overflow: visible; }
.viewer-sheet .panel > section { padding: 14px 0; }
.viewer-sheet .layers { padding: 14px 0; margin: 0; }
.viewer-sheet details { padding: 14px 0; }
.viewer-sheet summary { cursor: pointer; }
/* More's own controls, like the viewer's chrome (#39): a double tap or long press on them selects no
   words (More opens under the finger, so the second tap lands on whatever row is there); a field in
   them stays selectable. */
.viewer-sheet :is(.sheet-header, .sheet-setting, .layers, details) { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.viewer-sheet :is(.sheet-header, .sheet-setting, .layers, details) :is(input, textarea, select) { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
.pro-secondary { flex: none; border-bottom: 1px solid var(--rule); padding: 4px 12px; align-items: center; }
.pro-secondary .pro-tools { padding: 0; margin: 0; border: 0; }
.pro-secondary .pro-tool > button { min-height: 44px; }
/* The question never pushes its own buttons off screen: Cancel sits by the question, the typed
   scale or length above the presets, and only the presets scroll. */
#scale-step { display: flex; flex-direction: column; max-height: min(62dvh, 34rem); padding-top: 6px; }
.scale-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.scale-head button { flex: none; min-height: 44px; }
#scale-note { margin: 6px 0 0; font-size: 15px; color: var(--graphite); }
#scale-step .row { margin: 8px 0 0; }
.scale-presets { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 6px; min-height: 52px; overflow-y: auto; overscroll-behavior: contain; }
.scale-presets:empty { display: none; }
.scale-presets button { flex: 1 0 20%; min-height: 48px; justify-content: center; }
#scale-step h2 { font-size: 18px; margin: 0; }
#scale-step input { min-height: 44px; }
#scale-known-read { flex-basis: 100%; }
@media (max-height: 500px) {
  #scale-step { max-height: 58dvh; }
  .scale-presets button { flex-basis: 15%; min-height: 44px; }
}
@media (min-width: 901px) {
  .bar-actions { max-width: 40rem; margin: 0 auto; }
  .result-row, .measure-results { justify-content: center; }
  .viewer-bar { text-align: center; }
  .scale-presets { max-width: 48rem; margin: 10px auto; }
}
@media (max-width: 900px) {
  .app .workspace.pro { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 30dvh); }
  .pro-secondary .pro-tools { flex-basis: auto; border-top: 0; }
  .pro-secondary { flex-wrap: nowrap; overflow: auto; padding: 3px 6px; }
  .app .toolbar { padding: 4px 8px; }
  .viewer-bar { padding-left: 8px; padding-right: 8px; }
  .bar-actions button { font-size: 16px; padding: 5px 8px; }
  .measure-results { gap: 3px 12px; }
  .measure-results strong { font-size: 17px; }
}
@media (any-pointer: coarse), (hover: none) {
  .tip, .desktop-only { display: none !important; }
  kbd { display: none; }
}
@media (prefers-reduced-motion: reduce) { .viewer-bar .status { transition: none; } }
@media print { .viewer-bar, .pro-secondary, .viewer-sheet { display: none !important; } }

/* Loading is the whole screen: the only primary action is Cancel, or Close after an error. In the
   chrome's colours: dark grey with the Black background (style.css, .dark-chrome). */
.loading-screen { position: fixed; inset: 0; width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; padding: max(24px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); border: 0; border-radius: 0; background: var(--paper); color: var(--graphite); overflow-y: auto; }
.loading-screen[open] { display: flex; align-items: center; justify-content: center; }
.loading-content { width: min(100%, 32rem); text-align: center; margin: auto; }
.loading-file { margin: 0 0 28px; color: var(--pencil); font-size: 16px; overflow-wrap: anywhere; }
.loading-content h1 { font-size: clamp(25px, 5vw, 32px); line-height: 1.2; text-wrap: balance; }
.loading-content > p:not(.loading-file) { font-size: 18px; line-height: 1.5; margin: 18px 0 0; }
.loading-motion { width: 40px; height: 40px; margin: 0 auto 28px; border: 3px solid var(--rule); border-top-color: var(--graphite); border-radius: 50%; animation: loading-turn 1.8s linear infinite; }
.loading-content progress { display: block; width: 100%; height: 12px; margin: 28px 0 0; accent-color: var(--graphite); }
.loading-content progress.idle { visibility: hidden; }
.loading-content > :is(button, .button) { width: 100%; justify-content: center; min-height: 54px; font-size: 19px; margin-top: 32px; }
.loading-content > :is(button, .button):not([hidden]) ~ :is(button, .button) { margin-top: 12px; }
.loading-content details { margin-top: 22px; text-align: left; font-size: 14px; color: var(--pencil); }
.loading-content summary { cursor: pointer; width: fit-content; margin: 0 auto; padding: 8px; }
.loading-content pre { font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; padding: 12px; border: 1px solid var(--rule); }
@keyframes loading-turn { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading-motion { animation: none; } }
@media print { .loading-screen { display: none !important; } }

/* A long press on the drawing or model measures: it never selects the page's text or opens iOS's
   callout or magnifier (ViewerShell also stops the touch's default on the canvas). Fields and the
   measured results stay selectable. */
.toolbar, .stage, .viewer-bar { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
:is(.toolbar, .stage, .viewer-bar) :is(input, textarea, select, .measure-results, .readout) { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
