/* The workbench fits normal phone viewports; sheets contain optional content. */
@media(max-width:760px), (max-width:960px) and (max-height:500px){
  :root{--touch:44px;--action-radius:16px}
  .mobile-only,.header>.mobile-only{display:flex}
  .shell{height:100dvh;min-height:540px;max-width:none;padding:env(safe-area-inset-top) 0 0;display:flex;flex-direction:column}
  .header{flex:none;min-height:60px;display:grid;grid-template-columns:minmax(0,1fr) auto auto auto;gap:4px;padding:8px max(16px,env(safe-area-inset-right)) 8px max(16px,env(safe-area-inset-left))}
  .brand{min-width:0}.brand strong{display:block;overflow:hidden;text-overflow:ellipsis;font-size:var(--base);letter-spacing:0;white-space:nowrap}
  .brand-icon,.brand small,.brand-en,.header-actions{display:none}
  .mode-picker{min-width:64px;min-height:44px;font-size:var(--sm);background:transparent;color:var(--primary);border-radius:12px;padding:0 8px}
  .icon-button,#mobile-pause button{width:44px;height:44px;border:0;border-radius:12px;background:transparent;box-shadow:none;padding:0;font-size:var(--sm)}
  .header button{display:flex;align-items:center;justify-content:center}
  #settings{font-size:24px}#mobile-pause button:disabled{opacity:.45}
  .icon-button[aria-pressed="true"]{background:var(--sidebar)}
  button:active:not(:disabled){transform:scale(.97)}button:active:focus-visible{transform:none}
  main{display:flex;flex:1;flex-direction:column;min-height:0}
  .mobile-status{flex:none;min-height:32px;align-items:center;justify-content:space-between;gap:8px;padding:4px 16px;font-size:var(--sm);color:var(--muted);font-variant-numeric:tabular-nums}
  .mobile-status b{font-weight:600;color:var(--foreground)}
  .workspace{display:flex;flex:1;min-height:0;margin:0;gap:0}
  .order-panel,.lab-top,footer{display:none}
  .lab-panel{flex:1;border:0;border-radius:0;box-shadow:none;min-height:0;overflow:visible;animation:none}
  .stage{min-height:max(240px,calc(var(--stage-footer-height,124px) + 128px));flex:1}
  .art-area{display:block;position:absolute;inset:8px 0 calc(var(--stage-footer-height,124px) + 8px);pointer-events:none}
  .pour-zone{top:50%;height:360px;transform:translate(-50%,-50%) scale(var(--scene-scale,.88));pointer-events:auto}
  .compact-stage .pour-zone{height:220px}
  .compact-stage .dish{top:0}
  .compact-stage .pipette,.compact-stage .drop-stream{display:none}
  .stage-overlay{display:flex;flex-direction:column;gap:8px;position:absolute;bottom:0;width:100%;padding:0 16px 12px}
  .stage-message{position:static;min-height:42px;padding:0;display:flex;align-items:center;justify-content:center;line-height:1.5}
  .meter-box{position:static;transform:none;width:100%;margin:auto}
  .meter-title{margin-bottom:8px}.meter-foot{gap:4px;font-size:12px}
  .combo-badge{top:8px;right:16px}
  .tools{flex:none;display:flex;flex-direction:column;align-items:stretch;padding:8px max(16px,env(safe-area-inset-right)) max(12px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));gap:8px;min-height:0}
  .ball-picker{min-height:44px;border:1px solid var(--border);background:var(--panel);border-radius:12px;padding:0 12px;align-items:center;justify-content:space-between;gap:8px;font-size:var(--base)}
  .ball-picker>span:last-child{font-size:var(--sm);color:var(--muted)}
  .ball-picker:disabled{color:var(--muted)}
  .palette-group,.pour-group{display:block}.tool-label{display:none}
  .palette{display:grid;grid-template-columns:repeat(6,minmax(44px,1fr));gap:4px}
  .swatch{width:100%;min-height:64px;height:auto;border:1px solid transparent;border-radius:12px;padding:4px 0;background:transparent;box-shadow:none;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;transition:none}
  .swatch-color{display:block;position:relative;width:32px;height:32px;border:1px solid #18181b18;border-radius:10px;background:var(--swatch);box-shadow:inset 0 1px 1px #ffffff80}
  .swatch-label{display:block;font-size:var(--sm);line-height:1.5;white-space:nowrap;font-weight:500}
  /* The hit area fills the column; selection belongs to the fixed-size pigment. */
  .swatch[aria-pressed="true"]{background:transparent;border-color:transparent;box-shadow:none}
  .swatch[aria-pressed="true"]::after{content:none}
  .swatch[aria-pressed="true"] .swatch-color{outline:2px solid var(--primary);outline-offset:2px}
  .swatch[aria-pressed="true"] .swatch-color::after{content:"✓";position:absolute;inset:0;display:grid;place-items:center;font-size:var(--sm);font-weight:700;color:#171717;text-shadow:0 1px 3px white}
  @media(hover:hover){
    .swatch:hover:not(:disabled){box-shadow:none;background:transparent}
    .swatch:hover:not(:disabled) .swatch-color{filter:brightness(.96)}
  }
  .primary-button,.pour-button{background:var(--primary);border-color:var(--primary);box-shadow:none;border-radius:var(--action-radius);transition:none}
  .primary-button:disabled,.pour-button:disabled{background:var(--sidebar);border-color:var(--border);box-shadow:none}
  .pour-button{width:100%;height:56px;min-width:0;padding:0 16px}
  .pour-button kbd{display:none}
  .pour-button[data-phase="pouring"]{background:#991770;transform:scale(.985)}
  .pour-button[data-phase="pouring"]:focus-visible{transform:none}
  .text-button{width:100%;min-height:48px;margin-top:12px;padding:12px 16px;font-size:var(--base);border:1px solid var(--border);border-radius:var(--action-radius);background:var(--panel);color:var(--foreground)}
  dialog{padding:24px;overscroll-behavior:contain}
  dialog[open]{animation:none}
  .bottom-sheet{margin:auto auto 0;width:100%;max-width:600px;max-height:calc(100dvh - 24px);border-radius:24px 24px 0 0;padding:24px 16px max(24px,env(safe-area-inset-bottom));text-align:left}
  .bottom-sheet h2{font-size:var(--base);padding-right:44px}
  .bottom-sheet .collection{border:0;padding:0;animation:none}
  .collection-heading{display:block;margin-bottom:16px}.collection-heading h2{display:block;margin:0}
  .collection-heading h2 span{display:block;margin-top:4px}.collection-heading p{margin-top:8px}
  .collection-grid{grid-template-columns:repeat(3,minmax(0,1fr));gap:12px}
  .collection-cell{padding:8px 8px 12px;border-radius:20px;transition:none}
  .mode-tabs{min-height:52px;padding:4px;border-radius:16px;gap:4px;box-shadow:none}
  .mode-tabs button{flex:1;min-height:44px;font-size:var(--base);border-radius:12px;transition:none;padding:8px}
  .mode-tabs .active{background:var(--card);box-shadow:0 1px 3px #18181b12}
  .settings-row{display:flex;align-items:center;justify-content:space-between;min-height:60px;border-bottom:1px solid var(--border);font-size:var(--base)}
  #settings-best .best{display:flex;align-items:center;justify-content:space-between;margin:16px 0 0}
}
@media(min-width:600px) and (max-width:960px) and (max-height:500px){
  .shell{min-height:360px}
  .lab-panel{flex-direction:row}
  .stage{min-width:0;min-height:240px}
  .tools{width:296px;justify-content:center;border-top:0;border-left:1px solid var(--border)}
  .palette{grid-template-columns:repeat(3,minmax(44px,1fr))}
}
/* Narrow viewports can scroll to keep every control reachable. */
@media(max-width:340px){
  .header{padding-left:12px;padding-right:12px}
  .brand strong{font-size:16px}
}
@media(max-width:319px){
  .palette{grid-template-columns:repeat(3,minmax(44px,1fr))}
}
@media(prefers-reduced-motion:reduce){
  button:active:not(:disabled),.pour-button[data-phase="pouring"]{transform:none}
}
