/* Phone layout: a usable preview followed by the complete editing controls. */
@media (max-width: 900px) {
  html { scroll-padding-top: 60px; }
  body { height: auto; min-height: 100dvh; overflow-x: hidden; overflow-y: auto; }
  .topbar { height: auto; min-height: 76px; padding: max(12px, env(safe-area-inset-top)) 16px 12px; gap: 12px; flex-wrap: wrap; }
  .brand h1 { font-size: 18px; }
  .top-actions { flex-wrap: wrap; gap: 8px; }
  .top-actions button, .top-actions .repo-link { min-height: 44px; padding: 10px 12px; font-size: 12px; }
  .top-actions :is(#save-image,#gallery-button):not([hidden]) { display: inline-flex; align-items: center; max-width: none; }
  #mobile-materials { display: none !important; }
  .workspace-tabs { position: sticky; top: 0; z-index: 5; height: 48px; padding-inline: 8px; overflow-x: auto; overscroll-behavior-x: contain; }
  .workspace-tabs button { min-height: 44px; font-size: 13px; padding-inline: 16px; }
  body .workspace { display: flex !important; flex-direction: column; height: auto; min-width: 0; }
  body .workspace > .viewport { order: 0; width: 100%; height: clamp(280px, 48svh, 440px); flex: none; }
  body .workspace > aside { position: static; transform: none; visibility: visible; width: 100%; max-height: none; min-height: 0; padding: 24px 20px; overflow: visible; display: block !important; }
  body .workspace > aside[class$="library"], body .workspace > .library { order: 1; }
  body .workspace > aside[class$="inspector"], body .workspace > .inspector { order: 2; border-top: 1px solid #e1dacd; padding-bottom: max(28px, env(safe-area-inset-bottom)); }
  body .workspace > aside[hidden] { display: none !important; }
  .workspace :is(.collection-list,.ability-list,.item-list,.structure-list,.living-list,.class-list) { max-height: 300px; overflow-y: auto; overscroll-behavior-y: contain; }
  .class-list { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); }
  .workspace aside > section { min-width: 0; }
  .living-transport { flex-wrap: wrap; }
  .collection-filters { margin-top: 20px; }
  .collection-card span, .class-copy b { font-size: 14px; }
  .collection-card small, .class-copy small { font-size: 12px; }
  .workspace :is(input,select) { font-size: 16px !important; max-width: 100%; }
  .workspace :is(button,select,.check) { min-height: 44px; }
  .workspace input[type=range] { min-height: 40px; }
  .workspace input[type=color] { width: 44px; height: 44px; }
  .workspace :is(p,dd,a) { overflow-wrap: anywhere; }
  .collection-inspector section+section, .inspector section+section { margin-top: 28px; }
  .view-top { inset: 14px 16px auto; display: flex; gap: 12px; align-items: start; }
  .character-heading { min-width: 0; }
  .character-heading h2 { font-size: 25px; overflow-wrap: anywhere; }
  .camera-buttons { max-width: 156px; flex-shrink: 0; margin-top: 0; }
  .camera-buttons button { min-height: 40px; min-width: 44px; font-size: 11px; padding: 5px; }
  .view-bottom { inset: auto 16px 12px; font-size: 11px; }
  .library-footer { margin-top: 24px; }
  #toast { max-width: calc(100vw - 32px); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 20; }
  dialog { padding: 18px; max-width: calc(100vw - 24px); }
}
@media (max-width: 900px) and (max-height: 500px) {
  body .workspace > .viewport { height: 320px; }
}
